1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once "Services/Object/classes/class.ilObjectLP.php"; 5 6/** 7 * Test to lp connector 8 * 9 * @author Jörg Lützenkirchen <luetzenkirchen@leifos.com> 10 * @version $Id: class.ilLPStatusPlugin.php 43734 2013-07-29 15:27:58Z jluetzen $ 11 * @package ModulesTest 12 */ 13class ilTestLP extends ilObjectLP 14{ 15 /** 16 * @var \ilObjTest 17 */ 18 protected $testObj; 19 20 public static function getDefaultModes($a_lp_active) 21 { 22 return array( 23 ilLPObjSettings::LP_MODE_DEACTIVATED, 24 ilLPObjSettings::LP_MODE_TEST_FINISHED, 25 ilLPObjSettings::LP_MODE_TEST_PASSED 26 ); 27 } 28 29 public function getDefaultMode() 30 { 31 return ilLPObjSettings::LP_MODE_TEST_PASSED; 32 } 33 34 public function getValidModes() 35 { 36 return array( 37 ilLPObjSettings::LP_MODE_DEACTIVATED, 38 ilLPObjSettings::LP_MODE_TEST_FINISHED, 39 ilLPObjSettings::LP_MODE_TEST_PASSED 40 ); 41 } 42 43 public function isAnonymized() 44 { 45 include_once './Modules/Test/classes/class.ilObjTest.php'; 46 return (bool) ilObjTest::_lookupAnonymity($this->obj_id); 47 } 48 49 /** 50 * @param ilObjTest $test 51 */ 52 public function setTestObject(\ilObjTest $test) 53 { 54 $this->testObj = $test; 55 } 56 57 protected function resetCustomLPDataForUserIds(array $a_user_ids, $a_recursive = true) 58 { 59 /* @var ilObjTest $testOBJ */ 60 if ($this->testObj) { 61 // #19247 62 $testOBJ = $this->testObj; 63 } else { 64 require_once 'Services/Object/classes/class.ilObjectFactory.php'; 65 $testOBJ = ilObjectFactory::getInstanceByObjId($this->obj_id); 66 } 67 $testOBJ->removeTestResultsByUserIds($a_user_ids); 68 69 // :TODO: there has to be a better way 70 $test_ref_id = (int) $_REQUEST["ref_id"]; 71 if ($this->testObj && $this->testObj->getRefId()) { 72 $test_ref_id = $this->testObj->getRefId(); 73 } 74 if ($test_ref_id) { 75 require_once "Modules/Course/classes/Objectives/class.ilLOSettings.php"; 76 $course_obj_id = ilLOSettings::isObjectiveTest($test_ref_id); 77 if ($course_obj_id) { 78 // remove objective results data 79 $lo_settings = ilLOSettings::getInstanceByObjId($course_obj_id); 80 81 require_once "Modules/Course/classes/Objectives/class.ilLOUserResults.php"; 82 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php'; 83 ilLOUserResults::deleteResultsFromLP( 84 $course_obj_id, 85 $a_user_ids, 86 ($lo_settings->getInitialTest() == $test_ref_id), 87 ($lo_settings->getQualifiedTest() == $test_ref_id), 88 ilLOTestAssignments::lookupObjectivesForTest($test_ref_id) 89 ); 90 91 // refresh LP - see ilLPStatusWrapper::_updateStatus() 92 require_once "Services/Tracking/classes/class.ilLPStatusFactory.php"; 93 $lp_status = ilLPStatusFactory::_getInstance($course_obj_id); 94 if (strtolower(get_class($lp_status)) != "illpstatus") { 95 foreach ($a_user_ids as $user_id) { 96 $lp_status->_updateStatus($course_obj_id, $user_id); 97 } 98 } 99 } 100 } 101 } 102 103 protected static function isLPMember(array &$a_res, $a_usr_id, $a_obj_ids) 104 { 105 global $DIC; 106 $ilDB = $DIC['ilDB']; 107 108 // if active id 109 $set = $ilDB->query("SELECT tt.obj_fi" . 110 " FROM tst_active ta" . 111 " JOIN tst_tests tt ON (ta.test_fi = tt.test_id)" . 112 " WHERE " . $ilDB->in("tt.obj_fi", (array) $a_obj_ids, false, "integer") . 113 " AND ta.user_fi = " . $ilDB->quote($a_usr_id, "integer")); 114 while ($row = $ilDB->fetchAssoc($set)) { 115 $a_res[$row["obj_fi"]] = true; 116 } 117 118 return true; 119 } 120} 121