aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/DataFieldComboEntry.php
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /lib/classes/DataFieldComboEntry.php
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/classes/DataFieldComboEntry.php')
-rw-r--r--lib/classes/DataFieldComboEntry.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/classes/DataFieldComboEntry.php b/lib/classes/DataFieldComboEntry.php
new file mode 100644
index 0000000..6047050
--- /dev/null
+++ b/lib/classes/DataFieldComboEntry.php
@@ -0,0 +1,79 @@
+<?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 DataFieldComboEntry extends DataFieldEntry
+{
+ protected $template = 'combo.php';
+
+ /**
+ * Constructs this datafield
+ *
+ * @param DataField $datafield Underlying model
+ * @param String $rangeID Range id
+ * @param mixed $value Value
+ */
+ public function __construct(DataField $struct, $range_id, $value)
+ {
+ parent::__construct($struct, $range_id, $value);
+
+ if ($this->getValue() === null) {
+ $parameters = $this->getParameters();
+ $this->setValue($parameters[0]); // first selectbox entry is default
+ }
+ }
+
+ /**
+ * Returns the number of html fields this datafield uses for input.
+ *
+ * @return int representing the number of html fields
+ */
+ public function numberOfHTMLFields()
+ {
+ return 2;
+ }
+
+ /**
+ * Sets the value from a post request
+ *
+ * @param mixed $submitted_value The value from request
+ */
+ public function setValueFromSubmit($value)
+ {
+ $index = $value['combo'];
+ $value = $value[$index];
+ parent::setValueFromSubmit($value);
+ }
+
+ /**
+ * 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 + [
+ 'values' => $this->getParameters(),
+ ]);
+ }
+
+ /**
+ * Returns the individual type parameters.
+ *
+ * @return array containing the individual type parameters
+ */
+ protected function getParameters()
+ {
+ $parameters = explode("\n", rtrim($this->model->typeparam));
+ $parameters = array_map('trim', $parameters);
+ return $parameters;
+ }
+}