ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
ilClozeGapInputBuilderGUI Class Reference
+ Inheritance diagram for ilClozeGapInputBuilderGUI:
+ Collaboration diagram for ilClozeGapInputBuilderGUI:

Public Member Functions

 setValue ($a_value)
 Set Value. More...
 
 getValue ()
 Get Value. More...
 
 setValueCombination ($value)
 
 getValueCombination ()
 Get Value. More...
 
 setValueCombinationFromDb ($value)
 
 checkInput ()
 
 setValueByArray ($data)
 
 insert (ilTemplate $template)
 
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem ($a_item)
 Add Subitem. More...
 
 getSubItems ()
 Get Subitems. More...
 
 getSubInputItemsRecursive ()
 returns a flat array of possibly existing subitems recursively More...
 
 checkSubItemsInput ()
 Check SubItems. More...
 
 getSubForm ()
 Get sub form html. More...
 
 getItemByPostVar ($a_post_var)
 Get item by post var. More...
 
- Public Member Functions inherited from ilFormPropertyGUI
 __construct ($a_title="", $a_postvar="")
 Constructor. More...
 
executeCommand ()
 Execute command. More...
 
 getType ()
 Get Type. More...
 
 setTitle ($a_title)
 Set Title. More...
 
 getTitle ()
 Get Title. More...
 
 setPostVar ($a_postvar)
 Set Post Variable. More...
 
 getPostVar ()
 Get Post Variable. More...
 
 getFieldId ()
 Get Post Variable. More...
 
 setInfo ($a_info)
 Set Information Text. More...
 
 getInfo ()
 Get Information Text. More...
 
 setAlert ($a_alert)
 Set Alert Text. More...
 
 getAlert ()
 Get Alert Text. More...
 
 setRequired ($a_required)
 Set Required. More...
 
 getRequired ()
 Get Required. More...
 
 setDisabled ($a_disabled)
 Set Disabled. More...
 
 getDisabled ()
 Get Disabled. More...
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 setParentForm ($a_parentform)
 Set Parent Form. More...
 
 getParentForm ()
 Get Parent Form. More...
 
 setParent ($a_val)
 Set Parent GUI object. More...
 
 getParent ()
 Get Parent GUI object. More...
 
 getSubForm ()
 Get sub form html. More...
 
 hideSubForm ()
 Sub form hidden on init? More...
 
 setHiddenTitle ($a_val)
 Set hidden title (for screenreaders) More...
 
 getHiddenTitle ()
 Get hidden title. More...
 
 getItemByPostVar ($a_post_var)
 Get item by post var. More...
 
 serializeData ()
 serialize data More...
 
 unserializeData ($a_data)
 unserialize data More...
 
 writeToSession ()
 Write to session. More...
 
 clearFromSession ()
 Clear session value. More...
 
 readFromSession ()
 Read from session. More...
 
 getHiddenTag ($a_post_var, $a_value)
 Get hidden tag (used for disabled properties) More...
 
 setMulti ($a_multi, $a_sortable=false, $a_addremove=true)
 Set Multi. More...
 
 getMulti ()
 Get Multi. More...
 
 setMultiValues (array $a_values)
 Set multi values. More...
 
 getMultiValues ()
 Get multi values. More...
 
 getContentOutsideFormTag ()
 Get content that has to reside outside of the parent form tag, e.g. More...
 
 removeProhibitedCharacters ($a_text)
 Remove prohibited characters see #19159. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ilFormPropertyGUI
 setType ($a_type)
 Set Type. More...
 
 getMultiIconsHTML ()
 Get HTML for multiple value icons. More...
 
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
 $sub_items = array()
 
- Protected Attributes inherited from ilFormPropertyGUI
 $type
 
 $title
 
 $postvar
 
 $info
 
 $alert
 
 $required = false
 
 $parentgui
 
 $parentform
 
 $hidden_title = ""
 
 $multi = false
 
 $multi_sortable = false
 
 $multi_addremove = true
 
 $multi_values
 

Detailed Description

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

Member Function Documentation

◆ checkInput()

ilClozeGapInputBuilderGUI::checkInput ( )

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

