4 include_once
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnit.php";
5 include_once
"./Modules/TestQuestionPool/classes/class.assFormulaQuestionUnitCategory.php";
66 public function isCRUDAllowed($a_category_id)
74 'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
88 public function copyCategory($a_category_id, $a_question_fi, $a_category_name = null)
96 'SELECT category FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
102 if(null === $a_category_name)
103 $a_category_name =
$row[
'category'];
105 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_ucat');
106 $ilDB->insert(
'il_qpl_qst_fq_ucat',
108 'category_id' =>
array(
'integer', $next_id),
109 'category' =>
array(
'text', $a_category_name),
110 'question_fi' =>
array(
'integer', (
int)$a_question_fi)
122 public function copyUnitsByCategories($a_from_category_id, $a_to_category_id, $a_question_fi)
129 $res = $ilDB->queryF(
130 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
132 array($a_from_category_id)
136 while(
$row = $ilDB->fetchAssoc(
$res))
138 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_unit');
141 $units[$i][
'new_unit_id'] = $next_id;
143 $ilDB->insert(
'il_qpl_qst_fq_unit',
145 'unit_id' =>
array(
'integer', $next_id),
147 'factor' =>
array(
'float',
$row[
'factor']),
148 'baseunit_fi' =>
array(
'integer', (
int)
$row[
'baseunit_fi']),
149 'category_fi' =>
array(
'integer', (
int)$a_to_category_id),
150 'sequence' =>
array(
'integer', (
int)$row[
'sequence']),
151 'question_fi' =>
array(
'integer', (
int)$a_question_fi)
159 $ilDB->update(
'il_qpl_qst_fq_unit',
160 array(
'baseunit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
162 'baseunit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
163 'category_fi' =>
array(
'integer', $a_to_category_id)
167 $ilDB->update(
'il_qpl_qst_fq_var',
168 array(
'unit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
170 'unit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
171 'question_fi' =>
array(
'integer', $a_question_fi)
175 $ilDB->update(
'il_qpl_qst_fq_res',
176 array(
'unit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
178 'unit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
179 'question_fi' =>
array(
'integer', $a_question_fi)
183 $ilDB->update(
'il_qpl_qst_fq_res_unit',
184 array(
'unit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
186 'unit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
187 'question_fi' =>
array(
'integer', $a_question_fi)
196 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
207 $result_1 = $ilDB->queryF(
"SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
212 $result_2 = $ilDB->queryF(
"SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
216 $result_3 = $ilDB->queryF(
"SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
221 $cnt_1 = $ilDB->numRows($result_1);
222 $cnt_2 = $ilDB->numRows($result_2);
223 $cnt_3 = $ilDB->numRows($result_3);
225 if($cnt_1 || $cnt_2 || $cnt_3)
239 public function checkDeleteCategory($id)
246 $res = $ilDB->queryF(
247 'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
251 if($ilDB->numRows(
$res))
253 while(
$row = $ilDB->fetchAssoc(
$res))
256 if(!is_null($unit_res))
return $unit_res;
268 $affectedRows = $ilDB->manipulateF(
"DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
281 SELECT units.*, il_qpl_qst_fq_ucat.category, baseunits.unit baseunit_title 282 FROM il_qpl_qst_fq_unit units 283 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 284 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 285 ORDER BY il_qpl_qst_fq_ucat.category, units.sequence" 293 $unit->initFormArray(
$row);
303 if(count($this->categorizedUnits) == 0)
306 SELECT units.*, il_qpl_qst_fq_ucat.category, il_qpl_qst_fq_ucat.question_fi, baseunits.unit baseunit_title 307 FROM il_qpl_qst_fq_unit units 308 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 309 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 310 WHERE units.question_fi = %s 311 ORDER BY il_qpl_qst_fq_ucat.category, units.sequence",
320 $unit->initFormArray(
$row);
321 if(strcmp($category, $unit->getCategory()) != 0)
324 $cat->initFormArray(
array(
325 'category_id' =>
$row[
'category_fi'],
326 'category' =>
$row[
'category'],
327 'question_fi' =>
$row[
'question_fi'],
329 array_push($this->categorizedUnits, $cat);
330 $category = $unit->getCategory();
332 array_push($this->categorizedUnits, $unit);
342 $this->units =
array();
347 $this->units[$unit->getId()] = $unit;
352 if(count($this->units) == 0)
365 SELECT units.*, baseunits.unit baseunit_title 366 FROM il_qpl_qst_fq_unit units 367 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 368 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 369 WHERE il_qpl_qst_fq_ucat.category_id = %s 370 ORDER BY units.sequence",
379 $unit->initFormArray(
$row);
380 array_push(
$units, $unit);
393 if(count($this->units) == 0)
397 if(array_key_exists($id, $this->units))
399 return $this->units[$id];
407 if(array_key_exists($id, $this->units))
409 return $this->units[$id];
420 $categories =
array();
421 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi > %s ORDER BY category",
427 $value = (strcmp(
"-qpl_qst_formulaquestion_" .
$row[
"category"] .
"-", $this->lng->txt(
$row[
"category"])) == 0) ?
$row[
"category"] : $this->lng->txt(
$row[
"category"]);
429 if(strlen(trim(
$row[
"category"])))
432 "value" =>
$row[
"category_id"],
434 "qst_id" =>
$row[
'question_fi']
436 $categories[
$row[
"category_id"]] = $cat;
448 $categories =
array();
449 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s ORDER BY category",
455 $value = (strcmp(
"-qpl_qst_formulaquestion_" .
$row[
"category"] .
"-", $this->lng->txt(
$row[
"category"])) == 0) ?
$row[
"category"] : $this->lng->txt(
$row[
"category"]);
457 if(strlen(trim(
$row[
"category"])))
460 "value" =>
$row[
"category_id"],
462 "qst_id" =>
$row[
'question_fi']
464 $categories[
$row[
"category_id"]] = $cat;
476 public function saveUnitOrder($unit_id, $sequence)
484 UPDATE il_qpl_qst_fq_unit 486 WHERE unit_id = %s AND question_fi = %s 488 array(
'integer',
'integer',
'integer'),
497 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
503 return $this->lng->txt(
"err_unit_in_variables");
505 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
511 return $this->lng->txt(
"err_unit_in_results");
513 if(!is_null($category_id))
515 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND category_fi != %s",
516 array(
'integer',
'integer',
'integer'),
517 array($id, $id, $category_id)
522 $result = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
523 array(
'integer',
'integer'),
529 return $this->lng->txt(
"err_unit_is_baseunit");
539 public function getUnitCategoryById($id)
546 $query =
'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = ' . $ilDB->quote($id,
'integer');
548 if(!$ilDB->numRows(
$res))
555 $category->initFormArray(
$row);
570 $res = $ilDB->queryF(
571 'SELECT * FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s AND category_id != %s',
572 array(
'text',
'integer',
'integer'),
575 if($ilDB->numRows(
$res))
581 'UPDATE il_qpl_qst_fq_ucat SET category = %s WHERE question_fi = %s AND category_id = %s',
582 array(
'text',
'integer',
'integer'),
598 $res = $ilDB->queryF(
599 'SELECT category FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s',
600 array(
'text',
'integer'),
603 if($ilDB->numRows(
$res))
608 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_ucat');
610 "INSERT INTO il_qpl_qst_fq_ucat (category_id, category, question_fi) VALUES (%s, %s, %s)",
611 array(
'integer',
'text',
'integer'),
618 $category->
setId($next_id);
624 public function getAllUnitCategories()
631 $categories =
array();
633 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s OR question_fi = %s ORDER BY category",
634 array(
'integer',
'integer'),
643 $categories[] = $category;
653 public function deleteCategory($id)
660 $res = $this->checkDeleteCategory($id);
661 if(!is_null(
$res))
return $this->lng->txt(
'err_category_in_use');
663 $res = $ilDB->queryF(
664 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
668 while(
$row = $ilDB->fetchAssoc(
$res))
672 $ar = $ilDB->manipulateF(
'DELETE FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
693 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_unit');
695 'INSERT INTO il_qpl_qst_fq_unit (unit_id, unit, factor, baseunit_fi, category_fi, sequence, question_fi) VALUES (%s, %s, %s, %s, %s, %s, %s)',
696 array(
'integer',
'text',
'float',
'integer',
'integer',
'integer',
'integer'),
707 $unit->
setId($next_id);
725 $res = $ilDB->queryF(
726 'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE unit_id = %s',
730 if($ilDB->fetchAssoc(
$res))
733 $sequence =
$row[
'sequence'];
738 $ar = $ilDB->manipulateF(
739 'UPDATE il_qpl_qst_fq_unit SET unit = %s, factor = %s, baseunit_fi = %s, category_fi = %s, sequence = %s WHERE unit_id = %s AND question_fi = %s',
740 array(
'text',
'float',
'integer',
'integer',
'integer',
'integer',
'integer'),
754 public function cloneUnits($a_from_consumer_id, $a_to_consumer_id)
761 $category_mapping =
array();
763 $res = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
array(
'integer'),
array($a_from_consumer_id));
764 while(
$row = $ilDB->fetchAssoc(
$res))
766 $new_category_id = $this->copyCategory(
$row[
'category_id'], $a_to_consumer_id);
767 $category_mapping[
$row[
'category_id']] = $new_category_id;
770 foreach($category_mapping as $old_category_id => $new_category_id)
772 $res = $ilDB->queryF(
773 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
775 array($old_category_id)
780 while(
$row = $ilDB->fetchAssoc(
$res))
782 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_unit');
785 $units[$i][
'new_unit_id'] = $next_id;
787 $ilDB->insert(
'il_qpl_qst_fq_unit',
789 'unit_id' =>
array(
'integer', $next_id),
791 'factor' =>
array(
'float',
$row[
'factor']),
792 'baseunit_fi' =>
array(
'integer', (
int)
$row[
'baseunit_fi']),
793 'category_fi' =>
array(
'integer', (
int)$new_category_id),
794 'sequence' =>
array(
'integer', (
int)$row[
'sequence']),
795 'question_fi' =>
array(
'integer', (
int)$a_to_consumer_id)
803 $ilDB->update(
'il_qpl_qst_fq_unit',
804 array(
'baseunit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
806 'baseunit_fi' =>
array(
'integer', (
int)$unit[
'old_unit_id']),
807 'question_fi' =>
array(
'integer', (
int)$a_to_consumer_id)
811 $ilDB->update(
'il_qpl_qst_fq_var',
812 array(
'unit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
814 'unit_fi' =>
array(
'integer', (
int)$unit[
'old_unit_id']),
815 'question_fi' =>
array(
'integer', (
int)$a_to_consumer_id)
819 $ilDB->update(
'il_qpl_qst_fq_res',
820 array(
'unit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
822 'unit_fi' =>
array(
'integer', (
int)$unit[
'old_unit_id']),
823 'question_fi' =>
array(
'integer', (
int)$a_to_consumer_id)
827 $ilDB->update(
'il_qpl_qst_fq_res_unit',
828 array(
'unit_fi' =>
array(
'integer', (
int)$unit[
'new_unit_id'])),
830 'unit_fi' =>
array(
'integer', (
int)$unit[
'old_unit_id']),
831 'question_fi' =>
array(
'integer', (
int) $a_to_consumer_id)
Base class for ILIAS Exception handling.
Class ilUnitConfigurationRepository.
getCategoryUnitCount($id)
loadUnitsForCategory($category)
setConsumerId($consumer_id)
Create styles array
The data for the language used.
checkDeleteUnit($id, $category_id=null)