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

Public Member Functions

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

Detailed Description

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

Member Function Documentation

◆ clearGapCombinationsFromDb()

assClozeGapCombination::clearGapCombinationsFromDb (   $question_id)

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

References $ilDB.

Referenced by assClozeTestImport\fromXML().

156  {
157  global $ilDB;
158 
159  $ilDB->manipulateF( 'DELETE FROM qpl_a_cloze_combi_res WHERE question_fi = %s',
160  array( 'integer' ),
161  array( $question_id )
162  );
163  }
global $ilDB
+ Here is the caller graph for this function:

◆ combinationExistsForQid()

assClozeGapCombination::combinationExistsForQid (   $question_id)

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

References $ilDB, and $result.

166  {
167  global $ilDB;
168 
169  $result = $ilDB->queryF('SELECT * FROM qpl_a_cloze_combi_res WHERE question_fi = %s ORDER BY gap_fi ASC',
170  array('integer'),
171  array($question_id)
172  );
173  if ($result->numRows() > 0)
174  {
175  return true;
176  }
177  else
178  {
179  return false;
180  }
181  }
$result
global $ilDB

◆ getBestSolutionCombination()

assClozeGapCombination::getBestSolutionCombination (   $question_id)

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

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

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

◆ getCleanCombinationArray()

assClozeGapCombination::getCleanCombinationArray (   $question_id)

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

51  {
52  $assClozeGapCombinationObj = new assClozeGapCombination();
53  $combination_from_db = $assClozeGapCombinationObj->loadFromDb($question_id);
54  $clean_array = array();
55  foreach($combination_from_db as $key => $value)
56  {
57  $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['answer'] = $value['answer'];
58  $clean_array[$value['cid']][$value['row_id']]['points'] = $value['points'];
59  $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['type'] = $value['type'];
60  }
61  return $clean_array;
62  }

◆ getGapsWhichAreUsedInCombination()

assClozeGapCombination::getGapsWhichAreUsedInCombination (   $question_id)

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

References $data, $ilDB, and $result.

184  {
185  global $ilDB;
186 
187  $result = $ilDB->queryF('SELECT gap_fi, combination_id FROM `qpl_a_cloze_combi_res` WHERE question_fi = %s GROUP BY gap_fi, combination_id',
188  array('integer'),
189  array($question_id)
190  );
191  $gaps = array();
192  if ($result->numRows() > 0)
193  {
194  while ($data = $ilDB->fetchAssoc($result))
195  {
196  $gaps[$data['gap_fi']] = $data['combination_id'];
197  }
198  }
199  return $gaps;
200  }
$result
global $ilDB

◆ getMaxPointsForCombination()

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

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

References $data, $ilDB, and $result.

203  {
204  global $ilDB;
205 
206  if($combination_id == -1)
207  {
208  $result = $ilDB->queryF('SELECT combination_id, points FROM qpl_a_cloze_combi_res WHERE question_fi = %s AND best_solution=1 GROUP BY combination_id, points',
209  array('integer'),
210  array($question_id)
211  );
212  if ($result->numRows() > 0)
213  {
214  $points = 0;
215  while ($data = $ilDB->fetchAssoc($result))
216  {
217  $points += $data['points'];
218  }
219  return $points;
220  }
221  }
222  else
223  {
224  $result = $ilDB->queryF('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',
225  array('integer', 'integer'),
226  array($question_id, $combination_id)
227  );
228  if ($result->numRows() > 0)
229  {
230  $points = 0;
231  while ($data = $ilDB->fetchAssoc($result))
232  {
233  $points += $data['points'];
234  }
235  return $points;
236  }
237  }
238  return 0;
239  }
$result
global $ilDB

◆ importGapCombinationToDb()

assClozeGapCombination::importGapCombinationToDb (   $question_id,
  $gap_combinations 
)

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

References $ilDB, and $row.

Referenced by assClozeTestImport\fromXML().

