ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 {
17  var $ilDB;
18  var $tree;
19  var $lng;
20 
21  var $item_group_id = 0;
23  var $items = array();
24 
30  function ilItemGroupItems($a_item_group_ref_id = 0)
31  {
32  global $ilDB, $lng, $tree, $objDefinition;
33 
34  $this->db = $ilDB;
35  $this->lng = $lng;
36  $this->tree = $tree;
37  $this->obj_def = $objDefinition;
38 
39  $this->setItemGroupRefId((int) $a_item_group_ref_id);
40  if ($this->getItemGroupRefId() > 0)
41  {
42  $this->setItemGroupId((int) ilObject::_lookupObjId($a_item_group_ref_id));
43  }
44 
45  if ($this->getItemGroupId() > 0)
46  {
47  $this->read();
48  }
49  }
50 
56  function setItemGroupId($a_val)
57  {
58  $this->item_group_id = $a_val;
59  }
60 
66  function getItemGroupId()
67  {
68  return $this->item_group_id;
69  }
70 
76  function setItemGroupRefId($a_val)
77  {
78  $this->item_group_ref_id = $a_val;
79  }
80 
86  function getItemGroupRefId()
87  {
89  }
90 
96  function setItems($a_val)
97  {
98  $this->items = $a_val;
99  }
100 
106  function getItems()
107  {
108  return $this->items;
109  }
110 
116  public function addItem($a_item_ref_id)
117  {
118  if (!in_array($a_item_ref_id, $this->items))
119  {
120  $this->items[] = (int) $a_item_ref_id;
121  }
122  }
123 
127  function delete()
128  {
129  $query = "DELETE FROM item_group_item ".
130  "WHERE item_group_id = ".$this->db->quote($this->getItemGroupId(), 'integer');
131  $this->db->manipulate($query);
132  }
133 
137  function update()
138  {
139  $this->delete();
140 
141  foreach($this->items as $item)
142  {
143  $query = "INSERT INTO item_group_item (item_group_id,item_ref_id) ".
144  "VALUES( ".
145  $this->db->quote($this->getItemGroupId() ,'integer').", ".
146  $this->db->quote($item ,'integer')." ".
147  ")";
148  $this->db->manipulate($query);
149  }
150  }
151 
155  public function read()
156  {
157  $this->items = array();
158  $set = $this->db->query("SELECT * FROM item_group_item ".
159  " WHERE item_group_id = ".$this->db->quote($this->getItemGroupId(), "integer")
160  );
161  while ($rec = $this->db->fetchAssoc($set))
162  {
163  $this->items[] = $rec["item_ref_id"];
164  }
165  }
166 
174  {
175  global $objDefinition;
176 
177  if ($this->getItemGroupRefId() <= 0)
178  {
179  return array();
180  }
181 
182  $parent_node = $this->tree->getNodeData(
183  $this->tree->getParentId($this->getItemGroupRefId()));
184 
185  $materials = array();
186  $nodes = $this->tree->getChilds($parent_node["child"]);
187 
188  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
189  foreach($nodes as $node)
190  {
191  // filter side blocks and session, item groups and role folder
192  if ($node['child'] == $parent_node["child"] ||
193  $this->obj_def->isSideBlock($node['type']) ||
194  in_array($node['type'], array('sess', 'itgr', 'rolf', 'adm')))
195  {
196  continue;
197  }
198 
199  // filter hidden files
200  // see http://www.ilias.de/mantis/view.php?id=10269
201  if ($node['type'] == "file" &&
202  ilObjFileAccess::_isFileHidden($node['title']))
203  {
204  continue;
205  }
206 
207  if ($objDefinition->isInactivePlugin($node['type']))
208  {
209  continue;
210  }
211 
212  $materials[] = $node;
213  }
214 
215  $materials = ilUtil::sortArray($materials, "title", "asc");
216 
217  return $materials;
218  }
219 
220 
227  function getValidItems()
228  {
229  $items = $this->getItems();
230  $ass_items = $this->getAssignableItems();
231  $valid_items = array();
232  foreach ($ass_items as $aitem)
233  {
234  if (in_array($aitem["ref_id"], $items))
235  {
236  $valid_items[] = $aitem["ref_id"];
237  }
238  }
239  return $valid_items;
240  }
241 
250  public function cloneItems($a_source_id,$a_copy_id)
251  {
252  global $ilObjDataCache,$ilLog;
253 
254  $ilLog->write(__METHOD__.': Begin cloning item group materials ... -'.$a_source_id.'-');
255 
256  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
257  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
258  $mappings = $cwo->getMappings();
259 
260  $new_items = array();
261 // check: is this a ref id!?
262  $source_ig = new ilItemGroupItems($a_source_id);
263  foreach($source_ig->getItems() as $item_ref_id)
264  {
265  if(isset($mappings[$item_ref_id]) and $mappings[$item_ref_id])
266  {
267  $ilLog->write(__METHOD__.': Clone item group item nr. '.$item_ref_id);
268  $new_items[] = $mappings[$item_ref_id];
269  }
270  else
271  {
272  $ilLog->write(__METHOD__.': No mapping found for item group item nr. '.$item_ref_id);
273  }
274  }
275  $this->setItems($new_items);
276  $this->update();
277  $ilLog->write(__METHOD__.': Finished cloning item group items ...');
278  return true;
279  }
280 
281  function _getItemsOfContainer($a_ref_id)
282  {
283  global $ilDB,$tree;
284 
285  $itgr_nodes = $tree->getChildsByType($a_ref_id,'itgr');
286  foreach ($itgr_nodes as $node)
287  {
288  $itgr_ids[] = $node['obj_id'];
289  }
290  $query = "SELECT item_ref_id FROM item_group_item ".
291  "WHERE ".$ilDB->in('item_group_id', $itgr_ids,false,'integer');
292 
293 
294  $res = $ilDB->query($query);
295  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
296  {
297  $items[] = $row->item_ref_id;
298  }
299  return $items ? $items : array();
300  }
301 
302 }
303 ?>
addItem($a_item_ref_id)
Add one item.
getAssignableItems()
Get assignable items.
static _isFileHidden($a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
ilItemGroupItems($a_item_group_ref_id=0)
Constructor.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getItemGroupId()
Get item group id.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
getValidItems()
Get valid items.
static _lookupObjId($a_id)
setItems($a_val)
Set items.
Item group items.
setItemGroupRefId($a_val)
Set item group ref id.
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.