ILIAS  release_8 Revision v8.23
assClozeGapCombination Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for assClozeGapCombination:

Public Member Functions

 loadFromDb ($question_id)
 
 getCleanCombinationArray ($question_id)
 
 saveGapCombinationToDb ($question_id, $gap_combinations, $gap_values)
 
 combinationExistsForQid ($question_id)
 
 getGapsWhichAreUsedInCombination ($question_id)
 
 getMaxPointsForCombination (int $question_id, int $combination_id=-1)
 
 getBestSolutionCombination ($question_id)
 

Static Public Member Functions

static importGapCombinationToDb ($question_id, $gap_combinations)
 
static clearGapCombinationsFromDb ($question_id)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 19 of file class.assClozeGapCombination.php.

Member Function Documentation

◆ clearGapCombinationsFromDb()

static assClozeGapCombination::clearGapCombinationsFromDb (   $question_id)
static

Definition at line 163 of file class.assClozeGapCombination.php.

References $DIC, and $ilDB.

Referenced by assClozeTestImport\fromXML().

163  : void
164  {
165  global $DIC;
166  $ilDB = $DIC['ilDB'];
167 
168  $ilDB->manipulateF(
169  'DELETE FROM qpl_a_cloze_combi_res WHERE question_fi = %s',
170  array( 'integer' ),
171  array( $question_id )
172  );
173  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ combinationExistsForQid()

assClozeGapCombination::combinationExistsForQid (   $question_id)

Definition at line 175 of file class.assClozeGapCombination.php.

References $DIC, and $ilDB.

175  : bool
176  {
177  global $DIC;
178  $ilDB = $DIC['ilDB'];
179 
180  $result = $ilDB->queryF(
181  'SELECT * FROM qpl_a_cloze_combi_res WHERE question_fi = %s ORDER BY gap_fi ASC',
182  array('integer'),
183  array($question_id)
184  );
185  if ($result->numRows() > 0) {
186  return true;
187  } else {
188  return false;
189  }
190  }
global $DIC
Definition: feed.php:28

◆ getBestSolutionCombination()

assClozeGapCombination::getBestSolutionCombination (   $question_id)

Definition at line 246 of file class.assClozeGapCombination.php.

References $data, $DIC, $ilDB, and $lng.

247  {
248  global $DIC;
249  $ilDB = $DIC['ilDB'];
250  $lng = $DIC['lng'];
251 
252  $result = $ilDB->queryF(
253  'SELECT * FROM qpl_a_cloze_combi_res WHERE question_fi = %s AND best_solution=1 ORDER BY gap_fi',
254  array('integer'),
255  array($question_id)
256  );
257  if ($result->numRows() > 0) {
258  $return_string = '<br>';
259  $combination_id = 0;
260  $points = 0;
261  while ($data = $ilDB->fetchAssoc($result)) {
262  if ($combination_id != $data['combination_id']) {
263  $combination_id = $data['combination_id'];
264  $return_string .= $points;
265  $return_string .= '<br>';
266  $return_string .= $data['answer'] . '|';
267  } else {
268  $return_string .= $data['answer'] . '|';
269  }
270 
271  $points = ' (' . $data['points'] . ' ' . $lng->txt('points') . ')';
272  }
273  return rtrim($return_string, '|') . $points;
274  } else {
275  return 0;
276  }
277  }
$lng
global $DIC
Definition: feed.php:28

◆ getCleanCombinationArray()

assClozeGapCombination::getCleanCombinationArray (   $question_id)

Definition at line 66 of file class.assClozeGapCombination.php.

References ILIAS\LTI\ToolProvider\$key.

66  : array
67  {
68  $assClozeGapCombinationObj = new assClozeGapCombination();
69  $combination_from_db = $assClozeGapCombinationObj->loadFromDb($question_id);
70  $clean_array = array();
71  foreach ($combination_from_db as $key => $value) {
72  $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['answer'] = $value['answer'];
73  $clean_array[$value['cid']][$value['row_id']]['points'] = $value['points'];
74  $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['type'] = $value['type'];
75  }
76  return $clean_array;
77  }
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getGapsWhichAreUsedInCombination()

assClozeGapCombination::getGapsWhichAreUsedInCombination (   $question_id)

Definition at line 192 of file class.assClozeGapCombination.php.

References $data, $DIC, and $ilDB.

192  : array
193  {
194  global $DIC;
195  $ilDB = $DIC['ilDB'];
196 
197  $result = $ilDB->queryF(
198  'SELECT gap_fi, combination_id FROM ' . $ilDB->quoteIdentifier('qpl_a_cloze_combi_res') . ' WHERE question_fi = %s GROUP BY gap_fi, combination_id',
199  array('integer'),
200  array($question_id)
201  );
202  $gaps = array();
203  if ($result->numRows() > 0) {
204  while ($data = $ilDB->fetchAssoc($result)) {
205  $gaps[$data['gap_fi']] = $data['combination_id'];
206  }
207  }
208  return $gaps;
209  }
global $DIC
Definition: feed.php:28

◆ getMaxPointsForCombination()

assClozeGapCombination::getMaxPointsForCombination ( int  $question_id,
int  $combination_id = -1 
)

Definition at line 211 of file class.assClozeGapCombination.php.

References $data, $DIC, and $ilDB.

211  : float
212  {
213  global $DIC;
214  $ilDB = $DIC['ilDB'];
215 
216  if ($combination_id == -1) {
217  $result = $ilDB->queryF(
218  'SELECT combination_id, points FROM qpl_a_cloze_combi_res WHERE question_fi = %s AND best_solution=1 GROUP BY combination_id, points',
219  array('integer'),
220  array($question_id)
221  );
222  if ($result->numRows() > 0) {
223  $points = 0;
224  while ($data = $ilDB->fetchAssoc($result)) {
225  $points += $data['points'];
226  }
227  return $points;
228  }
229  } else {
230  $result = $ilDB->queryF(
231  'SELECT combination_id, points FROM qpl_a_cloze_combi_res WHERE question_fi = %s AND combination_id = %s AND best_solution=1 GROUP BY combination_id, points',
232  array('integer', 'integer'),
233  array($question_id, $combination_id)
234  );
235  if ($result->numRows() > 0) {
236  $points = 0;
237  while ($data = $ilDB->fetchAssoc($result)) {
238  $points += $data['points'];
239  }
240  return $points;
241  }
242  }
243  return 0;
244  }
global $DIC
Definition: feed.php:28

◆ importGapCombinationToDb()

static assClozeGapCombination::importGapCombinationToDb (   $question_id,
  $gap_combinations 
)
static

Definition at line 127 of file class.assClozeGapCombination.php.

References $DIC, $ilDB, and ILIAS\LTI\ToolProvider\$key.

Referenced by assClozeTestImport\fromXML().

127  : void
128  {
129  global $DIC;
130  $ilDB = $DIC['ilDB'];
131 
132  foreach ($gap_combinations as $key => $row) {
133  if (is_object($row)) {
134  $row = get_object_vars($row);
135  }
136  if ($question_id != -1) {
137  $ilDB->manipulateF(
138  'INSERT INTO qpl_a_cloze_combi_res
139  (combination_id, question_fi, gap_fi, row_id, answer, points, best_solution) VALUES (%s, %s, %s, %s, %s, %s, %s)',
140  array(
141  'integer',
142  'integer',
143  'integer',
144  'integer',
145  'text',
146  'float',
147  'integer'
148  ),
149  array(
150  $row['cid'],
151  $question_id,
152  $row['gap_fi'],
153  $row['row_id'],
154  $row['answer'],
155  $row['points'],
156  $row['best_solution']
157  )
158  );
159  }
160  }
161  }
global $DIC
Definition: feed.php:28
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ loadFromDb()

assClozeGapCombination::loadFromDb (   $question_id)

Definition at line 21 of file class.assClozeGapCombination.php.

References $data, $DIC, and $ilDB.

21  : array
22  {
23  global $DIC;
24  $ilDB = $DIC['ilDB'];
25  $result = $ilDB->queryF(
26  '
27  SELECT combinations.combination_id,
28  combinations.gap_fi,
29  combinations.answer,
30  combinations.row_id,
31  combinations.points,
32  combinations.best_solution,
33  combinations.question_fi,
34  cloze.cloze_type
35  FROM qpl_a_cloze_combi_res AS combinations
36  INNER JOIN qpl_a_cloze AS cloze
37  WHERE combinations.question_fi = cloze.question_fi
38  AND combinations.gap_fi = cloze.gap_id
39  AND combinations.question_fi = %s
40  ORDER BY combination_id, row_id, gap_fi ASC
41  ',
42  array('integer'),
43  array($question_id)
44  );
45 
46  $return_array = array();
47  while ($data = $ilDB->fetchAssoc($result)) {
48  if (isset($return_array[$data['combination_id'] . '::' . $data['gap_fi']])) {
49  continue;
50  }
51 
52  $return_array[$data['combination_id'] . '::' . $data['row_id'] . '::' . $data['gap_fi']] = array(
53  'cid' => $data['combination_id'],
54  'gap_fi' => $data['gap_fi'],
55  'answer' => $data['answer'],
56  'points' => $data['points'],
57  'row_id' => $data['row_id'],
58  'type' => $data['cloze_type'],
59  'best_solution' => $data['best_solution']
60  );
61  }
62 
63  return array_values($return_array);
64  }
global $DIC
Definition: feed.php:28

◆ saveGapCombinationToDb()

assClozeGapCombination::saveGapCombinationToDb (   $question_id,
  $gap_combinations,
  $gap_values 
)

Definition at line 79 of file class.assClozeGapCombination.php.

References $DIC, $i, and $ilDB.

79  : void
80  {
81  global $DIC;
82  $ilDB = $DIC['ilDB'];
83  $best_solutions = array();
84  for ($i = 0; $i < count($gap_combinations['points']); $i++) {
85  $highest_points = 0;
86  for ($j = 0; $j < count($gap_combinations['points'][$i]); $j++) {
87  if ($highest_points < $gap_combinations['points'][$i][$j]) {
88  $highest_points = $gap_combinations['points'][$i][$j];
89  $best_solutions[$i] = $j;
90  }
91  }
92  }
93  for ($i = 0; $i < count($gap_values); $i++) {
94  for ($j = 0; $j < count($gap_values[$i]); $j++) {
95  for ($k = 0; $k < count($gap_values[$i][$j]); $k++) {
96  if ($best_solutions[$i] == $j) {
97  $best_solution = 1;
98  } else {
99  $best_solution = 0;
100  }
101  $ilDB->manipulateF(
102  'INSERT INTO qpl_a_cloze_combi_res
103  (combination_id, question_fi, gap_fi, row_id, answer, points, best_solution) VALUES (%s, %s, %s, %s, %s, %s, %s)',
104  array(
105  'integer',
106  'integer',
107  'integer',
108  'integer',
109  'text',
110  'float',
111  'integer'
112  ),
113  array(
114  $i,
115  $question_id,
116  $gap_combinations['select'][$i][$k],
117  $j,
118  $gap_values[$i][$j][$k],
119  (float) str_replace(',', '.', $gap_combinations['points'][$i][$j]),
120  $best_solution
121  )
122  );
123  }
124  }
125  }
126  }
global $DIC
Definition: feed.php:28
$i
Definition: metadata.php:41

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