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
00053 function getObjId()
00054 {
00055 return (int) $this->obj_id;
00056 }
00057
00058 function getItems()
00059 {
00060 return $this->items;
00061 }
00062
00063 function isAssigned($a_ref_id)
00064 {
00065 return (bool) in_array($a_ref_id,$this->items);
00066 }
00067
00068 function add($item_id)
00069 {
00070 $query = "DELETE FROM ut_lp_collections ".
00071 "WHERE obj_id = '".$this->obj_id."' ".
00072 "AND item_id = '".(int) $item_id."'";
00073 $this->db->query($query);
00074
00075 $query = "REPLACE INTO ut_lp_collections ".
00076 "SET obj_id = '".$this->obj_id."', ".
00077 "item_id = '".(int) $item_id."'";
00078 $this->db->query($query);
00079 $this->__read();
00080
00081 return true;
00082 }
00083
00084 function delete($item_id)
00085 {
00086 $query = "DELETE FROM ut_lp_collections ".
00087 "WHERE item_id = '".$item_id."' ".
00088 "AND obj_id = '".$this->obj_id."'";
00089 $this->db->query($query);
00090
00091 $this->__read();
00092
00093 return true;
00094 }
00095
00096
00097
00098 function _getPossibleItems($a_target_id)
00099 {
00100 global $tree;
00101
00102 if($tree->isDeleted($a_target_id))
00103 {
00104 return array();
00105 }
00106
00107 $node_data = $tree->getNodeData($a_target_id);
00108 foreach($tree->getSubTree($node_data) as $node)
00109 {
00110
00111 if($node['ref_id'] == $a_target_id)
00112 {
00113 continue;
00114 }
00115
00116 switch($node['type'])
00117 {
00118 case 'exc':
00119 case 'fold':
00120 case 'grp':
00121 case 'sahs':
00122 case 'lm':
00123 case 'tst':
00124 case 'htlm':
00125 $all_possible[] = $node['ref_id'];
00126 break;
00127 }
00128 }
00129
00130 return $all_possible ? $all_possible : array();
00131 }
00132
00133 function _getCountPossibleItems($a_target_id)
00134 {
00135 return count(ilLPCollections::_getPossibleItems($a_target_id));
00136 }
00137
00138 function _getCountPossibleSAHSItems($a_target_id)
00139 {
00140 return count(ilLPCollections::_getPossibleSAHSItems($a_target_id));
00141 }
00142
00143
00148 function _getPossibleSAHSItems($target_id)
00149 {
00150 include_once './content/classes/class.ilObjSAHSLearningModule.php';
00151
00152 switch(ilObjSAHSLearningModule::_lookupSubType($target_id))
00153 {
00154 case 'hacp':
00155 case 'aicc':
00156 include_once './content/classes/class.ilObjAICCLearningModule.php';
00157
00158 foreach(ilObjAICCLearningModule::_getTrackingItems($target_id) as $item)
00159 {
00160 $items["$item[obj_id]"]['title'] = $item['title'];
00161 #$items[$item->getId()]['title'] = $item->getTitle();
00162 }
00163 return $items ? $items : array();
00164
00165 case 'scorm':
00166 include_once './content/classes/class.ilObjSCORMLearningModule.php';
00167 include_once './content/classes/SCORM/class.ilSCORMItem.php';
00168
00169 foreach(ilObjSCORMLearningModule::_getTrackingItems($target_id) as $item)
00170 {
00171 $items[$item->getId()]['title'] = $item->getTitle();
00172 }
00173 return $items ? $items : array();
00174 }
00175 return array();
00176 }
00177
00178 function deleteAll()
00179 {
00180 return ilLPCollections::_deleteAll($this->getObjId());
00181 }
00182
00183
00184 function _deleteAll($a_obj_id)
00185 {
00186 global $ilDB;
00187
00188 $query = "DELETE FROM ut_lp_collections ".
00189 "WHERE obj_id = '".$a_obj_id."'";
00190 $ilDB->query($query);
00191
00192 return true;
00193 }
00194
00195 function &_getItems($a_obj_id)
00196 {
00197 global $ilObjDataCache;
00198 global $ilDB;
00199
00200 include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
00201
00202 $mode = ilLPObjSettings::_lookupMode($a_obj_id);
00203 if($mode == LP_MODE_OBJECTIVES)
00204 {
00205 include_once 'course/classes/class.ilCourseObjective.php';
00206 return ilCourseObjective::_getObjectiveIds($a_obj_id);
00207 }
00208 if($mode != LP_MODE_SCORM and $mode != LP_MODE_COLLECTION)
00209 {
00210 return array();
00211 }
00212
00213 if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
00214 {
00215 $course_ref_ids = ilObject::_getAllReferences($a_obj_id);
00216 $course_ref_id = end($course_ref_ids);
00217 $possible_items = ilLPCollections::_getPossibleItems($course_ref_id);
00218
00219 $query = "SELECT * FROM ut_lp_collections as utc ".
00220 "JOIN object_reference as obr ON item_id = ref_id ".
00221 "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
00222 "WHERE utc.obj_id = '".$a_obj_id."' ".
00223 "ORDER BY title";
00224 }
00225 else
00226 {
00227
00228 $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$a_obj_id."'";
00229 }
00230
00231 $res = $ilDB->query($query);
00232 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00233 {
00234 if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
00235 {
00236 if(!in_array($row->item_id,$possible_items))
00237 {
00238 ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
00239 continue;
00240 }
00241 }
00242
00243 if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
00244 {
00245 include_once 'assessment/classes/class.ilObjTest.php';
00246 if(ilObjTest::_lookupTestType($item_obj_id) == TYPE_SELF_ASSESSMENT)
00247 {
00248 ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
00249 continue;
00250 }
00251 }
00252 $items[] = $row->item_id;
00253 }
00254 return $items ? $items : array();
00255 }
00256
00257
00258 function __deleteEntry($a_obj_id,$a_item_id)
00259 {
00260 global $ilDB;
00261
00262 $query = "DELETE FROM ut_lp_collections ".
00263 "WHERE obj_id = '".$a_obj_id."' ".
00264 "AND item_id = '".$a_item_id."'";
00265 $ilDB->query($query);
00266 return true;
00267 }
00268
00269
00270 function __read()
00271 {
00272 global $ilObjDataCache;
00273
00274 if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
00275 {
00276 $course_ref_ids = ilObject::_getAllReferences($this->getObjId());
00277 $course_ref_id = end($course_ref_ids);
00278 $query = "SELECT * FROM ut_lp_collections as utc ".
00279 "JOIN object_reference as obr ON item_id = ref_id ".
00280 "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
00281 "WHERE utc.obj_id = '".$this->db->quote($this->obj_id)."' ".
00282 "ORDER BY title";
00283 }
00284 else
00285 {
00286 $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$this->getObjId()."'";
00287 }
00288 $res = $this->db->query($query);
00289 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00290 {
00291 if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
00292 {
00293 if(!in_array($row->item_id,ilLPCollections::_getPossibleItems($course_ref_id)))
00294 {
00295 $this->__deleteEntry($this->getObjId(),$row->item_id);
00296 continue;
00297 }
00298 }
00299
00300 if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
00301 {
00302 include_once 'assessment/classes/class.ilObjTest.php';
00303 if(ilObjTest::_lookupTestType($item_obj_id) == TYPE_SELF_ASSESSMENT)
00304 {
00305 $this->__deleteEntry($a_obj_id,$row->item_id);
00306 continue;
00307 }
00308 }
00309 $this->items[] = $row->item_id;
00310 }
00311
00312 }
00313 }
00314 ?>