120  {
121  global $ilDB;
122 
123  foreach($gap_combinations as $key => $row)
124  {
125  if (is_object($row))
126  {
127  $row = get_object_vars($row);
128  }
129  if($question_id != -1)
130  {
131  $ilDB->manipulateF( 'INSERT INTO qpl_a_cloze_combi_res
132  (combination_id, question_fi, gap_fi, row_id, answer, points, best_solution) VALUES (%s, %s, %s, %s, %s, %s, %s)',
133  array(
134  'integer',
135  'integer',
136  'integer',
137  'integer',
138  'text',
139  'float',
140  'integer'
141  ),
142  array(
143  $row['cid'],
144  $question_id,
145  $row['gap_fi'],
146  $row['row_id'],
147  $row['answer'],
148  $row['points'],
149  $row['best_solution']
150  )
151  );
152  }
153  }
154  }
global $ilDB
+ Here is the caller graph for this function:

◆ loadFromDb()

assClozeGapCombination::loadFromDb (   $question_id)

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

References $data, $ilDB, and $result.

6  {
7  global $ilDB;
8  $result = $ilDB->queryF('
9  SELECT combinations.combination_id,
10  combinations.gap_fi,
11  combinations.answer,
12  combinations.row_id,
13  combinations.points,
14  combinations.best_solution,
15  combinations.question_fi,
16  cloze.cloze_type
17  FROM qpl_a_cloze_combi_res AS combinations
18  INNER JOIN qpl_a_cloze AS cloze
19  WHERE combinations.question_fi = cloze.question_fi
20  AND combinations.gap_fi = cloze.gap_id
21  AND combinations.question_fi = %s
22  ORDER BY combination_id, row_id, gap_fi ASC
23  ',
24  array('integer'),
25  array($question_id)
26  );
27 
28  $return_array = array();
29  while ($data = $ilDB->fetchAssoc($result))
30  {
31  if( isset($return_array[$data['combination_id'].'::'.$data['gap_fi']]) )
32  {
33  continue;
34  }
35 
36  $return_array[$data['combination_id'].'::'.$data['row_id'].'::'.$data['gap_fi']]=array(
37  'cid' => $data['combination_id'],
38  'gap_fi' => $data['gap_fi'],
39  'answer' => $data['answer'],
40  'points' => $data['points'],
41  'row_id' => $data['row_id'],
42  'type' => $data['cloze_type'],
43  'best_solution' => $data['best_solution']
44  );
45  }
46 
47  return array_values($return_array);
48  }
$result
global $ilDB

◆ saveGapCombinationToDb()

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

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

References $ilDB.

65  {
66  global $ilDB;
67  $best_solutions = array();
68  for($i = 0; $i < count($gap_combinations['points']); $i++)
69  {
70  $highest_points = 0;
71  for($j = 0; $j < count($gap_combinations['points'][$i]); $j++)
72  {
73  if($highest_points < $gap_combinations['points'][$i][$j])
74  {
75  $highest_points = $gap_combinations['points'][$i][$j];
76  $best_solutions[$i] = $j;
77  }
78  }
79  }
80  for($i = 0; $i < count($gap_values); $i++)
81  {
82  for($j = 0; $j < count($gap_values[$i]); $j++)
83  {
84  for($k = 0; $k < count($gap_values[$i][$j]); $k++)
85  {
86  if($best_solutions[$i] == $j )
87  {
88  $best_solution = 1;
89  }
90  else
91  {
92  $best_solution = 0;
93  }
94  $ilDB->manipulateF( 'INSERT INTO qpl_a_cloze_combi_res
95  (combination_id, question_fi, gap_fi, row_id, answer, points, best_solution) VALUES (%s, %s, %s, %s, %s, %s, %s)',
96  array(
97  'integer',
98  'integer',
99  'integer',
100  'integer',
101  'text',
102  'float',
103  'integer'
104  ),
105  array(
106  $i,
107  $question_id,
108  $gap_combinations['select'][$i][$k],
109  $j,
110  $gap_values[$i][$j][$k],
111  $gap_combinations['points'][$i][$j],
112  $best_solution
113  )
114  );
115  }
116  }
117  }
118  }
global $ilDB

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