ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
29
30 $this->db = $ilDB;
31 $this->role_id = $a_role_id;
32 }
33
34 public function getRoleId()
35 {
36 return $this->role_id;
37 }
38 public function setRoleId($a_role_id)
39 {
40 $this->role_id = $a_role_id;
41 }
42
43 public function add($a_item_id, $a_item_type)
44 {
45 global $ilDB;
46
47 if ($a_item_type and $a_item_id) {
48 $next_id = $ilDB->nextId('role_desktop_items');
49 $query = "INSERT INTO role_desktop_items (role_item_id,role_id,item_id,item_type) " .
50 "VALUES (" .
51 $ilDB->quote($next_id, 'integer') . ',' .
52 $ilDB->quote($this->getRoleId(), 'integer') . ", " .
53 $ilDB->quote($a_item_id, 'integer') . ", " .
54 $ilDB->quote($a_item_type, 'text') . " " .
55 ")";
56 $res = $ilDB->manipulate($query);
57 $this->__assign($a_item_id, $a_item_type);
58
59 return true;
60 }
61 return false;
62 }
63 public function delete($a_role_item_id)
64 {
65 global $ilDB;
66
67 $query = "DELETE FROM role_desktop_items " .
68 "WHERE role_item_id = " . $ilDB->quote($a_role_item_id, 'integer');
69 $res = $ilDB->manipulate($query);
70
71 return true;
72 }
73
74 public function deleteAll()
75 {
76 global $ilDB;
77
78 $query = "DELETE FROM role_desktop_items " .
79 "WHERE role_id = " . $ilDB->quote($this->getRoleId(), 'integer');
80 $res = $ilDB->manipulate($query);
81
82 return true;
83 }
84
85 public function isAssigned($a_item_ref_id)
86 {
87 global $ilDB;
88
89 $query = "SELECT * FROM role_desktop_items " .
90 "WHERE role_id = " . $ilDB->quote($this->getRoleId(), 'integer') . " " .
91 "AND item_id = " . $ilDB->quote($a_item_ref_id, 'integer') . " ";
92 $res = $ilDB->query($query);
93
94 return $res->numRows() ? true : false;
95 }
96
97 public function getItem($a_role_item_id)
98 {
99 global $ilDB;
100
101 $query = "SELECT * FROM role_desktop_items " .
102 "WHERE role_id = " . $ilDB->quote($this->getRoleId(), 'integer') . " " .
103 "AND role_item_id = " . $ilDB->quote($a_role_item_id, 'integer') . " ";
104
105 $res = $ilDB->query($query);
106 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
107 $item['item_id'] = $row->item_id;
108 $item['item_type'] = $row->item_type;
109 }
110
111 return $item ? $item : array();
112 }
113
114
115
116 public function getAll()
117 {
118 global $tree;
119 global $ilDB;
120
121 $query = "SELECT * FROM role_desktop_items " .
122 "WHERE role_id = " . $this->db->quote($this->getRoleId(), 'integer') . " ";
123
124 $res = $ilDB->query($query);
125 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
126 // TODO this check must be modified for non tree objects
127 if (!$tree->isInTree($row->item_id)) {
128 $this->delete($row->role_item_id);
129 continue;
130 }
131 $items[$row->role_item_id]['item_id'] = $row->item_id;
132 $items[$row->role_item_id]['item_type'] = $row->item_type;
133 }
134
135 return $items ? $items : array();
136 }
137
138 // PRIVATE
139 public function __assign($a_item_id, $a_item_type)
140 {
141 global $rbacreview;
142
143 foreach ($rbacreview->assignedUsers($this->getRoleId()) as $user_id) {
144 if (is_object($tmp_user = ilObjectFactory::getInstanceByObjId($user_id, false))) {
145 if (!$tmp_user->isDesktopItem($a_item_id, $a_item_type)) {
146 $tmp_user->addDesktopItem($a_item_id, $a_item_type);
147 }
148 }
149 }
150 return true;
151 }
152}
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)
$query
foreach($_POST as $key=> $value) $res
global $ilDB