ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $container_obj_id = ilObject::_lookupObjId($a_container_id);
172
173 $all_materials = $tree->getSubTree($tree->getNodeData($a_container_id),true);
174 $all_materials = ilUtil::sortArray($all_materials,'title','asc');
175
176 // Filter
177 foreach($all_materials as $material)
178 {
179 switch($material['type'])
180 {
181 case 'tst':
182
183 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
184 $type = ilLOTestAssignments::getInstance($container_obj_id)->getTypeByTest($material['child']);
186 {
187 continue;
188 }
189 else
190 {
191 $assignable[] = $material;
192 }
193 break;
194
195 case 'crs':
196 case 'rolf':
197 case 'itgr':
198 continue;
199
200 default:
201 $assignable[] = $material;
202 break;
203 }
204 }
205 return $assignable ? $assignable : array();
206 }
207
216 public static function _getAllAssignedMaterials($a_container_id)
217 {
218 global $ilDB;
219
220 $query = "SELECT DISTINCT(com.ref_id) ref_id FROM crs_objectives co ".
221 "JOIN crs_objective_lm com ON co.objective_id = com.objective_id ".
222 "JOIN object_reference obr ON com.ref_id = obr.ref_id ".
223 "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
224 "WHERE co.crs_id = ".$ilDB->quote($a_container_id,'integer')." ".
225 "ORDER BY obd.title ";
226
227 $res = $ilDB->query($query);
228 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
229 {
230 $ref_ids[] = $row->ref_id;
231 }
232 return $ref_ids ? $ref_ids : array();
233 }
234
235 public function getMaterials()
236 {
237 return $this->lms ? $this->lms : array();
238 }
239
240 function getChapters()
241 {
242 foreach($this->lms as $lm_data)
243 {
244 if($lm_data['type'] == 'st')
245 {
246 $chapters[] = $lm_data;
247 }
248 if($lm_data['type'] == 'pg')
249 {
250 $chapters[] = $lm_data;
251 }
252 }
253 return $chapters ? $chapters : array();
254 }
255
256 function getLM($lm_id)
257 {
258 return $this->lms[$lm_id] ? $this->lms[$lm_id] : array();
259 }
260
261 function getObjectiveId()
262 {
263 return $this->objective_id;
264 }
265
266 function setLMRefId($a_ref_id)
267 {
268 $this->lm_ref_id = $a_ref_id;
269 }
270 function getLMRefId()
271 {
272 return $this->lm_ref_id ? $this->lm_ref_id : 0;
273 }
274 function setLMObjId($a_obj_id)
275 {
276 $this->lm_obj_id = $a_obj_id;
277 }
278 function getLMObjId()
279 {
280 return $this->lm_obj_id ? $this->lm_obj_id : 0;
281 }
282 function setType($a_type)
283 {
284 $this->type = $a_type;
285 }
286 function getType()
287 {
288 return $this->type;
289 }
290
299 public function isAssigned($a_ref_id, $a_get_id = false)
300 {
301 global $ilDB;
302
303 $query = "SELECT * FROM crs_objective_lm ".
304 "WHERE ref_id = ".$this->db->quote($a_ref_id ,'integer')." ".
305 "AND objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
306 "AND type != 'st' AND type != 'pg' ";
307 $res = $this->db->query($query);
308
309 // begin-patch lok
310 if(!$a_get_id)
311 {
312 return $res->numRows() ? true : false;
313 }
314 else
315 {
316 $row = $this->db->fetchAssoc($res);
317 return $row["lm_ass_id"];
318 }
319 // end-patch lok
320 }
321
330 public function isChapterAssigned($a_ref_id,$a_obj_id)
331 {
332 global $ilDB;
333
334 $query = "SELECT * FROM crs_objective_lm ".
335 "WHERE ref_id = ".$this->db->quote($a_ref_id ,'integer')." ".
336 "AND obj_id = ".$this->db->quote($a_obj_id ,'integer')." ".
337 "AND objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
338 "AND (type = 'st' OR type = 'pg')";
339 $res = $this->db->query($query);
340 return $res->numRows() ? true : false;
341 }
342 function checkExists()
343 {
344 global $ilDB;
345
346 if($this->getLMObjId())
347 {
348 $query = "SELECT * FROM crs_objective_lm ".
349 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
350 "AND ref_id = ".$ilDB->quote($this->getLMRefId() ,'integer')." ".
351 "AND obj_id = ".$ilDB->quote($this->getLMObjId() ,'integer')." ";
352 }
353 else
354 {
355 $query = "SELECT * FROM crs_objective_lm ".
356 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
357 "AND ref_id = ".$ilDB->quote($this->getLMRefId() ,'integer')." ";
358 }
359
360 $res = $this->db->query($query);
361
362 return $res->numRows() ? true : false;
363 }
364
365 function add()
366 {
367 global $ilDB;
368
369 $next_id = $ilDB->nextId('crs_objective_lm');
370 $query = "INSERT INTO crs_objective_lm (lm_ass_id,objective_id,ref_id,obj_id,type) ".
371 "VALUES( ".
372 $ilDB->quote($next_id, 'integer').", ".
373 $ilDB->quote($this->getObjectiveId() ,'integer').", ".
374 $ilDB->quote($this->getLMRefId() ,'integer').", ".
375 $ilDB->quote($this->getLMObjId() ,'integer').", ".
376 $ilDB->quote($this->getType() ,'text').
377 ")";
378 $res = $ilDB->manipulate($query);
379
380 return (int) $next_id;
381 }
382 function delete($lm_id)
383 {
384 global $ilDB;
385
386 if(!$lm_id)
387 {
388 return false;
389 }
390
391 $query = "DELETE FROM crs_objective_lm ".
392 "WHERE lm_ass_id = ".$ilDB->quote($lm_id ,'integer')." ";
393 $res = $ilDB->manipulate($query);
394
395 return true;
396 }
397
398 function deleteAll()
399 {
400 global $ilDB;
401
402 $query = "DELETE FROM crs_objective_lm ".
403 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
404 $res = $ilDB->manipulate($query);
405 return true;
406 }
407
408 // begin-patch lok
409
417 public function writePosition($a_ass_id, $a_position)
418 {
419 global $ilDB;
420
421 $query = "UPDATE crs_objective_lm ".
422 "SET position = ".$this->db->quote((string) $a_position ,'integer')." ".
423 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ".
424 "AND lm_ass_id = ".$ilDB->quote($a_ass_id, "integer");
425 $res = $ilDB->manipulate($query);
426 }
427
428 // end-patch lok
429
430 // PRIVATE
431 function __read()
432 {
433 global $tree,$ilDB;
434
435 include_once('Modules/Course/classes/class.ilCourseObjective.php');
437 $container_ref_id = current($container_ref_ids);
438
439 // begin-patch lok
440
441 $this->lms = array();
442 $query = "SELECT position,lm_ass_id,lm.ref_id,lm.obj_id,lm.type FROM crs_objective_lm lm ".
443 "JOIN object_reference obr ON lm.ref_id = obr.ref_id ".
444 "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
445 "LEFT JOIN lm_data lmd ON lmd.obj_id = lm.obj_id ".
446 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId(),'integer')." ".
447 "ORDER BY position,obd.title,lmd.title";
448
449 $res = $this->db->query($query);
450 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
451 {
452 if(!$tree->isInTree($row->ref_id) or !$tree->isGrandChild($container_ref_id,$row->ref_id))
453 {
454 $this->delete($row->lm_ass_id);
455 continue;
456 }
457 $lm['ref_id'] = $row->ref_id;
458 $lm['obj_id'] = $row->obj_id;
459 $lm['type'] = $row->type;
460 $lm['lm_ass_id'] = $row->lm_ass_id;
461 $lm['position'] = $row->position;
462
463 $this->lms[$row->lm_ass_id] = $lm;
464 }
465
466 // end-patch lok
467
468 return true;
469 }
470
471 // begin-patch optes_lok_export
472
477 public function toXml(ilXmlWriter $writer)
478 {
479 foreach($this->getMaterials() as $material)
480 {
481 $writer->xmlElement(
482 'Material',
483 array(
484 'refId' => $material['ref_id'],
485 'objId' => $material['obj_id'],
486 'type' => $material['type'],
487 'position' => $material['position']
488 )
489 );
490 }
491 return true;
492 }
493
494}
495?>
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 getInstance($a_container_id)
Get instance by container id.
static _lookupObjId($a_id)
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
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
global $ilDB