ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilRecommendedContentDBRepository Class Reference

Recommended content db repository. More...

+ Collaboration diagram for ilRecommendedContentDBRepository:

Public Member Functions

 __construct (\ilDBInterface $db=null)
 Constructor. More...
 
 addRoleRecommendation (int $role_id, int $ref_id)
 Add role recommendation. More...
 
 removeRoleRecommendation (int $role_id, int $ref_id)
 Remove role recommendation. More...
 
 addObjectRecommendation (int $user_id, int $ref_id)
 Add object recommendation. More...
 
 removeObjectRecommendation (int $user_id, int $ref_id)
 Remove object recommendation. More...
 
 removeRecommendationsOfRefId (int $ref_id)
 Remove all recommendations of a ref id (role and user/object related) More...
 
 removeRecommendationsOfUser (int $user_id)
 Remove all recommendations of a user. More...
 
 removeRecommendationsOfRole (int $role_id)
 Remove all recommendations of a role. More...
 
 declineObjectRecommendation (int $user_id, int $ref_id)
 Decline object recommendation. More...
 
 getRecommendationsOfRoles (array $role_ids)
 Get recommendations of roles. More...
 
 getOpenRecommendationsOfUser (int $user_id, array $role_ids)
 Open recommendations of user (by role or object, without declined ones) More...
 

Protected Member Functions

 ifExistsObjectRecommendation (int $user_id, int $ref_id)
 Does object recommendation exist? More...
 
 getUserObjectRecommendations (int $user_id)
 Get user object recommendations. More...
 
 getDeclinedUserObjectRecommendations (int $user_id)
 Get declined user object recommendations. More...
 

Protected Attributes

 $db
 

Detailed Description

Recommended content db repository.

Table rep_rec_content_obj (A repo object is directly recommended for a user, users can decline recommendations)

  • user_id
  • ref_id
  • declined

Table rep_rec_content_role (A repo object is recommended for users of a role)

  • role_id
  • ref_id
Author
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 19 of file class.ilRecommendedContentDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilRecommendedContentDBRepository::__construct ( \ilDBInterface  $db = null)

Constructor.

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

References $db, and $DIC.

30  {
31  global $DIC;
32 
33  $this->db = (is_null($db))
34  ? $DIC->database()
35  : $db;
36  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ addObjectRecommendation()

ilRecommendedContentDBRepository::addObjectRecommendation ( int  $user_id,
int  $ref_id 
)

Add object recommendation.

Parameters
int$role_id
int$ref_id

Definition at line 80 of file class.ilRecommendedContentDBRepository.php.

References $db, and ifExistsObjectRecommendation().

81  {
82  $db = $this->db;
83 
84  if (!$this->ifExistsObjectRecommendation($user_id, $ref_id)) {
85  $db->insert("rep_rec_content_obj", [
86  "user_id" => ["integer", $user_id],
87  "ref_id" => ["integer", $ref_id],
88  "declined" => ["integer", false]
89  ]);
90  }
91  }
ifExistsObjectRecommendation(int $user_id, int $ref_id)
Does object recommendation exist?
+ Here is the call graph for this function:

◆ addRoleRecommendation()

ilRecommendedContentDBRepository::addRoleRecommendation ( int  $role_id,
int  $ref_id 
)

Add role recommendation.

Parameters
int$role_id
int$ref_id

Definition at line 44 of file class.ilRecommendedContentDBRepository.php.

References $db.

45  {
46  $db = $this->db;
47 
48  $db->replace(
49  "rep_rec_content_role",
50  [ // pk
51  "role_id" => ["integer", $role_id],
52  "ref_id" => ["integer", $ref_id]
53  ],
54  []
55  );
56  }

◆ declineObjectRecommendation()

ilRecommendedContentDBRepository::declineObjectRecommendation ( int  $user_id,
int  $ref_id 
)

Decline object recommendation.

Parameters
int$user_id
int$ref_id

Definition at line 197 of file class.ilRecommendedContentDBRepository.php.

References $db, and ifExistsObjectRecommendation().

198  {
199  $db = $this->db;
200 
201  if ($this->ifExistsObjectRecommendation($user_id, $ref_id)) {
202  $db->update(
203  "rep_rec_content_obj",
204  [
205  "declined" => ["integer", true]
206  ],
207  [ // where
208  "user_id" => ["integer", $user_id],
209  "ref_id" => ["integer", $ref_id]
210  ]
211  );
212  } else {
213  $db->insert("rep_rec_content_obj", [
214  "user_id" => ["integer", $user_id],
215  "ref_id" => ["integer", $ref_id],
216  "declined" => ["integer", true]
217  ]);
218  }
219  }
ifExistsObjectRecommendation(int $user_id, int $ref_id)
Does object recommendation exist?
+ Here is the call graph for this function:

◆ getDeclinedUserObjectRecommendations()

ilRecommendedContentDBRepository::getDeclinedUserObjectRecommendations ( int  $user_id)
protected

Get declined user object recommendations.

Parameters
int$user_id
Returns
int[] ref ids of declined recommendations

Definition at line 263 of file class.ilRecommendedContentDBRepository.php.

References $db.

Referenced by getOpenRecommendationsOfUser().

263  : array
264  {
265  $db = $this->db;
266 
267  $set = $db->queryF(
268  "SELECT ref_id FROM rep_rec_content_obj " .
269  " WHERE user_id = %s AND declined = %s",
270  ["integer", "integer"],
271  [$user_id, true]
272  );
273  return array_column($db->fetchAll($set), "ref_id");
274  }
+ Here is the caller graph for this function:

◆ getOpenRecommendationsOfUser()

ilRecommendedContentDBRepository::getOpenRecommendationsOfUser ( int  $user_id,
array  $role_ids 
)

Open recommendations of user (by role or object, without declined ones)

Parameters
int$user_id
int[]$role_ids
Returns
int[] ref ids of open recommendations

Definition at line 284 of file class.ilRecommendedContentDBRepository.php.

References $i, getDeclinedUserObjectRecommendations(), getRecommendationsOfRoles(), and getUserObjectRecommendations().

284  : array
285  {
286  // recommendations of role
287  $role_recommendations = $this->getRecommendationsOfRoles($role_ids);
288 
289  // recommendations of user
290  $obj_recommendations = $this->getUserObjectRecommendations($user_id);
291 
292  $recommendations = array_unique($role_recommendations + $obj_recommendations);
293 
294  // filter declined recommendations
295  $declined_recommendations = $this->getDeclinedUserObjectRecommendations($user_id);
296  return array_filter($recommendations, function ($i) use ($declined_recommendations) {
297  return !in_array($i, $declined_recommendations);
298  });
299  }
getRecommendationsOfRoles(array $role_ids)
Get recommendations of roles.
getDeclinedUserObjectRecommendations(int $user_id)
Get declined user object recommendations.
getUserObjectRecommendations(int $user_id)
Get user object recommendations.
$i
Definition: metadata.php:24
+ Here is the call graph for this function:

◆ getRecommendationsOfRoles()

ilRecommendedContentDBRepository::getRecommendationsOfRoles ( array  $role_ids)

Get recommendations of roles.

Parameters
$role_idsint[] role ids
Returns
int[] ref ids of recommendations

Definition at line 227 of file class.ilRecommendedContentDBRepository.php.

References $db.

Referenced by getOpenRecommendationsOfUser().

228  {
229  $db = $this->db;
230 
231  $set = $db->query(
232  "SELECT DISTINCT ref_id FROM rep_rec_content_role " .
233  " WHERE " . $db->in("role_id", $role_ids, false, "integer")
234  );
235  return array_column($db->fetchAll($set), "ref_id");
236  }
+ Here is the caller graph for this function:

◆ getUserObjectRecommendations()

ilRecommendedContentDBRepository::getUserObjectRecommendations ( int  $user_id)
protected

Get user object recommendations.

Parameters
int$user_id
Returns
int[] ref ids of recommendations

Definition at line 244 of file class.ilRecommendedContentDBRepository.php.

References $db.

Referenced by getOpenRecommendationsOfUser().

244  : array
245  {
246  $db = $this->db;
247 
248  $set = $db->queryF(
249  "SELECT ref_id FROM rep_rec_content_obj " .
250  " WHERE user_id = %s AND declined = %s",
251  ["integer", "integer"],
252  [$user_id, false]
253  );
254  return array_column($db->fetchAll($set), "ref_id");
255  }
+ Here is the caller graph for this function:

◆ ifExistsObjectRecommendation()

ilRecommendedContentDBRepository::ifExistsObjectRecommendation ( int  $user_id,
int  $ref_id 
)
protected

Does object recommendation exist?

Parameters

Definition at line 174 of file class.ilRecommendedContentDBRepository.php.

References $db.

Referenced by addObjectRecommendation(), and declineObjectRecommendation().

175  {
176  $db = $this->db;
177 
178  $set = $db->queryF(
179  "SELECT * FROM rep_rec_content_obj " .
180  " WHERE user_id = %s AND ref_id = %s",
181  ["integer","integer"],
182  [$user_id, $ref_id]
183  );
184  if ($rec = $db->fetchAssoc($set)) {
185  return true;
186  }
187  return false;
188  }
+ Here is the caller graph for this function:

◆ removeObjectRecommendation()

ilRecommendedContentDBRepository::removeObjectRecommendation ( int  $user_id,
int  $ref_id 
)

Remove object recommendation.

Parameters
int$user_id
int$ref_id

Definition at line 98 of file class.ilRecommendedContentDBRepository.php.

References $db.

99  {
100  $db = $this->db;
101 
102  $db->manipulateF(
103  "DELETE FROM rep_rec_content_obj WHERE " .
104  " user_id = %s AND ref_id = %s",
105  ["integer", "integer"],
106  [$user_id, $ref_id]
107  );
108  }

◆ removeRecommendationsOfRefId()

ilRecommendedContentDBRepository::removeRecommendationsOfRefId ( int  $ref_id)

Remove all recommendations of a ref id (role and user/object related)

Parameters
int$ref_id

Definition at line 115 of file class.ilRecommendedContentDBRepository.php.

References $db.

116  {
117  $db = $this->db;
118 
119  $db->manipulateF(
120  "DELETE FROM rep_rec_content_obj WHERE " .
121  " ref_id = %s",
122  ["integer"],
123  [$ref_id]
124  );
125 
126  $db->manipulateF(
127  "DELETE FROM rep_rec_content_role WHERE " .
128  " ref_id = %s",
129  ["integer"],
130  [$ref_id]
131  );
132  }

◆ removeRecommendationsOfRole()

ilRecommendedContentDBRepository::removeRecommendationsOfRole ( int  $role_id)

Remove all recommendations of a role.

Parameters
int$role_id

Definition at line 156 of file class.ilRecommendedContentDBRepository.php.

References $db.

157  {
158  $db = $this->db;
159 
160  $db->manipulateF(
161  "DELETE FROM rep_rec_content_role WHERE " .
162  " role_id = %s",
163  ["integer"],
164  [$role_id]
165  );
166  }

◆ removeRecommendationsOfUser()

ilRecommendedContentDBRepository::removeRecommendationsOfUser ( int  $user_id)

Remove all recommendations of a user.

Parameters
int$user_id

Definition at line 139 of file class.ilRecommendedContentDBRepository.php.

References $db.

140  {
141  $db = $this->db;
142 
143  $db->manipulateF(
144  "DELETE FROM rep_rec_content_obj WHERE " .
145  " user_id = %s",
146  ["integer"],
147  [$user_id]
148  );
149  }

◆ removeRoleRecommendation()

ilRecommendedContentDBRepository::removeRoleRecommendation ( int  $role_id,
int  $ref_id 
)

Remove role recommendation.

Parameters
int$role_id
int$ref_id

Definition at line 63 of file class.ilRecommendedContentDBRepository.php.

References $db.

64  {
65  $db = $this->db;
66 
67  $db->manipulateF(
68  "DELETE FROM rep_rec_content_role WHERE " .
69  " role_id = %s AND ref_id = %s",
70  ["integer", "integer"],
71  [$role_id, $ref_id]
72  );
73  }

Field Documentation

◆ $db


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