ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMultipleTextsInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Form/classes/class.ilIdentifiedMultiValuesInputGUI.php';
5 
13 {
17  protected $editElementOccuranceEnabled = false;
18 
22  protected $editElementOrderEnabled = false;
23 
30  public function __construct($a_title = "", $a_postvar = "")
31  {
32  global $DIC;
33 
34  $this->lng = $DIC->language();
35  parent::__construct($a_title, $a_postvar);
36  $this->validationRegexp = "";
37  }
38 
43  {
45  }
46 
51  {
52  $this->editElementOccuranceEnabled = $editElementOccuranceEnabled;
53  }
54 
58  public function isEditElementOrderEnabled()
59  {
61  }
62 
67  {
68  $this->editElementOrderEnabled = $editElementOrderEnabled;
69  }
70 
76  public function onCheckInput()
77  {
78  $lng = $this->lng;
79 
80  $submittedElements = $_POST[$this->getPostVar()];
81 
82  if (!is_array($submittedElements) && $this->getRequired()) {
83  $this->setAlert($lng->txt("msg_input_is_required"));
84  return false;
85  }
86 
87  foreach ($submittedElements as $submittedValue) {
88  $submittedContentText = $this->fetchContentTextFromValue($submittedValue);
89 
90  if ($this->getRequired() && trim($submittedContentText) == "") {
91  $this->setAlert($lng->txt('msg_input_is_required'));
92  return false;
93  }
94 
95  if (strlen($this->getValidationRegexp())) {
96  if (!preg_match($this->getValidationRegexp(), $submittedContentText)) {
97  $this->setAlert($lng->txt('msg_wrong_format'));
98  return false;
99  }
100  }
101  }
102 
103  return $this->checkSubItemsInput();
104  }
105 
110  public function render($a_mode = "")
111  {
112  $tpl = new ilTemplate("tpl.prop_multi_text_inp.html", true, true, "Services/Form");
113  $i = 0;
114  foreach ($this->getIdentifiedMultiValues() as $identifier => $value) {
115  if (strlen($value)) {
116  $tpl->setCurrentBlock("prop_text_propval");
117  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value));
118  $tpl->parseCurrentBlock();
119  }
120  if ($this->isEditElementOrderEnabled()) {
121  $tpl->setCurrentBlock("move");
122  $tpl->setVariable("ID_UP", $this->getMultiValuePosIndexedSubFieldId($identifier, 'up', $i));
123  $tpl->setVariable("ID_DOWN", $this->getMultiValuePosIndexedSubFieldId($identifier, 'down', $i));
124  $tpl->setVariable("CMD_UP", $this->buildMultiValueSubmitVar($identifier, $i, 'up'));
125  $tpl->setVariable("CMD_DOWN", $this->buildMultiValueSubmitVar($identifier, $i, 'down'));
126  $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
127  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
128  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
129  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
130  $tpl->parseCurrentBlock();
131  }
132  $tpl->setCurrentBlock("row");
133  $tpl->setVariable("POST_VAR", $this->getMultiValuePostVarPosIndexed($identifier, $i));
134  $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
135  $tpl->setVariable("SIZE", $this->getSize());
136  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
137 
138  if ($this->getDisabled()) {
139  $tpl->setVariable(
140  "DISABLED",
141  " disabled=\"disabled\""
142  );
143  } elseif ($this->isEditElementOccuranceEnabled()) {
144  $tpl->setVariable("ID_ADD", $this->getMultiValuePosIndexedSubFieldId($identifier, 'add', $i));
145  $tpl->setVariable("ID_REMOVE", $this->getMultiValuePosIndexedSubFieldId($identifier, 'remove', $i));
146  $tpl->setVariable("CMD_ADD", $this->buildMultiValueSubmitVar($identifier, $i, 'add'));
147  $tpl->setVariable("CMD_REMOVE", $this->buildMultiValueSubmitVar($identifier, $i, 'remove'));
148  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
149  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
150  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
151  }
152 
153  $tpl->parseCurrentBlock();
154  $i++;
155  }
156  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
157 
158  if (!$this->getDisabled()) {
159  $tpl->setCurrentBlock('js_engine_initialisation');
160  $tpl->touchBlock('js_engine_initialisation');
161  $tpl->parseCurrentBlock();
162 
163  $globalTpl = $GLOBALS['DIC'] ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
164  $globalTpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
165  $globalTpl->addJavascript("./Services/Form/js/ServiceFormIdentifiedWizardInputExtend.js");
166  }
167 
168  return $tpl->get();
169  }
170 
175  protected function valueHasContentText($value)
176  {
177  if ($value === null || is_array($value) || is_object($value)) {
178  return false;
179  }
180 
181  return (bool) strlen($value);
182  }
183 
188  protected function fetchContentTextFromValue($value)
189  {
190  if ($this->valueHasContentText($value)) {
191  return $value;
192  }
193 
194  return null;
195  }
196 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
__construct($a_title="", $a_postvar="")
Constructor.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
onCheckInput()
Check input, strip slashes etc.
getPostVar()
Get Post Variable.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static get($a_glyph, $a_text="")
Get glyph html.
setAlert($a_alert)
Set Alert Text.
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
getValidationRegexp()
Get validation regexp.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setEditElementOrderEnabled($editElementOrderEnabled)
$i
Definition: disco.tpl.php:19
$_POST["username"]
setEditElementOccuranceEnabled($editElementOccuranceEnabled)