ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  if ($this->getItemGroupRefId() <= 0)
176  {
177  return array();
178  }
179 
180  $parent_node = $this->tree->getNodeData(
181  $this->tree->getParentId($this->getItemGroupRefId()));
182 
183  $materials = array();
184  $nodes = $this->tree->getChilds($parent_node["child"]);
185 
186  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
187  foreach($nodes as $node)
188  {
189  // filter side blocks and session, item groups and role folder
190  if ($node['child'] == $parent_node["child"] ||
191  $this->obj_def->isSideBlock($node['type']) ||
192  in_array($node['type'], array('sess', 'itgr', 'rolf', 'adm')))
193  {
194  continue;
195  }
196 
197  // filter hidden files
198  // see http://www.ilias.de/mantis/view.php?id=10269
199  if ($node['type'] == "file" &&
200  ilObjFileAccess::_isFileHidden($node['title']))
201  {
202  continue;
203  }
204 
205  $materials[] = $node;
206  }
207 
208  $materials = ilUtil::sortArray($materials, "title", "asc");
209 
210  return $materials;
211  }
212 
213 
220  function getValidItems()
221  {
222  $items = $this->getItems();
223  $ass_items = $this->getAssignableItems();
224  $valid_items = array();
225  foreach ($ass_items as $aitem)
226  {
227  if (in_array($aitem["ref_id"], $items))
228  {
229  $valid_items[] = $aitem["ref_id"];
230  }
231  }
232  return $valid_items;
233  }
234 
243  public function cloneItems($a_source_id,$a_copy_id)
244  {
245  global $ilObjDataCache,$ilLog;
246 
247  $ilLog->write(__METHOD__.': Begin cloning item group materials ... -'.$a_source_id.'-');
248 
249  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
250  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
251  $mappings = $cwo->getMappings();
252 
253  $new_items = array();
254 // check: is this a ref id!?
255  $source_ig = new ilItemGroupItems($a_source_id);
256  foreach($source_ig->getItems() as $item_ref_id)
257  {
258  if(isset($mappings[$item_ref_id]) and $mappings[$item_ref_id])
259  {
260  $ilLog->write(__METHOD__.': Clone item group item nr. '.$item_ref_id);
261  $new_items[] = $mappings[$item_ref_id];
262  }
263  else
264  {
265  $ilLog->write(__METHOD__.': No mapping found for item group item nr. '.$item_ref_id);
266  }
267  }
268  $this->setItems($new_items);
269  $this->update();
270  $ilLog->write(__METHOD__.': Finished cloning item group items ...');
271  return true;
272  }
273 
274  function _getItemsOfContainer($a_ref_id)
275  {
276  global $ilDB,$tree;
277 
278  $itgr_nodes = $tree->getChildsByType($a_ref_id,'itgr');
279  foreach ($itgr_nodes as $node)
280  {
281  $itgr_ids[] = $node['obj_id'];
282  }
283  $query = "SELECT item_ref_id FROM item_group_item ".
284  "WHERE ".$ilDB->in('item_group_id', $itgr_ids,false,'integer');
285 
286 
287  $res = $ilDB->query($query);
288  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
289  {
290  $items[] = $row->item_ref_id;
291  }
292  return $items ? $items : array();
293  }
294 
295 }
296 ?>