3 declare(strict_types=1);
38 $lng = $DIC->language();
40 $this->db = $DIC->database();
57 $res = $this->db->queryF(
58 'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
62 $row = $this->db->fetchAssoc(
$res);
63 return isset($row[
'question_fi']) && (
int) $row[
'question_fi'] === $this->
getConsumerId();
66 public function copyCategory(
int $category_id,
int $question_fi, ?
string $category_name = null):
int 68 $res = $this->db->queryF(
69 'SELECT category FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
73 $row = $this->db->fetchAssoc(
$res);
75 if (null === $category_name) {
76 $category_name = $row[
'category'];
79 $next_id = $this->db->nextId(
'il_qpl_qst_fq_ucat');
83 'category_id' => [
'integer', $next_id],
84 'category' => [
'text', $category_name],
85 'question_fi' => [
'integer', (
int) $question_fi]
94 $res = $this->db->queryF(
95 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
101 while ($row = $this->db->fetchAssoc(
$res)) {
102 $next_id = $this->db->nextId(
'il_qpl_qst_fq_unit');
104 $units[
$i][
'old_unit_id'] = $row[
'unit_id'];
105 $units[
$i][
'new_unit_id'] = $next_id;
108 'il_qpl_qst_fq_unit',
110 'unit_id' => [
'integer', $next_id],
111 'unit' => [
'text', $row[
'unit']],
112 'factor' => [
'float', $row[
'factor']],
113 'baseunit_fi' => [
'integer', (
int) $row[
'baseunit_fi']],
114 'category_fi' => [
'integer', (
int) $to_category_id],
115 'sequence' => [
'integer', (
int) $row[
'sequence']],
116 'question_fi' => [
'integer', (
int) $qustion_fi]
122 foreach ($units as $unit) {
125 'il_qpl_qst_fq_unit',
126 [
'baseunit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
128 'baseunit_fi' => [
'integer', $unit[
'old_unit_id']],
129 'category_fi' => [
'integer', $to_category_id]
136 [
'unit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
138 'unit_fi' => [
'integer', $unit[
'old_unit_id']],
139 'question_fi' => [
'integer', $qustion_fi]
146 [
'unit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
148 'unit_fi' => [
'integer', $unit[
'old_unit_id']],
149 'question_fi' => [
'integer', $qustion_fi]
155 'il_qpl_qst_fq_res_unit',
156 [
'unit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
158 'unit_fi' => [
'integer', $unit[
'old_unit_id']],
159 'question_fi' => [
'integer', $qustion_fi]
167 $result = $this->db->queryF(
168 "SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s",
173 return $this->db->numRows($result);
178 $result_1 = $this->db->queryF(
179 "SELECT unit_fi FROM il_qpl_qst_fq_res_unit WHERE unit_fi = %s",
184 $result_2 = $this->db->queryF(
185 "SELECT unit_fi FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
189 $result_3 = $this->db->queryF(
190 "SELECT unit_fi FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
195 $cnt_1 = $this->db->numRows($result_1);
196 $cnt_2 = $this->db->numRows($result_2);
197 $cnt_3 = $this->db->numRows($result_3);
199 return $cnt_1 > 0 || $cnt_2 > 0 || $cnt_3 > 0;
204 $res = $this->db->queryF(
205 'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
210 if ($this->db->numRows(
$res)) {
211 while ($row = $this->db->fetchAssoc(
$res)) {
213 if (!is_null($unit_res)) {
225 if (!is_null(
$res)) {
229 $affectedRows = $this->db->manipulateF(
230 "DELETE FROM il_qpl_qst_fq_unit WHERE unit_id = %s",
235 if ($affectedRows > 0) {
244 $result = $this->db->query(
246 SELECT units.*, il_qpl_qst_fq_ucat.category, baseunits.unit baseunit_title 247 FROM il_qpl_qst_fq_unit units 248 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 249 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 250 ORDER BY il_qpl_qst_fq_ucat.category, units.sequence" 253 if ($this->db->numRows($result)) {
254 while ($row = $this->db->fetchAssoc($result)) {
256 $unit->initFormArray($row);
267 if (count($this->categorizedUnits) === 0) {
268 $result = $this->db->queryF(
270 SELECT units.*, il_qpl_qst_fq_ucat.category, il_qpl_qst_fq_ucat.question_fi, baseunits.unit baseunit_title 271 FROM il_qpl_qst_fq_unit units 272 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 273 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 274 WHERE units.question_fi = %s 275 ORDER BY il_qpl_qst_fq_ucat.category, units.sequence",
280 if ($this->db->numRows($result) > 0) {
282 while ($row = $this->db->fetchAssoc($result)) {
284 $unit->initFormArray($row);
286 if ($category !== $unit->getCategory()) {
288 $cat->initFormArray([
289 'category_id' => (
int) $row[
'category_fi'],
290 'category' => $row[
'category'],
291 'question_fi' => (
int) $row[
'question_fi'],
293 $this->categorizedUnits[] = $cat;
294 $category = $unit->getCategory();
297 $this->categorizedUnits[] = $unit;
312 $this->units[$unit->
getId()] = $unit;
320 if (count($this->units) === 0) {
333 $ilDB = $DIC[
'ilDB'];
336 $result =
$ilDB->queryF(
337 "SELECT units.*, baseunits.unit baseunit_title, il_qpl_qst_fq_ucat.category 338 FROM il_qpl_qst_fq_unit units 339 INNER JOIN il_qpl_qst_fq_ucat ON il_qpl_qst_fq_ucat.category_id = units.category_fi 340 LEFT JOIN il_qpl_qst_fq_unit baseunits ON baseunits.unit_id = units.baseunit_fi 341 WHERE il_qpl_qst_fq_ucat.category_id = %s 342 ORDER BY units.sequence",
347 if ($result->numRows() > 0) {
348 while ($row =
$ilDB->fetchAssoc($result)) {
350 $unit->initFormArray($row);
364 if (count($this->units) === 0) {
368 if (array_key_exists($id, $this->units)) {
369 return $this->units[
$id];
376 return $this->units[
$id] ?? null;
385 $result = $this->db->queryF(
386 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi > %s ORDER BY category",
391 if ($this->db->numRows($result)) {
392 while ($row = $this->db->fetchAssoc($result)) {
393 $value = strcmp(
'-qpl_qst_formulaquestion_' . $row[
'category'] .
'-', $this->
lng->txt($row[
'category'])) === 0
395 : $this->
lng->txt($row[
'category']);
397 if (trim($row[
'category']) !==
'') {
399 'value' => (
int) $row[
'category_id'],
401 'qst_id' => (
int) $row[
'question_fi']
403 $categories[(
int) $row[
'category_id']] = $cat;
418 $result = $this->db->queryF(
419 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s ORDER BY category",
424 if ($result = $this->db->numRows($result)) {
425 while ($row = $this->db->fetchAssoc($result)) {
426 $value = strcmp(
'-qpl_qst_formulaquestion_' . $row[
'category'] .
'-', $this->
lng->txt($row[
'category'])) === 0
428 : $this->
lng->txt($row[
'category']);
430 if (trim($row[
'category']) !==
'') {
432 'value' => (
int) $row[
'category_id'],
434 'qst_id' => (
int) $row[
'question_fi']
436 $categories[(
int) $row[
'category_id']] = $cat;
446 $this->db->manipulateF(
447 'UPDATE il_qpl_qst_fq_unit SET sequence = %s WHERE unit_id = %s AND question_fi = %s',
448 [
'integer',
'integer',
'integer'],
455 $result = $this->db->queryF(
456 "SELECT * FROM il_qpl_qst_fq_var WHERE unit_fi = %s",
460 if ($this->db->numRows($result) > 0) {
461 return $this->
lng->txt(
"err_unit_in_variables");
464 $result = $this->db->queryF(
465 "SELECT * FROM il_qpl_qst_fq_res WHERE unit_fi = %s",
469 if ($this->db->numRows($result) > 0) {
470 return $this->
lng->txt(
"err_unit_in_results");
473 if (!is_null($category_id)) {
474 $result = $this->db->queryF(
475 "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND category_fi != %s",
476 [
'integer',
'integer',
'integer'],
477 [$id, $id, $category_id]
480 $result = $this->db->queryF(
481 "SELECT * FROM il_qpl_qst_fq_unit WHERE baseunit_fi = %s AND unit_id != %s",
482 [
'integer',
'integer'],
487 if ($this->db->numRows($result) > 0) {
488 return $this->
lng->txt(
"err_unit_is_baseunit");
496 $query =
'SELECT * FROM il_qpl_qst_fq_ucat WHERE category_id = ' . $this->db->quote($id,
'integer');
498 if (!$this->db->numRows(
$res)) {
502 $row = $this->db->fetchAssoc(
$res);
504 $category->initFormArray($row);
510 $res = $this->db->queryF(
511 'SELECT * FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s AND category_id != %s',
512 [
'text',
'integer',
'integer'],
515 if ($this->db->numRows(
$res)) {
519 $this->db->manipulateF(
520 'UPDATE il_qpl_qst_fq_ucat SET category = %s WHERE question_fi = %s AND category_id = %s',
521 [
'text',
'integer',
'integer'],
528 $res = $this->db->queryF(
529 'SELECT category FROM il_qpl_qst_fq_ucat WHERE category = %s AND question_fi = %s',
533 if ($this->db->numRows(
$res)) {
537 $next_id = $this->db->nextId(
'il_qpl_qst_fq_ucat');
538 $this->db->manipulateF(
539 "INSERT INTO il_qpl_qst_fq_ucat (category_id, category, question_fi) VALUES (%s, %s, %s)",
540 [
'integer',
'text',
'integer'],
547 $category->
setId($next_id);
556 $result = $this->db->queryF(
557 "SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s OR question_fi = %s ORDER BY category",
558 [
'integer',
'integer'],
562 if ($result->numRows() > 0) {
563 while ($row = $this->db->fetchAssoc($result)) {
565 $category->initFormArray($row);
566 $categories[] = $category;
575 if (!is_null(
$res)) {
576 return $this->
lng->txt(
'err_category_in_use');
579 $res = $this->db->queryF(
580 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
584 while ($row = $this->db->fetchAssoc(
$res)) {
588 $ar = $this->db->manipulateF(
589 'DELETE FROM il_qpl_qst_fq_ucat WHERE category_id = %s',
603 $next_id = $this->db->nextId(
'il_qpl_qst_fq_unit');
604 $this->db->manipulateF(
605 '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)',
606 [
'integer',
'text',
'float',
'integer',
'integer',
'integer',
'integer'],
617 $unit->
setId($next_id);
627 $res = $this->db->queryF(
628 'SELECT unit_id FROM il_qpl_qst_fq_unit WHERE unit_id = %s',
632 if ($this->db->numRows(
$res)) {
633 $row = $this->db->fetchAssoc(
$res);
639 $ar = $this->db->manipulateF(
640 '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',
641 [
'text',
'float',
'integer',
'integer',
'integer',
'integer',
'integer'],
656 public function cloneUnits(
int $from_consumer_id,
int $to_consumer_id): void
658 $category_mapping = [];
660 $res = $this->db->queryF(
"SELECT * FROM il_qpl_qst_fq_ucat WHERE question_fi = %s", [
'integer'], [$from_consumer_id]);
661 while ($row = $this->db->fetchAssoc(
$res)) {
662 $new_category_id = $this->
copyCategory((
int) $row[
'category_id'], $to_consumer_id);
663 $category_mapping[$row[
'category_id']] = $new_category_id;
666 foreach ($category_mapping as $old_category_id => $new_category_id) {
667 $res = $this->db->queryF(
668 'SELECT * FROM il_qpl_qst_fq_unit WHERE category_fi = %s',
675 while ($row = $this->db->fetchAssoc(
$res)) {
676 $next_id = $this->db->nextId(
'il_qpl_qst_fq_unit');
678 $units[
$i][
'old_unit_id'] = $row[
'unit_id'];
679 $units[
$i][
'new_unit_id'] = $next_id;
682 'il_qpl_qst_fq_unit',
684 'unit_id' => [
'integer', $next_id],
685 'unit' => [
'text', $row[
'unit']],
686 'factor' => [
'float', $row[
'factor']],
687 'baseunit_fi' => [
'integer', (
int) $row[
'baseunit_fi']],
688 'category_fi' => [
'integer', (
int) $new_category_id],
689 'sequence' => [
'integer', (
int) $row[
'sequence']],
690 'question_fi' => [
'integer', $to_consumer_id]
696 foreach ($units as $unit) {
699 'il_qpl_qst_fq_unit',
700 [
'baseunit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
702 'baseunit_fi' => [
'integer', (
int) $unit[
'old_unit_id']],
703 'question_fi' => [
'integer', $to_consumer_id]
710 [
'unit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
712 'unit_fi' => [
'integer', (
int) $unit[
'old_unit_id']],
713 'question_fi' => [
'integer', $to_consumer_id]
720 [
'unit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
722 'unit_fi' => [
'integer', (
int) $unit[
'old_unit_id']],
723 'question_fi' => [
'integer', $to_consumer_id]
729 'il_qpl_qst_fq_res_unit',
730 [
'unit_fi' => [
'integer', (
int) $unit[
'new_unit_id']]],
732 'unit_fi' => [
'integer', (
int) $unit[
'old_unit_id']],
733 'question_fi' => [
'integer', $to_consumer_id]
setConsumerId(int $consumer_id)
saveCategory(assFormulaQuestionUnitCategory $category)
loadUnitsForCategory(int $category)
createNewUnit(assFormulaQuestionUnit $unit)
getCategoryUnitCount(int $id)
__construct(int $consumer_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
copyUnitsByCategories(int $from_category_id, int $to_category_id, int $qustion_fi)
checkDeleteUnit(int $id, ?int $category_id=null)
saveUnitOrder(int $unit_id, int $sequence)
copyCategory(int $category_id, int $question_fi, ?string $category_name=null)
addUnit(assFormulaQuestionUnit $unit)
isCRUDAllowed(int $category_id)
checkDeleteCategory(int $id)
saveUnit(assFormulaQuestionUnit $unit)
getUnitCategoryById(int $id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
saveNewUnitCategory(assFormulaQuestionUnitCategory $category)
cloneUnits(int $from_consumer_id, int $to_consumer_id)