Exemplo n.º 1
0
 /**
  * 
  * @param type $a_container_id
  * @param type $a_objective_id
  * @param type $a_test_type
  */
 public static function lookupObjectiveRequiredPercentage($a_container_id, $a_objective_id, $a_test_ref_id, $a_max_points)
 {
     include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
     $settings = ilLOSettings::getInstanceByObjId($a_container_id);
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     $assignments = ilLOTestAssignments::getInstance($a_container_id);
     $a_test_type = $assignments->getTypeByTest($a_test_ref_id);
     if ($assignments->isSeparateTest($a_test_ref_id)) {
         include_once './Services/Object/classes/class.ilObjectFactory.php';
         $factory = new ilObjectFactory();
         $tst = $factory->getInstanceByRefId($a_test_ref_id, FALSE);
         if ($tst instanceof ilObjTest) {
             $schema = $tst->getMarkSchema();
             foreach ($schema->getMarkSteps() as $mark) {
                 if ($mark->getPassed()) {
                     return (int) $mark->getMinimumLevel();
                 }
             }
         }
     }
     $tst_ref_id = $a_test_ref_id;
     if (self::lookupRandomTest(ilObject::_lookupObjId($tst_ref_id))) {
         include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
         return (int) ilLORandomTestQuestionPools::lookupLimit($a_container_id, $a_objective_id, $a_test_type);
     } else {
         include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
         $limit = ilCourseObjectiveQuestion::loookupTestLimit(ilObject::_lookupObjId($tst_ref_id), $a_objective_id);
         return $limit;
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor
  * @param ilObject
  */
 public function __construct(ilObject $a_parent)
 {
     $this->parent_obj = $a_parent;
     $this->settings = ilLOSettings::getInstanceByObjId($this->getParentObject()->getId());
     $this->assignments = ilLOTestAssignments::getInstance($this->getParentObject()->getId());
     $this->ctrl = $GLOBALS['ilCtrl'];
     $this->lng = $GLOBALS['lng'];
     include_once './Modules/Course/classes/class.ilCourseObjective.php';
     $this->objectives = ilCourseObjective::_getObjectiveIds($this->getParentObject()->getId());
 }
 /**
  * Lookup all relevant objective ids for a specific test
  * @return array
  */
 protected function lookupRelevantObjectiveIdsForTest($a_container_id, $a_tst_ref_id, $a_user_id)
 {
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     $assignments = ilLOTestAssignments::getInstance($a_container_id);
     include_once './Modules/Course/classes/class.ilCourseObjective.php';
     $objective_ids = ilCourseObjective::_getObjectiveIds($a_container_id);
     $relevant_objective_ids = array();
     if (!$this->getSettings()->hasSeparateInitialTests()) {
         if ($a_tst_ref_id == $this->getSettings()->getInitialTest()) {
             $relevant_objective_ids = $objective_ids;
         }
     } elseif (!$this->getSettings()->hasSeparateQualifiedTests()) {
         if ($a_tst_ref_id == $this->getSettings()->getQualifiedTest()) {
             $relevant_objective_ids = $objective_ids;
         }
     }
     foreach ((array) $objective_ids as $objective_id) {
         $assigned_itest = $assignments->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL);
         if ($assigned_itest == $a_tst_ref_id) {
             $relevant_objective_ids[] = $objective_id;
         }
         $assigned_qtest = $assignments->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
         if ($assigned_qtest == $a_tst_ref_id) {
             $relevant_objective_ids[] = $objective_id;
         }
     }
     $relevant_objective_ids = array_unique($relevant_objective_ids);
     if (count($relevant_objective_ids) <= 1) {
         return $relevant_objective_ids;
     }
     // filter passed objectives
     $test_type = $assignments->getTypeByTest($a_tst_ref_id);
     $passed_objectives = array();
     include_once './Modules/Course/classes/Objectives/class.ilLOUserResults.php';
     $results = new ilLOUserResults($a_container_id, $a_user_id);
     $passed = $results->getCompletedObjectiveIds();
     $GLOBALS['ilLog']->write(__METHOD__ . ': Passed objectives are ' . print_r($passed, TRUE) . ' test_type = ' . $test_type);
     // all completed => show all objectives
     if (count($passed) >= count($relevant_objective_ids)) {
         return $relevant_objective_ids;
     }
     $unpassed = array();
     foreach ($relevant_objective_ids as $objective_id) {
         if (!in_array($objective_id, $passed)) {
             $unpassed[] = $objective_id;
         }
     }
     return $unpassed;
 }
 /**
  * Get assignable tests
  * @return array
  */
 protected function getAssignableTests()
 {
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     $assignments = ilLOTestAssignments::getInstance($this->getContainer()->getId());
     $tests = array();
     foreach ($GLOBALS['tree']->getChildsByType($this->getContainer()->getRefId(), 'tst') as $tree_node) {
         if (!in_array($tree_node['child'], $assignments->getTests())) {
             $tests[] = $tree_node['child'];
         }
     }
     return $tests;
 }
 protected function parseLOUserResults()
 {
     global $ilUser;
     $res = array();
     include_once "Modules/Course/classes/Objectives/class.ilLOTestAssignments.php";
     $lo_ass = ilLOTestAssignments::getInstance($this->getContainerObject()->getId());
     include_once "Modules/Course/classes/Objectives/class.ilLOUserResults.php";
     $lur = new ilLOUserResults($this->getContainerObject()->getId(), $ilUser->getId());
     foreach ($lur->getCourseResultsForUserPresentation() as $objective_id => $types) {
         // show either initial or qualified for objective
         if (isset($types[ilLOUserResults::TYPE_INITIAL])) {
             $initial_status = $types[ilLOUserResults::TYPE_INITIAL]["status"];
         }
         // qualified test has priority
         if (isset($types[ilLOUserResults::TYPE_QUALIFIED])) {
             $result = $types[ilLOUserResults::TYPE_QUALIFIED];
             $result["type"] = ilLOUserResults::TYPE_QUALIFIED;
             $result["initial"] = $types[ilLOUserResults::TYPE_INITIAL];
         } else {
             $result = $types[ilLOUserResults::TYPE_INITIAL];
             $result["type"] = ilLOUserResults::TYPE_INITIAL;
         }
         $result["initial_status"] = $initial_status;
         $result["itest"] = $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL);
         $result["qtest"] = $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
         $res[$objective_id] = $result;
     }
     return $res;
 }
 function reset($a_course_id)
 {
     global $ilDB;
     include_once './Modules/Course/classes/class.ilCourseObjective.php';
     include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
     include_once './Services/Object/classes/class.ilObjectFactory.php';
     $factory = new ilObjectFactory();
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
     $assignments = ilLOTestAssignments::getInstance($a_course_id);
     foreach (array_merge($assignments->getAssignmentsByType(ilLOSettings::TYPE_TEST_INITIAL), $assignments->getAssignmentsByType(ilLOSettings::TYPE_TEST_QUALIFIED)) as $assignment) {
         $tst = $factory->getInstanceByRefId($assignment->getTestRefId(), FALSE);
         if ($tst instanceof ilObjTest) {
             $this->resetTestForUser($tst, $this->getUserId());
         }
     }
     $initial = ilLOSettings::getInstanceByObjId($a_course_id)->getInitialTest();
     $initial_tst = $factory->getInstanceByRefId($initial, FALSE);
     if ($initial_tst instanceof ilObjTest) {
         $this->resetTestForUser($initial_tst, $this->getUserId());
     }
     $qualified = ilLOSettings::getInstanceByObjId($a_course_id)->getQualifiedTest();
     $qualified_tst = $factory->getInstanceByRefId($qualified, FALSE);
     if ($qualified_tst instanceof ilObjTest) {
         $this->resetTestForUser($qualified_tst, $this->getUserId());
     }
     $objectives = ilCourseObjective::_getObjectiveIds($a_course_id, FALSE);
     if (count($objectives)) {
         $query = "DELETE FROM crs_objective_status " . "WHERE " . $ilDB->in('objective_id', $objectives, false, 'integer') . ' ' . "AND user_id = " . $ilDB->quote($this->getUserId(), 'integer') . " ";
         $res = $ilDB->manipulate($query);
         $query = "DELETE FROM crs_objective_status_p " . "WHERE " . $ilDB->in('objective_id', $objectives, false, 'integer') . ' ' . "AND user_id = " . $ilDB->quote($this->getUserId()) . "";
         $res = $ilDB->manipulate($query);
         $query = "DELETE FROM loc_user_results " . "WHERE " . $ilDB->in('objective_id', $objectives, false, 'integer') . ' ' . "AND user_id = " . $ilDB->quote($this->getUserId()) . "";
     }
     // update/reset LP for course
     include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
     ilLPStatusWrapper::_updateStatus($a_course_id, $this->getUserId());
     return true;
 }