References $_POST, $row, CLOZE_NUMERIC, CLOZE_SELECT, CLOZE_TEXT, ilUtil\stripSlashes(), and ilUtil\stripSlashesRecursive().

74  {
75  $error = false;
76  $json = ilUtil::stripSlashesRecursive(json_decode($_POST['gap_json_post']), false);
78  $gaps_used_in_combination = array();
79  if(array_key_exists('gap_combination', $_POST))
80  {
81  $_POST['gap_combination'] = ilUtil::stripSlashesRecursive($_POST['gap_combination']);
82  $_POST['gap_combination_values'] = ilUtil::stripSlashesRecursive($_POST['gap_combination_values']);
83  $gap_with_points = array();
84 
85  for($i=0; $i < count($_POST['gap_combination']['select']); $i++)
86  {
87  foreach($_POST['gap_combination']['select'][$i] as $key => $item)
88  {
89  if($item == 'none_selected_minus_one')
90  {
91  return false;
92  }
93  $gaps_used_in_combination[$item] = $item;
94  $check_points_for_best_scoring = false;
95  foreach($_POST['gap_combination_values'][$i] as $index => $answeritems)
96  {
97  foreach($answeritems as $answeritem )
98  {
99  if($answeritem == 'none_selected_minus_one')
100  {
101  return false;
102  }
103  }
104  $points = $_POST['gap_combination']['points'][$i][$index];
105  if($points > 0)
106  {
107  $check_points_for_best_scoring = true;
108  }
109  }
110  if(!$check_points_for_best_scoring)
111  {
112  return false;
113  }
114  }
115 
116  }
117  }
118 
119  if(isset($_POST['gap']) && is_array($_POST['gap']))
120  {
121  foreach($_POST['gap'] as $key => $item)
122  {
123  $_POST['clozetype_' . $key] = ilUtil::stripSlashes($_POST['clozetype_' . $key]);
124  $getType = $_POST['clozetype_' . $key];
125  $gapsize = $_POST['gap_' . $key . '_gapsize'];
126  $json[0][$key]->text_field_length = $gapsize > 0 ? $gapsize : '';
127  $select_at_least_on_positive = false;
128  if($getType == CLOZE_TEXT || $getType == CLOZE_SELECT)
129  {
130  $_POST['gap_' . $key] = ilUtil::stripSlashesRecursive($_POST['gap_' . $key], false);
131  $gapText = $_POST['gap_' . $key];
132  foreach($gapText['answer'] as $row => $answer)
133  {
134  if(!isset($answer) || $answer == '')
135  {
136  $error = true;
137  }
138  }
139  $points_sum = 0;
140  if(array_key_exists('points', $gapText))
141  {
142  foreach($gapText['points'] as $row => $points)
143  {
144  if(isset($points) && $points != '' && is_numeric($points))
145  {
146  $points_sum += $points;
147  if($points > 0)
148  {
149  $select_at_least_on_positive = true;
150  }
151  }
152  else
153  {
154  $error = true;
155  }
156  }
157  if(is_array($gap_with_points) && array_key_exists($key, $gap_with_points))
158  {
159  $points_sum += $gap_with_points[$key];
160  }
161  if($points_sum <= 0)
162  {
163  if(!array_key_exists($key, $gaps_used_in_combination) && (!$getType == 'select' || $select_at_least_on_positive == false))
164  {
165  $error = true;
166  }
167  }
168  if($getType == CLOZE_SELECT)
169  {
170  $_POST['shuffle_' . $key] = ilUtil::stripSlashes($_POST['shuffle_' . $key]);
171  if(!isset($_POST['shuffle_' . $key]))
172  {
173  $error = true;
174  }
175  }
176  }
177  else
178  {
179  $error = true;
180  }
181  }
182  if($getType == CLOZE_NUMERIC)
183  {
184 // fau: fixGapFormula - fix post indices, streamlined checks
185  include_once("./Services/Math/classes/class.EvalMath.php");
186  $eval = new EvalMath();
187  $eval->suppress_errors = true;
188 
189  $mark_errors = array('answer' => false, 'lower' => false, 'upper' => false, 'points' => false);
190  foreach (array( 'answer' => '_numeric',
191  'lower' => '_numeric_lower',
192  'upper' => '_numeric_upper',
193  'points' => '_numeric_points') as $part => $suffix)
194  {
195  $val = ilUtil::stripSlashes($_POST['gap_'.$key.$suffix], FALSE);
196  $val = str_replace(',', '.', $val);
197  if ($eval->e($val) === FALSE)
198  {
199  $mark_errors[$part] = true;
200  $error = true;
201  }
202 
203  if ($part == 'points')
204  {
205  $points = $val;
206  }
207  }
208 // fau.
209  if(is_array($gap_with_points) && array_key_exists($key, $gap_with_points))
210  {
211  $points += $gap_with_points[$key];
212  }
213 
214  if(!isset($points) || $points == '' || !is_numeric($points) || $points == 0)
215  {
216  if(!array_key_exists($key, $gaps_used_in_combination))
217  {
218  $error = true;
219  }
220  }
221 
222  $json[0][$key]->values[0]->error = $mark_errors;
223  }
224  }
225  }
226  $_POST['gap_json_post'] = json_encode($json);
227  return !$error;
228  }
$_POST['username']
Definition: cron.php:12
const CLOZE_TEXT
Cloze question constants.
const CLOZE_SELECT
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
const CLOZE_NUMERIC
+ Here is the call graph for this function:

