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'];
106 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_ucat');
108 'il_qpl_qst_fq_ucat',
110 'category_id' =>
array(
'integer', $next_id),
111 'category' =>
array(
'text', $a_category_name),
112 'question_fi' =>
array(
'integer', (
int) $a_question_fi)
124 public function copyUnitsByCategories($a_from_category_id, $a_to_category_id, $a_question_fi)
131 $res = $ilDB->queryF(
132 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
134 array($a_from_category_id)
138 while (
$row = $ilDB->fetchAssoc(
$res)) {
139 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_unit');
142 $units[
$i][
'new_unit_id'] = $next_id;
145 'il_qpl_qst_fq_unit',
147 'unit_id' =>
array(
'integer', $next_id),
149 'factor' =>
array(
'float',
$row[
'factor']),
150 'baseunit_fi' =>
array(
'integer', (
int)
$row[
'baseunit_fi']),
151 'category_fi' =>
array(
'integer', (
int) $a_to_category_id),
152 'sequence' =>
array(
'integer', (
int) $row[
'sequence']),
153 'question_fi' =>
array(
'integer', (
int) $a_question_fi)
159 foreach (
$units as $unit) {
162 'il_qpl_qst_fq_unit',
163 array(
'baseunit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
165 'baseunit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
166 'category_fi' =>
array(
'integer', $a_to_category_id)
173 array(
'unit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
175 'unit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
176 'question_fi' =>
array(
'integer', $a_question_fi)
183 array(
'unit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
185 'unit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
186 'question_fi' =>
array(
'integer', $a_question_fi)
192 'il_qpl_qst_fq_res_unit',
193 array(
'unit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
195 'unit_fi' =>
array(
'integer', $unit[
'old_unit_id']),
196 'question_fi' =>
array(
'integer', $a_question_fi)
207 "SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
218 $result_1 = $ilDB->queryF(
219 "SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
224 $result_2 = $ilDB->queryF(
225 "SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
229 $result_3 = $ilDB->queryF(
230 "SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
235 $cnt_1 = $ilDB->numRows($result_1);
236 $cnt_2 = $ilDB->numRows($result_2);
237 $cnt_3 = $ilDB->numRows($result_3);
239 if ($cnt_1 || $cnt_2 || $cnt_3) {
250 public function checkDeleteCategory(
$id)
257 $res = $ilDB->queryF(
258 'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
262 if ($ilDB->numRows(
$res)) {
263 while (
$row = $ilDB->fetchAssoc(
$res)) {
265 if (!is_null($unit_res)) {
278 if (!is_null(
$res)) {
281 $affectedRows = $ilDB->manipulateF(
282 "DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
286 if ($affectedRows > 0) {
298 SELECT units.*, il_qpl_qst_fq_ucat.category, baseunits.unit baseunit_title 299 FROM il_qpl_qst_fq_unit units 300 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 301 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 302 ORDER BY il_qpl_qst_fq_ucat.category, units.sequence" 308 $unit->initFormArray(
$row);
318 if (count($this->categorizedUnits) == 0) {
321 SELECT units.*, il_qpl_qst_fq_ucat.category, il_qpl_qst_fq_ucat.question_fi, baseunits.unit baseunit_title 322 FROM il_qpl_qst_fq_unit units 323 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 324 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 325 WHERE units.question_fi = %s 326 ORDER BY il_qpl_qst_fq_ucat.category, units.sequence",
335 $unit->initFormArray(
$row);
336 if (strcmp($category, $unit->getCategory()) != 0) {
338 $cat->initFormArray(
array(
339 'category_id' =>
$row[
'category_fi'],
340 'category' =>
$row[
'category'],
341 'question_fi' =>
$row[
'question_fi'],
343 array_push($this->categorizedUnits, $cat);
344 $category = $unit->getCategory();
346 array_push($this->categorizedUnits, $unit);
356 $this->units =
array();
361 $this->units[$unit->getId()] = $unit;
366 if (count($this->units) == 0) {
379 SELECT units.*, baseunits.unit baseunit_title 380 FROM il_qpl_qst_fq_unit units 381 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 382 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 383 WHERE il_qpl_qst_fq_ucat.category_id = %s 384 ORDER BY units.sequence",
391 $unit->initFormArray(
$row);
392 array_push(
$units, $unit);
404 if (count($this->units) == 0) {
407 if (array_key_exists(
$id, $this->units)) {
408 return $this->units[
$id];
414 if (array_key_exists(
$id, $this->units)) {
415 return $this->units[
$id];
426 $categories =
array();
428 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi > %s ORDER BY category",
434 $value = (strcmp(
"-qpl_qst_formulaquestion_" .
$row[
"category"] .
"-", $this->lng->txt(
$row[
"category"])) == 0) ?
$row[
"category"] : $this->lng->txt(
$row[
"category"]);
436 if (strlen(trim(
$row[
"category"]))) {
438 "value" =>
$row[
"category_id"],
440 "qst_id" =>
$row[
'question_fi']
442 $categories[
$row[
"category_id"]] = $cat;
453 $categories =
array();
455 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s ORDER BY category",
461 $value = (strcmp(
"-qpl_qst_formulaquestion_" .
$row[
"category"] .
"-", $this->lng->txt(
$row[
"category"])) == 0) ?
$row[
"category"] : $this->lng->txt(
$row[
"category"]);
463 if (strlen(trim(
$row[
"category"]))) {
465 "value" =>
$row[
"category_id"],
467 "qst_id" =>
$row[
'question_fi']
469 $categories[
$row[
"category_id"]] = $cat;
481 public function saveUnitOrder($unit_id, $sequence)
490 UPDATE il_qpl_qst_fq_unit 492 WHERE unit_id = %s AND question_fi = %s 494 array(
'integer',
'integer',
'integer'),
504 "SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
509 return $this->lng->txt(
"err_unit_in_variables");
512 "SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
517 return $this->lng->txt(
"err_unit_in_results");
519 if (!is_null($category_id)) {
521 "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND category_fi != %s",
522 array(
'integer',
'integer',
'integer'),
527 "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
528 array(
'integer',
'integer'),
533 return $this->lng->txt(
"err_unit_is_baseunit");
543 public function getUnitCategoryById(
$id)
550 $query =
'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = ' . $ilDB->quote(
$id,
'integer');
552 if (!$ilDB->numRows(
$res)) {
558 $category->initFormArray(
$row);
573 $res = $ilDB->queryF(
574 'SELECT * FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s AND category_id != %s',
575 array(
'text',
'integer',
'integer'),
578 if ($ilDB->numRows(
$res)) {
583 'UPDATE il_qpl_qst_fq_ucat SET category = %s WHERE question_fi = %s AND category_id = %s',
584 array(
'text',
'integer',
'integer'),
600 $res = $ilDB->queryF(
601 'SELECT category FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s',
602 array(
'text',
'integer'),
605 if ($ilDB->numRows(
$res)) {
609 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_ucat');
611 "INSERT INTO il_qpl_qst_fq_ucat (category_id, category, question_fi) VALUES (%s, %s, %s)",
612 array(
'integer',
'text',
'integer'),
619 $category->
setId($next_id);
625 public function getAllUnitCategories()
632 $categories =
array();
634 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s OR question_fi = %s ORDER BY category",
635 array(
'integer',
'integer'),
642 $categories[] = $category;
652 public function deleteCategory(
$id)
659 $res = $this->checkDeleteCategory(
$id);
660 if (!is_null(
$res)) {
661 return $this->lng->txt(
'err_category_in_use');
664 $res = $ilDB->queryF(
665 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
669 while (
$row = $ilDB->fetchAssoc(
$res)) {
672 $ar = $ilDB->manipulateF(
673 '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)) {
732 $sequence =
$row[
'sequence'];
736 $ar = $ilDB->manipulateF(
737 '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',
738 array(
'text',
'float',
'integer',
'integer',
'integer',
'integer',
'integer'),
751 public function cloneUnits($a_from_consumer_id, $a_to_consumer_id)
758 $category_mapping =
array();
760 $res = $ilDB->queryF(
"SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s",
array(
'integer'),
array($a_from_consumer_id));
761 while (
$row = $ilDB->fetchAssoc(
$res)) {
762 $new_category_id = $this->copyCategory(
$row[
'category_id'], $a_to_consumer_id);
763 $category_mapping[
$row[
'category_id']] = $new_category_id;
766 foreach ($category_mapping as $old_category_id => $new_category_id) {
767 $res = $ilDB->queryF(
768 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
770 array($old_category_id)
775 while (
$row = $ilDB->fetchAssoc(
$res)) {
776 $next_id = $ilDB->nextId(
'il_qpl_qst_fq_unit');
779 $units[
$i][
'new_unit_id'] = $next_id;
782 'il_qpl_qst_fq_unit',
784 'unit_id' =>
array(
'integer', $next_id),
786 'factor' =>
array(
'float',
$row[
'factor']),
787 'baseunit_fi' =>
array(
'integer', (
int)
$row[
'baseunit_fi']),
788 'category_fi' =>
array(
'integer', (
int) $new_category_id),
789 'sequence' =>
array(
'integer', (
int) $row[
'sequence']),
790 'question_fi' =>
array(
'integer', (
int) $a_to_consumer_id)
796 foreach (
$units as $unit) {
799 'il_qpl_qst_fq_unit',
800 array(
'baseunit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
802 'baseunit_fi' =>
array(
'integer', (
int) $unit[
'old_unit_id']),
803 'question_fi' =>
array(
'integer', (
int) $a_to_consumer_id)
810 array(
'unit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
812 'unit_fi' =>
array(
'integer', (
int) $unit[
'old_unit_id']),
813 'question_fi' =>
array(
'integer', (
int) $a_to_consumer_id)
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)
829 'il_qpl_qst_fq_res_unit',
830 array(
'unit_fi' =>
array(
'integer', (
int) $unit[
'new_unit_id'])),
832 'unit_fi' =>
array(
'integer', (
int) $unit[
'old_unit_id']),
833 'question_fi' =>
array(
'integer', (
int) $a_to_consumer_id)
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilUnitConfigurationRepository.
foreach($_POST as $key=> $value) $res
getCategoryUnitCount($id)
loadUnitsForCategory($category)
setConsumerId($consumer_id)
Create styles array
The data for the language used.
checkDeleteUnit($id, $category_id=null)