Exemplo n.º 7
0
 /**
  * clone objectives
  *
  * @access public
  * @param int target id
  * @param int copy id
  * 
  */
 public function ilClone($a_target_id, $a_copy_id)
 {
     global $ilLog;
     $ilLog->write(__METHOD__ . ': Start cloning learning objectives...');
     $query = "SELECT * FROM crs_objectives " . "WHERE crs_id  = " . $this->db->quote($this->course_obj->getId(), 'integer') . ' ' . "ORDER BY position ";
     $res = $this->db->query($query);
     if (!$res->numRows()) {
         $ilLog->write(__METHOD__ . ': ... no objectives found.');
         return true;
     }
     if (!is_object($new_course = ilObjectFactory::getInstanceByRefId($a_target_id, false))) {
         $ilLog->write(__METHOD__ . ': Cannot init new course object.');
         return true;
     }
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $new_objective = new ilCourseObjective($new_course);
         $new_objective->setTitle($row->title);
         $new_objective->setDescription($row->description);
         $new_objective->setActive($row->active);
         $objective_id = $new_objective->add();
         $ilLog->write(__METHOD__ . ': Added new objective nr: ' . $objective_id);
         // Clone crs_objective_tst entries
         include_once 'Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
         $objective_qst = new ilCourseObjectiveQuestion($row->objective_id);
         $objective_qst->cloneDependencies($objective_id, $a_copy_id);
         // Clone test assignments
         include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
         include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
         $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
         $assignment_it = $assignments->getAssignmentByObjective($row->objective_id, ilLOSettings::TYPE_TEST_INITIAL);
         if ($assignment_it) {
             $assignment_it->cloneSettings($a_copy_id, $new_course->getId(), $objective_id);
         }
         $assignment_qt = $assignments->getAssignmentByObjective($row->objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
         if ($assignment_qt) {
             $assignment_qt->cloneSettings($a_copy_id, $new_course->getId(), $objective_id);
         }
         $ilLog->write(__METHOD__ . ': Finished objective question dependencies: ' . $objective_id);
         // Clone crs_objective_lm entries (assigned course materials)
         include_once 'Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
         $objective_material = new ilCourseObjectiveMaterials($row->objective_id);
         $objective_material->cloneDependencies($objective_id, $a_copy_id);
     }
     $ilLog->write(__METHOD__ . ': Finished cloning objectives.');
 }
 /**
  * Create test result link
  * @param type $a_type
  * @param type $a_objective_id
  */
 protected function createTestResultLink($a_type, $a_objective_id)
 {
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     $assignments = ilLOTestAssignments::getInstance($this->getParentContainer()->getId());
     $test_ref_id = $assignments->getTestByObjective($a_objective_id, $a_type);
     if (!$test_ref_id) {
         return '';
     }
     include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';
     return ilLOUtils::getTestResultLinkForUser($test_ref_id, $this->getUserId());
 }
