ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 Check input, strip slashes etc. More...
 
 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...
 
 stripSlashesAddSpaceFallback ($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...
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFormPropertyGUI
static removeProhibitedCharacters ($a_text)
 Remove prohibited characters see #19159. More...
 
- 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
 $ctrl
 
 $lng
 
 $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 ( )

Check input, strip slashes etc.

set alert, if input is not ok.

Returns
boolean Input ok, true/false

Reimplemented from ilFormPropertyGUI.

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

68 {
69 $error = false;
70 $json = ilUtil::stripSlashesRecursive(json_decode($_POST['gap_json_post']), false);
72 $gaps_used_in_combination = array();
73 if (array_key_exists('gap_combination', $_POST)) {
74 $_POST['gap_combination'] = ilUtil::stripSlashesRecursive($_POST['gap_combination']);
75 $_POST['gap_combination_values'] = ilUtil::stripSlashesRecursive($_POST['gap_combination_values']);
76 $gap_with_points = array();
77
78 for ($i = 0; $i < count($_POST['gap_combination']['select']); $i++) {
79 foreach ($_POST['gap_combination']['select'][$i] as $key => $item) {
80 if ($item == 'none_selected_minus_one') {
81 return false;
82 }
83 $gaps_used_in_combination[$item] = $item;
84 $check_points_for_best_scoring = false;
85 foreach ($_POST['gap_combination_values'][$i] as $index => $answeritems) {
86 foreach ($answeritems as $answeritem) {
87 if ($answeritem == 'none_selected_minus_one') {
88 return false;
89 }
90 }
91 $points = $_POST['gap_combination']['points'][$i][$index];
92 if ($points > 0) {
93 $check_points_for_best_scoring = true;
94 }
95 }
96 if (!$check_points_for_best_scoring) {
97 return false;
98 }
99 }
100 }
101 }
102
103 if (isset($_POST['gap']) && is_array($_POST['gap'])) {
104 foreach ($_POST['gap'] as $key => $item) {
105 $_POST['clozetype_' . $key] = ilUtil::stripSlashes($_POST['clozetype_' . $key]);
106 $getType = $_POST['clozetype_' . $key];
107 $gapsize = $_POST['gap_' . $key . '_gapsize'];
108 $json[0][$key]->text_field_length = $gapsize > 0 ? $gapsize : '';
109 $select_at_least_on_positive = false;
110 if ($getType == CLOZE_TEXT || $getType == CLOZE_SELECT) {
111 $_POST['gap_' . $key] = ilUtil::stripSlashesRecursive($_POST['gap_' . $key], false);
112 $gapText = $_POST['gap_' . $key];
113 foreach ($gapText['answer'] as $row => $answer) {
114 if (!isset($answer) || $answer == '') {
115 $error = true;
116 }
117 }
118 $points_sum = 0;
119 if (array_key_exists('points', $gapText)) {
120 foreach ($gapText['points'] as $row => $points) {
121 if (isset($points) && $points != '' && is_numeric($points)) {
122 $points_sum += $points;
123 if ($points > 0) {
124 $select_at_least_on_positive = true;
125 }
126 } else {
127 $error = true;
128 }
129 }
130 if (is_array($gap_with_points) && array_key_exists($key, $gap_with_points)) {
131 $points_sum += $gap_with_points[$key];
132 }
133 if ($points_sum <= 0) {
134 if (!array_key_exists($key, $gaps_used_in_combination) && (!$getType == 'select' || $select_at_least_on_positive == false)) {
135 $error = true;
136 }
137 }
138 if ($getType == CLOZE_SELECT) {
139 $_POST['shuffle_' . $key] = ilUtil::stripSlashes($_POST['shuffle_' . $key]);
140 if (!isset($_POST['shuffle_' . $key])) {
141 $error = true;
142 }
143 }
144 } else {
145 $error = true;
146 }
147 }
148 if ($getType == CLOZE_NUMERIC) {
149 // fau: fixGapFormula - fix post indices, streamlined checks
150 include_once("./Services/Math/classes/class.EvalMath.php");
151 $eval = new EvalMath();
152 $eval->suppress_errors = true;
153
154 $mark_errors = array('answer' => false, 'lower' => false, 'upper' => false, 'points' => false);
155 foreach (array( 'answer' => '_numeric',
156 'lower' => '_numeric_lower',
157 'upper' => '_numeric_upper',
158 'points' => '_numeric_points') as $part => $suffix) {
159 $val = ilUtil::stripSlashes($_POST['gap_' . $key . $suffix], false);
160 $val = str_replace(',', '.', $val);
161 if ($eval->e($val) === false) {
162 $mark_errors[$part] = true;
163 $error = true;
164 }
165
166 if ($part == 'points') {
167 $points = $val;
168 }
169 }
170 // fau.
171 if (is_array($gap_with_points) && array_key_exists($key, $gap_with_points)) {
172 $points += $gap_with_points[$key];
173 }
174
175 if (!isset($points) || $points == '' || !is_numeric($points) || $points == 0) {
176 if (!array_key_exists($key, $gaps_used_in_combination)) {
177 $error = true;
178 }
179 }
180
181 $json[0][$key]->values[0]->error = $mark_errors;
182 }
183 }
184 }
185 $_POST['gap_json_post'] = json_encode($json);
186 return !$error;
187 }
$_POST["username"]
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
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
$index
Definition: metadata.php:60
$row

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

+ 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.

24 {
25 $editOrOpen = $this->value;
26 if (isset($editOrOpen['author'])) {
27 $json = json_decode(ilUtil::stripSlashes($_POST['gap_json_post']));
28 return $json[0];
29 }
30 return $this->value;
31 }

References $_POST, and ilUtil\stripSlashes().

Referenced by insert().

+ 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 42 of file class.ilClozeGapInputBuilderGUI.php.

43 {
44 $editOrOpen = $this->value;
45 if (isset($editOrOpen['author'])) {
46 $json = json_decode(ilUtil::stripSlashes($_POST['gap_json_combination_post']));
47 return $json;
48 }
49 return (array) $this->value_combination;
50 }

References $_POST, and ilUtil\stripSlashes().

Referenced by insert().

+ 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 197 of file class.ilClozeGapInputBuilderGUI.php.

198 {
199 global $DIC;
200 $lng = $DIC['lng'];
201 require_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
202 $modal = ilModalGUI::getInstance();
203 $modal->setHeading($lng->txt(''));
204 $modal->setId("ilGapModal");
205 //$modal->setBackdrop(ilModalGUI::BACKDROP_OFF);
206 $modal->setBody('');
207
208 $custom_template = new ilTemplate('tpl.il_as_cloze_gap_builder.html', true, true, 'Modules/TestQuestionPool');
209 $custom_template->setVariable("MY_MODAL", $modal->getHTML());
210 $custom_template->setVariable('GAP_JSON', json_encode(array($this->getValue())));
211 $custom_template->setVariable('GAP', $lng->txt('gap'));
212 $custom_template->setVariable('GAP_COMBINATION_JSON', json_encode($this->getValueCombination()));
213 $custom_template->setVariable('TEXT_GAP', $lng->txt('text_gap'));
214 $custom_template->setVariable('SELECT_GAP', $lng->txt('select_gap'));
215 $custom_template->setVariable('NUMERIC_GAP', $lng->txt('numeric_gap'));
216 $custom_template->setVariable('GAP_SIZE', $lng->txt('cloze_fixed_textlength'));
217 $custom_template->setVariable('GAP_SIZE_INFO', $lng->txt('cloze_gap_size_info'));
218 $custom_template->setVariable('ANSWER_TEXT', $lng->txt('answer_text'));
219 $custom_template->setVariable('POINTS', $lng->txt('points'));
220 $custom_template->setVariable('VALUE', $lng->txt('value'));
221 $custom_template->setVariable('UPPER_BOUND', $lng->txt('range_upper_limit'));
222 $custom_template->setVariable('LOWER_BOUND', $lng->txt('range_lower_limit'));
223 $custom_template->setVariable('ACTIONS', $lng->txt('actions'));
224 $custom_template->setVariable('REMOVE_GAP', $lng->txt('remove_gap'));
225 $custom_template->setVariable('SHUFFLE_ANSWERS', $lng->txt('shuffle_answers'));
226 $custom_template->setVariable('POINTS_ERROR', $lng->txt('enter_enough_positive_points'));
227 $custom_template->setVariable('MISSING_VALUE', $lng->txt('msg_input_is_required'));
228 $custom_template->setVariable('NOT_A_FORMULA', $lng->txt('err_no_formula'));
229 $custom_template->setVariable('NOT_A_NUMBER', $lng->txt('err_no_numeric_value'));
230 $custom_template->setVariable('CLOSE', $lng->txt('close'));
231 $custom_template->setVariable('DELETE_GAP', $lng->txt('are_you_sure'));
232 $custom_template->setVariable('PLEASE_SELECT', $lng->txt('please_select'));
233 $custom_template->setVariable('BEST_POSSIBLE_SOLUTION_HEADER', $lng->txt('tst_best_solution_is'));
234 $custom_template->setVariable('BEST_POSSIBLE_SOLUTION', $lng->txt('value'));
235 $custom_template->setVariable('MAX_POINTS', $lng->txt('max_points'));
236 $custom_template->setVariable('OUT_OF_BOUND', $lng->txt('out_of_range'));
237 $custom_template->setVariable('TYPE', $lng->txt('type'));
238 $custom_template->setVariable('VALUES', $lng->txt('values'));
239 $custom_template->setVariable('GAP_COMBINATION', $lng->txt('gap_combination'));
240 $custom_template->setVariable('COPY', $lng->txt('copy_of'));
241 $custom_template->setVariable('OK', $lng->txt('ok'));
242 $custom_template->setVariable('CANCEL', $lng->txt('cancel'));
243 $custom_template->setVariable('WHITESPACE_FRONT', $lng->txt('cloze_textgap_whitespace_before'));
244 $custom_template->setVariable('WHITESPACE_BACK', $lng->txt('cloze_textgap_whitespace_after'));
245 $custom_template->setVariable('WHITESPACE_MULTIPLE', $lng->txt('cloze_textgap_multiple_whitespace'));
246 $template->setCurrentBlock('prop_generic');
247 $template->setVariable('PROP_GENERIC', $custom_template->get());
248 $template->parseCurrentBlock();
249 }
static getInstance()
Get instance.
special template class to simplify handling of ITX/PEAR
$template
global $DIC
Definition: saml.php:7

References $DIC, ilFormPropertyGUI\$lng, $template, ilModalGUI\getInstance(), getValue(), and getValueCombination().

+ 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.

15 {
16 $this->value = $a_value;
17 }

Referenced by setValueByArray().

+ Here is the caller graph for this function:

◆ setValueByArray()

ilClozeGapInputBuilderGUI::setValueByArray (   $data)

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

190 {
191 $this->setValue($data);
192 }
$data
Definition: bench.php:6

References $data, and setValue().

+ Here is the call graph for this function:

◆ setValueCombination()

ilClozeGapInputBuilderGUI::setValueCombination (   $value)

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

34 {
35 $this->value_combination = $value;
36 }

Referenced by setValueCombinationFromDb().

+ Here is the caller graph for this function:

◆ setValueCombinationFromDb()

ilClozeGapInputBuilderGUI::setValueCombinationFromDb (   $value)

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

53 {
54 $return_array = array();
55 if ($value) {
56 foreach ($value as $row) {
57 if ($row['row_id'] == 0) {
58 $return_array[$row['cid']][0][] = $row['gap_fi'];
59 }
60 $return_array[$row['cid']][1][$row['row_id']][] = $row['answer'];
61 $return_array[$row['cid']][2][$row['row_id']] = $row['points']; //= array('key' => $row['cid'], 'points' => $row['points'], 'best_solution' => $row['best_solution']);
62 }
63 $this->setValueCombination($return_array);
64 }
65 }

References $row, and setValueCombination().

+ Here is the call graph for this function:

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