ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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

 __construct (private readonly ilDBInterface $db)
 
 loadFromDb (int $question_id)
 
 getCleanCombinationArray (int $question_id)
 
 saveGapCombinationToDb (int $question_id, array $gap_combinations, array $gap_values)
 
 importGapCombinationToDb (int $question_id, array $gap_combinations)
 
 clearGapCombinationsFromDb ($question_id)
 
 combinationExistsForQid ($question_id)
 
 getGapsWhichAreUsedInCombination ($question_id)
 
 getMaxPointsForCombination (int $question_id, int $combination_id=-1)
 

Private Member Functions

 fetchResult (int $question_id, int $combination_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.

Constructor & Destructor Documentation

◆ __construct()

assClozeGapCombination::__construct ( private readonly ilDBInterface  $db)

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

23 {
24
25 }

Member Function Documentation

◆ clearGapCombinationsFromDb()

assClozeGapCombination::clearGapCombinationsFromDb (   $question_id)

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

164 : void
165 {
166 $this->db->manipulateF(
167 'DELETE FROM qpl_a_cloze_combi_res WHERE question_fi = %s',
168 [ 'integer' ],
169 [ $question_id ]
170 );
171 }

◆ combinationExistsForQid()

assClozeGapCombination::combinationExistsForQid (   $question_id)

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

173 : bool
174 {
175 $result = $this->db->queryF(
176 'SELECT * FROM qpl_a_cloze_combi_res WHERE question_fi = %s ORDER BY gap_fi ASC',
177 ['integer'],
178 [$question_id]
179 );
180 if ($result->numRows() > 0) {
181 return true;
182 }
183 return false;
184 }

◆ fetchResult()

assClozeGapCombination::fetchResult ( int  $question_id,
int  $combination_id 
)
private

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

221 if ($combination_id === -1) {
222 return $this->db->queryF(
223 'SELECT combination_id, points' . PHP_EOL
224 . 'FROM qpl_a_cloze_combi_res' . PHP_EOL
225 . 'WHERE question_fi = %s' . PHP_EOL
226 . 'AND best_solution=1' . PHP_EOL
227 . 'GROUP BY combination_id, points',
228 ['integer'],
229 [$question_id]
230 );
231 }
232 return $this->db->queryF(
233 'SELECT combination_id, points' . PHP_EOL
234 . 'FROM qpl_a_cloze_combi_res' . PHP_EOL
235 . 'WHERE question_fi = %s' . PHP_EOL
236 . 'AND combination_id = %s' . PHP_EOL
237 . 'AND best_solution=1' . PHP_EOL
238 . 'GROUP BY combination_id, points',
239 ['integer', 'integer'],
240 [$question_id, $combination_id]
241 );
242 }
Class ilPDOStatement is a Wrapper Class for PDOStatement.

◆ getCleanCombinationArray()

assClozeGapCombination::getCleanCombinationArray ( int  $question_id)

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

69 : array
70 {
71 $combination_from_db = $this->loadFromDb($question_id);
72 $clean_array = [];
73 foreach ($combination_from_db as $key => $value) {
74 $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['answer'] = $value['answer'];
75 $clean_array[$value['cid']][$value['row_id']]['points'] = $value['points'];
76 $clean_array[$value['cid']][$value['row_id']][$value['gap_fi']]['type'] = $value['type'];
77 }
78 return $clean_array;
79 }

References loadFromDb().

+ Here is the call graph for this function:

◆ getGapsWhichAreUsedInCombination()

assClozeGapCombination::getGapsWhichAreUsedInCombination (   $question_id)

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

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

References $data.

◆ getMaxPointsForCombination()

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

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

207 : float {
208 $result = $this->fetchResult($question_id, $combination_id);
209
210 $points = 0.0;
211 while (($data = $this->db->fetchAssoc($result)) !== null) {
212 $points += $data['points'];
213 }
214 return $points;
215 }
fetchResult(int $question_id, int $combination_id)

References $data.

◆ importGapCombinationToDb()

assClozeGapCombination::importGapCombinationToDb ( int  $question_id,
array  $gap_combinations 
)

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

130 : void
131 {
132 foreach ($gap_combinations as $row) {
133 if (is_object($row)) {
134 $row = get_object_vars($row);
135 }
136 if ($question_id != -1) {
137 $this->db->manipulateF(
138 'INSERT INTO qpl_a_cloze_combi_res
139 (combination_id, question_fi, gap_fi, row_id, answer, points, best_solution)
140 VALUES (%s, %s, %s, %s, %s, %s, %s)',
141 [
142 'integer',
143 'integer',
144 'integer',
145 'integer',
146 'text',
147 'float',
148 'integer'
149 ],
150 [
151 $row['cid'],
152 $question_id,
153 $row['gap_fi'],
154 $row['row_id'],
155 $row['answer'],
156 $row['points'],
157 $row['best_solution']
158 ]
159 );
160 }
161 }
162 }

◆ loadFromDb()

assClozeGapCombination::loadFromDb ( int  $question_id)

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

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

References $data.

Referenced by getCleanCombinationArray().

+ Here is the caller graph for this function:

◆ saveGapCombinationToDb()

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

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

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

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