Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035 class ilLPCollections
00036 {
00037 var $db = null;
00038
00039 var $obj_id = null;
00040 var $items = array();
00041
00042 function ilLPCollections($a_obj_id)
00043 {
00044 global $ilObjDataCache,$ilDB;
00045
00046 $this->db =& $ilDB;
00047
00048 $this->obj_id = $a_obj_id;
00049
00050 $this->__read();
00051 }
00052
00060 public function cloneCollections($a_target_id,$a_copy_id)
00061 {
00062 global $ilObjDataCache,$ilLog;
00063
00064 $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
00065
00066 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00067 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
00068 $mappings = $cwo->getMappings();
00069
00070 $new_collections = new ilLPCollections($target_obj_id);
00071 foreach($this->items as $item)
00072 {
00073 if(!isset($mappings[$item]) or !$mappings[$item])
00074 {
00075 continue;
00076 }
00077 $new_collections->add($mappings[$item]);
00078 $ilLog->write(__METHOD__.': Added learning progress collection.');
00079 }
00080 }
00081
00082 function getObjId()
00083 {
00084 return (int) $this->obj_id;
00085 }
00086
00087 function getItems()
00088 {
00089 return $this->items;
00090 }
00091
00092 function isAssigned($a_ref_id)
00093 {
00094 return (bool) in_array($a_ref_id,$this->items);
00095 }
00096
00097 function add($item_id)
00098 {
00099 $query = "DELETE FROM ut_lp_collections ".
00100 "WHERE obj_id = '".$this->obj_id."' ".
00101 "AND item_id = '".(int) $item_id."'";
00102 $this->db->query($query);
00103
00104 $query = "REPLACE INTO ut_lp_collections ".
00105 "SET obj_id = '".$this->obj_id."', ".
00106 "item_id = '".(int) $item_id."'";
00107 $this->db->query($query);
00108 $this->__read();
00109
00110 return true;
00111 }
00112
00113 function delete($item_id)
00114 {
00115 $query = "DELETE FROM ut_lp_collections ".
00116 "WHERE item_id = '".$item_id."' ".
00117 "AND obj_id = '".$this->obj_id."'";
00118 $this->db->query($query);
00119
00120 $this->__read();
00121
00122 return true;
00123 }
00124
00125
00126
00127 function _getPossibleItems($a_target_id)
00128 {
00129 global $tree;
00130
00131 if($tree->isDeleted($a_target_id))
00132 {
00133 return array();
00134 }
00135
00136 $node_data = $tree->getNodeData($a_target_id);
00137 foreach($tree->getSubTree($node_data) as $node)
00138 {
00139
00140 if($node['ref_id'] == $a_target_id)
00141 {
00142 continue;
00143 }
00144
00145 switch($node['type'])
00146 {
00147 case 'exc':
00148 case 'fold':
00149 case 'grp':
00150 case 'sahs':
00151 case 'lm':
00152 case 'tst':
00153 case 'htlm':
00154 $all_possible[] = $node['ref_id'];
00155 break;
00156 }
00157 }
00158
00159 return $all_possible ? $all_possible : array();
00160 }
00161
00162 function _getCountPossibleItems($a_target_id)
00163 {
00164 return count(ilLPCollections::_getPossibleItems($a_target_id));
00165 }
00166
00167 function _getCountPossibleSAHSItems($a_target_id)
00168 {
00169 return count(ilLPCollections::_getPossibleSAHSItems($a_target_id));
00170 }
00171
00172
00177 function _getPossibleSAHSItems($target_id)
00178 {
00179 include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
00180
00181 switch(ilObjSAHSLearningModule::_lookupSubType($target_id))
00182 {
00183 case 'hacp':
00184 case 'aicc':
00185 include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
00186
00187 foreach(ilObjAICCLearningModule::_getTrackingItems($target_id) as $item)
00188 {
00189 $items["$item[obj_id]"]['title'] = $item['title'];
00190 #$items[$item->getId()]['title'] = $item->getTitle();
00191 }
00192 return $items ? $items : array();
00193
00194 case 'scorm':
00195 include_once './Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
00196 include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
00197
00198 foreach(ilObjSCORMLearningModule::_getTrackingItems($target_id) as $item)
00199 {
00200 $items[$item->getId()]['title'] = $item->getTitle();
00201 }
00202 return $items ? $items : array();
00203
00204 case 'scorm2004':
00205 include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
00206
00207 foreach(ilObjSCORM2004LearningModule::_getTrackingItems($target_id) as $item)
00208 {
00209 $items[$item["id"]]['title'] = $item["title"];
00210 }
00211 return $items ? $items : array();
00212 }
00213 return array();
00214 }
00215
00216 function deleteAll()
00217 {
00218 return ilLPCollections::_deleteAll($this->getObjId());
00219 }
00220
00221
00222 function _deleteAll($a_obj_id)
00223 {
00224 global $ilDB;
00225
00226 $query = "DELETE FROM ut_lp_collections ".
00227 "WHERE obj_id = '".$a_obj_id."'";
00228 $ilDB->query($query);
00229
00230 return true;
00231 }
00232
00233 function &_getItems($a_obj_id)
00234 {
00235 global $ilObjDataCache;
00236 global $ilDB;
00237
00238 include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
00239
00240 $mode = ilLPObjSettings::_lookupMode($a_obj_id);
00241 if($mode == LP_MODE_OBJECTIVES)
00242 {
00243 include_once 'Modules/Course/classes/class.ilCourseObjective.php';
00244 return ilCourseObjective::_getObjectiveIds($a_obj_id);
00245 }
00246 if($mode != LP_MODE_SCORM and $mode != LP_MODE_COLLECTION and $mode != LP_MODE_MANUAL_BY_TUTOR)
00247 {
00248 return array();
00249 }
00250
00251 if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
00252 {
00253 $course_ref_ids = ilObject::_getAllReferences($a_obj_id);
00254 $course_ref_id = end($course_ref_ids);
00255 $possible_items = ilLPCollections::_getPossibleItems($course_ref_id);
00256
00257 $query = "SELECT * FROM ut_lp_collections as utc ".
00258 "JOIN object_reference as obr ON item_id = ref_id ".
00259 "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
00260 "WHERE utc.obj_id = ".$ilDB->quote($a_obj_id)." ".
00261 "ORDER BY title";
00262 }
00263 else
00264 {
00265
00266 $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$a_obj_id."'";
00267 }
00268
00269 $res = $ilDB->query($query);
00270 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00271 {
00272 if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
00273 {
00274 if(!in_array($row->item_id,$possible_items))
00275 {
00276 ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
00277 continue;
00278 }
00279 }
00280
00281 if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
00282 {
00283 include_once './Modules/Test/classes/class.ilObjTest.php';
00284 if(ilObjTest::_lookupAnonymity($item_obj_id))
00285 {
00286 ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
00287 continue;
00288 }
00289 }
00290 $items[] = $row->item_id;
00291 }
00292 return $items ? $items : array();
00293 }
00294
00295
00296 function __deleteEntry($a_obj_id,$a_item_id)
00297 {
00298 global $ilDB;
00299
00300 $query = "DELETE FROM ut_lp_collections ".
00301 "WHERE obj_id = '".$a_obj_id."' ".
00302 "AND item_id = '".$a_item_id."'";
00303 $ilDB->query($query);
00304 return true;
00305 }
00306
00307
00308 function __read()
00309 {
00310 global $ilObjDataCache;
00311
00312 if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
00313 {
00314 $course_ref_ids = ilObject::_getAllReferences($this->getObjId());
00315 $course_ref_id = end($course_ref_ids);
00316 $query = "SELECT * FROM ut_lp_collections as utc ".
00317 "JOIN object_reference as obr ON item_id = ref_id ".
00318 "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
00319 "WHERE utc.obj_id = ".$this->db->quote($this->obj_id)." ".
00320 "ORDER BY title";
00321 }
00322 else
00323 {
00324 $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$this->getObjId()."'";
00325 }
00326 $res = $this->db->query($query);
00327 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00328 {
00329 if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
00330 {
00331 if(!in_array($row->item_id,ilLPCollections::_getPossibleItems($course_ref_id)))
00332 {
00333 $this->__deleteEntry($this->getObjId(),$row->item_id);
00334 continue;
00335 }
00336 }
00337
00338 if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
00339 {
00340 include_once './Modules/Test/classes/class.ilObjTest.php';
00341 if(ilObjTest::_lookupAnonymity($item_obj_id))
00342 {
00343 $this->__deleteEntry($this->getObjId(),$row->item_id);
00344 continue;
00345 }
00346 }
00347 $this->items[] = $row->item_id;
00348 }
00349
00350 }
00351 }
00352 ?>