ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 public $db;
20 public $role_id;
21
26 public function __construct($a_role_id)
27 {
28 global $DIC;
29
30 $ilDB = $DIC['ilDB'];
31
32 $this->db = $ilDB;
33 $this->role_id = $a_role_id;
34 }
35
36 public function getRoleId()
37 {
38 return $this->role_id;
39 }
40 public function setRoleId($a_role_id)
41 {
42 $this->role_id = $a_role_id;
43 }
44
45 public function add($a_item_id, $a_item_type)
46 {
47 global $DIC;
48
49 $ilDB = $DIC['ilDB'];
50
51 if ($a_item_type and $a_item_id) {
52 $next_id = $ilDB->nextId('role_desktop_items');
53 $query = "INSERT INTO role_desktop_items (role_item_id,role_id,item_id,item_type) " .
54 "VALUES (" .
55 $ilDB->quote($next_id, 'integer') . ',' .
56 $ilDB->quote($this->getRoleId(), 'integer') . ", " .
57 $ilDB->quote($a_item_id, 'integer') . ", " .
58 $ilDB->quote($a_item_type, 'text') . " " .
59 ")";
60 $res = $ilDB->manipulate($query);
61 $this->__assign($a_item_id, $a_item_type);
62
63 return true;
64 }
65 return false;
66 }
67 public function delete($a_role_item_id)
68 {
69 global $DIC;
70
71 $ilDB = $DIC['ilDB'];
72
73 $query = "DELETE FROM role_desktop_items " .
74 "WHERE role_item_id = " . $ilDB->quote($a_role_item_id, 'integer');
75 $res = $ilDB->manipulate($query);
76
77 return true;
78 }
79
80 public function deleteAll()
81 {
82 global $DIC;
83
84 $ilDB = $DIC['ilDB'];
85
86 $query = "DELETE FROM role_desktop_items " .
87 "WHERE role_id = " . $ilDB->quote($this->getRoleId(), 'integer');
88 $res = $ilDB->manipulate($query);
89
90 return true;
91 }
92
93 public function isAssigned($a_item_ref_id)
94 {
95 global $DIC;
96
97 $ilDB = $DIC['ilDB'];
98
99 $query = "SELECT * FROM role_desktop_items " .
100 "WHERE role_id = " . $ilDB->quote($this->getRoleId(), 'integer') . " " .
101 "AND item_id = " . $ilDB->quote($a_item_ref_id, 'integer') . " ";
102 $res = $ilDB->query($query);
103
104 return $res->numRows() ? true : false;
105 }
106
107 public function getItem($a_role_item_id)
108 {
109 global $DIC;
110
111 $ilDB = $DIC['ilDB'];
112
113 $query = "SELECT * FROM role_desktop_items " .
114 "WHERE role_id = " . $ilDB->quote($this->getRoleId(), 'integer') . " " .
115 "AND role_item_id = " . $ilDB->quote($a_role_item_id, 'integer') . " ";
116
117 $res = $ilDB->query($query);
118 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119 $item['item_id'] = $row->item_id;
120 $item['item_type'] = $row->item_type;
121 }
122
123 return $item ? $item : array();
124 }
125
126
127
128 public function getAll()
129 {
130 global $DIC;
131
132 $tree = $DIC['tree'];
133 global $DIC;
134
135 $ilDB = $DIC['ilDB'];
136
137 $query = "SELECT * FROM role_desktop_items " .
138 "WHERE role_id = " . $this->db->quote($this->getRoleId(), 'integer') . " ";
139
140 $res = $ilDB->query($query);
141 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
142 // TODO this check must be modified for non tree objects
143 if (!$tree->isInTree($row->item_id)) {
144 $this->delete($row->role_item_id);
145 continue;
146 }
147 $items[$row->role_item_id]['item_id'] = $row->item_id;
148 $items[$row->role_item_id]['item_type'] = $row->item_type;
149 }
150
151 return $items ? $items : array();
152 }
153
154 // PRIVATE
155 public function __assign($a_item_id, $a_item_type)
156 {
157 global $DIC;
158
159 $rbacreview = $DIC['rbacreview'];
160
161 foreach ($rbacreview->assignedUsers($this->getRoleId()) as $user_id) {
162 if (is_object($tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false))) {
163 if (!$tmp_user->isDesktopItem($a_item_id, $a_item_type)) {
164 $tmp_user->addDesktopItem($a_item_id, $a_item_type);
165 }
166 }
167 }
168 return true;
169 }
170}
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
add($a_item_id, $a_item_type)
__construct($a_role_id)
Constructor @access public.
__assign($a_item_id, $a_item_type)
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB