ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilFavouritesDBRepository Class Reference
+ Collaboration diagram for ilFavouritesDBRepository:

Public Member Functions

 __construct (\ilDBInterface $db=null, ilTree $tree=null)
 Constructor. More...
 
 add (int $user_id, int $ref_id)
 Add favourite. More...
 
 remove (int $user_id, int $ref_id)
 Remove favourite. More...
 
 getFavouritesOfUser (int $user_id, array $a_types=null)
 Get all desktop items of user and specified type. More...
 
 ifIsFavourite ($user_id, $ref_id)
 check wether an item is on the users desktop or not More...
 
 loadData (int $user_id, array $ref_ids)
 Load favourites data. More...
 
 removeFavouritesOfRefId (int $ref_id)
 Remove favourite entries of a repository item. More...
 
 removeFavouritesOfUser (int $user_id)
 Remove favourite entries of a user. More...
 

Static Public Attributes

static $is_desktop_item = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

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

References $DIC.

22  {
23  global $DIC;
24 
25  $this->db = (is_null($db))
26  ? $DIC->database()
27  : $db;
28  $this->tree = (is_null($tree))
29  ? $DIC->repositoryTree()
30  : $tree;
31  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ add()

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

Add favourite.

Parameters
int$user_id
int$ref_id

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

References $type, and ilObject\_lookupType().

40  {
41  $db = $this->db;
42 
43  $type = ilObject::_lookupType($ref_id, true);
44 
45  $item_set = $db->queryF(
46  "SELECT * FROM desktop_item WHERE " .
47  "item_id = %s AND type = %s AND user_id = %s",
48  ["integer", "text", "integer"],
49  [$ref_id, $type, $user_id]
50  );
51 
52  // only insert if item is not already on desktop
53  if (!$db->fetchAssoc($item_set)) {
54  $db->manipulateF(
55  "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES " .
56  " (%s,%s,%s,%s)",
57  array("integer", "text", "integer", "text"),
58  array($ref_id,$type,$user_id,"")
59  );
60  }
61  }
$type
static _lookupType($a_id, $a_reference=false)
lookup object type
+ 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...

Parameters
int$user_id
array | null$a_types
Returns
array

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

References $a_type, $ilDB, ilObject\_lookupDescription(), and ilObject\_lookupTitle().

91  : array
92  {
93  $tree = $this->tree;
94  $ilDB = $this->db;
95 
96  if (is_null($a_types)) {
97  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type " .
98  " FROM desktop_item it, object_reference oref " .
99  ", object_data obj" .
100  " WHERE " .
101  "it.item_id = oref.ref_id AND " .
102  "oref.obj_id = obj.obj_id AND " .
103  "it.user_id = %s", array("integer"), array($user_id));
104  $items = $all_parent_path = array();
105  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
106  if ($tree->isInTree($item_rec["ref_id"])
107  && $item_rec["type"] != "rolf"
108  && $item_rec["type"] != "itgr") { // due to bug 11508
109  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
110 
111  if (!isset($all_parent_path[$parent_ref])) {
112  if ($parent_ref > 0) { // workaround for #0023176
113  $node = $tree->getNodeData($parent_ref);
114  $all_parent_path[$parent_ref] = $node["title"];
115  } else {
116  $all_parent_path[$parent_ref] = "";
117  }
118  }
119 
120  $parent_path = $all_parent_path[$parent_ref];
121 
122  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
123  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
124  $items[$parent_path . $title . $item_rec["ref_id"]] =
125  array("ref_id" => $item_rec["ref_id"],
126  "obj_id" => $item_rec["obj_id"],
127  "type" => $item_rec["type"],
128  "title" => $title,
129  "description" => $desc,
130  "parent_ref" => $parent_ref);
131  }
132  }
133  ksort($items);
134  } else {
135  $items = array();
136  foreach ($a_types as $a_type) {
137  if ($a_type == "itgr") {
138  continue;
139  }
140  $item_set = $ilDB->queryF(
141  "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref " .
142  ", object_data obj WHERE " .
143  "it.item_id = oref.ref_id AND " .
144  "oref.obj_id = obj.obj_id AND " .
145  "it.type = %s AND " .
146  "it.user_id = %s " .
147  "ORDER BY title",
148  array("text", "integer"),
149  array($a_type, $user_id)
150  );
151 
152  while ($item_rec = $ilDB->fetchAssoc($item_set)) {
153  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
154  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
155  $items[$title . $a_type . $item_rec["ref_id"]] =
156  array("ref_id" => $item_rec["ref_id"],
157  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
158  "title" => $title, "description" => $desc);
159  }
160  }
161  ksort($items);
162  }
163  return $items;
164  }
static _lookupTitle($a_id)
lookup object title
$a_type
Definition: workflow.php:92
static _lookupDescription($a_id)
lookup object description
global $ilDB
+ Here is the call graph for this function:

◆ ifIsFavourite()

ilFavouritesDBRepository::ifIsFavourite (   $user_id,
  $ref_id 
)

check wether an item is on the users desktop or not

Parameters
$user_id
$ref_id
Returns
bool

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

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

◆ loadData()

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

Load favourites data.

Parameters
int$user_id
array$ref_ids

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

199  {
200  $db = $this->db;
201  if (!is_array($ref_ids)) {
202  return;
203  }
204 
205  $load_ref_ids = [];
206  foreach ($ref_ids as $ref_id) {
207  if (!isset(self::$is_desktop_item[$user_id . ":" . $ref_id])) {
208  $load_ref_ids[] = $ref_id;
209  }
210  }
211 
212  if (count($load_ref_ids) > 0) {
213  $item_set = $db->query("SELECT item_id FROM desktop_item WHERE " .
214  $db->in("item_id", $load_ref_ids, false, "integer") .
215  " AND user_id = " . $db->quote($user_id, "integer"));
216  while ($r = $db->fetchAssoc($item_set)) {
217  self::$is_desktop_item[$user_id . ":" . $r["item_id"]] = true;
218  }
219  foreach ($load_ref_ids as $ref_id) {
220  if (!isset(self::$is_desktop_item[$user_id . ":" . $ref_id])) {
221  self::$is_desktop_item[$user_id . ":" . $ref_id] = false;
222  }
223  }
224  }
225  }

◆ remove()

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

Remove favourite.

Parameters
int$user_id
int$ref_id

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

70  {
71  $db = $this->db;
72 
73  $db->manipulateF(
74  "DELETE FROM desktop_item WHERE " .
75  " item_id = %s AND user_id = %s",
76  array("integer", "integer"),
77  array($ref_id, $user_id)
78  );
79  }

◆ removeFavouritesOfRefId()

ilFavouritesDBRepository::removeFavouritesOfRefId ( int  $ref_id)

Remove favourite entries of a repository item.

Parameters
int$ref_id

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

233  {
234  $db = $this->db;
235 
236  $db->manipulateF(
237  "DELETE FROM desktop_item WHERE " .
238  " item_id = %s",
239  ["integer"],
240  [$ref_id]
241  );
242  }

◆ removeFavouritesOfUser()

ilFavouritesDBRepository::removeFavouritesOfUser ( int  $user_id)

Remove favourite entries of a user.

Parameters
int$user_id

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

250  {
251  $db = $this->db;
252 
253  $db->manipulateF(
254  "DELETE FROM desktop_item WHERE " .
255  " user_id = %s",
256  ["integer"],
257  [$user_id]
258  );
259  }

Field Documentation

◆ $is_desktop_item

ilFavouritesDBRepository::$is_desktop_item = []
static

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


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