diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2025-06-19 16:32:39 +0200 |
|---|---|---|
| committer | Michaela Brückner <brueckner@data-quest.de> | 2025-06-20 10:12:41 +0200 |
| commit | 8f302c13e33fbb9f2a9ad21df588166a31b86f30 (patch) | |
| tree | 211530c6ef45c1b7867c20508cc472958db3190b /lib/classes | |
| parent | 3135ac2048681948b6b354d365b1502a68512c2b (diff) | |
allow date and time data fields entries to be emptied (unless they are required) and fix time datafield input, fixes #5649, fixes #5650
Closes #5649 and #5650
Merge request studip/studip!4267
Diffstat (limited to 'lib/classes')
| -rw-r--r-- | lib/classes/DataFieldDateEntry.class.php | 21 | ||||
| -rw-r--r-- | lib/classes/DataFieldTimeEntry.class.php | 30 |
2 files changed, 18 insertions, 33 deletions
diff --git a/lib/classes/DataFieldDateEntry.class.php b/lib/classes/DataFieldDateEntry.class.php index bf7d518..4b8c049 100644 --- a/lib/classes/DataFieldDateEntry.class.php +++ b/lib/classes/DataFieldDateEntry.class.php @@ -17,16 +17,16 @@ class DataFieldDateEntry extends DataFieldEntry * * @param mixed $submitted_value The value from request */ - public function setValueFromSubmit($value) + public function setValueFromSubmit($submitted_value) { - if ($value) { - $value = trim($value); - $items = explode(".", $value); - $value = array_reverse($items); - $value = array_filter($value); - $date = implode('-', $value); - parent::setValueFromSubmit($date); + if ($submitted_value) { + $submitted_value = trim($submitted_value); + $items = explode('.', $submitted_value); + $submitted_value = array_reverse($items); + $submitted_value = array_filter($submitted_value); + $submitted_value = implode('-', $submitted_value); } + parent::setValueFromSubmit($submitted_value); } /** @@ -35,7 +35,7 @@ class DataFieldDateEntry extends DataFieldEntry * @param bool $entities Should html entities be encoded (defaults to true) * @return String containg the rendered value */ - public function getDisplayValue($entries = true) + public function getDisplayValue($entities = true) { if ($this->isValid()) { $value = trim($this->value); @@ -75,6 +75,7 @@ class DataFieldDateEntry extends DataFieldEntry return parent::isValid(); } - return parent::isValid() && strtotime($value) !== false; + return parent::isValid() + && strtotime($value) !== false; } } diff --git a/lib/classes/DataFieldTimeEntry.class.php b/lib/classes/DataFieldTimeEntry.class.php index 96e5835..2e62c49 100644 --- a/lib/classes/DataFieldTimeEntry.class.php +++ b/lib/classes/DataFieldTimeEntry.class.php @@ -13,35 +13,19 @@ class DataFieldTimeEntry extends DataFieldEntry protected $template = 'time.php'; /** - * Sets the value from a post request - * - * @param mixed $submitted_value The value from request - */ - public function setValueFromSubmit($value) - { - if ($value) { - parent::setValueFromSubmit($value); - } - } - - /** - * Checks if the datafield is empty (was not set) - * - * @return bool true if empty, else false - */ - public function isEmpty() - { - return $this->getValue() == ':'; - } - - /** * Returns whether the datafield contents are valid * * @return boolean indicating whether the datafield contents are valid */ public function isValid() { - $parts = explode(':', $this->value); + $value = trim($this->value); + + if (!$value) { + return parent::isValid(); + } + + $parts = explode(':', $value); return parent::isValid() && $parts[0] >= 0 && $parts[0] <= 24 |
