46 $this->
logger = $DIC->logger()->crs();
48 $this->db = $DIC->database();
49 $this->tree = $DIC->repositoryTree();
51 $this->objective_id = $a_objective_id;
62 $ilDB = $DIC->database();
63 $query =
'SELECT objective_id FROM crs_objective_qst ' .
64 'WHERE question_id = ' .
$ilDB->quote($a_qid,
'integer');
66 $objectiveIds = array();
68 $objectiveIds[] = (
int) $row->objective_id;
77 $ilDB = $DIC->database();
79 $query =
"SELECT qst_ass_id FROM crs_objective_qst " .
80 "WHERE ref_id = " .
$ilDB->quote($a_test_id,
'integer') .
" " .
81 "AND objective_id = " .
$ilDB->quote($a_objective_id,
'integer');
83 return (
bool)
$res->numRows();
89 $mappings = $cwo->getMappings();
91 $mapping_key = $question[
'ref_id'] .
'_question_' . $question[
'question_id'];
92 if (!isset($mappings[$mapping_key]) || !$mappings[$mapping_key]) {
95 $question_ref_id = $question[
'ref_id'];
96 $question_obj_id = $question[
'obj_id'];
97 $question_qst_id = $question[
'question_id'];
98 $new_ref_id = (
int) $mappings[$question_ref_id];
101 if ($new_obj_id == $question_obj_id) {
102 $this->
logger->info(
'Test has been linked. Keeping question id');
104 $new_question_id = $question_qst_id;
106 $new_question_info = $mappings[$question_ref_id .
'_question_' . $question_qst_id];
107 $new_question_arr = explode(
'_', $new_question_info);
108 if (!isset($new_question_arr[2]) || !$new_question_arr[2]) {
109 $this->
logger->debug(
'found invalid format of question id mapping: ' . print_r(
115 $new_question_id = $new_question_arr[2];
116 $this->
logger->info(
'New question id is: ' . $new_question_id);
121 $new_question->setTestRefId($new_ref_id);
122 $new_question->setTestObjId($new_obj_id);
123 $new_question->setQuestionId($new_question_id);
124 $new_question->add();
128 foreach ($this->
getTests() as $test) {
129 if (!isset($mappings[
"$test[ref_id]"])) {
132 $new_test_id = $mappings[
"$test[ref_id]"];
134 $query =
"UPDATE crs_objective_tst " .
135 "SET tst_status = " . $this->db->quote($test[
'tst_status'],
'integer') .
", " .
136 "tst_limit_p = " . $this->db->quote($test[
'tst_limit'],
'integer') .
" " .
137 "WHERE objective_id = " . $this->db->quote($a_new_objective,
'integer') .
" " .
138 "AND ref_id = " . $this->db->quote($new_test_id,
'integer');
139 $res = $this->db->manipulate($query);
147 $tree = $DIC->repositoryTree();
154 $this->tst_status = $a_status;
164 $this->tst_limit = $a_limit;
174 $query =
"UPDATE crs_objective_tst " .
175 "SET tst_status = " . $this->db->quote($this->
getTestStatus(),
'integer') .
" " .
176 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
177 "AND ref_id = " . $this->db->quote($this->
getTestRefId(),
'integer') .
" ";
178 $res = $this->db->manipulate($query);
181 $query =
"SELECT * FROM crs_objective_tst " .
182 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
183 "AND ref_id = " . $this->db->quote($this->
getTestRefId(),
'integer') .
"";
185 $res = $this->db->query($query);
186 if (
$res->numRows()) {
191 $query =
"SELECT tst_limit_p FROM crs_objective_tst " .
192 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
193 "AND tst_status = " . $this->db->quote($this->
getTestStatus(),
'integer') .
" ";
194 $res = $this->db->query($query);
197 $limit_in_db = (
int) $row->tst_limit_p;
201 if (is_null($limit_in_db) && $this->tst_limit > 0 && $this->tst_limit <= 100) {
204 if (!is_null($limit_in_db)) {
205 $limit = $limit_in_db;
208 $next_id = $this->db->nextId(
'crs_objective_tst');
209 $query =
"INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) " .
211 $this->db->quote($next_id,
'integer') .
", " .
213 $this->db->quote($this->
getTestRefId(),
'integer') .
", " .
214 $this->db->quote($this->
getTestObjId(),
'integer') .
", " .
216 $this->db->quote($limit,
'integer') .
" " .
218 $res = $this->db->manipulate($query);
224 $query =
"DELETE FROM crs_objective_qst " .
225 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
226 "AND ref_id = " . $this->db->quote($a_test_ref_id,
'integer') .
" ";
227 $res = $this->db->manipulate($query);
230 $query =
"DELETE FROM crs_objective_tst " .
231 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
232 "AND ref_id = " . $this->db->quote($a_test_ref_id,
'integer') .
" ";
233 $res = $this->db->manipulate($query);
234 unset($this->tests[$a_test_ref_id]);
237 public static function _updateTestLimits(
int $a_objective_id,
int $a_status,
int $a_limit): void
241 $ilDB = $DIC[
'ilDB'];
243 $query =
"UPDATE crs_objective_tst " .
244 "SET tst_limit_p = " .
$ilDB->quote($a_limit,
'integer') .
" " .
245 "WHERE tst_status = " .
$ilDB->quote($a_status,
'integer') .
" " .
246 "AND objective_id = " .
$ilDB->quote($a_objective_id,
'integer');
252 $query =
"UPDATE crs_objective_tst " .
253 "SET tst_status = " . $this->db->quote($this->
getTestStatus(),
'integer') .
", " .
255 "WHERE test_objective_id = " . $this->db->quote($a_objective_id,
'integer') .
"";
256 $res = $this->db->manipulate($query);
261 $query =
"SELECT * FROM crs_objective_tst cot " .
262 "JOIN object_data obd ON cot.obj_id = obd.obj_id " .
263 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
266 $res = $this->db->query($query);
269 $test[
'test_objective_id'] = (
int) $row->test_objective_id;
270 $test[
'objective_id'] = (
int) $row->objective_id;
271 $test[
'ref_id'] = (
int) $row->ref_id;
272 $test[
'obj_id'] = (
int) $row->obj_id;
273 $test[
'tst_status'] = (
int) $row->tst_status;
274 $test[
'tst_limit'] = (
int) $row->tst_limit_p;
275 $test[
'title'] = (string) $row->title;
285 foreach ($this->tests as $test) {
286 if ($test[
'status'] == self::TYPE_SELF_ASSESSMENT) {
296 foreach ($this->tests as $test) {
297 if ($test[
'status'] == self::TYPE_FINAL_TEST) {
304 public static function _getTest(
int $a_test_objective_id): array
308 $ilDB = $DIC->database();
309 $query =
"SELECT * FROM crs_objective_tst " .
310 "WHERE test_objective_id = " .
$ilDB->quote($a_test_objective_id,
'integer') .
" ";
315 $test[
'test_objective_id'] = (
int) $row->test_objective_id;
316 $test[
'objective_id'] = (
int) $row->objective_id;
317 $test[
'ref_id'] = (
int) $row->ref_id;
318 $test[
'obj_id'] = (
int) $row->obj_id;
319 $test[
'tst_status'] = (
int) $row->tst_status;
320 $test[
'tst_limit'] = (
int) $row->tst_limit_p;
334 foreach ($this->questions as $question) {
335 if ($question[
'test_type'] == self::TYPE_SELF_ASSESSMENT) {
346 $points += $question[
'points'];
355 $points += $question[
'points'];
362 foreach ($this->questions as $question) {
363 if ($question[
'question_id'] == $a_question_id) {
364 return $question[
'test_type'] === self::TYPE_SELF_ASSESSMENT;
372 foreach ($this->questions as $question) {
373 if ($question[
'question_id'] == $a_question_id) {
374 return $question[
'test_type'] === self::TYPE_FINAL_TEST;
383 foreach ($this->questions as $question) {
384 if ($question[
'test_type'] == self::TYPE_FINAL_TEST) {
385 $final[] = $question;
395 if ($a_test_id == $qst[
'obj_id']) {
404 if ($this->questions[$question_id]) {
418 $this->tst_ref_id = $a_ref_id;
428 $this->tst_obj_id = $a_obj_id;
438 $this->question_id = $a_question_id;
452 $points += $tmp_question->getMaximumPoints();
462 if ($question[
'ref_id'] == $a_test_ref_id) {
464 $points += $tmp_question->getMaximumPoints();
473 return $DIC->testQuestion()->getGeneralQuestionProperties($a_question_id)->getAvailablePoints();
480 if ($question[
'ref_id'] == $a_test_ref_id) {
491 if ($question[
'ref_id'] == $a_test_ref_id) {
492 $qst[] = $question[
'question_id'];
501 foreach ($this->tests as $test_data) {
502 switch ($test_data[
'status']) {
503 case self::TYPE_SELF_ASSESSMENT:
507 case self::TYPE_FINAL_TEST:
511 if ($test_data[
'limit'] == -1 || $test_data[
'limit'] > $points) {
512 switch ($test_data[
'status']) {
513 case self::TYPE_SELF_ASSESSMENT:
517 case self::TYPE_FINAL_TEST:
521 $query =
"UPDATE crs_objective_tst " .
522 "SET tst_limit = " . $this->db->quote($points,
'integer') .
" " .
523 "WHERE test_objective_id = " . $this->db->quote($test_data[
'test_objective_id'],
'integer') .
" ";
524 $res = $this->db->manipulate($query);
529 public function add(): void
531 $query =
"DELETE FROM crs_objective_qst " .
532 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
533 "AND question_id = " . $this->db->quote($this->
getQuestionId(),
'integer') .
" ";
534 $res = $this->db->manipulate($query);
536 $next_id = $this->db->nextId(
'crs_objective_qst');
537 $query =
"INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) " .
539 $this->db->quote($next_id,
'integer') .
", " .
541 $this->db->quote($this->
getTestRefId(),
'integer') .
", " .
542 $this->db->quote($this->
getTestObjId(),
'integer') .
", " .
545 $res = $this->db->manipulate($query);
551 public function delete(
int $qst_id):
void 557 $query =
"SELECT * FROM crs_objective_qst " .
558 "WHERE qst_ass_id = " . $this->db->quote($qst_id,
'integer') .
" ";
560 $test_rid = $test_oid = 0;
561 $res = $this->db->query($query);
563 $test_rid = (
int) $row->ref_id;
564 $test_oid = (
int) $row->obj_id;
567 $query =
"DELETE FROM crs_objective_qst " .
568 "WHERE qst_ass_id = " . $this->db->quote($qst_id,
'integer') .
" ";
569 $res = $this->db->manipulate($query);
572 $query =
"SELECT * FROM crs_objective_qst " .
573 "WHERE ref_id = " . $this->db->quote($test_rid,
'integer') .
" " .
574 "AND obj_id = " . $this->db->quote($test_oid,
'integer') .
" " .
575 "AND objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" ";
577 $res = $this->db->query($query);
578 if (
$res->numRows() === 0) {
588 $ilDB = $DIC->database();
589 $query =
'DELETE FROM crs_objective_tst ' .
590 'WHERE ref_id = ' .
$ilDB->quote($a_tst_ref_id,
'integer');
591 $ilDB->manipulate($query);
593 $query =
'DELETE FROM crs_objective_qst ' .
594 'WHERE ref_id = ' .
$ilDB->quote($a_tst_ref_id,
'integer');
595 $ilDB->manipulate($query);
601 $deletable_refs = array();
602 foreach ($this->tests as $tst_data) {
603 if ($tst_data[
'status'] == $a_type) {
604 $deletable_refs[] = $tst_data[
'ref_id'];
608 $query =
'DELETE from crs_objective_tst ' .
609 'WHERE objective_id = ' . $this->db->quote($this->
getObjectiveId(),
'integer') .
' ' .
610 'AND tst_status = ' . $this->db->quote($a_type,
'integer');
611 $this->db->manipulate($query);
613 $query =
'DELETE from crs_objective_tst ' .
614 'WHERE objective_id = ' . $this->db->quote($this->
getObjectiveId(),
'integer') .
' ' .
615 'AND ' . $this->db->in(
'ref_id', $deletable_refs,
false,
'integer');
616 $this->db->manipulate($query);
621 $query =
"DELETE FROM crs_objective_qst " .
622 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" ";
623 $res = $this->db->manipulate($query);
625 $query =
"DELETE FROM crs_objective_tst " .
626 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" ";
627 $res = $this->db->manipulate($query);
633 $container_ref_id = current($container_ref_ids);
636 $query =
"SELECT * FROM crs_objective_tst " .
637 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" ";
638 $res = $this->db->query($query);
640 $this->tests[(
int) $row->ref_id][
'test_objective_id'] = (
int) $row->test_objective_id;
641 $this->tests[(
int) $row->ref_id][
'ref_id'] = (
int) $row->ref_id;
642 $this->tests[(
int) $row->ref_id][
'obj_id'] = (
int) $row->obj_id;
643 $this->tests[(
int) $row->ref_id][
'status'] = (
int) $row->tst_status;
644 $this->tests[(
int) $row->ref_id][
'limit'] = (
int) $row->tst_limit_p;
647 $this->questions = array();
648 $query =
"SELECT * FROM crs_objective_qst coq " .
649 "JOIN qpl_questions qq ON coq.question_id = qq.question_id " .
650 "WHERE objective_id = " . $this->db->quote($this->
getObjectiveId(),
'integer') .
" " .
653 $res = $this->db->query($query);
655 if (!array_key_exists((
int) $row->ref_id, $this->tests)) {
659 if (!$this->tree->isInTree((
int) $row->ref_id) || !$this->tree->isGrandChild(
667 $this->
delete((
int) $row->question_id);
670 $qst[
'ref_id'] = (
int) $row->ref_id;
671 $qst[
'obj_id'] = (
int) $row->obj_id;
672 $qst[
'question_id'] = (
int) $row->question_id;
673 $qst[
'qst_ass_id'] = (
int) $row->qst_ass_id;
674 $qst[
'title'] = $question->getTitle();
675 $qst[
'description'] = $question->getComment();
676 $qst[
'test_type'] = (
int) $this->tests[(
int) $row->ref_id][
'status'];
677 $qst[
'points'] = (float) $question->getPoints();
679 $this->questions[(
int) $row->qst_ass_id] = $qst;
683 public static function _hasTests(
int $a_course_id): bool
687 $ilDB = $DIC[
'ilDB'];
689 $query =
"SELECT co.objective_id FROM crs_objectives co JOIN " .
690 "crs_objective_tst cot ON co.objective_id = cot.objective_id " .
691 "WHERE crs_id = " .
$ilDB->quote($a_course_id,
'integer') .
" ";
693 return (
bool)
$res->numRows();
696 public static function _isAssigned(
int $a_objective_id,
int $a_tst_ref_id,
int $a_question_id):
int 700 $ilDB = $DIC->database();
701 $query =
"SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj " .
702 "WHERE crs_qst.objective_id = crs_obj.objective_id " .
703 "AND crs_qst.objective_id = " .
$ilDB->quote($a_objective_id,
'integer') .
" " .
704 "AND ref_id = " .
$ilDB->quote($a_tst_ref_id,
'integer') .
" " .
705 "AND question_id = " .
$ilDB->quote($a_question_id,
'integer') .
" ";
710 $objective_id = (
int) $row->objective_id;
719 $ilDB = $DIC->database();
720 $query =
'SELECT question_id FROM crs_objective_qst ' .
721 'WHERE objective_id = ' .
$ilDB->quote($a_objective,
'integer') .
' ' .
722 'AND obj_id = ' .
$ilDB->quote($a_test_id,
'integer');
725 $questions = array();
727 $questions[] = $row->question_id;
736 $ilDB = $DIC[
'ilDB'];
737 $query =
'SELECT tst_limit_p FROM crs_objective_tst ' .
738 'WHERE objective_id = ' .
$ilDB->quote($a_objective_id,
'integer') .
' ' .
739 'AND obj_id = ' .
$ilDB->quote($a_test_id,
'integer');
742 return (
int) $row->tst_limit_p;
749 foreach ($this->
getTests() as $test) {
754 'refId' => $test[
'ref_id'],
755 'testType' => $test[
'tst_status'],
756 'limit' => $test[
'tst_limit']
762 $writer->
xmlElement(
'Question', array(
'id' => $question_id));
isSelfAssessmentQuestion(int $a_question_id)
static _isTestAssignedToObjective(int $a_test_id, int $a_objective_id)
getNumberOfQuestionsByTest(int $a_test_ref_id)
static _getAssignableTests(int $a_container_ref_id)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
static getLogger(string $a_component_id)
Get component logger.
const TYPE_SELF_ASSESSMENT
static _lookupMaximumPointsOfQuestion(int $a_question_id)
static lookupQuestionsByObjective(int $a_test_id, int $a_objective)
isFinalTestQuestion(int $a_question_id)
setTestRefId(int $a_ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
getQuestionsByTest(int $a_test_ref_id)
getSelfAssessmentPoints()
setQuestionId(int $a_question_id)
toXml(ilXmlWriter $writer)
getQuestionsOfTest(int $a_test_id)
static _lookupContainerIdByObjectiveId(int $a_objective_id)
static loookupTestLimit(int $a_test_id, int $a_objective_id)
setTestSuggestedLimit(int $a_limit)
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__deleteTest(int $a_test_ref_id)
setTestObjId(int $a_obj_id)
static _getTest(int $a_test_objective_id)
getQuestion(int $question_id)
static _updateTestLimits(int $a_objective_id, int $a_status, int $a_limit)
__construct(int $a_objective_id=0)
ilObjectDataCache $objectDataCache
getMaxPointsByTest(int $a_test_ref_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _isAssigned(int $a_objective_id, int $a_tst_ref_id, int $a_question_id)
getSelfAssessmentQuestions()
cloneDependencies(int $a_new_objective, int $a_copy_id)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
static _getInstance(int $a_copy_id)
static _hasTests(int $a_course_id)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
updateTest(int $a_objective_id)
static deleteTest(int $a_tst_ref_id)
deleteByTestType(int $a_type)
static lookupObjectivesOfQuestion(int $a_qid)
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTestStatus(int $a_status)
getMaxPointsByObjective()