◆ getValue()

ilClozeGapInputBuilderGUI::getValue ( )

Get Value.

Returns
string Value

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

References $_POST, and ilUtil\stripSlashes().

Referenced by insert().

24  {
25  $editOrOpen = $this->value;
26  if(isset($editOrOpen['author']))
27  {
28  $json = json_decode(ilUtil::stripSlashes($_POST['gap_json_post']));
29  return $json[0];
30  }
31  return $this->value;
32  }
$_POST['username']
Definition: cron.php:12
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValueCombination()

ilClozeGapInputBuilderGUI::getValueCombination ( )

Get Value.

Returns
string Value

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

References $_POST, and ilUtil\stripSlashes().

Referenced by insert().

44  {
45  $editOrOpen = $this->value;
46  if(isset($editOrOpen['author']))
47  {
48  $json = json_decode(ilUtil::stripSlashes($_POST['gap_json_combination_post']));
49  return $json;
50  }
51  return (array) $this->value_combination;
52  }
$_POST['username']
Definition: cron.php:12
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert()

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

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

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

239  {
240  global $lng;
241  require_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
242  $modal = ilModalGUI::getInstance();
243  $modal->setHeading($lng->txt(''));
244  $modal->setId("ilGapModal");
245  //$modal->setBackdrop(ilModalGUI::BACKDROP_OFF);
246  $modal->setBody('');
247 
248  $custom_template = new ilTemplate('tpl.il_as_cloze_gap_builder.html', true, true, 'Modules/TestQuestionPool');
249  $custom_template->setVariable("MY_MODAL", $modal->getHTML());
250  $custom_template->setVariable('GAP_JSON', json_encode(array($this->getValue())));
251  $custom_template->setVariable('GAP', $lng->txt('gap'));
252  $custom_template->setVariable('GAP_COMBINATION_JSON', json_encode($this->getValueCombination()));
253  $custom_template->setVariable('TEXT_GAP', $lng->txt('text_gap'));
254  $custom_template->setVariable('SELECT_GAP', $lng->txt('select_gap'));
255  $custom_template->setVariable('NUMERIC_GAP', $lng->txt('numeric_gap'));
256  $custom_template->setVariable('GAP_SIZE', $lng->txt('cloze_fixed_textlength'));
257  $custom_template->setVariable('GAP_SIZE_INFO', $lng->txt('cloze_gap_size_info'));
258  $custom_template->setVariable('ANSWER_TEXT', $lng->txt('answer_text'));
259  $custom_template->setVariable('POINTS', $lng->txt('points'));
260  $custom_template->setVariable('VALUE', $lng->txt('value'));
261  $custom_template->setVariable('UPPER_BOUND', $lng->txt('range_upper_limit'));
262  $custom_template->setVariable('LOWER_BOUND', $lng->txt('range_lower_limit'));
263  $custom_template->setVariable('ACTIONS', $lng->txt('actions'));
264  $custom_template->setVariable('REMOVE_GAP', $lng->txt('remove_gap'));
265  $custom_template->setVariable('SHUFFLE_ANSWERS', $lng->txt('shuffle_answers'));
266  $custom_template->setVariable('POINTS_ERROR', $lng->txt('enter_enough_positive_points'));
267  $custom_template->setVariable('MISSING_VALUE', $lng->txt('msg_input_is_required'));
268  $custom_template->setVariable('NOT_A_FORMULA', $lng->txt('err_no_formula'));
269  $custom_template->setVariable('NOT_A_NUMBER', $lng->txt('err_no_numeric_value'));
270  $custom_template->setVariable('CLOSE', $lng->txt('close'));
271  $custom_template->setVariable('DELETE_GAP', $lng->txt('are_you_sure'));
272  $custom_template->setVariable('PLEASE_SELECT', $lng->txt('please_select'));
273  $custom_template->setVariable('BEST_POSSIBLE_SOLUTION_HEADER', $lng->txt('tst_best_solution_is'));
274  $custom_template->setVariable('BEST_POSSIBLE_SOLUTION', $lng->txt('value'));
275  $custom_template->setVariable('MAX_POINTS', $lng->txt('max_points'));
276  $custom_template->setVariable('OUT_OF_BOUND', $lng->txt('out_of_range'));
277  $custom_template->setVariable('TYPE', $lng->txt('type'));
278  $custom_template->setVariable('VALUES', $lng->txt('values'));
279  $custom_template->setVariable('GAP_COMBINATION', $lng->txt('gap_combination'));
280  $custom_template->setVariable('COPY', $lng->txt('copy_of'));
281  $custom_template->setVariable('OK', $lng->txt('ok'));
282  $custom_template->setVariable('CANCEL', $lng->txt('cancel'));
283  $custom_template->setVariable('WHITESPACE_FRONT', $lng->txt('cloze_textgap_whitespace_before'));
284  $custom_template->setVariable('WHITESPACE_BACK', $lng->txt('cloze_textgap_whitespace_after'));
285  $custom_template->setVariable('WHITESPACE_MULTIPLE', $lng->txt('cloze_textgap_multiple_whitespace'));
286  $template->setCurrentBlock('prop_generic');
287  $template->setVariable('PROP_GENERIC', $custom_template->get());
288  $template->parseCurrentBlock();
289  }
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:626
special template class to simplify handling of ITX/PEAR
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
static getInstance()
Get instance.
global $lng
Definition: privfeed.php:40
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...
+ Here is the call graph for this function:

◆ setValue()

ilClozeGapInputBuilderGUI::setValue (   $a_value)

Set Value.

Parameters
string$a_valueValue

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

Referenced by setValueByArray().

15  {
16  $this->value = $a_value;
17  }
+ Here is the caller graph for this function:

◆ setValueByArray()

ilClozeGapInputBuilderGUI::setValueByArray (   $data)

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

References $data, and setValue().

231  {
232  $this->setValue($data);
233  }
+ Here is the call graph for this function:

◆ setValueCombination()

ilClozeGapInputBuilderGUI::setValueCombination (   $value)

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

Referenced by setValueCombinationFromDb().

35  {
36  $this->value_combination = $value;
37  }
+ Here is the caller graph for this function:

◆ setValueCombinationFromDb()

ilClozeGapInputBuilderGUI::setValueCombinationFromDb (   $value)

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

References $row, and setValueCombination().

55  {
56  $return_array = array();
57  if($value)
58  {
59  foreach($value as $row)
60  {
61  if($row['row_id'] == 0)
62  {
63  $return_array[$row['cid']][0][] = $row['gap_fi'];
64  }
65  $return_array[$row['cid']][1][$row['row_id']][] = $row['answer'];
66  $return_array[$row['cid']][2][$row['row_id']] = $row['points']; //= array('key' => $row['cid'], 'points' => $row['points'], 'best_solution' => $row['best_solution']);
67 
68  }
69  $this->setValueCombination($return_array);
70  }
71  }
+ Here is the call graph for this function:

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