Exemplo n.º 9
0
 /**
  * Check if test ref_id is used in an objective course
  * @param int ref_id
  * 
  * @todo refactor check assignments
  */
 public static function isObjectiveTest($a_trst_ref_id)
 {
     global $ilDB;
     // Check for direct assignment
     $query = 'SELECT obj_id FROM loc_settings ' . 'WHERE itest = ' . $ilDB->quote($a_trst_ref_id, 'integer') . ' ' . 'OR qtest = ' . $ilDB->quote($a_trst_ref_id, 'integer');
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         return $row->obj_id;
     }
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     return ilLOTestAssignments::lookupContainerForTest($a_trst_ref_id);
 }
Exemplo n.º 10
0
 /**
  * Delete assignments
  * @param type $a_type
  */
 protected function deleteAssignments($a_type)
 {
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     $assignments = ilLOTestAssignments::getInstance($this->getParentObject()->getId());
     foreach ($assignments->getAssignmentsByType($a_type) as $assignment) {
         $assignment->delete();
     }
     return;
 }
 /**
  * parse
  *
  * @access public
  * @param array array of objective id's
  */
 public function parse($a_objective_ids)
 {
     $position = 1;
     foreach ($a_objective_ids as $objective_id) {
         $objective = new ilCourseObjective($this->course_obj, $objective_id);
         $objective_data['id'] = $objective_id;
         $objective_data['position'] = sprintf("%.1f", $position++) * 10;
         $objective_data['title'] = $objective->getTitle();
         $objective_data['description'] = $objective->getDescription();
         // begin-patch lok
         $objective_data['online'] = $objective->isActive();
         $objective_data['passes'] = $objective->getPasses();
         // end-patch lok
         // assigned materials
         $materials = array();
         $ass_materials = new ilCourseObjectiveMaterials($objective_id);
         foreach ($ass_materials->getMaterials() as $material) {
             $materials[$material['ref_id']]['obj_id'] = $obj_id = ilObject::_lookupObjId($material['ref_id']);
             $materials[$material['ref_id']]['type'] = ilObject::_lookupType($obj_id);
             switch ($material['type']) {
                 case 'pg':
                 case 'st':
                     $materials[$material['ref_id']]['items'][] = $material;
                     break;
                 default:
             }
         }
         $objective_data['materials'] = $materials;
         $question_obj = new ilCourseObjectiveQuestion($objective_id);
         // self assessment questions
         // begin-patch lok
         if ($this->getSettings()->worksWithInitialTest()) {
             if ($this->getSettings()->hasSeparateInitialTests()) {
                 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
                 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
                 $assignment = $assignments->getAssignmentByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL);
                 $objective_data['initial'] = 0;
                 if ($assignment instanceof ilLOTestAssignment) {
                     $test_id = $assignment->getTestRefId();
                     include_once './Services/Object/classes/class.ilObjectFactory.php';
                     $factory = new ilObjectFactory();
                     $test_candidate = $factory->getInstanceByRefId($test_id, FALSE);
                     if ($test_candidate instanceof ilObjTest) {
                         $objective_data['initial'] = $test_id;
                     }
                 }
             } elseif (ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getInitialTest()))) {
                 $test = array();
                 include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
                 $rnd = new ilLORandomTestQuestionPools($this->course_obj->getId(), $objective_id, ilLOSettings::TYPE_TEST_INITIAL);
                 $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getInitialTest());
                 $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getInitialTest(), $rnd->getQplSequence());
                 if ($qst) {
                     $test['questions'][] = array('title' => $qst);
                 }
                 $objective_data['self'] = array($test);
             } else {
                 $tests = array();
                 foreach ($question_obj->getSelfAssessmentTests() as $test) {
                     $questions = array();
                     foreach ($question_obj->getQuestionsOfTest($test['obj_id']) as $qst) {
                         $questions[] = $qst;
                     }
                     $tmp_test = $test;
                     $tmp_test['questions'] = $questions;
                     $tests[] = $tmp_test;
                 }
                 $objective_data['self'] = $tests;
             }
         }
         // end-patch lok
         // final test questions
         // begin-patch lok
         // single test assignments
         if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) {
             include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
             $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
             $assignment = $assignments->getAssignmentByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
             $objective_data['final'] = 0;
             if ($assignment instanceof ilLOTestAssignment) {
                 $test_id = $assignment->getTestRefId();
                 include_once './Services/Object/classes/class.ilObjectFactory.php';
                 $factory = new ilObjectFactory();
                 $test_candidate = $factory->getInstanceByRefId($test_id, FALSE);
                 if ($test_candidate instanceof ilObjTest) {
                     $objective_data['final'] = $test_id;
                 }
             }
         } elseif ($this->getSettings()->getQualifiedTest()) {
             if (ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getQualifiedTest()))) {
                 $test = array();
                 include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
                 $rnd = new ilLORandomTestQuestionPools($this->course_obj->getId(), $objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
                 $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getQualifiedTest());
                 $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getQualifiedTest(), $rnd->getQplSequence());
                 if ($qst) {
                     $test['questions'][] = array('title' => $qst);
                 }
                 $objective_data['final'] = array($test);
             } else {
                 $tests = array();
                 foreach ($question_obj->getFinalTests() as $test) {
                     $questions = array();
                     foreach ($question_obj->getQuestionsOfTest($test['obj_id']) as $qst) {
                         $questions[] = $qst;
                     }
                     $tmp_test = $test;
                     $tmp_test['questions'] = $questions;
                     $tests[] = $tmp_test;
                 }
                 $objective_data['final'] = $tests;
             }
         }
         // end-patch lok
         $objectives[] = (array) $objective_data;
     }
     $this->setData($objectives ? $objectives : array());
 }
 /**
  * Get an array of course material ids that can be assigned to learning objectives
  * No tst, fold and grp.
  *
  * @access public
  * @static
  *
  * @param int obj id of course
  * @return array data of course materials
  */
 public static function _getAssignableMaterials($a_container_id)
 {
     global $tree, $ilDB;
     $container_obj_id = ilObject::_lookupObjId($a_container_id);
     $all_materials = $tree->getSubTree($tree->getNodeData($a_container_id), true);
     $all_materials = ilUtil::sortArray($all_materials, 'title', 'asc');
     // Filter
     foreach ($all_materials as $material) {
         switch ($material['type']) {
             case 'tst':
                 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
                 $type = ilLOTestAssignments::getInstance($container_obj_id)->getTypeByTest($material['child']);
                 if ($type != ilLOSettings::TYPE_TEST_UNDEFINED) {
                     continue;
                 } else {
                     $assignable[] = $material;
                 }
                 break;
             case 'crs':
             case 'rolf':
             case 'itgr':
                 continue;
             default:
                 $assignable[] = $material;
                 break;
         }
     }
     return $assignable ? $assignable : array();
 }
 public function parseMultipleAssignments()
 {
     include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
     $assignments = ilLOTestAssignments::getInstance($this->container_id);
     $available = $assignments->getAssignmentsByType($this->test_type);
     $data = array();
     foreach ($available as $assignment) {
         try {
             $tmp = $this->doParse($assignment->getTestRefId(), $assignment->getObjectiveId());
         } catch (ilLOInvalidConfigurationException $e) {
             $assignment->delete();
             continue;
         }
         if ($tmp) {
             // add assignment id
             $tmp['assignment_id'] = $assignment->getAssignmentId();
             $data[] = $tmp;
         }
     }
     $this->setData($data);
 }
Exemplo n.º 14
0
 protected function parseObjectives($a_obj_id, $a_user_id)
 {
     $res = array();
     // we need the collection for the correct order
     include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
     include_once "Services/Tracking/classes/collection/class.ilLPCollectionOfObjectives.php";
     $coll_objtv = new ilLPCollectionOfObjectives($a_obj_id, ilLPObjSettings::LP_MODE_OBJECTIVES);
     $coll_objtv = $coll_objtv->getItems();
     if ($coll_objtv) {
         // #13373
         $lo_results = $this->parseLOUserResults($a_obj_id, $a_user_id);
         include_once "Modules/Course/classes/Objectives/class.ilLOTestAssignments.php";
         $lo_ass = ilLOTestAssignments::getInstance($a_obj_id);
         $tmp = array();
         include_once "Modules/Course/classes/class.ilCourseObjective.php";
         foreach ($coll_objtv as $objective_id) {
             // patch optes start
             $title = ilCourseObjective::lookupObjectiveTitle($objective_id, true);
             $tmp[$objective_id] = array("id" => $objective_id, "title" => $title["title"], "desc" => $title["description"], "itest" => $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL), "qtest" => $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED));
             // patch optes end
             if (array_key_exists($objective_id, $lo_results)) {
                 $lo_result = $lo_results[$objective_id];
                 $tmp[$objective_id]["user_id"] = $lo_result["user_id"];
                 $tmp[$objective_id]["result_perc"] = $lo_result["result_perc"];
                 $tmp[$objective_id]["limit_perc"] = $lo_result["limit_perc"];
                 $tmp[$objective_id]["status"] = $lo_result["status"];
                 $tmp[$objective_id]["type"] = $lo_result["type"];
                 $tmp[$objective_id]["initial"] = $lo_result["initial"];
             }
         }
         // order
         foreach ($coll_objtv as $objtv_id) {
             $res[] = $tmp[$objtv_id];
         }
     }
     return $res;
 }