ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
14 abstract 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  $this->read($a_obj_id);
27  }
28  }
29 
30  public static function getInstanceByMode($a_obj_id, $a_mode)
31  {
32  $path = "Services/Tracking/classes/collection/";
33 
34  switch ($a_mode) {
37  include_once $path . "class.ilLPCollectionOfRepositoryObjects.php";
38  return new ilLPCollectionOfRepositoryObjects($a_obj_id, $a_mode);
39 
41  include_once $path . "class.ilLPCollectionOfObjectives.php";
42  return new ilLPCollectionOfObjectives($a_obj_id, $a_mode);
43 
45  include_once $path . "class.ilLPCollectionOfSCOs.php";
46  return new ilLPCollectionOfSCOs($a_obj_id, $a_mode);
47 
50  include_once $path . "class.ilLPCollectionOfLMChapters.php";
51  return new ilLPCollectionOfLMChapters($a_obj_id, $a_mode);
52 
54  include_once $path . "class.ilLPCollectionOfMediaObjects.php";
55  return new ilLPCollectionOfMediaObjects($a_obj_id, $a_mode);
56  }
57  }
58 
59  public static function getCollectionModes()
60  {
61  return array(
68  );
69  }
70 
71  public function hasSelectableItems()
72  {
73  return true;
74  }
75 
76  public function cloneCollection($a_target_id, $a_copy_id)
77  {
78  global $DIC;
79 
80  $ilLog = $DIC['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  if (!isset($mappings[$item]) or !$mappings[$item]) {
92  continue;
93  }
94 
95  $new_collection->addEntry($mappings[$item]);
96  }
97 
98  $ilLog->write(__METHOD__ . ': cloned learning progress collection.');
99  }
100 
101 
102  //
103  // CRUD
104  //
105 
106  public function getItems()
107  {
108  return $this->items;
109  }
110 
111  protected function read($a_obj_id)
112  {
113  global $DIC;
114 
115  $ilDB = $DIC['ilDB'];
116 
117  $items = array();
118 
119  $res = $ilDB->query("SELECT * FROM ut_lp_collections" .
120  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer"));
121  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
122  if ($this->validateEntry($row->item_id)) {
123  $items[] = $row->item_id;
124  } else {
125  $this->deleteEntry($row->item_id);
126  }
127  }
128 
129  $this->items = $items;
130  }
131 
132  public function delete()
133  {
134  global $DIC;
135 
136  $ilDB = $DIC['ilDB'];
137 
138  $query = "DELETE FROM ut_lp_collections" .
139  " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer");
140  $ilDB->manipulate($query);
141 
142  $query = "DELETE FROM ut_lp_coll_manual" .
143  " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer");
144  $ilDB->manipulate($query);
145 
146  // #15462 - reset internal data
147  $this->items = array();
148 
149  return true;
150  }
151 
152  //
153  // ENTRIES
154  //
155 
156  protected function validateEntry($a_item_id)
157  {
158  return true;
159  }
160 
161  public function isAssignedEntry($a_item_id)
162  {
163  if (is_array($this->items)) {
164  return (bool) in_array($a_item_id, $this->items);
165  }
166  return false;
167  }
168 
169  protected function addEntry($a_item_id)
170  {
171  global $DIC;
172 
173  $ilDB = $DIC['ilDB'];
174 
175  if (!$this->isAssignedEntry($a_item_id)) {
176  $query = "INSERT INTO ut_lp_collections" .
177  " (obj_id, lpmode, item_id)" .
178  " VALUES (" . $ilDB->quote($this->obj_id, "integer") .
179  ", " . $ilDB->quote($this->mode, "integer") .
180  ", " . $ilDB->quote($a_item_id, "integer") .
181  ")";
182  $ilDB->manipulate($query);
183  $this->items[] = $a_item_id;
184  }
185  return true;
186  }
187 
188  protected function deleteEntry($a_item_id)
189  {
190  global $DIC;
191 
192  $ilDB = $DIC['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  $this->deleteEntry($item_id);
205  }
206  }
207 
208  public function activateEntries(array $a_item_ids)
209  {
210  foreach ($a_item_ids as $item_id) {
211  $this->addEntry($item_id);
212  }
213  }
214 }
$path
Definition: aliased.php:25
global $DIC
Definition: saml.php:7
LP collection of learning module chapters.
static getInstanceByMode($a_obj_id, $a_mode)
cloneCollection($a_target_id, $a_copy_id)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
deactivateEntries(array $a_item_ids)
static _lookupObjId($a_id)
$query
$row
LP collection base class.
__construct($a_obj_id, $a_mode)
isAssignedEntry($a_item_id)
global $ilDB
activateEntries(array $a_item_ids)