ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilCourseObjectiveMaterials.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
34{
35 var $db = null;
36
37 var $objective_id = null;
38 var $lms;
39
40 public function __construct($a_objective_id)
41 {
42 global $ilDB;
43
44 $this->db =& $ilDB;
45
46 $this->objective_id = $a_objective_id;
47
48 $this->__read();
49 }
50
60 public function cloneDependencies($a_new_objective,$a_copy_id)
61 {
62 global $ilObjDataCache,$ilLog;
63
64 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
65 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
66 $mappings = $cwo->getMappings();
67 #$ilLog->write(__METHOD__.': 1');
68 foreach($this->getMaterials() as $material)
69 {
70 #$ilLog->write(__METHOD__.': 2');
71 // Copy action omit ?
72 if(!isset($mappings[$material['ref_id']]) or !$mappings[$material['ref_id']])
73 {
74 continue;
75 }
76 #$ilLog->write(__METHOD__.': 3');
77 $material_ref_id = $material['ref_id'];
78 $material_rbac_obj_id = $ilObjDataCache->lookupObjId($material_ref_id);
79 $material_obj_id = $material['obj_id'];
80 $new_ref_id = $mappings[$material_ref_id];
81 $new_rbac_obj_id = $ilObjDataCache->lookupObjId($new_ref_id);
82 #$ilLog->write(__METHOD__.': 4');
83
84 // Link
85 if($new_rbac_obj_id == $material_rbac_obj_id)
86 {
87 #$ilLog->write(__METHOD__.': 5');
88 $ilLog->write(__METHOD__.': Material has been linked. Keeping object id.');
89 $new_obj_id = $material_obj_id;
90 }
91 elseif($material['type'] == 'st' or $material['type'] == 'pg')
92 {
93
94 #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($material,TRUE));
95 #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($mappings,TRUE));
96
97 #$ilLog->write(__METHOD__.': 6');
98 // Chapter assignment
99 $new_material_info = isset($mappings[$material_ref_id.'_'.$material_obj_id]) ?
100 $mappings[$material_ref_id.'_'.$material_obj_id] :
101 '';
102 $new_material_arr = explode('_',$new_material_info);
103 if(!isset($new_material_arr[1]) or !$new_material_arr[1])
104 {
105 $ilLog->write(__METHOD__.': No mapping found for chapter: '.$material_obj_id);
106 continue;
107 }
108 $new_obj_id = $new_material_arr[1];
109 $ilLog->write(__METHOD__.': New material id is: '.$new_obj_id);
110 }
111 else
112 {
113 #$ilLog->write(__METHOD__.': 7');
114 // Any type
115 $new_obj_id = $ilObjDataCache->lookupObjId($mappings[$material_ref_id]);
116 }
117
118 #$ilLog->write(__METHOD__.': 8');
119 $new_material = new ilCourseObjectiveMaterials($a_new_objective);
120 #$ilLog->write(__METHOD__.': 8.1');
121 $new_material->setLMRefId($new_ref_id);
122 #$ilLog->write(__METHOD__.': 8.2');
123 $new_material->setLMObjId($new_obj_id);
124 #$ilLog->write(__METHOD__.': 8.3');
125 $new_material->setType($material['type']);
126 #$ilLog->write(__METHOD__.': 8.4');
127 $new_material->add();
128 #$ilLog->write(__METHOD__.': 9');
129
130 }
131 }
132
141 public static function _getAssignedMaterials($a_objective_id)
142 {
143 global $ilDB;
144
145 $query = "SELECT DISTINCT(ref_id) ref_id FROM crs_objective_lm ".
146 "WHERE objective_id = ".$ilDB->quote($a_objective_id ,'integer');
147 $res = $ilDB->query($query);
148 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
149 {
150 $ref_ids[] = $row->ref_id;
151 }
152 return $ref_ids ? $ref_ids : array();
153 }
154
155
156
167 public static function _getAssignableMaterials($a_container_id)
168 {
169 global $tree,$ilDB;
170
171 $all_materials = $tree->getSubTree($tree->getNodeData($a_container_id),true);
172 $all_materials = ilUtil::sortArray($all_materials,'title','asc');
173
174 // Filter
175 foreach($all_materials as $material)
176 {
177 switch($material['type'])
178 {
179 case 'tst':
180 if(ilLOSettings::getInstanceByObjId($a_container_id)->isObjectiveTest($material['child']))
181 {
182 continue;
183 }
184 else
185 {
186 $assignable[] = $material;
187 }
188 break;
189
190 case 'crs':
191 case 'rolf':
192 case 'itgr':
193 continue;
194
195 default:
196 $assignable[] = $material;
197 break;
198 }
199 }
200 return $assignable ? $assignable : array();
201 }
202
211 public static function _getAllAssignedMaterials($a_container_id)
212 {
213 global $ilDB;
214
215 $query = "SELECT DISTINCT(com.ref_id) ref_id FROM crs_objectives co ".
216 "JOIN crs_objective_lm com ON co.objective_id = com.objective_id ".
217 "JOIN object_reference obr ON com.ref_id = obr.ref_id ".
218 "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
219 "WHERE co.crs_id = ".$ilDB->quote($a_container_id,'integer')." ".
220 "ORDER BY obd.title ";
221
222 $res = $ilDB->query($query);
223 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
224 {
225 $ref_ids[] = $row->ref_id;
226 }
227 return $ref_ids ? $ref_ids : array();
228 }
229
230 public function getMaterials()
231 {
232 return $this->lms ? $this->lms : array();
233 }
234
235 function getChapters()
236 {
237 foreach($this->lms as $lm_data)
238 {
239 if($lm_data['type'] == 'st')
240 {
241 $chapters[] = $lm_data;
242 }
243 if($lm_data['type'] == 'pg')
244 {
245 $chapters[] = $lm_data;
246 }
247 }
248 return $chapters ? $chapters : array();
249 }
250
251 function getLM($lm_id)
252 {
253 return $this->lms[$lm_id] ? $this->lms[$lm_id] : array();
254 }
255
256 function getObjectiveId()
257 {
258 return $this->objective_id;
259 }
260
261 function setLMRefId($a_ref_id)
262 {
263 $this->lm_ref_id = $a_ref_id;
264 }
265 function getLMRefId()
266 {
267 return $this->lm_ref_id ? $this->lm_ref_id : 0;
268 }
269 function setLMObjId($a_obj_id)
270 {
271 $this->lm_obj_id = $a_obj_id;
272 }
273 function getLMObjId()
274 {
275 return $this->lm_obj_id ? $this->lm_obj_id : 0;
276 }
277 function setType($a_type)
278 {
279 $this->type = $a_type;
280 }
281 function getType()
282 {
283 return $this->type;
284 }
285
294 public function isAssigned($a_ref_id, $a_get_id = false)
295 {
296 global $ilDB;
297
298 $query = "SELECT * FROM crs_objective_lm ".
299 "WHERE ref_id = ".$this->db->quote($a_ref_id ,'integer')." ".
300 "AND objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
301 "AND type != 'st' AND type != 'pg' ";
302 $res = $this->db->query($query);
303
304 // begin-patch lok
305 if(!$a_get_id)
306 {
307 return $res->numRows() ? true : false;
308 }
309 else
310 {
311 $row = $this->db->fetchAssoc($res);
312 return $row["lm_ass_id"];
313 }
314 // end-patch lok
315 }
316
325 public function isChapterAssigned($a_ref_id,$a_obj_id)
326 {
327 global $ilDB;
328
329 $query = "SELECT * FROM crs_objective_lm ".
330 "WHERE ref_id = ".$this->db->quote($a_ref_id ,'integer')." ".
331 "AND obj_id = ".$this->db->quote($a_obj_id ,'integer')." ".
332 "AND objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
333 "AND (type = 'st' OR type = 'pg')";
334 $res = $this->db->query($query);
335 return $res->numRows() ? true : false;
336 }
337 function checkExists()
338 {
339 global $ilDB;
340
341 if($this->getLMObjId())
342 {
343 $query = "SELECT * FROM crs_objective_lm ".
344 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
345 "AND ref_id = ".$ilDB->quote($this->getLMRefId() ,'integer')." ".
346 "AND obj_id = ".$ilDB->quote($this->getLMObjId() ,'integer')." ";
347 }
348 else
349 {
350 $query = "SELECT * FROM crs_objective_lm ".
351 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
352 "AND ref_id = ".$ilDB->quote($this->getLMRefId() ,'integer')." ";
353 }
354
355 $res = $this->db->query($query);
356
357 return $res->numRows() ? true : false;
358 }
359
360 function add()
361 {
362 global $ilDB;
363
364 $next_id = $ilDB->nextId('crs_objective_lm');
365 $query = "INSERT INTO crs_objective_lm (lm_ass_id,objective_id,ref_id,obj_id,type) ".
366 "VALUES( ".
367 $ilDB->quote($next_id, 'integer').", ".
368 $ilDB->quote($this->getObjectiveId() ,'integer').", ".
369 $ilDB->quote($this->getLMRefId() ,'integer').", ".
370 $ilDB->quote($this->getLMObjId() ,'integer').", ".
371 $ilDB->quote($this->getType() ,'text').
372 ")";
373 $res = $ilDB->manipulate($query);
374
375 return true;
376 }
377 function delete($lm_id)
378 {
379 global $ilDB;
380
381 if(!$lm_id)
382 {
383 return false;
384 }
385
386 $query = "DELETE FROM crs_objective_lm ".
387 "WHERE lm_ass_id = ".$ilDB->quote($lm_id ,'integer')." ";
388 $res = $ilDB->manipulate($query);
389
390 return true;
391 }
392
393 function deleteAll()
394 {
395 global $ilDB;
396
397 $query = "DELETE FROM crs_objective_lm ".
398 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
399 $res = $ilDB->manipulate($query);
400 return true;
401 }
402
403 // begin-patch lok
404
412 public function writePosition($a_ass_id, $a_position)
413 {
414 global $ilDB;
415
416 $query = "UPDATE crs_objective_lm ".
417 "SET position = ".$this->db->quote((string) $a_position ,'integer')." ".
418 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
419 "AND lm_ass_id = ".$ilDB->quote($a_ass_id, "integer");
420 $res = $ilDB->manipulate($query);
421 }
422
423 // end-patch lok
424
425 // PRIVATE
426 function __read()
427 {
428 global $tree,$ilDB;
429
430 include_once('Modules/Course/classes/class.ilCourseObjective.php');
432 $container_ref_id = current($container_ref_ids);
433
434 // begin-patch lok
435
436 $this->lms = array();
437 $query = "SELECT position,lm_ass_id,lm.ref_id,lm.obj_id,lm.type FROM crs_objective_lm lm ".
438 "JOIN object_reference obr ON lm.ref_id = obr.ref_id ".
439 "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
440 "LEFT JOIN lm_data lmd ON lmd.obj_id = lm.obj_id ".
441 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId(),'integer')." ".
442 "ORDER BY position,obd.title,lmd.title";
443
444 $res = $this->db->query($query);
445 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
446 {
447 if(!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id,$row->ref_id))
448 {
449 $this->delete($row->lm_ass_id);
450 continue;
451 }
452 $lm['ref_id'] = $row->ref_id;
453 $lm['obj_id'] = $row->obj_id;
454 $lm['type'] = $row->type;
455 $lm['lm_ass_id'] = $row->lm_ass_id;
456 $lm['position'] = $row->position;
457
458 $this->lms[$row->lm_ass_id] = $lm;
459 }
460
461 // end-patch lok
462
463 return true;
464 }
465
466}
467?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _getInstance($a_copy_id)
Get instance of copy wizard options.
class ilCourseObjectiveMaterials
cloneDependencies($a_new_objective, $a_copy_id)
clone objective materials
static _getAssignableMaterials($a_container_id)
Get an array of course material ids that can be assigned to learning objectives No tst,...
isAssigned($a_ref_id, $a_get_id=false)
Check if material is assigned.
static _getAssignedMaterials($a_objective_id)
get assigned materials
static _getAllAssignedMaterials($a_container_id)
Get all assigned materials.
isChapterAssigned($a_ref_id, $a_obj_id)
Check if chapter is assigned.
writePosition($a_ass_id, $a_position)
write position
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
static getInstanceByObjId($a_obj_id)
get singleton instance
static _getAllReferences($a_id)
get all reference ids of object
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
global $ilDB