ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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.

References $db, $DIC, and $tree.

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:22

Member Function Documentation

◆ add()

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

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

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

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  }
manipulateF(string $query, array $types, array $values)
fetchAssoc(ilDBStatement $statement)
$ref_id
Definition: ltiauth.php:65
queryF(string $query, array $types, array $values)
static _lookupType(int $id, bool $reference=false)
+ 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.

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

89  : array
90  {
92  $ilDB = $this->db;
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  ksort($items);
166 
167  return $items;
168  }
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
isInTree(?int $a_node_id)
get all information of a node.
static _lookupTitle(int $obj_id)
getParentId(int $a_node_id)
get parent id of given node
static _lookupDescription(int $obj_id)
+ Here is the call graph for this function:

◆ ifIsFavourite()

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

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

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

171  : bool
172  {
173  $db = $this->db;
174  $user_identification = $user_id . ':' . $ref_id;
175  if (!isset(self::$is_desktop_item[$user_identification])) {
176  $item_set = $db->queryF(
177  'SELECT item_id FROM desktop_item WHERE ' .
178  'item_id = %s AND user_id = %s',
179  ['integer', 'integer'],
180  [$ref_id, $user_id]
181  );
182 
183  if ($db->fetchAssoc($item_set)) {
184  self::$is_desktop_item[$user_identification] = true;
185  } else {
186  self::$is_desktop_item[$user_identification] = false;
187  }
188  }
189 
190  return self::$is_desktop_item[$user_identification];
191  }
fetchAssoc(ilDBStatement $statement)
$ref_id
Definition: ltiauth.php:65
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ loadData()

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

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

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

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

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

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'],
79  [$ref_id, $user_id]
80  );
81  }
manipulateF(string $query, array $types, array $values)
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:

◆ removeFavouritesOfRefId()

ilFavouritesDBRepository::removeFavouritesOfRefId ( int  $ref_id)

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

References $db, and ilDBInterface\manipulateF().

226  : void
227  {
228  $db = $this->db;
229 
230  $db->manipulateF(
231  'DELETE FROM desktop_item WHERE ' .
232  ' item_id = %s',
233  ['integer'],
234  [$ref_id]
235  );
236  }
manipulateF(string $query, array $types, array $values)
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:

◆ removeFavouritesOfUser()

ilFavouritesDBRepository::removeFavouritesOfUser ( int  $user_id)

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

References $db, and ilDBInterface\manipulateF().

239  : void
240  {
241  $db = $this->db;
242 
243  $db->manipulateF(
244  'DELETE FROM desktop_item WHERE ' .
245  ' user_id = %s',
246  ['integer'],
247  [$user_id]
248  );
249  }
manipulateF(string $query, array $types, array $values)
+ 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: