ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilLog;
79 
80  $target_obj_id = ilObject::_lookupObjId($a_target_id);
81 
82  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
83  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
84  $mappings = $cwo->getMappings();
85 
86  // #12067
87  $new_collection = new static($target_obj_id, $this->mode);
88  foreach ($this->items as $item) {
89  if (!isset($mappings[$item]) or !$mappings[$item]) {
90  continue;
91  }
92 
93  $new_collection->addEntry($mappings[$item]);
94  }
95 
96  $ilLog->write(__METHOD__ . ': cloned learning progress collection.');
97  }
98 
99 
100  //
101  // CRUD
102  //
103 
104  public function getItems()
105  {
106  return $this->items;
107  }
108 
109  protected function read($a_obj_id)
110  {
111  global $ilDB;
112 
113  $items = array();
114 
115  $res = $ilDB->query("SELECT * FROM ut_lp_collections" .
116  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer"));
117  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
118  if ($this->validateEntry($row->item_id)) {
119  $items[] = $row->item_id;
120  } else {
121  $this->deleteEntry($row->item_id);
122  }
123  }
124 
125  $this->items = $items;
126  }
127 
128  public function delete()
129  {
130  global $ilDB;
131 
132  $query = "DELETE FROM ut_lp_collections" .
133  " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer");
134  $ilDB->manipulate($query);
135 
136  $query = "DELETE FROM ut_lp_coll_manual" .
137  " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer");
138  $ilDB->manipulate($query);
139 
140  // #15462 - reset internal data
141  $this->items = array();
142 
143  return true;
144  }
145 
146  //
147  // ENTRIES
148  //
149 
150  protected function validateEntry($a_item_id)
151  {
152  return true;
153  }
154 
155  public function isAssignedEntry($a_item_id)
156  {
157  if (is_array($this->items)) {
158  return (bool) in_array($a_item_id, $this->items);
159  }
160  return false;
161  }
162 
163  protected function addEntry($a_item_id)
164  {
165  global $ilDB;
166 
167  if (!$this->isAssignedEntry($a_item_id)) {
168  $query = "INSERT INTO ut_lp_collections" .
169  " (obj_id, lpmode, item_id)" .
170  " VALUES (" . $ilDB->quote($this->obj_id, "integer") .
171  ", " . $ilDB->quote($this->mode, "integer") .
172  ", " . $ilDB->quote($a_item_id, "integer") .
173  ")";
174  $ilDB->manipulate($query);
175  $this->items[] = $a_item_id;
176  }
177  return true;
178  }
179 
180  protected function deleteEntry($a_item_id)
181  {
182  global $ilDB;
183 
184  $query = "DELETE FROM ut_lp_collections" .
185  " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer") .
186  " AND item_id = " . $ilDB->quote($a_item_id, "integer");
187  $ilDB->manipulate($query);
188  return true;
189  }
190 
191  public function deactivateEntries(array $a_item_ids)
192  {
193  foreach ($a_item_ids as $item_id) {
194  $this->deleteEntry($item_id);
195  }
196  }
197 
198  public function activateEntries(array $a_item_ids)
199  {
200  foreach ($a_item_ids as $item_id) {
201  $this->addEntry($item_id);
202  }
203  }
204 }
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
Create styles array
The data for the language used.
LP collection base class.
__construct($a_obj_id, $a_mode)
isAssignedEntry($a_item_id)
global $ilDB
activateEntries(array $a_item_ids)