ILIAS  release_4-4 Revision
class.ilRoleDesktopItem.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
18 {
19  var $db;
20  var $role_id;
21 
26  function ilRoleDesktopItem($a_role_id)
27  {
28  global $ilDB;
29 
30  $this->db =& $ilDB;
31  $this->role_id = $a_role_id;
32  }
33 
34  function getRoleId()
35  {
36  return $this->role_id;
37  }
38  function setRoleId($a_role_id)
39  {
40  $this->role_id = $a_role_id;
41  }
42 
43  function add($a_item_id,$a_item_type)
44  {
45  global $ilDB;
46 
47  if($a_item_type and $a_item_id)
48  {
49  $next_id = $ilDB->nextId('role_desktop_items');
50  $query = "INSERT INTO role_desktop_items (role_item_id,role_id,item_id,item_type) ".
51  "VALUES (".
52  $ilDB->quote($next_id,'integer').','.
53  $ilDB->quote($this->getRoleId(),'integer').", ".
54  $ilDB->quote($a_item_id,'integer').", ".
55  $ilDB->quote($a_item_type,'text')." ".
56  ")";
57  $res = $ilDB->manipulate($query);
58  $this->__assign($a_item_id,$a_item_type);
59 
60  return true;
61  }
62  return false;
63  }
64  function delete($a_role_item_id)
65  {
66  global $ilDB;
67 
68  $query = "DELETE FROM role_desktop_items ".
69  "WHERE role_item_id = ".$ilDB->quote($a_role_item_id,'integer');
70  $res = $ilDB->manipulate($query);
71 
72  return true;
73  }
74 
75  function deleteAll()
76  {
77  global $ilDB;
78 
79  $query = "DELETE FROM role_desktop_items ".
80  "WHERE role_id = ".$ilDB->quote($this->getRoleId(),'integer');
81  $res = $ilDB->manipulate($query);
82 
83  return true;
84  }
85 
86  function isAssigned($a_item_ref_id)
87  {
88  global $ilDB;
89 
90  $query = "SELECT * FROM role_desktop_items ".
91  "WHERE role_id = ".$ilDB->quote($this->getRoleId(),'integer')." ".
92  "AND item_id = ".$ilDB->quote($a_item_ref_id,'integer')." ";
93  $res = $ilDB->query($query);
94 
95  return $res->numRows() ? true : false;
96  }
97 
98  function getItem($a_role_item_id)
99  {
100  global $ilDB;
101 
102  $query = "SELECT * FROM role_desktop_items ".
103  "WHERE role_id = ".$ilDB->quote($this->getRoleId(),'integer')." ".
104  "AND role_item_id = ".$ilDB->quote($a_role_item_id,'integer')." ";
105 
106  $res = $ilDB->query($query);
107  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
108  {
109  $item['item_id'] = $row->item_id;
110  $item['item_type'] = $row->item_type;
111  }
112 
113  return $item ? $item : array();
114  }
115 
116 
117 
118  function getAll()
119  {
120  global $tree;
121  global $ilDB;
122 
123  $query = "SELECT * FROM role_desktop_items ".
124  "WHERE role_id = ".$this->db->quote($this->getRoleId(),'integer')." ";
125 
126  $res = $ilDB->query($query);
127  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
128  {
129  // TODO this check must be modified for non tree objects
130  if(!$tree->isInTree($row->item_id))
131  {
132  $this->delete($row->role_item_id);
133  continue;
134  }
135  $items[$row->role_item_id]['item_id'] = $row->item_id;
136  $items[$row->role_item_id]['item_type'] = $row->item_type;
137  }
138 
139  return $items ? $items : array();
140  }
141 
142  // PRIVATE
143  function __assign($a_item_id,$a_item_type)
144  {
145  global $rbacreview;
146 
147  foreach($rbacreview->assignedUsers($this->getRoleId()) as $user_id)
148  {
149  if(is_object($tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false)))
150  {
151  if(!$tmp_user->isDesktopItem($a_item_id,$a_item_type))
152  {
153  $tmp_user->addDesktopItem($a_item_id,$a_item_type);
154  }
155  }
156  }
157  return true;
158  }
159 }
160 ?>
add($a_item_id, $a_item_type)
Class ilObjRoleGUI.
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
__assign($a_item_id, $a_item_type)
ilRoleDesktopItem($a_role_id)
Constructor public.