datetimefield.class.inc.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Form\Field;
  19. use \AttributeDatetime;
  20. use \Combodo\iTop\Form\Field\StringField;
  21. /**
  22. * A field for Dates and Date & Times, supporting custom formats
  23. */
  24. class DateTimeField extends StringField
  25. {
  26. protected $sJSDateTimeFormat;
  27. protected $sPHPDateTimeFormat;
  28. protected $bDateOnly;
  29. /**
  30. * Overloaded constructor
  31. *
  32. * @param string $sId
  33. * @param Closure $onFinalizeCallback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
  34. */
  35. public function __construct($sId, Closure $onFinalizeCallback = null)
  36. {
  37. parent::__construct($sId, $onFinalizeCallback);
  38. $this->bDateOnly = false;
  39. }
  40. /**
  41. * Get the PHP format string
  42. * @return string
  43. */
  44. public function GetPHPDateTimeFormat()
  45. {
  46. return $this->sPHPDateTimeFormat;
  47. }
  48. /**
  49. *
  50. * @param string $sFormat
  51. * @return \Combodo\iTop\Form\Field\DateTimeField
  52. */
  53. public function SetPHPDateTimeFormat($sDateTimeFormat)
  54. {
  55. $this->sPHPDateTimeFormat = $sDateTimeFormat;
  56. return $this;
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function GetJSDateTimeFormat()
  62. {
  63. return $this->sDateTimeFormat;
  64. }
  65. /**
  66. *
  67. * @param string $sFormat
  68. * @return \Combodo\iTop\Form\Field\DateTimeField
  69. */
  70. public function SetJSDateTimeFormat($sDateTimeFormat)
  71. {
  72. $this->sDateTimeFormat = $sDateTimeFormat;
  73. return $this;
  74. }
  75. public function GetDisplayValue()
  76. {
  77. return $this->currentValue;
  78. }
  79. /**
  80. * Set the DateOnly flag
  81. * @return \Combodo\iTop\Form\Field\DateTimeField
  82. */
  83. public function SetDateOnly($bDateOnly)
  84. {
  85. return $this->bDateOnly = $bDateOnly;
  86. return $this;
  87. }
  88. /**
  89. * @return bool
  90. */
  91. public function IsDateOnly()
  92. {
  93. return $this->bDateOnly;
  94. }
  95. }