ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilFavouritesDBRepository Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ 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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

References $db, $DIC, and $tree.

32  {
33  global $DIC;
34 
35  $this->db = (is_null($db))
36  ? $DIC->database()
37  : $db;
38  $this->tree = (is_null($tree))
39  ? $DIC->repositoryTree()
40  : $tree;
41  }
global $DIC
Definition: feed.php:28

Member Function Documentation

◆ add()

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

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

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

45  : void
46  {
47  $db = $this->db;
48 
50 
51  $item_set = $db->queryF(
52  "SELECT * FROM desktop_item WHERE " .
53  "item_id = %s AND type = %s AND user_id = %s",
54  ["integer", "text", "integer"],
55  [$ref_id, $type, $user_id]
56  );
57 
58  // only insert if item is not already on desktop
59  if (!$db->fetchAssoc($item_set)) {
61  "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES " .
62  " (%s,%s,%s,%s)",
63  ["integer", "text", "integer", "text"],
64  [$ref_id, $type, $user_id, ""]
65  );
66  }
67  }
manipulateF(string $query, array $types, array $values)
$type
fetchAssoc(ilDBStatement $statement)
$ref_id
Definition: ltiauth.php:67
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  return $items;
167  }
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 170 of file class.ilFavouritesDBRepository.php.

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

170  : bool
171  {
172  $db = $this->db;
173 
174  if (!isset(self::$is_desktop_item[$user_id . ":" . $ref_id])) {
175  $item_set = $db->queryF(
176  "SELECT item_id FROM desktop_item WHERE " .
177  "item_id = %s AND user_id = %s",
178  ["integer", "integer"],
179  [$ref_id, $user_id]
180  );
181 
182  if ($db->fetchAssoc($item_set)) {
183  self::$is_desktop_item[$user_id . ":" . $ref_id] = true;
184  } else {
185  self::$is_desktop_item[$user_id . ":" . $ref_id] = false;
186  }
187  }
188  return self::$is_desktop_item[$user_id . ":" . $ref_id];
189  }
fetchAssoc(ilDBStatement $statement)
$ref_id
Definition: ltiauth.php:67
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 192 of file class.ilFavouritesDBRepository.php.

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

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

◆ remove()

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

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

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

70  : void
71  {
72  $db = $this->db;
73 
75  "DELETE FROM desktop_item WHERE " .
76  " item_id = %s AND user_id = %s",
77  ["integer", "integer"],
78  [$ref_id, $user_id]
79  );
80  }
manipulateF(string $query, array $types, array $values)
$ref_id
Definition: ltiauth.php:67
+ Here is the call graph for this function:

◆ removeFavouritesOfRefId()

ilFavouritesDBRepository::removeFavouritesOfRefId ( int  $ref_id)

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

References $db, and ilDBInterface\manipulateF().

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

◆ removeFavouritesOfUser()

ilFavouritesDBRepository::removeFavouritesOfUser ( int  $user_id)

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

References $db, and ilDBInterface\manipulateF().

235  : void
236  {
237  $db = $this->db;
238 
239  $db->manipulateF(
240  "DELETE FROM desktop_item WHERE " .
241  " user_id = %s",
242  ["integer"],
243  [$user_id]
244  );
245  }
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 25 of file class.ilFavouritesDBRepository.php.

◆ $tree

ilTree ilFavouritesDBRepository::$tree
protected

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

Referenced by __construct(), and getFavouritesOfUser().


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