ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilClozeGapInputBuilderGUI Class Reference
+ Inheritance diagram for ilClozeGapInputBuilderGUI:
+ Collaboration diagram for ilClozeGapInputBuilderGUI:

Public Member Functions

 __construct (string $a_title="", string $a_postvar="")
 
 setValue ($a_value)
 Set Value. More...
 
 getValue ()
 
 setValueCombination ($value)
 
 getValueCombination ()
 
 setValueCombinationFromDb ($value)
 
 checkInput ()
 
 setValueByArray ($data)
 
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem (ilFormPropertyGUI $a_item)
 
 getSubItems ()
 
 getSubInputItemsRecursive ()
 returns a flat array of possibly existing subitems recursively More...
 
 checkSubItemsInput ()
 Check SubItems. More...
 
 getSubForm ()
 
 getItemByPostVar (string $a_post_var)
 
- Public Member Functions inherited from ilFormPropertyGUI
 __construct (string $a_title="", string $a_postvar="")
 
 executeCommand ()
 
 getType ()
 
 setTitle (string $a_title)
 
 getTitle ()
 
 setPostVar (string $a_postvar)
 
 getPostVar ()
 
 getFieldId ()
 
 setInfo (string $a_info)
 
 getInfo ()
 
 setAlert (string $a_alert)
 
 getAlert ()
 
 setRequired (bool $a_required)
 
 getRequired ()
 
 setDisabled (bool $a_disabled)
 
 getDisabled ()
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 setParentForm (ilPropertyFormGUI $a_parentform)
 
 getParentForm ()
 
 setParent (ilFormPropertyGUI $a_val)
 
 getParent ()
 
 getSubForm ()
 
 hideSubForm ()
 
 setHiddenTitle (string $a_val)
 
 getHiddenTitle ()
 
 getItemByPostVar (string $a_post_var)
 Get item by post var. More...
 
 serializeData ()
 
 unserializeData (string $a_data)
 
 setParentTable ($a_val)
 Set parent table. More...
 
 getParentTable ()
 Get parent table. More...
 
 writeToSession ()
 
 clearFromSession ()
 
 readFromSession ()
 
 getHiddenTag (string $a_post_var, string $a_value)
 
 setMulti (bool $a_multi, bool $a_sortable=false, bool $a_addremove=true)
 
 getMulti ()
 
 setMultiValues (array $a_values)
 
 getMultiValues ()
 
 getContentOutsideFormTag ()
 Get content that has to reside outside of the parent form tag, e.g. More...
 
 stripSlashesAddSpaceFallback (string $a_str)
 Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727. More...
 
 getTableFilterLabelFor ()
 Get label "for" attribute value for filter. More...
 
 getFormLabelFor ()
 Get label "for" attribute value for form. More...
 
 setRequestParam (string $key, $val)
 This writes the request (aka post) values. More...
 

Static Public Member Functions

static stripSlashesRecursive ($a_data, bool $a_strip_html=true, string $a_allow="")
 
- Static Public Member Functions inherited from ilFormPropertyGUI
static removeProhibitedCharacters (string $a_text)
 Remove prohibited characters see #19159. More...
 

Private Attributes

 $value_combination
 
 $value
 
ArrayBasedRequestWrapper $post
 
ArrayBasedRequestWrapper $query
 

Additional Inherited Members

- Protected Member Functions inherited from ilFormPropertyGUI
 symbol ()
 
 setType (string $a_type)
 
 checkParentFormTable ()
 
 getSessionKey ()
 
 getMultiIconsHTML ()
 
 int ($key)
 
 intArray ($key)
 
 str ($key)
 
 raw ($key)
 
 strArray ($key)
 
 arrayArray ($key)
 
 isRequestParamArray (string $key)
 
 getRequestParam (string $key, Refinery\Transformation $t)
 
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
array $sub_items = array()
 
- Protected Attributes inherited from ilFormPropertyGUI
array $set_params = []
 
ilTable2GUI $parent_table = null
 
ilFormPropertyGUI $parent_gui = null
 
ilCtrl $ctrl
 
ilLanguage $lng
 
string $type = ""
 
string $title = ""
 
string $postvar = ""
 
string $info = ""
 
string $alert = ""
 
bool $required = false
 
ilPropertyFormGUI $parentform = null
 
string $hidden_title = ""
 
bool $multi = false
 
bool $multi_sortable = false
 
bool $multi_addremove = true
 
array $multi_values = []
 
RequestInterface $request
 
HTTP Services $http
 
Refinery Factory $refinery = null
 
bool $disabled = false
 
ilGlobalTemplateInterface $global_tpl = null
 

Detailed Description

Definition at line 22 of file class.ilClozeGapInputBuilderGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilClozeGapInputBuilderGUI::__construct ( string  $a_title = "",
string  $a_postvar = "" 
)

Definition at line 29 of file class.ilClozeGapInputBuilderGUI.php.

References ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\FileDelivery\http().

30  {
31  parent::__construct($a_title, $a_postvar);
32  $this->post = $this->http->wrapper()->post();
33  $this->query = $this->http->wrapper()->query();
34  }
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkInput()

