ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilFavouritesDBRepository Class Reference
+ Collaboration diagram for ilFavouritesDBRepository:

Public Member Functions

 __construct (?ilDBInterface $db=null, ?ilTree $tree=null)
 
 add (int $user_id, int $ref_id)
 
 remove (int $user_id, int $ref_id)
 
 getFavouritesOfUser (int $user_id, ?array $a_types=null)
 Get all desktop items of user and specified type. More...
 
 ifIsFavourite (int $user_id, int $ref_id)
 
 loadData (int $user_id, array $ref_ids)
 
 removeFavouritesOfRefId (int $ref_id)
 
 removeFavouritesOfUser (int $user_id)
 

Static Public Attributes

static array $is_desktop_item = []
 

Protected Attributes

ilDBInterface $db
 
ilTree $tree
 

Detailed Description

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 24 of file class.ilFavouritesDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilFavouritesDBRepository::__construct ( ?ilDBInterface  $db = null,
?ilTree  $tree = null 
)

Definition at line 31 of file class.ilFavouritesDBRepository.php.

34 {
35 global $DIC;
36
37 $this->db = (is_null($db))
38 ? $DIC->database()
39 : $db;
40 $this->tree = (is_null($tree))
41 ? $DIC->repositoryTree()
42 : $tree;
43 }
global $DIC
Definition: shib_login.php:26

References $db, $DIC, and $tree.

Member Function Documentation

◆ add()

ilFavouritesDBRepository::add ( int  $user_id,
int  $ref_id 
)

Definition at line 46 of file class.ilFavouritesDBRepository.php.

46 : void
47 {
48 $db = $this->db;
49
50 $type = ilObject::_lookupType($ref_id, true);
51
52 $item_set = $db->queryF(
53 'SELECT * FROM desktop_item WHERE ' .
54 'item_id = %s AND type = %s AND user_id = %s',
55 ['integer', 'text', 'integer'],
56 [$ref_id, $type, $user_id]
57 );
58
59 // only insert if item is not already on desktop
60 if (!$db->fetchAssoc($item_set)) {
62 'INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ' .
63 ' (%s,%s,%s,%s)',
64 ['integer', 'text', 'integer', 'text'],
65 [$ref_id, $type, $user_id, '']
66 );
67 }
68 }
static _lookupType(int $id, bool $reference=false)
manipulateF(string $query, array $types, array $values)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
$ref_id
Definition: ltiauth.php:66

References $db, $ref_id, $user_id, ilObject\_lookupType(), ilDBInterface\fetchAssoc(), ilDBInterface\manipulateF(), and ilDBInterface\queryF().

+ Here is the call graph for this function:

◆ getFavouritesOfUser()

ilFavouritesDBRepository::getFavouritesOfUser ( int  $user_id,
?array  $a_types = null 
)

Get all desktop items of user and specified type.

note: the implementation of this method is not good style (directly reading tables object_data and object_reference), must be revised someday...

Definition at line 89 of file class.ilFavouritesDBRepository.php.

89 : array
90 {
93
94 if (is_null($a_types)) {
95 $item_set = $ilDB->queryF('SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ' .
96 ' FROM desktop_item it, object_reference oref ' .
97 ', object_data obj' .
98 ' WHERE ' .
99 'it.item_id = oref.ref_id AND ' .
100 'oref.obj_id = obj.obj_id AND ' .
101 'it.user_id = %s', ['integer'], [$user_id]);
102 $items = $all_parent_path = [];
103 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
104 if ($item_rec['type'] !== 'rolf' &&
105 $item_rec['type'] !== 'itgr' &&
106 $tree->isInTree((int) $item_rec['ref_id'])) { // due to bug 11508
107 $parent_ref = $tree->getParentId((int) $item_rec['ref_id']);
108
109 if (!isset($all_parent_path[$parent_ref])) {
110 if ($parent_ref > 0) { // workaround for #0023176
111 $node = $tree->getNodeData($parent_ref);
112 $all_parent_path[$parent_ref] = $node['title'];
113 } else {
114 $all_parent_path[$parent_ref] = '';
115 }
116 }
117
118 $parent_path = $all_parent_path[$parent_ref];
119
120 $title = ilObject::_lookupTitle($item_rec['obj_id']);
121 $desc = ilObject::_lookupDescription($item_rec['obj_id']);
122 $items[$parent_path . $title . $item_rec['ref_id']] =
123 [
124 'ref_id' => (int) $item_rec['ref_id'],
125 'obj_id' => (int) $item_rec['obj_id'],
126 'type' => $item_rec['type'],
127 'title' => $title,
128 'description' => $desc,
129 'parent_ref' => (int) $parent_ref
130 ];
131 }
132 }
133 } else {
134 $items = [];
135 foreach ($a_types as $a_type) {
136 if ($a_type === 'itgr') {
137 continue;
138 }
139 $item_set = $ilDB->queryF(
140 'SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ' .
141 ', object_data obj WHERE ' .
142 'it.item_id = oref.ref_id AND ' .
143 'oref.obj_id = obj.obj_id AND ' .
144 'it.type = %s AND ' .
145 'it.user_id = %s ' .
146 'ORDER BY title',
147 ['text', 'integer'],
148 [$a_type, $user_id]
149 );
150
151 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
152 $title = ilObject::_lookupTitle($item_rec['obj_id']);
153 $desc = ilObject::_lookupDescription($item_rec['obj_id']);
154 $items[$title . $a_type . $item_rec['ref_id']] =
155 [
156 'ref_id' => (int) $item_rec['ref_id'],
157 'obj_id' => (int) $item_rec['obj_id'],
158 'type' => $a_type,
159 'title' => $title,
160 'description' => $desc
161 ];
162 }
163 }
164 }
165
166 return $items;
167 }
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
isInTree(?int $a_node_id)
get all information of a node.
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getParentId(int $a_node_id)
get parent id of given node

References $db, $ilDB, $tree, $user_id, ilObject\_lookupDescription(), ilObject\_lookupTitle(), ilTree\getNodeData(), ilTree\getParentId(), ILIAS\Repository\int(), and ilTree\isInTree().

+ Here is the call graph for this function:

◆ ifIsFavourite()

ilFavouritesDBRepository::ifIsFavourite ( int  $user_id,
int  $ref_id 
)

Definition at line 170 of file class.ilFavouritesDBRepository.php.

170 : bool
171 {
172 $db = $this->db;
173 $user_identification = $user_id . ':' . $ref_id;
174 if (!isset(self::$is_desktop_item[$user_identification])) {
175 $item_set = $db->queryF(
176 'SELECT item_id FROM desktop_item WHERE ' .
177 'item_id = %s AND user_id = %s',
178 ['integer', 'integer'],
180 );
181
182 if ($db->fetchAssoc($item_set)) {
183 self::$is_desktop_item[$user_identification] = true;
184 } else {
185 self::$is_desktop_item[$user_identification] = false;
186 }
187 }
188
189 return self::$is_desktop_item[$user_identification];
190 }

References $db, $ref_id, $user_id, ilDBInterface\fetchAssoc(), and ilDBInterface\queryF().

+ Here is the call graph for this function:

◆ loadData()

ilFavouritesDBRepository::loadData ( int  $user_id,
array  $ref_ids 
)

Definition at line 193 of file class.ilFavouritesDBRepository.php.

193 : void
194 {
195 $db = $this->db;
196 if (!is_array($ref_ids)) {
197 return;
198 }
199
200 $load_ref_ids = [];
201 foreach ($ref_ids as $ref_id) {
202 $user_identification = $user_id . ':' . $ref_id;
203 if (!isset(self::$is_desktop_item[$user_identification])) {
204 $load_ref_ids[] = $ref_id;
205 }
206 }
207
208 if (count($load_ref_ids) > 0) {
209 $item_set = $db->query('SELECT item_id FROM desktop_item WHERE ' .
210 $db->in('item_id', $load_ref_ids, false, 'integer') .
211 ' AND user_id = ' . $db->quote($user_id, 'integer'));
212 while ($r = $db->fetchAssoc($item_set)) {
213 self::$is_desktop_item[$user_id . ':' . $r['item_id']] = true;
214 }
215 foreach ($load_ref_ids as $ref_id) {
216 $user_identification = $user_id . ':' . $ref_id;
217 if (!isset(self::$is_desktop_item[$user_identification])) {
218 self::$is_desktop_item[$user_id . ':' . $ref_id] = false;
219 }
220 }
221 }
222 }
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")

References $db, $ref_id, $user_id, ilDBInterface\fetchAssoc(), ilDBInterface\in(), ilDBInterface\query(), and ilDBInterface\quote().

+ Here is the call graph for this function:

◆ remove()

ilFavouritesDBRepository::remove ( int  $user_id,
int  $ref_id 
)

Definition at line 71 of file class.ilFavouritesDBRepository.php.

71 : void
72 {
73 $db = $this->db;
74
76 'DELETE FROM desktop_item WHERE ' .
77 ' item_id = %s AND user_id = %s',
78 ['integer', 'integer'],
80 );
81 }

References $db, $ref_id, $user_id, and ilDBInterface\manipulateF().

+ Here is the call graph for this function:

◆ removeFavouritesOfRefId()

ilFavouritesDBRepository::removeFavouritesOfRefId ( int  $ref_id)

Definition at line 225 of file class.ilFavouritesDBRepository.php.

225 : void
226 {
227 $db = $this->db;
228
230 'DELETE FROM desktop_item WHERE ' .
231 ' item_id = %s',
232 ['integer'],
233 [$ref_id]
234 );
235 }

References $db, $ref_id, and ilDBInterface\manipulateF().

+ Here is the call graph for this function:

◆ removeFavouritesOfUser()

ilFavouritesDBRepository::removeFavouritesOfUser ( int  $user_id)

Definition at line 238 of file class.ilFavouritesDBRepository.php.

238 : void
239 {
240 $db = $this->db;
241
243 'DELETE FROM desktop_item WHERE ' .
244 ' user_id = %s',
245 ['integer'],
246 [$user_id]
247 );
248 }

References $db, $user_id, and ilDBInterface\manipulateF().

+ Here is the call graph for this function:

Field Documentation

◆ $db

◆ $is_desktop_item

array ilFavouritesDBRepository::$is_desktop_item = []
static

Definition at line 27 of file class.ilFavouritesDBRepository.php.

◆ $tree

ilTree ilFavouritesDBRepository::$tree
protected

Definition at line 29 of file class.ilFavouritesDBRepository.php.

Referenced by __construct(), and getFavouritesOfUser().


The documentation for this class was generated from the following file: