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

Class ilBuddySystemRelationRepository. More...

+ Collaboration diagram for ilBuddySystemRelationRepository:

Public Member Functions

 __construct (int $usrId, ilDBInterface $db=null)
 
 getAll ()
 Reads all items from database. More...
 
 destroy ()
 
 save (ilBuddySystemRelation $relation)
 

Protected Attributes

ilDBInterface $db
 
int $usrId
 

Private Member Functions

 getRelationByDatabaseRecord (array $row)
 
 addToApprovedBuddies (ilBuddySystemRelation $relation)
 
 removeFromApprovedBuddies (ilBuddySystemRelation $relation)
 
 addToRequestedBuddies (ilBuddySystemRelation $relation, bool $ignored)
 
 removeFromRequestedBuddies (ilBuddySystemRelation $relation)
 

Private Attributes

const TYPE_APPROVED = 'app'
 
const TYPE_REQUESTED = 'req'
 
const TYPE_IGNORED = 'ign'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemRelationRepository::__construct ( int  $usrId,
ilDBInterface  $db = null 
)

Definition at line 34 of file class.ilBuddySystemRelationRepository.php.

References $DIC, and $usrId.

35  {
36  global $DIC;
37 
38  $this->db = $db ?? $DIC->database();
39  $this->usrId = $usrId;
40  }
global $DIC
Definition: feed.php:28

Member Function Documentation

◆ addToApprovedBuddies()

ilBuddySystemRelationRepository::addToApprovedBuddies ( ilBuddySystemRelation  $relation)
private

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

References ilBuddySystemRelation\getBuddyUsrId(), ilBuddySystemRelation\getTimestamp(), and ilBuddySystemRelation\getUsrId().

Referenced by save().

141  : void
142  {
143  $this->db->replace(
144  'buddylist',
145  [
146  'usr_id' => ['integer', $relation->getUsrId()],
147  'buddy_usr_id' => ['integer', $relation->getBuddyUsrId()]
148  ],
149  [
150  'ts' => ['integer', $relation->getTimestamp()]
151  ]
152  );
153 
154  $this->db->replace(
155  'buddylist',
156  [
157  'usr_id' => ['integer', $relation->getBuddyUsrId()],
158  'buddy_usr_id' => ['integer', $relation->getUsrId()]
159  ],
160  [
161  'ts' => ['integer', $relation->getTimestamp()]
162  ]
163  );
164  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addToRequestedBuddies()

ilBuddySystemRelationRepository::addToRequestedBuddies ( ilBuddySystemRelation  $relation,
bool  $ignored 
)
private

Definition at line 181 of file class.ilBuddySystemRelationRepository.php.

References ilBuddySystemRelation\getBuddyUsrId(), ilBuddySystemRelation\getTimestamp(), ilBuddySystemRelation\getUsrId(), and ILIAS\Repository\int().

Referenced by save().

181  : void
182  {
183  $this->db->replace(
184  'buddylist_requests',
185  [
186  'usr_id' => ['integer', $relation->getUsrId()],
187  'buddy_usr_id' => ['integer', $relation->getBuddyUsrId()]
188  ],
189  [
190  'ts' => ['integer', $relation->getTimestamp()],
191  'ignored' => ['integer', (int) $ignored]
192  ]
193  );
194  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

ilBuddySystemRelationRepository::destroy ( )

Definition at line 126 of file class.ilBuddySystemRelationRepository.php.

126  : void
127  {
128  $this->db->manipulateF(
129  'DELETE FROM buddylist WHERE usr_id = %s OR buddy_usr_id = %s',
130  ['integer', 'integer'],
131  [$this->usrId, $this->usrId]
132  );
133 
134  $this->db->manipulateF(
135  'DELETE FROM buddylist_requests WHERE usr_id = %s OR buddy_usr_id = %s',
136  ['integer', 'integer'],
137  [$this->usrId, $this->usrId]
138  );
139  }

◆ getAll()

ilBuddySystemRelationRepository::getAll ( )

Reads all items from database.

Returns
ilBuddySystemRelation[]

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

References ILIAS\LTI\ToolProvider\$key, $res, and getRelationByDatabaseRecord().

46  : array
47  {
48  $relations = [];
49 
50  $res = $this->db->queryF(
51  '
52  SELECT
53  buddylist.usr_id, buddylist.buddy_usr_id, buddylist.ts, %s rel_type
54  FROM buddylist
55  INNER JOIN usr_data ud
56  ON ud.usr_id = buddylist.usr_id
57  INNER JOIN usr_data udbuddy
58  ON udbuddy.usr_id = buddylist.buddy_usr_id
59  WHERE buddylist.usr_id = %s
60  UNION
61  SELECT
62  buddylist_requests.usr_id, buddylist_requests.buddy_usr_id, buddylist_requests.ts, (CASE WHEN ignored = 1 THEN %s ELSE %s END) rel_type
63  FROM buddylist_requests
64  INNER JOIN usr_data ud ON ud.usr_id = buddylist_requests.usr_id
65  INNER JOIN usr_data udbuddy ON udbuddy.usr_id = buddylist_requests.buddy_usr_id
66  WHERE buddylist_requests.usr_id = %s OR buddylist_requests.buddy_usr_id = %s
67  ',
68  [
69  'text',
70  'integer',
71  'text',
72  'text',
73  'integer',
74  'integer'
75  ],
76  [
77  self::TYPE_APPROVED,
78  $this->usrId,
79  self::TYPE_IGNORED,
80  self::TYPE_REQUESTED,
81  $this->usrId,
82  $this->usrId
83  ]
84  );
85 
86  while ($row = $this->db->fetchAssoc($res)) {
87  $relation = $this->getRelationByDatabaseRecord($row);
88  $key = $this->usrId === $relation->getUsrId() ? $relation->getBuddyUsrId() : $relation->getUsrId();
89  $relations[$key] = $relation;
90  }
91 
92  return $relations;
93  }
$res
Definition: ltiservices.php:69
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ getRelationByDatabaseRecord()

ilBuddySystemRelationRepository::getRelationByDatabaseRecord ( array  $row)
private

Definition at line 95 of file class.ilBuddySystemRelationRepository.php.

Referenced by getAll().

96  {
97  if (self::TYPE_APPROVED === $row['rel_type']) {
98  return new ilBuddySystemRelation(
100  (int) $row['usr_id'],
101  (int) $row['buddy_usr_id'],
102  (int) $row['usr_id'] === $this->usrId,
103  (int) $row['ts']
104  );
105  }
106 
107  if (self::TYPE_IGNORED === $row['rel_type']) {
108  return new ilBuddySystemRelation(
110  (int) $row['usr_id'],
111  (int) $row['buddy_usr_id'],
112  (int) $row['usr_id'] === $this->usrId,
113  (int) $row['ts']
114  );
115  }
116 
117  return new ilBuddySystemRelation(
119  (int) $row['usr_id'],
120  (int) $row['buddy_usr_id'],
121  (int) $row['usr_id'] === $this->usrId,
122  (int) $row['ts']
123  );
124  }
+ Here is the caller graph for this function:

◆ removeFromApprovedBuddies()

ilBuddySystemRelationRepository::removeFromApprovedBuddies ( ilBuddySystemRelation  $relation)
private

Definition at line 166 of file class.ilBuddySystemRelationRepository.php.

References ilBuddySystemRelation\getBuddyUsrId(), and ilBuddySystemRelation\getUsrId().

Referenced by save().

166  : void
167  {
168  $this->db->manipulateF(
169  'DELETE FROM buddylist WHERE usr_id = %s AND buddy_usr_id = %s',
170  ['integer', 'integer'],
171  [$relation->getUsrId(), $relation->getBuddyUsrId()]
172  );
173 
174  $this->db->manipulateF(
175  'DELETE FROM buddylist WHERE buddy_usr_id = %s AND usr_id = %s',
176  ['integer', 'integer'],
177  [$relation->getUsrId(), $relation->getBuddyUsrId()]
178  );
179  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeFromRequestedBuddies()

ilBuddySystemRelationRepository::removeFromRequestedBuddies ( ilBuddySystemRelation  $relation)
private

Definition at line 196 of file class.ilBuddySystemRelationRepository.php.

References ilBuddySystemRelation\getBuddyUsrId(), and ilBuddySystemRelation\getUsrId().

Referenced by save().

196  : void
197  {
198  $this->db->manipulateF(
199  'DELETE FROM buddylist_requests WHERE usr_id = %s AND buddy_usr_id = %s',
200  ['integer', 'integer'],
201  [$relation->getUsrId(), $relation->getBuddyUsrId()]
202  );
203 
204  $this->db->manipulateF(
205  'DELETE FROM buddylist_requests WHERE buddy_usr_id = %s AND usr_id = %s',
206  ['integer', 'integer'],
207  [$relation->getUsrId(), $relation->getBuddyUsrId()]
208  );
209  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBuddySystemRelationRepository::save ( ilBuddySystemRelation  $relation)

Definition at line 211 of file class.ilBuddySystemRelationRepository.php.

References $ilDB, addToApprovedBuddies(), addToRequestedBuddies(), ilBuddySystemRelation\isIgnored(), ilBuddySystemRelation\isLinked(), ilBuddySystemRelation\isRequested(), removeFromApprovedBuddies(), removeFromRequestedBuddies(), ilBuddySystemRelation\wasIgnored(), ilBuddySystemRelation\wasLinked(), and ilBuddySystemRelation\wasRequested().

211  : void
212  {
213  $ilAtomQuery = $this->db->buildAtomQuery();
214  $ilAtomQuery->addTableLock('buddylist_requests');
215  $ilAtomQuery->addTableLock('buddylist');
216 
217  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($relation): void {
218  if ($relation->isLinked()) {
219  $this->addToApprovedBuddies($relation);
220  } elseif ($relation->wasLinked()) {
221  $this->removeFromApprovedBuddies($relation);
222  }
223 
224  if ($relation->isRequested()) {
225  $this->addToRequestedBuddies($relation, false);
226  } elseif ($relation->isIgnored()) {
227  $this->addToRequestedBuddies($relation, true);
228  } elseif ($relation->wasRequested() || $relation->wasIgnored()) {
229  $this->removeFromRequestedBuddies($relation);
230  }
231  });
232 
233  $ilAtomQuery->run();
234  }
removeFromRequestedBuddies(ilBuddySystemRelation $relation)
addToRequestedBuddies(ilBuddySystemRelation $relation, bool $ignored)
removeFromApprovedBuddies(ilBuddySystemRelation $relation)
addToApprovedBuddies(ilBuddySystemRelation $relation)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilBuddySystemRelationRepository::$db
protected

Definition at line 31 of file class.ilBuddySystemRelationRepository.php.

◆ $usrId

int ilBuddySystemRelationRepository::$usrId
protected

Definition at line 32 of file class.ilBuddySystemRelationRepository.php.

Referenced by __construct().

◆ TYPE_APPROVED

const ilBuddySystemRelationRepository::TYPE_APPROVED = 'app'
private

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

◆ TYPE_IGNORED

const ilBuddySystemRelationRepository::TYPE_IGNORED = 'ign'
private

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

◆ TYPE_REQUESTED

const ilBuddySystemRelationRepository::TYPE_REQUESTED = 'req'
private

Definition at line 28 of file class.ilBuddySystemRelationRepository.php.


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