ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLPCollection.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14abstract class ilLPCollection
15{
16 protected $obj_id; // [int]
17 protected $mode; // [int]
18 protected $items; // [array]
19
20 public function __construct($a_obj_id, $a_mode)
21 {
22 $this->obj_id = $a_obj_id;
23 $this->mode = $a_mode;
24
25 if($a_obj_id)
26 {
27 $this->read($a_obj_id);
28 }
29 }
30
31 public static function getInstanceByMode($a_obj_id, $a_mode)
32 {
33 $path = "Services/Tracking/classes/collection/";
34
35 switch($a_mode)
36 {
39 include_once $path."class.ilLPCollectionOfRepositoryObjects.php";
40 return new ilLPCollectionOfRepositoryObjects($a_obj_id, $a_mode);
41
43 include_once $path."class.ilLPCollectionOfObjectives.php";
44 return new ilLPCollectionOfObjectives($a_obj_id, $a_mode);
45
47 include_once $path."class.ilLPCollectionOfSCOs.php";
48 return new ilLPCollectionOfSCOs($a_obj_id, $a_mode);
49
52 include_once $path."class.ilLPCollectionOfLMChapters.php";
53 return new ilLPCollectionOfLMChapters($a_obj_id, $a_mode);
54
56 include_once $path."class.ilLPCollectionOfMediaObjects.php";
57 return new ilLPCollectionOfMediaObjects($a_obj_id, $a_mode);
58 }
59 }
60
61 public static function getCollectionModes()
62 {
63 return array(
70 );
71 }
72
73 public function hasSelectableItems()
74 {
75 return true;
76 }
77
78 public function cloneCollection($a_target_id, $a_copy_id)
79 {
80 global $ilLog;
81
82 $target_obj_id = ilObject::_lookupObjId($a_target_id);
83
84 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
85 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
86 $mappings = $cwo->getMappings();
87
88 // #12067
89 $new_collection = new static($target_obj_id, $this->mode);
90 foreach($this->items as $item)
91 {
92 if(!isset($mappings[$item]) or !$mappings[$item])
93 {
94 continue;
95 }
96
97 $new_collection->addEntry($mappings[$item]);
98 }
99
100 $ilLog->write(__METHOD__.': cloned learning progress collection.');
101 }
102
103
104 //
105 // CRUD
106 //
107
108 public function getItems()
109 {
110 return $this->items;
111 }
112
113 protected function read()
114 {
115 global $ilDB;
116
117 $items = array();
118
119 $res = $ilDB->query("SELECT * FROM ut_lp_collections".
120 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer"));
121 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
122 {
123 if($this->validateEntry($row->item_id))
124 {
125 $items[] = $row->item_id;
126 }
127 else
128 {
129 $this->deleteEntry($row->item_id);
130 }
131 }
132
133 $this->items = $items;
134 }
135
136 public function delete()
137 {
138 global $ilDB;
139
140 $query = "DELETE FROM ut_lp_collections".
141 " WHERE obj_id = ".$ilDB->quote($this->obj_id ,"integer");
142 $ilDB->manipulate($query);
143
144 $query = "DELETE FROM ut_lp_coll_manual".
145 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer");
146 $ilDB->manipulate($query);
147
148 // #15462 - reset internal data
149 $this->items = array();
150
151 return true;
152 }
153
154 //
155 // ENTRIES
156 //
157
158 protected function validateEntry($a_item_id)
159 {
160 return true;
161 }
162
163 public function isAssignedEntry($a_item_id)
164 {
165 if(is_array($this->items))
166 {
167 return (bool)in_array($a_item_id, $this->items);
168 }
169 return false;
170 }
171
172 protected function addEntry($a_item_id)
173 {
174 global $ilDB;
175
176 if(!$this->isAssignedEntry($a_item_id))
177 {
178 $query = "INSERT INTO ut_lp_collections".
179 " (obj_id, lpmode, item_id)".
180 " VALUES (".$ilDB->quote($this->obj_id , "integer").
181 ", ".$ilDB->quote($this->mode, "integer").
182 ", ".$ilDB->quote($a_item_id , "integer").
183 ")";
184 $ilDB->manipulate($query);
185 $this->items[] = $a_item_id;
186 }
187 return true;
188 }
189
190 protected function deleteEntry($a_item_id)
191 {
192 global $ilDB;
193
194 $query = "DELETE FROM ut_lp_collections".
195 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer").
196 " AND item_id = ".$ilDB->quote($a_item_id, "integer");
197 $ilDB->manipulate($query);
198 return true;
199 }
200
201 public function deactivateEntries(array $a_item_ids)
202 {
203 foreach($a_item_ids as $item_id)
204 {
205 $this->deleteEntry($item_id);
206 }
207 }
208
209 public function activateEntries(array $a_item_ids)
210 {
211 foreach($a_item_ids as $item_id)
212 {
213 $this->addEntry($item_id);
214 }
215 }
216}
217
218?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _getInstance($a_copy_id)
Get instance of copy wizard options.
LP collection of learning module chapters.
LP collection base class.
isAssignedEntry($a_item_id)
activateEntries(array $a_item_ids)
cloneCollection($a_target_id, $a_copy_id)
__construct($a_obj_id, $a_mode)
deactivateEntries(array $a_item_ids)
static getInstanceByMode($a_obj_id, $a_mode)
static _lookupObjId($a_id)
$path
Definition: index.php:22
global $ilDB