ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilItemGroupItems.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
16 {
20  protected $db;
21 
25  protected $obj_def;
26 
30  protected $obj_data_cache;
31 
35  protected $log;
36 
37  public $ilDB;
38  public $tree;
39  public $lng;
40 
41  public $item_group_id = 0;
42  public $item_group_ref_id = 0;
43  public $items = array();
44 
50  public function __construct($a_item_group_ref_id = 0)
51  {
52  global $DIC;
53 
54  $this->obj_data_cache = $DIC["ilObjDataCache"];
55  $this->log = $DIC["ilLog"];
56  $ilDB = $DIC->database();
57  $lng = $DIC->language();
58  $tree = $DIC->repositoryTree();
59  $objDefinition = $DIC["objDefinition"];
60 
61  $this->db = $ilDB;
62  $this->lng = $lng;
63  $this->tree = $tree;
64  $this->obj_def = $objDefinition;
65 
66  $this->setItemGroupRefId((int) $a_item_group_ref_id);
67  if ($this->getItemGroupRefId() > 0) {
68  $this->setItemGroupId((int) ilObject::_lookupObjId($a_item_group_ref_id));
69  }
70 
71  if ($this->getItemGroupId() > 0) {
72  $this->read();
73  }
74  }
75 
81  public function setItemGroupId($a_val)
82  {
83  $this->item_group_id = $a_val;
84  }
85 
91  public function getItemGroupId()
92  {
93  return $this->item_group_id;
94  }
95 
101  public function setItemGroupRefId($a_val)
102  {
103  $this->item_group_ref_id = $a_val;
104  }
105 
111  public function getItemGroupRefId()
112  {
114  }
115 
121  public function setItems($a_val)
122  {
123  $this->items = $a_val;
124  }
125 
131  public function getItems()
132  {
133  return $this->items;
134  }
135 
141  public function addItem($a_item_ref_id)
142  {
143  if (!in_array($a_item_ref_id, $this->items)) {
144  $this->items[] = (int) $a_item_ref_id;
145  }
146  }
147 
151  public function delete()
152  {
153  $query = "DELETE FROM item_group_item " .
154  "WHERE item_group_id = " . $this->db->quote($this->getItemGroupId(), 'integer');
155  $this->db->manipulate($query);
156  }
157 
161  public function update()
162  {
163  $this->delete();
164 
165  foreach ($this->items as $item) {
166  $query = "INSERT INTO item_group_item (item_group_id,item_ref_id) " .
167  "VALUES( " .
168  $this->db->quote($this->getItemGroupId(), 'integer') . ", " .
169  $this->db->quote($item, 'integer') . " " .
170  ")";
171  $this->db->manipulate($query);
172  }
173  }
174 
178  public function read()
179  {
180  $this->items = array();
181  $set = $this->db->query(
182  "SELECT * FROM item_group_item " .
183  " WHERE item_group_id = " . $this->db->quote($this->getItemGroupId(), "integer")
184  );
185  while ($rec = $this->db->fetchAssoc($set)) {
186  $this->items[] = $rec["item_ref_id"];
187  }
188  }
189 
196  public function getAssignableItems()
197  {
198  $objDefinition = $this->obj_def;
199 
200  if ($this->getItemGroupRefId() <= 0) {
201  return array();
202  }
203 
204  $parent_node = $this->tree->getNodeData(
205  $this->tree->getParentId($this->getItemGroupRefId())
206  );
207 
208  $materials = array();
209  $nodes = $this->tree->getChilds($parent_node["child"]);
210 
211  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
212  foreach ($nodes as $node) {
213  // filter side blocks and session, item groups and role folder
214  if ($node['child'] == $parent_node["child"] ||
215  $this->obj_def->isSideBlock($node['type']) ||
216  in_array($node['type'], array('sess', 'itgr', 'rolf', 'adm'))) {
217  continue;
218  }
219 
220  // filter hidden files
221  // see http://www.ilias.de/mantis/view.php?id=10269
222  if ($node['type'] == "file" &&
223  ilObjFileAccess::_isFileHidden($node['title'])) {
224  continue;
225  }
226 
227  if ($objDefinition->isInactivePlugin($node['type'])) {
228  continue;
229  }
230 
231  $materials[] = $node;
232  }
233 
234  $materials = ilUtil::sortArray($materials, "title", "asc");
235 
236  return $materials;
237  }
238 
239 
246  public function getValidItems()
247  {
248  $items = $this->getItems();
249  $ass_items = $this->getAssignableItems();
250  $valid_items = array();
251  foreach ($ass_items as $aitem) {
252  if (in_array($aitem["ref_id"], $items)) {
253  $valid_items[] = $aitem["ref_id"];
254  }
255  }
256  return $valid_items;
257  }
258 
267  public function cloneItems($a_source_id, $a_copy_id)
268  {
269  $ilObjDataCache = $this->obj_data_cache;
270  $ilLog = $this->log;
271 
272  $ilLog->write(__METHOD__ . ': Begin cloning item group materials ... -' . $a_source_id . '-');
273 
274  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
275  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
276  $mappings = $cwo->getMappings();
277 
278  $new_items = array();
279  // check: is this a ref id!?
280  $source_ig = new ilItemGroupItems($a_source_id);
281  foreach ($source_ig->getItems() as $item_ref_id) {
282  if (isset($mappings[$item_ref_id]) and $mappings[$item_ref_id]) {
283  $ilLog->write(__METHOD__ . ': Clone item group item nr. ' . $item_ref_id);
284  $new_items[] = $mappings[$item_ref_id];
285  } else {
286  $ilLog->write(__METHOD__ . ': No mapping found for item group item nr. ' . $item_ref_id);
287  }
288  }
289  $this->setItems($new_items);
290  $this->update();
291  $ilLog->write(__METHOD__ . ': Finished cloning item group items ...');
292  return true;
293  }
294 
295  public static function _getItemsOfContainer($a_ref_id)
296  {
297  global $DIC;
298 
299  $ilDB = $DIC->database();
300  $tree = $DIC->repositoryTree();
301 
302  $itgr_nodes = $tree->getChildsByType($a_ref_id, 'itgr');
303  foreach ($itgr_nodes as $node) {
304  $itgr_ids[] = $node['obj_id'];
305  }
306  $query = "SELECT item_ref_id FROM item_group_item " .
307  "WHERE " . $ilDB->in('item_group_id', $itgr_ids, false, 'integer');
308 
309 
310  $res = $ilDB->query($query);
311  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
312  $items[] = $row->item_ref_id;
313  }
314  return $items ? $items : array();
315  }
316 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
addItem($a_item_ref_id)
Add one item.
global $DIC
Definition: saml.php:7
__construct($a_item_group_ref_id=0)
Constructor.
getAssignableItems()
Get assignable items.
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
getItemGroupId()
Get item group id.
static _getItemsOfContainer($a_ref_id)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
getValidItems()
Get valid items.
foreach($_POST as $key=> $value) $res
static _lookupObjId($a_id)
setItems($a_val)
Set items.
Item group items.
setItemGroupRefId($a_val)
Set item group ref id.
$query
Create styles array
The data for the language used.
setItemGroupId($a_val)
Set item group id.
getItemGroupRefId()
Get item group ref id.
update()
Update item group items.
cloneItems($a_source_id, $a_copy_id)
Clone items.
read()
Read item group items.