ilClozeGapInputBuilderGUI::checkInput ( )
Exceptions
JsonException

Definition at line 99 of file class.ilClozeGapInputBuilderGUI.php.

References ilFormPropertyGUI\raw(), ILIAS\Repository\refinery(), ilUtil\stripSlashes(), assClozeGap\TYPE_NUMERIC, assClozeGap\TYPE_SELECT, and assClozeGap\TYPE_TEXT.

99  : bool
100  {
101  $error = false;
102  $json = self::stripSlashesRecursive(
103  json_decode(
104  $this->post->retrieve(
105  "gap_json_post",
106  $this->refinery->kindlyTo()->string()
107  ),
108  true,
109  512,
110  JSON_THROW_ON_ERROR
111  ),
112  false
113  );
114  $gap = self::stripSlashesRecursive($this->raw('gap'));
115  $gaps_used_in_combination = [];
116  if ($this->post->has('gap_combination')) {
117  $gapCombination = $this->post->retrieve(
118  "gap_combination",
119  $this->refinery->kindlyTo()->recordOf(
120  [
121  'select' => new ListTransformation(
122  new ListTransformation($this->refinery->kindlyTo()->string())
123  ),
124  'points' => new ListTransformation(
125  new ListTransformation($this->refinery->kindlyTo()->string())
126  ),
127  ]
128  )
129  );
130  $gapCombinationValues = $this->post->retrieve(
131  "gap_combination_values",
132  $this->refinery->kindlyTo()->listOf(
133  new ListTransformation(
134  new ListTransformation($this->refinery->kindlyTo()->string())
135  )
136  )
137  );
138 
139  $gap_with_points = [];
140 
141  for ($i = 0, $iMax = count($gapCombination['select']); $i < $iMax; $i++) {
142  foreach ($gapCombination['select'][$i] as $key => $item) {
143  if ($item == 'none_selected_minus_one') {
144  return false;
145  }
146  $gaps_used_in_combination[$item] = $item;
147  $check_points_for_best_scoring = false;
148  foreach ($gapCombinationValues[$i] as $index => $answeritems) {
149  foreach ($answeritems as $answeritem) {
150  if ($answeritem == 'none_selected_minus_one') {
151  return false;
152  }
153  }
154  $points = $gapCombination['points'][$i][$index];
155  if ($points > 0) {
156  $check_points_for_best_scoring = true;
157  }
158  }
159  if (!$check_points_for_best_scoring) {
160  return false;
161  }
162  }
163  }
164  }
165 
166  if (is_array($gap)) {
167  foreach ($gap as $key => $item) {
168  $getType = ilUtil::stripSlashes($this->raw('clozetype_' . $key));
169  $gapsize = $this->raw('gap_' . $key . '_gapsize');
170 
171  $json[0][$key]['text_field_length'] = $gapsize > 0 ? $gapsize : '';
172 
173  $select_at_least_on_positive = false;
174  if ($getType == assClozeGap::TYPE_TEXT || $getType == assClozeGap::TYPE_SELECT) {
175  $gapText = self::stripSlashesRecursive($this->raw('gap_' . $key), false);
176  foreach ($gapText['answer'] as $row => $answer) {
177  if (!isset($answer) || $answer == '') {
178  $error = true;
179  }
180  }
181  $points_sum = 0;
182  if (array_key_exists('points', $gapText)) {
183  foreach ($gapText['points'] as $row => $points) {
184  $points = str_replace(',', '.', $points);
185  if (isset($points) && $points != '' && is_numeric($points)) {
186  $points_sum += $points;
187  if ($points > 0) {
188  $select_at_least_on_positive = true;
189  }
190  } else {
191  $error = true;
192  }
193  }
194  if (isset($gap_with_points) && is_array($gap_with_points) && array_key_exists($key, $gap_with_points)) {
195  $points_sum += $gap_with_points[$key];
196  }
197  if ($points_sum <= 0) {
198  if (!array_key_exists($key, $gaps_used_in_combination) && (!$getType == 'select' || $select_at_least_on_positive == false)) {
199  $error = true;
200  }
201  }
202  } else {
203  $error = true;
204  }
205  }
206  if ($getType == assClozeGap::TYPE_NUMERIC) {
207  $eval = new EvalMath();
208  $eval->suppress_errors = true;
209 
210  $mark_errors = ['answer' => false, 'lower' => false, 'upper' => false, 'points' => false];
211  foreach ([ 'answer' => '_numeric',
212  'lower' => '_numeric_lower',
213  'upper' => '_numeric_upper',
214  'points' => '_numeric_points'] as $part => $suffix) {
215  $val = ilUtil::stripSlashes($this->raw('gap_' . $key . $suffix) ?? '', false);
216  $val = str_replace(',', '.', $val);
217  if ($eval->e($val) === false) {
218  $mark_errors[$part] = true;
219  $error = true;
220  }
221 
222  if ($part == 'points') {
223  $points = $val;
224  }
225  }
226 
227  if (isset($gap_with_points) && is_array($gap_with_points) && array_key_exists($key, $gap_with_points)) {
228  $points += $gap_with_points[$key];
229  }
230 
231  if (!isset($points) || $points == '' || !is_numeric($points) || $points == 0) {
232  if (!array_key_exists($key, $gaps_used_in_combination)) {
233  $error = true;
234  }
235  }
236 
237  $json[0][$key]["values"][0]["error"] = $mark_errors;
238  }
239  }
240  }
241  return !$error;
242  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:

◆ getValue()

ilClozeGapInputBuilderGUI::getValue ( )
Exceptions
JsonException

Definition at line 48 of file class.ilClozeGapInputBuilderGUI.php.

References $value.

Referenced by setValueByArray().

49  {
50  $editOrOpen = $this->value;
51  if (isset($editOrOpen['author'])) {
52  $json = json_decode($this->post->retrieve(
53  "gap_json_post",
54  $this->refinery->kindlyTo()->string()
55  ), true, 512, JSON_THROW_ON_ERROR);
56  return $json[0];
57  }
58  return $this->value;
59  }
+ Here is the caller graph for this function:

◆ getValueCombination()

ilClozeGapInputBuilderGUI::getValueCombination ( )
Exceptions
JsonException

Definition at line 69 of file class.ilClozeGapInputBuilderGUI.php.

References $value, and $value_combination.

Referenced by setValueByArray().

70  {
71  $editOrOpen = $this->value;
72  if (isset($editOrOpen['author'])) {
73  return json_decode($this->post->retrieve(
74  "gap_json_combination_post",
75  $this->refinery->kindlyTo()->string()
76  ), true, 512, JSON_THROW_ON_ERROR);
77  }
78  return (array) $this->value_combination;
79  }
+ Here is the caller graph for this function:

◆ setValue()

ilClozeGapInputBuilderGUI::setValue (   $a_value)

Set Value.

Parameters
string$a_valueValue

Definition at line 40 of file class.ilClozeGapInputBuilderGUI.php.

Referenced by setValueByArray().

40  : void
41  {
42  $this->value = $a_value;
43  }
+ Here is the caller graph for this function:

◆ setValueByArray()

ilClozeGapInputBuilderGUI::setValueByArray (   $data)

◆ setValueCombination()

ilClozeGapInputBuilderGUI::setValueCombination (   $value)

Definition at line 61 of file class.ilClozeGapInputBuilderGUI.php.

References $value.

Referenced by setValueCombinationFromDb().

61  : void
62  {
63  $this->value_combination = $value;
64  }
+ Here is the caller graph for this function:

◆ setValueCombinationFromDb()

ilClozeGapInputBuilderGUI::setValueCombinationFromDb (   $value)

Definition at line 81 of file class.ilClozeGapInputBuilderGUI.php.

References $value, and setValueCombination().

81  : void
82  {
83  $return_array = [];
84  if ($value) {
85  foreach ($value as $row) {
86  if ($row['row_id'] == 0) {
87  $return_array[$row['cid']][0][] = $row['gap_fi'];
88  }
89  $return_array[$row['cid']][1][$row['row_id']][] = $row['answer'];
90  $return_array[$row['cid']][2][$row['row_id']] = $row['points']; //= array('key' => $row['cid'], 'points' => $row['points'], 'best_solution' => $row['best_solution']);
91  }
92  $this->setValueCombination($return_array);
93  }
94  }
+ Here is the call graph for this function:

◆ stripSlashesRecursive()

static ilClozeGapInputBuilderGUI::stripSlashesRecursive (   $a_data,
bool  $a_strip_html = true,
string  $a_allow = "" 
)
static
Parameters
$datastring|array
Deprecated:

Definition at line 331 of file class.ilClozeGapInputBuilderGUI.php.

References null, and ilUtil\stripSlashes().

332  {
333  if (is_array($a_data)) {
334  foreach ($a_data as $k => $v) {
335  if (is_array($v)) {
336  $a_data[$k] = self::stripSlashesRecursive($v, $a_strip_html, $a_allow);
337  } else {
338  $a_data[$k] = ilUtil::stripSlashes($v, $a_strip_html, $a_allow);
339  }
340  }
341  } else {
342  if ($a_data != null) {
343  $a_data = ilUtil::stripSlashes($a_data, $a_strip_html, $a_allow);
344  }
345  }
346 
347  return $a_data;
348  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

Field Documentation

◆ $post

ArrayBasedRequestWrapper ilClozeGapInputBuilderGUI::$post
private

Definition at line 26 of file class.ilClozeGapInputBuilderGUI.php.

◆ $query

ArrayBasedRequestWrapper ilClozeGapInputBuilderGUI::$query
private

Definition at line 27 of file class.ilClozeGapInputBuilderGUI.php.

◆ $value

ilClozeGapInputBuilderGUI::$value
private

◆ $value_combination

ilClozeGapInputBuilderGUI::$value_combination
private

Definition at line 24 of file class.ilClozeGapInputBuilderGUI.php.

Referenced by getValueCombination().


The documentation for this class was generated from the following file: