ILIAS  release_8 Revision v8.23
ilCourseObjectiveQuestion Class Reference

class ilcourseobjectiveQuestion More...

+ Collaboration diagram for ilCourseObjectiveQuestion:

Public Member Functions

 __construct (int $a_objective_id=0)
 
 cloneDependencies (int $a_new_objective, int $a_copy_id)
 
 setTestStatus (int $a_status)
 
 getTestStatus ()
 
 setTestSuggestedLimit (int $a_limit)
 
 getTestSuggestedLimit ()
 
 __addTest ()
 
 __deleteTest (int $a_test_ref_id)
 
 updateTest (int $a_objective_id)
 
 getTests ()
 
 getSelfAssessmentTests ()
 
 getFinalTests ()
 
 getQuestions ()
 
 getSelfAssessmentQuestions ()
 
 getSelfAssessmentPoints ()
 
 getFinalTestPoints ()
 
 isSelfAssessmentQuestion (int $a_question_id)
 
 isFinalTestQuestion (int $a_question_id)
 
 getFinalTestQuestions ()
 
 getQuestionsOfTest (int $a_test_id)
 
 getQuestion (int $question_id)
 
 getObjectiveId ()
 
 setTestRefId (int $a_ref_id)
 
 getTestRefId ()
 
 setTestObjId (int $a_obj_id)
 
 getTestObjId ()
 
 setQuestionId (int $a_question_id)
 
 getQuestionId ()
 
 getMaxPointsByObjective ()
 
 getMaxPointsByTest (int $a_test_ref_id)
 
 getNumberOfQuestionsByTest (int $a_test_ref_id)
 
 getQuestionsByTest (int $a_test_ref_id)
 
 updateLimits ()
 
 add ()
 
 delete (int $qst_id)
 
 deleteByTestType (int $a_type)
 
 deleteAll ()
 
 __read ()
 
 toXml (ilXmlWriter $writer)
 

Static Public Member Functions

static lookupObjectivesOfQuestion (int $a_qid)
 
static _isTestAssignedToObjective (int $a_test_id, int $a_objective_id)
 
static _getAssignableTests (int $a_container_ref_id)
 
static _updateTestLimits (int $a_objective_id, int $a_status, int $a_limit)
 
static _getTest (int $a_test_objective_id)
 
static _lookupMaximumPointsOfQuestion (int $a_question_id)
 
static deleteTest (int $a_tst_ref_id)
 
static _hasTests (int $a_course_id)
 
static _isAssigned (int $a_objective_id, int $a_tst_ref_id, int $a_question_id)
 
static lookupQuestionsByObjective (int $a_test_id, int $a_objective)
 
static loookupTestLimit (int $a_test_id, int $a_objective_id)
 

Data Fields

const TYPE_SELF_ASSESSMENT = 0
 
const TYPE_FINAL_TEST = 1
 

Protected Attributes

ilLogger $logger
 
ilDBInterface $db
 
ilObjectDataCache $objectDataCache
 
ilTree $tree
 

Private Attributes

int $objective_id = 0
 
array $questions = []
 
array $tests = []
 
int $tst_status = 0
 
int $tst_limit = 0
 
int $tst_ref_id = 0
 
int $tst_obj_id = 0
 
int $question_id = 0
 

Detailed Description

class ilcourseobjectiveQuestion

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.ilCourseObjectiveQuestion.php.

Constructor & Destructor Documentation

◆ __construct()

ilCourseObjectiveQuestion::__construct ( int  $a_objective_id = 0)

Definition at line 44 of file class.ilCourseObjectiveQuestion.php.

References $DIC, __read(), and ILIAS\Repository\logger().

45  {
46  global $DIC;
47 
48  $this->logger = $DIC->logger()->crs();
49  $this->objectDataCache = $DIC['ilObjDataCache'];
50  $this->db = $DIC->database();
51  $this->tree = $DIC->repositoryTree();
52 
53  $this->objective_id = $a_objective_id;
54  $this->__read();
55  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ __addTest()

ilCourseObjectiveQuestion::__addTest ( )

Definition at line 174 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, getObjectiveId(), getTestObjId(), getTestRefId(), getTestStatus(), and ILIAS\Repository\int().

Referenced by add().

174  : void
175  {
176  $query = "UPDATE crs_objective_tst " .
177  "SET tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " " .
178  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
179  "AND ref_id = " . $this->db->quote($this->getTestRefId(), 'integer') . " ";
180  $res = $this->db->manipulate($query);
181 
182  // CHECK if entry already exists
183  $query = "SELECT * FROM crs_objective_tst " .
184  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
185  "AND ref_id = " . $this->db->quote($this->getTestRefId(), 'integer') . "";
186 
187  $res = $this->db->query($query);
188  if ($res->numRows()) {
189  return;
190  }
191 
192  // Check for existing limit
193  $query = "SELECT tst_limit_p FROM crs_objective_tst " .
194  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
195  "AND tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . " ";
196 
197  $res = $this->db->query($query);
198 
199  $limit = 100;
200  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
201  $limit = (int) $row->tst_limit_p;
202  }
203 
204  $next_id = $this->db->nextId('crs_objective_tst');
205  $query = "INSERT INTO crs_objective_tst (test_objective_id,objective_id,ref_id,obj_id,tst_status,tst_limit_p) " .
206  "VALUES( " .
207  $this->db->quote($next_id, 'integer') . ", " .
208  $this->db->quote($this->getObjectiveId(), 'integer') . ", " .
209  $this->db->quote($this->getTestRefId(), 'integer') . ", " .
210  $this->db->quote($this->getTestObjId(), 'integer') . ", " .
211  $this->db->quote($this->getTestStatus(), 'integer') . ", " .
212  $this->db->quote($limit, 'integer') . " " .
213  ")";
214  $res = $this->db->manipulate($query);
215  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __deleteTest()

ilCourseObjectiveQuestion::__deleteTest ( int  $a_test_ref_id)

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

References $query, $res, and getObjectiveId().

Referenced by __read(), and delete().

217  : void
218  {
219  // Delete questions
220  $query = "DELETE FROM crs_objective_qst " .
221  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
222  "AND ref_id = " . $this->db->quote($a_test_ref_id, 'integer') . " ";
223  $res = $this->db->manipulate($query);
224 
225  // delete tst entries
226  $query = "DELETE FROM crs_objective_tst " .
227  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
228  "AND ref_id = " . $this->db->quote($a_test_ref_id, 'integer') . " ";
229  $res = $this->db->manipulate($query);
230  unset($this->tests[$a_test_ref_id]);
231  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __read()

ilCourseObjectiveQuestion::__read ( )

Definition at line 625 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, __deleteTest(), ilObject\_getAllReferences(), ilObjTest\_instanciateQuestion(), ilCourseObjective\_lookupContainerIdByObjectiveId(), ilDBConstants\FETCHMODE_OBJECT, getObjectiveId(), and ILIAS\Repository\int().

Referenced by __construct(), and add().

625  : void
626  {
627  $container_ref_ids = ilObject::_getAllReferences(ilCourseObjective::_lookupContainerIdByObjectiveId($this->objective_id));
628  $container_ref_id = current($container_ref_ids);
629 
630  // Read test data
631  $query = "SELECT * FROM crs_objective_tst " .
632  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
633  $res = $this->db->query($query);
634  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
635  $this->tests[(int) $row->ref_id]['test_objective_id'] = (int) $row->test_objective_id;
636  $this->tests[(int) $row->ref_id]['ref_id'] = (int) $row->ref_id;
637  $this->tests[(int) $row->ref_id]['obj_id'] = (int) $row->obj_id;
638  $this->tests[(int) $row->ref_id]['status'] = (int) $row->tst_status;
639  $this->tests[(int) $row->ref_id]['limit'] = (int) $row->tst_limit_p;
640  }
641 
642  $this->questions = array();
643  $query = "SELECT * FROM crs_objective_qst coq " .
644  "JOIN qpl_questions qq ON coq.question_id = qq.question_id " .
645  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
646  "ORDER BY title";
647 
648  $res = $this->db->query($query);
649  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
650  if (!$this->tree->isInTree((int) $row->ref_id) || !$this->tree->isGrandChild(
651  $container_ref_id,
652  (int) $row->ref_id
653  )) {
654  $this->__deleteTest((int) $row->ref_id);
655  continue;
656  }
657  if (($question = ilObjTest::_instanciateQuestion((int) $row->question_id)) === null) {
658  $this->delete((int) $row->question_id);
659  continue;
660  }
661  $qst['ref_id'] = (int) $row->ref_id;
662  $qst['obj_id'] = (int) $row->obj_id;
663  $qst['question_id'] = (int) $row->question_id;
664  $qst['qst_ass_id'] = (int) $row->qst_ass_id;
665  $qst['title'] = $question->getTitle();
666  $qst['description'] = $question->getComment();
667  $qst['test_type'] = (int) $this->tests[(int) $row->ref_id]['status'];
668  $qst['points'] = (float) $question->getPoints();
669 
670  $this->questions[(int) $row->qst_ass_id] = $qst;
671  }
672  }
$res
Definition: ltiservices.php:69
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupContainerIdByObjectiveId(int $a_objective_id)
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getAssignableTests()

static ilCourseObjectiveQuestion::_getAssignableTests ( int  $a_container_ref_id)
static

Definition at line 145 of file class.ilCourseObjectiveQuestion.php.

References $DIC, ilTree\getNodeData(), and ilTree\getSubTree().

Referenced by ilCourseObjectivesGUI\finalTestAssignment(), and ilCourseObjectivesGUI\selfAssessmentAssignment().

145  : array
146  {
147  global $DIC;
148 
149  $tree = $DIC->repositoryTree();
150  return $tree->getSubTree($tree->getNodeData($a_container_ref_id), true, ['tst']);
151  }
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
global $DIC
Definition: feed.php:28
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getTest()

static ilCourseObjectiveQuestion::_getTest ( int  $a_test_objective_id)
static

Definition at line 300 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

300  : array
301  {
302  global $DIC;
303 
304  $ilDB = $DIC->database();
305  $query = "SELECT * FROM crs_objective_tst " .
306  "WHERE test_objective_id = " . $ilDB->quote($a_test_objective_id, 'integer') . " ";
307 
308  $res = $ilDB->query($query);
309  $test = [];
310  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
311  $test['test_objective_id'] = (int) $row->test_objective_id;
312  $test['objective_id'] = (int) $row->objective_id;
313  $test['ref_id'] = (int) $row->ref_id;
314  $test['obj_id'] = (int) $row->obj_id;
315  $test['tst_status'] = (int) $row->tst_status;
316  $test['tst_limit'] = (int) $row->tst_limit_p;
317  }
318 
319  return $test;
320  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:

◆ _hasTests()

static ilCourseObjectiveQuestion::_hasTests ( int  $a_course_id)
static

Definition at line 674 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, and $res.

674  : bool
675  {
676  global $DIC;
677 
678  $ilDB = $DIC['ilDB'];
679 
680  $query = "SELECT co.objective_id FROM crs_objectives co JOIN " .
681  "crs_objective_tst cot ON co.objective_id = cot.objective_id " .
682  "WHERE crs_id = " . $ilDB->quote($a_course_id, 'integer') . " ";
683  $res = $ilDB->query($query);
684  return (bool) $res->numRows();
685  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query

◆ _isAssigned()

static ilCourseObjectiveQuestion::_isAssigned ( int  $a_objective_id,
int  $a_tst_ref_id,
int  $a_question_id 
)
static

Definition at line 687 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $objective_id, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

687  : int
688  {
689  global $DIC;
690 
691  $ilDB = $DIC->database();
692  $query = "SELECT crs_qst.objective_id objective_id FROM crs_objective_qst crs_qst, crs_objectives crs_obj " .
693  "WHERE crs_qst.objective_id = crs_obj.objective_id " .
694  "AND crs_qst.objective_id = " . $ilDB->quote($a_objective_id, 'integer') . " " .
695  "AND ref_id = " . $ilDB->quote($a_tst_ref_id, 'integer') . " " .
696  "AND question_id = " . $ilDB->quote($a_question_id, 'integer') . " ";
697 
698  $res = $ilDB->query($query);
699  $objective_id = 0;
700  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
701  $objective_id = (int) $row->objective_id;
702  }
703  return $objective_id;
704  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:

◆ _isTestAssignedToObjective()

static ilCourseObjectiveQuestion::_isTestAssignedToObjective ( int  $a_test_id,
int  $a_objective_id 
)
static

Definition at line 75 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, and $res.

75  : bool
76  {
77  global $DIC;
78 
79  $ilDB = $DIC->database();
80 
81  $query = "SELECT qst_ass_id FROM crs_objective_qst " .
82  "WHERE ref_id = " . $ilDB->quote($a_test_id, 'integer') . " " .
83  "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
84  $res = $ilDB->query($query);
85  return (bool) $res->numRows();
86  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query

◆ _lookupMaximumPointsOfQuestion()

static ilCourseObjectiveQuestion::_lookupMaximumPointsOfQuestion ( int  $a_question_id)
static

Definition at line 466 of file class.ilCourseObjectiveQuestion.php.

References assQuestion\_getMaximumPoints().

Referenced by ilLOTestQuestionAdapter\updateFixedQuestions(), ilLOTestQuestionAdapter\updateRandomQuestions(), and ilLOTestQuestionAdapter\updateSeparateTestQuestions().

466  : float
467  {
468  return assQuestion::_getMaximumPoints($a_question_id);
469  }
static _getMaximumPoints(int $question_id)
Returns the maximum points, a learner can reach answering the question.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _updateTestLimits()

static ilCourseObjectiveQuestion::_updateTestLimits ( int  $a_objective_id,
int  $a_status,
int  $a_limit 
)
static

Definition at line 233 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, and $res.

Referenced by ilCourseObjectivesGUI\saveQuestionOverview().

233  : void
234  {
235  global $DIC;
236 
237  $ilDB = $DIC['ilDB'];
238 
239  $query = "UPDATE crs_objective_tst " .
240  "SET tst_limit_p = " . $ilDB->quote($a_limit, 'integer') . " " .
241  "WHERE tst_status = " . $ilDB->quote($a_status, 'integer') . " " .
242  "AND objective_id = " . $ilDB->quote($a_objective_id, 'integer');
243  $res = $ilDB->manipulate($query);
244  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ add()

ilCourseObjectiveQuestion::add ( )

Definition at line 524 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, __addTest(), __read(), getObjectiveId(), getQuestionId(), getTestObjId(), and getTestRefId().

524  : void
525  {
526  $query = "DELETE FROM crs_objective_qst " .
527  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
528  "AND question_id = " . $this->db->quote($this->getQuestionId(), 'integer') . " ";
529  $res = $this->db->manipulate($query);
530 
531  $next_id = $this->db->nextId('crs_objective_qst');
532  $query = "INSERT INTO crs_objective_qst (qst_ass_id, objective_id,ref_id,obj_id,question_id) " .
533  "VALUES( " .
534  $this->db->quote($next_id, 'integer') . ", " .
535  $this->db->quote($this->getObjectiveId(), 'integer') . ", " .
536  $this->db->quote($this->getTestRefId(), 'integer') . ", " .
537  $this->db->quote($this->getTestObjId(), 'integer') . ", " .
538  $this->db->quote($this->getQuestionId(), 'integer') .
539  ")";
540  $res = $this->db->manipulate($query);
541 
542  $this->__addTest();
543  $this->__read();
544  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ cloneDependencies()

ilCourseObjectiveQuestion::cloneDependencies ( int  $a_new_objective,
int  $a_copy_id 
)

Definition at line 88 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, ilCopyWizardOptions\_getInstance(), ilLoggerFactory\getLogger(), getQuestions(), getTests(), ILIAS\Repository\int(), and ILIAS\Repository\logger().

88  : void
89  {
90  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
91  $mappings = $cwo->getMappings();
92  foreach ($this->getQuestions() as $question) {
93  $mapping_key = $question['ref_id'] . '_question_' . $question['question_id'];
94  if (!isset($mappings[$mapping_key]) || !$mappings[$mapping_key]) {
95  continue;
96  }
97  $question_ref_id = $question['ref_id'];
98  $question_obj_id = $question['obj_id'];
99  $question_qst_id = $question['question_id'];
100  $new_ref_id = (int) $mappings[$question_ref_id];
101  $new_obj_id = $this->objectDataCache->lookupObjId($new_ref_id);
102 
103  if ($new_obj_id == $question_obj_id) {
104  $this->logger->info('Test has been linked. Keeping question id');
105  // Object has been linked
106  $new_question_id = $question_qst_id;
107  } else {
108  $new_question_info = $mappings[$question_ref_id . '_question_' . $question_qst_id];
109  $new_question_arr = explode('_', $new_question_info);
110  if (!isset($new_question_arr[2]) || !$new_question_arr[2]) {
111  $this->logger->debug('found invalid format of question id mapping: ' . print_r(
112  $new_question_arr,
113  true
114  ));
115  continue;
116  }
117  $new_question_id = $new_question_arr[2];
118  $this->logger->info('New question id is: ' . $new_question_id);
119  }
120 
121  ilLoggerFactory::getLogger('crs')->debug('Copying question assignments');
122  $new_question = new ilCourseObjectiveQuestion($a_new_objective);
123  $new_question->setTestRefId($new_ref_id);
124  $new_question->setTestObjId($new_obj_id);
125  $new_question->setQuestionId($new_question_id);
126  $new_question->add();
127  }
128 
129  // Copy tests
130  foreach ($this->getTests() as $test) {
131  if (!isset($mappings["$test[ref_id]"])) {
132  continue;
133  }
134  $new_test_id = $mappings["$test[ref_id]"];
135 
136  $query = "UPDATE crs_objective_tst " .
137  "SET tst_status = " . $this->db->quote($test['tst_status'], 'integer') . ", " .
138  "tst_limit_p = " . $this->db->quote($test['tst_limit'], 'integer') . " " .
139  "WHERE objective_id = " . $this->db->quote($a_new_objective, 'integer') . " " .
140  "AND ref_id = " . $this->db->quote($new_test_id, 'integer');
141  $res = $this->db->manipulate($query);
142  }
143  }
$res
Definition: ltiservices.php:69
static getLogger(string $a_component_id)
Get component logger.
$query
static _getInstance(int $a_copy_id)
class ilcourseobjectiveQuestion
+ Here is the call graph for this function:

◆ delete()

ilCourseObjectiveQuestion::delete ( int  $qst_id)

Definition at line 546 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, __deleteTest(), ilDBConstants\FETCHMODE_OBJECT, getObjectiveId(), and ILIAS\Repository\int().

546  : void
547  {
548  if (!$qst_id) {
549  return;
550  }
551 
552  $query = "SELECT * FROM crs_objective_qst " .
553  "WHERE qst_ass_id = " . $this->db->quote($qst_id, 'integer') . " ";
554 
555  $test_rid = $test_oid = 0;
556  $res = $this->db->query($query);
557  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
558  $test_rid = (int) $row->ref_id;
559  $test_oid = (int) $row->obj_id;
560  }
561 
562  $query = "DELETE FROM crs_objective_qst " .
563  "WHERE qst_ass_id = " . $this->db->quote($qst_id, 'integer') . " ";
564  $res = $this->db->manipulate($query);
565 
566  // delete test if it was the last question
567  $query = "SELECT * FROM crs_objective_qst " .
568  "WHERE ref_id = " . $this->db->quote($test_rid, 'integer') . " " .
569  "AND obj_id = " . $this->db->quote($test_oid, 'integer') . " " .
570  "AND objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
571 
572  $res = $this->db->query($query);
573  if ($res->numRows() === 0) {
574  $this->__deleteTest($test_rid);
575  }
576  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ deleteAll()

ilCourseObjectiveQuestion::deleteAll ( )

Definition at line 614 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, and getObjectiveId().

614  : void
615  {
616  $query = "DELETE FROM crs_objective_qst " .
617  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
618  $res = $this->db->manipulate($query);
619 
620  $query = "DELETE FROM crs_objective_tst " .
621  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " ";
622  $res = $this->db->manipulate($query);
623  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

◆ deleteByTestType()

ilCourseObjectiveQuestion::deleteByTestType ( int  $a_type)

Definition at line 593 of file class.ilCourseObjectiveQuestion.php.

References $query, and getObjectiveId().

593  : void
594  {
595  // Read tests by type
596  $deletable_refs = array();
597  foreach ($this->tests as $tst_data) {
598  if ($tst_data['status'] == $a_type) {
599  $deletable_refs[] = $tst_data['ref_id'];
600  }
601  }
602 
603  $query = 'DELETE from crs_objective_tst ' .
604  'WHERE objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ' ' .
605  'AND tst_status = ' . $this->db->quote($a_type, 'integer');
606  $this->db->manipulate($query);
607 
608  $query = 'DELETE from crs_objective_tst ' .
609  'WHERE objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ' ' .
610  'AND ' . $this->db->in('ref_id', $deletable_refs, false, 'integer');
611  $this->db->manipulate($query);
612  }
$query
+ Here is the call graph for this function:

◆ deleteTest()

static ilCourseObjectiveQuestion::deleteTest ( int  $a_tst_ref_id)
static

Definition at line 579 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, and $query.

Referenced by ilLOEditorGUI\deleteTest(), and ilLOEditorGUI\deleteTests().

579  : void
580  {
581  global $DIC;
582 
583  $ilDB = $DIC->database();
584  $query = 'DELETE FROM crs_objective_tst ' .
585  'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
586  $ilDB->manipulate($query);
587 
588  $query = 'DELETE FROM crs_objective_qst ' .
589  'WHERE ref_id = ' . $ilDB->quote($a_tst_ref_id, 'integer');
590  $ilDB->manipulate($query);
591  }
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ getFinalTestPoints()

ilCourseObjectiveQuestion::getFinalTestPoints ( )

Definition at line 347 of file class.ilCourseObjectiveQuestion.php.

References getFinalTestQuestions().

Referenced by updateLimits().

347  : int
348  {
349  $points = 0;
350  foreach ($this->getFinalTestQuestions() as $question) {
351  $points += $question['points'];
352  }
353  return $points;
354  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFinalTestQuestions()

ilCourseObjectiveQuestion::getFinalTestQuestions ( )

Definition at line 376 of file class.ilCourseObjectiveQuestion.php.

Referenced by getFinalTestPoints().

376  : array
377  {
378  $final = [];
379  foreach ($this->questions as $question) {
380  if ($question['test_type'] == self::TYPE_FINAL_TEST) {
381  $final[] = $question;
382  }
383  }
384  return $final;
385  }
+ Here is the caller graph for this function:

◆ getFinalTests()

ilCourseObjectiveQuestion::getFinalTests ( )

Definition at line 289 of file class.ilCourseObjectiveQuestion.php.

289  : array
290  {
291  $final = [];
292  foreach ($this->tests as $test) {
293  if ($test['status'] == self::TYPE_FINAL_TEST) {
294  $final[] = $test;
295  }
296  }
297  return $final;
298  }

◆ getMaxPointsByObjective()

ilCourseObjectiveQuestion::getMaxPointsByObjective ( )

Definition at line 442 of file class.ilCourseObjectiveQuestion.php.

References ilObjTest\_instanciateQuestion(), ilObjectFactory\getInstanceByRefId(), and getQuestions().

442  : int
443  {
444  $points = 0;
445  foreach ($this->getQuestions() as $question) {
446  $tmp_test = ilObjectFactory::getInstanceByRefId($question['ref_id']);
447  $tmp_question = ilObjTest::_instanciateQuestion($question['question_id']);
448  $points += $tmp_question->getMaximumPoints();
449  }
450  return $points;
451  }
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
+ Here is the call graph for this function:

◆ getMaxPointsByTest()

ilCourseObjectiveQuestion::getMaxPointsByTest ( int  $a_test_ref_id)

Definition at line 453 of file class.ilCourseObjectiveQuestion.php.

References ilObjTest\_instanciateQuestion(), ilObjectFactory\getInstanceByRefId(), and getQuestions().

453  : int
454  {
455  $points = 0;
456  $tmp_test = ilObjectFactory::getInstanceByRefId($a_test_ref_id);
457  foreach ($this->getQuestions() as $question) {
458  if ($question['ref_id'] == $a_test_ref_id) {
459  $tmp_question = ilObjTest::_instanciateQuestion($question['question_id']);
460  $points += $tmp_question->getMaximumPoints();
461  }
462  }
463  return $points;
464  }
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
+ Here is the call graph for this function:

◆ getNumberOfQuestionsByTest()

ilCourseObjectiveQuestion::getNumberOfQuestionsByTest ( int  $a_test_ref_id)

Definition at line 471 of file class.ilCourseObjectiveQuestion.php.

References getQuestions().

471  : int
472  {
473  $counter = 0;
474  foreach ($this->getQuestions() as $question) {
475  if ($question['ref_id'] == $a_test_ref_id) {
476  ++$counter;
477  }
478  }
479  return $counter;
480  }
+ Here is the call graph for this function:

◆ getObjectiveId()

ilCourseObjectiveQuestion::getObjectiveId ( )

Definition at line 407 of file class.ilCourseObjectiveQuestion.php.

References $objective_id.

Referenced by __addTest(), __deleteTest(), __read(), add(), delete(), deleteAll(), deleteByTestType(), and getTests().

407  : int
408  {
409  return $this->objective_id;
410  }
+ Here is the caller graph for this function:

◆ getQuestion()

ilCourseObjectiveQuestion::getQuestion ( int  $question_id)

Definition at line 398 of file class.ilCourseObjectiveQuestion.php.

References $question_id.

398  : array
399  {
400  if ($this->questions[$question_id]) {
401  return $this->questions[$question_id];
402  } else {
403  return array();
404  }
405  }

◆ getQuestionId()

ilCourseObjectiveQuestion::getQuestionId ( )

Definition at line 437 of file class.ilCourseObjectiveQuestion.php.

References $question_id.

Referenced by add().

437  : int
438  {
439  return $this->question_id;
440  }
+ Here is the caller graph for this function:

◆ getQuestions()

ilCourseObjectiveQuestion::getQuestions ( )

Definition at line 322 of file class.ilCourseObjectiveQuestion.php.

References $questions.

Referenced by cloneDependencies(), getMaxPointsByObjective(), getMaxPointsByTest(), getNumberOfQuestionsByTest(), getQuestionsByTest(), and getQuestionsOfTest().

322  : array
323  {
324  return $this->questions;
325  }
+ Here is the caller graph for this function:

◆ getQuestionsByTest()

ilCourseObjectiveQuestion::getQuestionsByTest ( int  $a_test_ref_id)

Definition at line 482 of file class.ilCourseObjectiveQuestion.php.

References getQuestions().

Referenced by toXml().

482  : array
483  {
484  $qst = [];
485  foreach ($this->getQuestions() as $question) {
486  if ($question['ref_id'] == $a_test_ref_id) {
487  $qst[] = $question['question_id'];
488  }
489  }
490  return $qst;
491  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getQuestionsOfTest()

ilCourseObjectiveQuestion::getQuestionsOfTest ( int  $a_test_id)

Definition at line 387 of file class.ilCourseObjectiveQuestion.php.

References $questions, and getQuestions().

387  : array
388  {
389  $questions = [];
390  foreach ($this->getQuestions() as $qst) {
391  if ($a_test_id == $qst['obj_id']) {
392  $questions[] = $qst;
393  }
394  }
395  return $questions;
396  }
+ Here is the call graph for this function:

◆ getSelfAssessmentPoints()

ilCourseObjectiveQuestion::getSelfAssessmentPoints ( )

Definition at line 338 of file class.ilCourseObjectiveQuestion.php.

References getSelfAssessmentQuestions().

Referenced by updateLimits().

338  : int
339  {
340  $points = 0;
341  foreach ($this->getSelfAssessmentQuestions() as $question) {
342  $points += $question['points'];
343  }
344  return $points;
345  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSelfAssessmentQuestions()

ilCourseObjectiveQuestion::getSelfAssessmentQuestions ( )

Definition at line 327 of file class.ilCourseObjectiveQuestion.php.

References TYPE_SELF_ASSESSMENT.

Referenced by getSelfAssessmentPoints().

327  : array
328  {
329  $self = [];
330  foreach ($this->questions as $question) {
331  if ($question['test_type'] == self::TYPE_SELF_ASSESSMENT) {
332  $self[] = $question;
333  }
334  }
335  return $self;
336  }
const TYPE_SELF_ASSESSMENT
+ Here is the caller graph for this function:

◆ getSelfAssessmentTests()

ilCourseObjectiveQuestion::getSelfAssessmentTests ( )

Definition at line 278 of file class.ilCourseObjectiveQuestion.php.

References TYPE_SELF_ASSESSMENT.

278  : array
279  {
280  $self = [];
281  foreach ($this->tests as $test) {
282  if ($test['status'] == self::TYPE_SELF_ASSESSMENT) {
283  $self[] = $test;
284  }
285  }
286  return $self;
287  }
const TYPE_SELF_ASSESSMENT

◆ getTestObjId()

ilCourseObjectiveQuestion::getTestObjId ( )

Definition at line 427 of file class.ilCourseObjectiveQuestion.php.

References $tst_obj_id.

Referenced by __addTest(), and add().

427  : int
428  {
429  return $this->tst_obj_id;
430  }
+ Here is the caller graph for this function:

◆ getTestRefId()

ilCourseObjectiveQuestion::getTestRefId ( )

Definition at line 417 of file class.ilCourseObjectiveQuestion.php.

References $tst_ref_id.

Referenced by __addTest(), and add().

417  : int
418  {
419  return $this->tst_ref_id;
420  }
+ Here is the caller graph for this function:

◆ getTests()

ilCourseObjectiveQuestion::getTests ( )

Definition at line 255 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, $tests, ilDBConstants\FETCHMODE_OBJECT, getObjectiveId(), and ILIAS\Repository\int().

Referenced by cloneDependencies(), and toXml().

255  : array
256  {
257  $query = "SELECT * FROM crs_objective_tst cot " .
258  "JOIN object_data obd ON cot.obj_id = obd.obj_id " .
259  "WHERE objective_id = " . $this->db->quote($this->getObjectiveId(), 'integer') . " " .
260  "ORDER BY title ";
261 
262  $res = $this->db->query($query);
263  $tests = [];
264  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
265  $test['test_objective_id'] = (int) $row->test_objective_id;
266  $test['objective_id'] = (int) $row->objective_id;
267  $test['ref_id'] = (int) $row->ref_id;
268  $test['obj_id'] = (int) $row->obj_id;
269  $test['tst_status'] = (int) $row->tst_status;
270  $test['tst_limit'] = (int) $row->tst_limit_p;
271  $test['title'] = (string) $row->title;
272 
273  $tests[] = $test;
274  }
275  return $tests;
276  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTestStatus()

ilCourseObjectiveQuestion::getTestStatus ( )

Definition at line 159 of file class.ilCourseObjectiveQuestion.php.

References $tst_status.

Referenced by __addTest(), and updateTest().

159  : int
160  {
161  return $this->tst_status;
162  }
+ Here is the caller graph for this function:

◆ getTestSuggestedLimit()

ilCourseObjectiveQuestion::getTestSuggestedLimit ( )

Definition at line 169 of file class.ilCourseObjectiveQuestion.php.

References $tst_limit.

Referenced by updateTest().

169  : int
170  {
171  return $this->tst_limit;
172  }
+ Here is the caller graph for this function:

◆ isFinalTestQuestion()

ilCourseObjectiveQuestion::isFinalTestQuestion ( int  $a_question_id)

Definition at line 366 of file class.ilCourseObjectiveQuestion.php.

366  : bool
367  {
368  foreach ($this->questions as $question) {
369  if ($question['question_id'] == $a_question_id) {
370  return $question['test_type'] === self::TYPE_FINAL_TEST;
371  }
372  }
373  return false;
374  }

◆ isSelfAssessmentQuestion()

ilCourseObjectiveQuestion::isSelfAssessmentQuestion ( int  $a_question_id)

Definition at line 356 of file class.ilCourseObjectiveQuestion.php.

References TYPE_SELF_ASSESSMENT.

356  : bool
357  {
358  foreach ($this->questions as $question) {
359  if ($question['question_id'] == $a_question_id) {
360  return $question['test_type'] === self::TYPE_SELF_ASSESSMENT;
361  }
362  }
363  return false;
364  }
const TYPE_SELF_ASSESSMENT

◆ lookupObjectivesOfQuestion()

static ilCourseObjectiveQuestion::lookupObjectivesOfQuestion ( int  $a_qid)
static
Returns
int[]

Definition at line 60 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by ilLOTestQuestionAdapter\lookupObjectiveIdByFixedQuestionId().

60  : array
61  {
62  global $DIC;
63 
64  $ilDB = $DIC->database();
65  $query = 'SELECT objective_id FROM crs_objective_qst ' .
66  'WHERE question_id = ' . $ilDB->quote($a_qid, 'integer');
67  $res = $ilDB->query($query);
68  $objectiveIds = array();
69  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
70  $objectiveIds[] = (int) $row->objective_id;
71  }
72  return $objectiveIds;
73  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupQuestionsByObjective()

static ilCourseObjectiveQuestion::lookupQuestionsByObjective ( int  $a_test_id,
int  $a_objective 
)
static

Definition at line 706 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, $questions, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilLOEditorStatus\lookupQuestionsAssigned(), and ilLOTestQuestionAdapter\updateFixedQuestions().

706  : array
707  {
708  global $DIC;
709 
710  $ilDB = $DIC->database();
711  $query = 'SELECT question_id FROM crs_objective_qst ' .
712  'WHERE objective_id = ' . $ilDB->quote($a_objective, 'integer') . ' ' .
713  'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
714  $res = $ilDB->query($query);
715 
716  $questions = array();
717  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
718  $questions[] = $row->question_id;
719  }
720  return $questions;
721  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ loookupTestLimit()

static ilCourseObjectiveQuestion::loookupTestLimit ( int  $a_test_id,
int  $a_objective_id 
)
static

Definition at line 723 of file class.ilCourseObjectiveQuestion.php.

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilLOUtils\lookupObjectiveRequiredPercentage().

723  : int
724  {
725  global $DIC;
726 
727  $ilDB = $DIC['ilDB'];
728  $query = 'SELECT tst_limit_p FROM crs_objective_tst ' .
729  'WHERE objective_id = ' . $ilDB->quote($a_objective_id, 'integer') . ' ' .
730  'AND obj_id = ' . $ilDB->quote($a_test_id, 'integer');
731  $res = $ilDB->query($query);
732  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
733  return (int) $row->tst_limit_p;
734  }
735  return 0;
736  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ Here is the caller graph for this function:

◆ setQuestionId()

ilCourseObjectiveQuestion::setQuestionId ( int  $a_question_id)

Definition at line 432 of file class.ilCourseObjectiveQuestion.php.

432  : void
433  {
434  $this->question_id = $a_question_id;
435  }

◆ setTestObjId()

ilCourseObjectiveQuestion::setTestObjId ( int  $a_obj_id)

Definition at line 422 of file class.ilCourseObjectiveQuestion.php.

422  : void
423  {
424  $this->tst_obj_id = $a_obj_id;
425  }

◆ setTestRefId()

ilCourseObjectiveQuestion::setTestRefId ( int  $a_ref_id)

Definition at line 412 of file class.ilCourseObjectiveQuestion.php.

412  : void
413  {
414  $this->tst_ref_id = $a_ref_id;
415  }

◆ setTestStatus()

ilCourseObjectiveQuestion::setTestStatus ( int  $a_status)

Definition at line 154 of file class.ilCourseObjectiveQuestion.php.

154  : void
155  {
156  $this->tst_status = $a_status;
157  }

◆ setTestSuggestedLimit()

ilCourseObjectiveQuestion::setTestSuggestedLimit ( int  $a_limit)

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

164  : void
165  {
166  $this->tst_limit = $a_limit;
167  }

◆ toXml()

ilCourseObjectiveQuestion::toXml ( ilXmlWriter  $writer)

Definition at line 738 of file class.ilCourseObjectiveQuestion.php.

References getQuestionsByTest(), getTests(), ilLOXmlWriter\TYPE_TST_ALL, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

738  : void
739  {
740  foreach ($this->getTests() as $test) {
741  $writer->xmlStartTag(
742  'Test',
743  array(
744  'type' => ilLOXmlWriter::TYPE_TST_ALL,
745  'refId' => $test['ref_id'],
746  'testType' => $test['tst_status'],
747  'limit' => $test['tst_limit']
748  )
749  );
750 
751  // questions
752  foreach ($this->getQuestionsByTest($test['ref_id']) as $question_id) {
753  $writer->xmlElement('Question', array('id' => $question_id));
754  }
755  $writer->xmlEndTag('Test');
756  }
757  }
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

◆ updateLimits()

ilCourseObjectiveQuestion::updateLimits ( )

Definition at line 493 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, getFinalTestPoints(), getSelfAssessmentPoints(), and TYPE_SELF_ASSESSMENT.

493  : void
494  {
495  $points = 0;
496  foreach ($this->tests as $test_data) {
497  switch ($test_data['status']) {
499  $points = $this->getSelfAssessmentPoints();
500  break;
501 
502  case self::TYPE_FINAL_TEST:
503  $points = $this->getFinalTestPoints();
504  break;
505  }
506  if ($test_data['limit'] == -1 || $test_data['limit'] > $points) {
507  switch ($test_data['status']) {
509  $points = $this->getSelfAssessmentPoints();
510  break;
511 
512  case self::TYPE_FINAL_TEST:
513  $points = $this->getFinalTestPoints();
514  break;
515  }
516  $query = "UPDATE crs_objective_tst " .
517  "SET tst_limit = " . $this->db->quote($points, 'integer') . " " .
518  "WHERE test_objective_id = " . $this->db->quote($test_data['test_objective_id'], 'integer') . " ";
519  $res = $this->db->manipulate($query);
520  }
521  }
522  }
$res
Definition: ltiservices.php:69
$query
const TYPE_SELF_ASSESSMENT
+ Here is the call graph for this function:

◆ updateTest()

ilCourseObjectiveQuestion::updateTest ( int  $a_objective_id)

Definition at line 246 of file class.ilCourseObjectiveQuestion.php.

References $query, $res, getTestStatus(), and getTestSuggestedLimit().

246  : void
247  {
248  $query = "UPDATE crs_objective_tst " .
249  "SET tst_status = " . $this->db->quote($this->getTestStatus(), 'integer') . ", " .
250  "tst_limit_p = " . $this->db->quote($this->getTestSuggestedLimit(), 'integer') . " " .
251  "WHERE test_objective_id = " . $this->db->quote($a_objective_id, 'integer') . "";
252  $res = $this->db->manipulate($query);
253  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilCourseObjectiveQuestion::$db
protected

Definition at line 40 of file class.ilCourseObjectiveQuestion.php.

◆ $logger

ilLogger ilCourseObjectiveQuestion::$logger
protected

Definition at line 39 of file class.ilCourseObjectiveQuestion.php.

◆ $objectDataCache

ilObjectDataCache ilCourseObjectiveQuestion::$objectDataCache
protected

Definition at line 41 of file class.ilCourseObjectiveQuestion.php.

◆ $objective_id

int ilCourseObjectiveQuestion::$objective_id = 0
private

Definition at line 30 of file class.ilCourseObjectiveQuestion.php.

Referenced by _isAssigned(), and getObjectiveId().

◆ $question_id

int ilCourseObjectiveQuestion::$question_id = 0
private

Definition at line 37 of file class.ilCourseObjectiveQuestion.php.

Referenced by getQuestion(), and getQuestionId().

◆ $questions

array ilCourseObjectiveQuestion::$questions = []
private

◆ $tests

array ilCourseObjectiveQuestion::$tests = []
private

Definition at line 32 of file class.ilCourseObjectiveQuestion.php.

Referenced by getTests().

◆ $tree

ilTree ilCourseObjectiveQuestion::$tree
protected

Definition at line 42 of file class.ilCourseObjectiveQuestion.php.

◆ $tst_limit

int ilCourseObjectiveQuestion::$tst_limit = 0
private

Definition at line 34 of file class.ilCourseObjectiveQuestion.php.

Referenced by getTestSuggestedLimit().

◆ $tst_obj_id

int ilCourseObjectiveQuestion::$tst_obj_id = 0
private

Definition at line 36 of file class.ilCourseObjectiveQuestion.php.

Referenced by getTestObjId().

◆ $tst_ref_id

int ilCourseObjectiveQuestion::$tst_ref_id = 0
private

Definition at line 35 of file class.ilCourseObjectiveQuestion.php.

Referenced by getTestRefId().

◆ $tst_status

int ilCourseObjectiveQuestion::$tst_status = 0
private

Definition at line 33 of file class.ilCourseObjectiveQuestion.php.

Referenced by getTestStatus().

◆ TYPE_FINAL_TEST

◆ TYPE_SELF_ASSESSMENT


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