aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/DataFieldSelectboxMultipleEntry.php
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2024-06-18 13:18:06 +0000
committerMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2024-06-18 13:18:06 +0000
commit33fd1358507b4a5abb3dcebe78d407d0567717c1 (patch)
tree6bd8f6959da4c3fc1b8907c0bbc28eb9e10d4a5a /lib/classes/DataFieldSelectboxMultipleEntry.php
parent42d46671c0309bddb71a91bbfdc5f2fa2e44384e (diff)
Deprecate `StudipAutoloader` and use composer's `autoload`
Closes #4282 Merge request studip/studip!3099
Diffstat (limited to 'lib/classes/DataFieldSelectboxMultipleEntry.php')
-rw-r--r--lib/classes/DataFieldSelectboxMultipleEntry.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/classes/DataFieldSelectboxMultipleEntry.php b/lib/classes/DataFieldSelectboxMultipleEntry.php
new file mode 100644
index 0000000..3abb373
--- /dev/null
+++ b/lib/classes/DataFieldSelectboxMultipleEntry.php
@@ -0,0 +1,93 @@
+<?php
+# Lifter002: DONE
+# Lifter007: TEST
+
+/**
+ * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
+ * @author Marcus Lunzenauer <mlunzena@uos.de>
+ * @author Martin Gieseking <mgieseki@uos.de>
+ * @license GPL2 or any later version
+ */
+class DataFieldSelectboxMultipleEntry extends DataFieldSelectboxEntry
+{
+ const SEPARATOR = '|';
+
+ /**
+ * Constructs this datafield
+ *
+ * @param DataField $datafield Underlying model
+ * @param String $rangeID Range id
+ * @param mixed $value Value
+ */
+ public function __construct(DataField $datafield = null, $rangeID = '', $value = null)
+ {
+ parent::__construct($datafield, $rangeID, $value);
+
+ if ($this->getValue() === null) {
+ $this->setValue('');
+ }
+ }
+
+ /**
+ * Returns the according input elements as html for this datafield
+ *
+ * @param String $name Name prefix of the associated input
+ * @param Array $variables Additional variables
+ * @return String containing the required html
+ */
+ public function getHTML($name = '', $variables = [])
+ {
+ return parent::getHTML($name, $variables + [
+ 'multiple' => true,
+ 'value' => explode(self::SEPARATOR, $this->value)
+ ]);
+ }
+
+ /**
+ * Returns the display/rendered value of this datafield
+ *
+ * @param bool $entities Should html entities be encoded (defaults to true)
+ * @return String containg the rendered value
+ */
+ public function getDisplayValue($entities = true)
+ {
+ $value = $this->getValue();
+ if ($value) {
+ $type_param = $this->type_param;
+
+ $mapper = 'trim';
+ if ($this->is_assoc_param) {
+ $mapper = function ($a) use ($type_param) {
+ $a = trim($a);
+ return $type_param[$a];
+ };
+ }
+
+ $value = explode(self::SEPARATOR, $value);
+ $value = array_map($mapper, $value);
+ $value = implode('; ', $value);
+ }
+ return $entities
+ ? htmlReady($value)
+ : $value;
+ }
+
+ /**
+ * Sets the value from a post request
+ *
+ * @param mixed $submitted_value The value from request
+ */
+ public function setValueFromSubmit($value)
+ {
+ if (is_array($value)) {
+ $value = array_map('trim', $value);
+ $value = array_filter($value);
+ $value = array_unique($value);
+ $value = implode(self::SEPARATOR, $value);
+ } else {
+ $value = '';
+ }
+
+ parent::setValueFromSubmit($value);
+ }
+}