ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables 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)
 
 insert (ilTemplate $template)
 
- 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
 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 $i, $index, ILIAS\LTI\ToolProvider\$key, CLOZE_NUMERIC, CLOZE_SELECT, CLOZE_TEXT, ilFormPropertyGUI\raw(), ILIAS\Repository\refinery(), and ilUtil\stripSlashes().

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 = array();
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 = array();
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  $json[0][$key]['text_field_length'] = $gapsize > 0 ? $gapsize : '';
173 
174  $select_at_least_on_positive = false;
175  if ($getType == CLOZE_TEXT || $getType == CLOZE_SELECT) {
176  $gapText = self::stripSlashesRecursive($this->raw('gap_' . $key), false);
177  foreach ($gapText['answer'] as $row => $answer) {
178  if (!isset($answer) || $answer == '') {
179  $error = true;
180  }
181  }
182  $points_sum = 0;
183  if (array_key_exists('points', $gapText)) {
184  foreach ($gapText['points'] as $row => $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 == CLOZE_NUMERIC) {
207  $eval = new EvalMath();
208  $eval->suppress_errors = true;
209 
210  $mark_errors = array('answer' => false, 'lower' => false, 'upper' => false, 'points' => false);
211  foreach (array( '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  //$_POST['gap_json_post'] = json_encode($json);
242  return !$error;
243  }
const CLOZE_TEXT
Cloze question constants.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$index
Definition: metadata.php:145
const CLOZE_SELECT
string $key
Consumer key/client ID value.
Definition: System.php:193
const CLOZE_NUMERIC
$i
Definition: metadata.php:41
+ 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 insert().

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 insert().

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:

◆ insert()

ilClozeGapInputBuilderGUI::insert ( ilTemplate  $template)
Parameters
ilTemplate$template

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

References $DIC, ilFormPropertyGUI\$lng, ilModalGUI\getInstance(), getValue(), getValueCombination(), ilTemplate\parseCurrentBlock(), ilTemplate\setCurrentBlock(), HTML_Template_IT\setVariable(), and ilLanguage\txt().

253  : void
254  {
255  global $DIC;
256  $lng = $DIC['lng'];
257  $modal = ilModalGUI::getInstance();
258  $modal->setHeading($lng->txt(''));
259  $modal->setId("ilGapModal");
260  $modal->setBody('');
261 
262  $cloze_settings_js = 'ClozeSettings = {'
263  . ' gaps_php : ' . json_encode(array($this->getValue()))
264  . ',gaps_combination : ' . json_encode($this->getValueCombination())
265  . ',gap_backup : []'
266  . ',unused_gaps_comb : []'
267  . ',outofbound_text : ' . '"' . $lng->txt('out_of_range') . '"'
268  . ',combination_error : ' . '"' . $lng->txt('please_select') . '"'
269  . ',combination_text : ' . '"' . $lng->txt('gap_combination') . '"'
270  . ',copy_of_combination : ' . '"' . $lng->txt('copy_of') . ' ' . $lng->txt('gap_combination') . '"'
271  . ',gap_in_more_than_one : ' . '""'
272  . ',gap_text : ' . '"' . $lng->txt('gap') . '"'
273  . ',ok_text : ' . '"' . $lng->txt('ok') . '"'
274  . ',cancel_text : ' . '"' . $lng->txt('cancel') . '"'
275  . '};';
276 
277  $DIC->ui()->mainTemplate()->addOnLoadCode(
278  $cloze_settings_js
279  . 'ClozeQuestionGapBuilder.Init();'
280  );
281  $DIC->ui()->mainTemplate()->addJavascript(
282  './Modules/TestQuestionPool/templates/default/clozeQuestionGapBuilder.js'
283  );
284 
285 
286  $custom_template = new ilTemplate('tpl.il_as_cloze_gap_builder.html', true, true, 'Modules/TestQuestionPool');
287  $custom_template->setVariable("MY_MODAL", $modal->getHTML());
288  $custom_template->setVariable('GAP_JSON', json_encode(array($this->getValue())));
289  $custom_template->setVariable('GAP', $lng->txt('gap'));
290  $custom_template->setVariable('GAP_COMBINATION_JSON', json_encode($this->getValueCombination()));
291  $custom_template->setVariable('TEXT_GAP', $lng->txt('text_gap'));
292  $custom_template->setVariable('SELECT_GAP', $lng->txt('select_gap'));
293  $custom_template->setVariable('NUMERIC_GAP', $lng->txt('numeric_gap'));
294  $custom_template->setVariable('GAP_SIZE', $lng->txt('cloze_fixed_textlength'));
295  $custom_template->setVariable('GAP_SIZE_INFO', $lng->txt('cloze_gap_size_info'));
296  $custom_template->setVariable('ANSWER_TEXT', $lng->txt('answer_text'));
297  $custom_template->setVariable('ANSWER_BYLINE', $lng->txt('cloze_answer_text_info'));
298  $custom_template->setVariable('POINTS', $lng->txt('points'));
299  $custom_template->setVariable('VALUE', $lng->txt('value'));
300  $custom_template->setVariable('UPPER_BOUND', $lng->txt('range_upper_limit'));
301  $custom_template->setVariable('LOWER_BOUND', $lng->txt('range_lower_limit'));
302  $custom_template->setVariable('ACTIONS', $lng->txt('actions'));
303  $custom_template->setVariable('REMOVE_GAP', $lng->txt('remove_gap'));
304  $custom_template->setVariable('SHUFFLE_ANSWERS', $lng->txt('shuffle_answers'));
305  $custom_template->setVariable('POINTS_ERROR', $lng->txt('enter_enough_positive_points'));
306  $custom_template->setVariable('MISSING_VALUE', $lng->txt('msg_input_is_required'));
307  $custom_template->setVariable('NOT_A_FORMULA', $lng->txt('err_no_formula'));
308  $custom_template->setVariable('NOT_A_NUMBER', $lng->txt('err_no_numeric_value'));
309  $custom_template->setVariable('CLOSE', $lng->txt('close'));
310  $custom_template->setVariable('DELETE_GAP', $lng->txt('are_you_sure'));
311  $custom_template->setVariable('PLEASE_SELECT', $lng->txt('please_select'));
312  $custom_template->setVariable('BEST_POSSIBLE_SOLUTION_HEADER', $lng->txt('tst_best_solution_is'));
313  $custom_template->setVariable('BEST_POSSIBLE_SOLUTION', $lng->txt('value'));
314  $custom_template->setVariable('MAX_POINTS', $lng->txt('max_points'));
315  $custom_template->setVariable('TYPE', $lng->txt('type'));
316  $custom_template->setVariable('VALUES', $lng->txt('values'));
317  $custom_template->setVariable('GAP_COMBINATION', $lng->txt('gap_combination'));
318  $custom_template->setVariable('COPY', $lng->txt('copy_of'));
319  $template->setCurrentBlock('prop_generic');
320  $template->setVariable('PROP_GENERIC', $custom_template->get());
321  $template->parseCurrentBlock();
322  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: feed.php:28
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static getInstance()
+ Here is the call 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)

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

References $data, and setValue().

245  : void
246  {
247  $this->setValue($data);
248  }
+ Here is the call graph for this function:

◆ 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 = 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 328 of file class.ilClozeGapInputBuilderGUI.php.

References ilUtil\stripSlashes().

329  {
330  if (is_array($a_data)) {
331  foreach ($a_data as $k => $v) {
332  if (is_array($v)) {
333  $a_data[$k] = self::stripSlashesRecursive($v, $a_strip_html, $a_allow);
334  } else {
335  $a_data[$k] = ilUtil::stripSlashes($v, $a_strip_html, $a_allow);
336  }
337  }
338  } else {
339  if ($a_data != null) {
340  $a_data = ilUtil::stripSlashes($a_data, $a_strip_html, $a_allow);
341  }
342  }
343 
344  return $a_data;
345  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ 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: