ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRecommendedContentDBRepository 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 ilRecommendedContentDBRepository:

Public Member Functions

 __construct (?ilDBInterface $db=null)
 
 addRoleRecommendation (int $role_id, int $ref_id)
 
 removeRoleRecommendation (int $role_id, int $ref_id)
 
 addObjectRecommendation (int $user_id, int $ref_id)
 
 removeObjectRecommendation (int $user_id, int $ref_id)
 
 removeRecommendationsOfRefId (int $ref_id)
 
 removeRecommendationsOfUser (int $user_id)
 
 removeRecommendationsOfRole (int $role_id)
 
 declineObjectRecommendation (int $user_id, int $ref_id)
 
 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)
 
 getUserObjectRecommendations (int $user_id)
 Get user object recommendations. More...
 
 getDeclinedUserObjectRecommendations (int $user_id)
 Get declined user object recommendations. More...
 

Protected Attributes

ilDBInterface $db
 

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 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
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

References $db, and $DIC.

Member Function Documentation

◆ addObjectRecommendation()

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

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

72 : void
73 {
74 $db = $this->db;
75
77 $db->insert("rep_rec_content_obj", [
78 "user_id" => ["integer", $user_id],
79 "ref_id" => ["integer", $ref_id],
80 "declined" => ["integer", false]
81 ]);
82 }
83 }
insert(string $table_name, array $values)
$ref_id
Definition: ltiauth.php:66

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

+ Here is the call graph for this function:

◆ addRoleRecommendation()

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

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

46 : void
47 {
48 $db = $this->db;
49
50 $db->replace(
51 "rep_rec_content_role",
52 [ // pk
53 "role_id" => ["integer", $role_id],
54 "ref_id" => ["integer", $ref_id]
55 ],
56 []
57 );
58 }
replace(string $table, array $primary_keys, array $other_columns)
Replace into method.

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

+ Here is the call graph for this function:

◆ declineObjectRecommendation()

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

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

157 : void
158 {
159 $db = $this->db;
160
162 $db->update(
163 "rep_rec_content_obj",
164 [
165 "declined" => ["integer", true]
166 ],
167 [ // where
168 "user_id" => ["integer", $user_id],
169 "ref_id" => ["integer", $ref_id]
170 ]
171 );
172 } else {
173 $db->insert("rep_rec_content_obj", [
174 "user_id" => ["integer", $user_id],
175 "ref_id" => ["integer", $ref_id],
176 "declined" => ["integer", true]
177 ]);
178 }
179 }
update(string $table_name, array $values, array $where)
@description $where MUST contain existing columns only.

References $db, $ref_id, $user_id, ifExistsObjectRecommendation(), ilDBInterface\insert(), and ilDBInterface\update().

+ Here is the call graph for this function:

◆ getDeclinedUserObjectRecommendations()

ilRecommendedContentDBRepository::getDeclinedUserObjectRecommendations ( int  $user_id)
protected

Get declined user object recommendations.

Returns
int[] ref ids of declined recommendations

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

221 : array
222 {
223 $db = $this->db;
224
225 $set = $db->queryF(
226 "SELECT ref_id FROM rep_rec_content_obj " .
227 " WHERE user_id = %s AND declined = %s",
228 ["integer", "integer"],
229 [$user_id, true]
230 );
231
232 return array_map('intval', array_column($db->fetchAll($set), "ref_id"));
233 }
fetchAll(ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
queryF(string $query, array $types, array $values)

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

Referenced by getOpenRecommendationsOfUser().

+ Here is the call graph for this function:
+ 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[]$role_ids
Returns
int[] ref ids of open recommendations

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

240 : array
241 {
242 // recommendations of role
243 $role_recommendations = $this->getRecommendationsOfRoles($role_ids);
244
245 // recommendations of user
246 $obj_recommendations = $this->getUserObjectRecommendations($user_id);
247
248 $recommendations = array_unique($role_recommendations + $obj_recommendations);
249
250 // filter declined recommendations
251 $declined_recommendations = $this->getDeclinedUserObjectRecommendations($user_id);
252 return array_filter($recommendations, static function (int $i) use ($declined_recommendations): bool {
253 return !in_array($i, $declined_recommendations, true);
254 });
255 }
getUserObjectRecommendations(int $user_id)
Get user object recommendations.
getRecommendationsOfRoles(array $role_ids)
Get recommendations of roles.
getDeclinedUserObjectRecommendations(int $user_id)
Get declined user object recommendations.

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

Referenced by ilRecommendedContentManager\getOpenRecommendationsOfUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecommendationsOfRoles()

ilRecommendedContentDBRepository::getRecommendationsOfRoles ( array  $role_ids)

Get recommendations of roles.

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

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

187 : array
188 {
189 $db = $this->db;
190
191 $set = $db->query(
192 "SELECT DISTINCT ref_id FROM rep_rec_content_role " .
193 " WHERE " . $db->in("role_id", $role_ids, false, "integer")
194 );
195
196 return array_map('intval', array_column($db->fetchAll($set), "ref_id"));
197 }
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")

References $db, ilDBInterface\fetchAll(), ilDBInterface\in(), and ilDBInterface\query().

Referenced by getOpenRecommendationsOfUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserObjectRecommendations()

ilRecommendedContentDBRepository::getUserObjectRecommendations ( int  $user_id)
protected

Get user object recommendations.

Returns
int[] ref ids of recommendations

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

203 : array
204 {
205 $db = $this->db;
206
207 $set = $db->queryF(
208 "SELECT ref_id FROM rep_rec_content_obj " .
209 " WHERE user_id = %s AND declined = %s",
210 ["integer", "integer"],
211 [$user_id, false]
212 );
213
214 return array_map('intval', array_column($db->fetchAll($set), "ref_id"));
215 }

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

Referenced by getOpenRecommendationsOfUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ifExistsObjectRecommendation()

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

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

141 : bool
142 {
143 $db = $this->db;
144
145 $set = $db->queryF(
146 "SELECT * FROM rep_rec_content_obj " .
147 " WHERE user_id = %s AND ref_id = %s",
148 ["integer","integer"],
150 );
151 if ($rec = $db->fetchAssoc($set)) {
152 return true;
153 }
154 return false;
155 }
fetchAssoc(ilDBStatement $statement)

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

Referenced by addObjectRecommendation(), and declineObjectRecommendation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeObjectRecommendation()

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

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

85 : void
86 {
87 $db = $this->db;
88
90 "DELETE FROM rep_rec_content_obj WHERE " .
91 " user_id = %s AND ref_id = %s",
92 ["integer", "integer"],
94 );
95 }
manipulateF(string $query, array $types, array $values)

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

+ Here is the call graph for this function:

◆ removeRecommendationsOfRefId()

ilRecommendedContentDBRepository::removeRecommendationsOfRefId ( int  $ref_id)

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

97 : void
98 {
99 $db = $this->db;
100
102 "DELETE FROM rep_rec_content_obj WHERE " .
103 " ref_id = %s",
104 ["integer"],
105 [$ref_id]
106 );
107
109 "DELETE FROM rep_rec_content_role WHERE " .
110 " ref_id = %s",
111 ["integer"],
112 [$ref_id]
113 );
114 }

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

+ Here is the call graph for this function:

◆ removeRecommendationsOfRole()

ilRecommendedContentDBRepository::removeRecommendationsOfRole ( int  $role_id)

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

128 : void
129 {
130 $db = $this->db;
131
133 "DELETE FROM rep_rec_content_role WHERE " .
134 " role_id = %s",
135 ["integer"],
136 [$role_id]
137 );
138 }

References $db, and ilDBInterface\manipulateF().

+ Here is the call graph for this function:

◆ removeRecommendationsOfUser()

ilRecommendedContentDBRepository::removeRecommendationsOfUser ( int  $user_id)

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

116 : void
117 {
118 $db = $this->db;
119
121 "DELETE FROM rep_rec_content_obj WHERE " .
122 " user_id = %s",
123 ["integer"],
124 [$user_id]
125 );
126 }

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

+ Here is the call graph for this function:

◆ removeRoleRecommendation()

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

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

60 : void
61 {
62 $db = $this->db;
63
65 "DELETE FROM rep_rec_content_role WHERE " .
66 " role_id = %s AND ref_id = %s",
67 ["integer", "integer"],
68 [$role_id, $ref_id]
69 );
70 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $db


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