ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRoleDesktopItem.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
38 {
39  var $db;
40  var $role_id;
41 
46  function ilRoleDesktopItem($a_role_id)
47  {
48  global $ilDB;
49 
50  $this->db =& $ilDB;
51  $this->role_id = $a_role_id;
52  }
53 
54  function getRoleId()
55  {
56  return $this->role_id;
57  }
58  function setRoleId($a_role_id)
59  {
60  $this->role_id = $a_role_id;
61  }
62 
63  function add($a_item_id,$a_item_type)
64  {
65  global $ilDB;
66 
67  if($a_item_type and $a_item_id)
68  {
69  $query = "INSERT INTO role_desktop_items ".
70  "SET role_id = ".$ilDB->quote($this->getRoleId()).", ".
71  "item_id = ".$ilDB->quote($a_item_id).", ".
72  "item_type = ".$ilDB->quote($a_item_type);
73 
74  $this->db->query($query);
75 
76  $this->__assign($a_item_id,$a_item_type);
77 
78  return true;
79  }
80  return false;
81  }
82  function delete($a_role_item_id)
83  {
84  global $ilDB;
85 
86  $query = "DELETE FROM role_desktop_items ".
87  "WHERE role_item_id = ".$ilDB->quote($a_role_item_id);
88 
89  $this->db->query($query);
90 
91  return true;
92  }
93 
94  function deleteAll()
95  {
96  global $ilDB;
97 
98  $query = "DELETE FROM role_desktop_items ".
99  "WHERE role_id = ".$ilDB->quote($this->getRoleId());
100 
101  $this->db->query($query);
102 
103  return true;
104  }
105 
106  function isAssigned($a_item_ref_id)
107  {
108  global $ilDB;
109 
110  $query = "SELECT * FROM role_desktop_items ".
111  "WHERE role_id = ".$ilDB->quote($this->getRoleId())." ".
112  "AND item_id = ".$ilDB->quote($a_item_ref_id)." ";
113 
114  $res = $this->db->query($query);
115 
116  return $res->numRows() ? true : false;
117  }
118 
119  function getItem($a_role_item_id)
120  {
121  global $ilDB;
122 
123  $query = "SELECT * FROM role_desktop_items ".
124  "WHERE role_id = ".$ilDB->quote($this->getRoleId())." ".
125  "AND role_item_id = ".$ilDB->quote($a_role_item_id)." ";
126 
127  $res = $this->db->query($query);
128  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
129  {
130  $item['item_id'] = $row->item_id;
131  $item['item_type'] = $row->item_type;
132  }
133 
134  return $item ? $item : array();
135  }
136 
137 
138 
139  function getAll()
140  {
141  global $tree;
142 
143  $query = "SELECT * FROM role_desktop_items ".
144  "WHERE role_id = ".$this->db->quote($this->getRoleId())." ";
145 
146  $res = $this->db->query($query);
147  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
148  {
149  // TODO this check must be modified for non tree objects
150  if(!$tree->isInTree($row->item_id))
151  {
152  $this->delete($row->role_item_id);
153  continue;
154  }
155  $items[$row->role_item_id]['item_id'] = $row->item_id;
156  $items[$row->role_item_id]['item_type'] = $row->item_type;
157  }
158 
159  return $items ? $items : array();
160  }
161 
162  // PRIVATE
163  function __assign($a_item_id,$a_item_type)
164  {
165  global $rbacreview;
166 
167  foreach($rbacreview->assignedUsers($this->getRoleId()) as $user_id)
168  {
169  if(is_object($tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false)))
170  {
171  if(!$tmp_user->isDesktopItem($a_item_id,$a_item_type))
172  {
173  $tmp_user->addDesktopItem($a_item_id,$a_item_type);
174  }
175  }
176  }
177  return true;
178  }
179 }
180 ?>