ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBuddySystemRelationRepository Class Reference

Class ilBuddySystemRelationRepository. More...

+ Collaboration diagram for ilBuddySystemRelationRepository:

Public Member Functions

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

Protected Attributes

ilDBInterface $db
 

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 ( protected int  $usrId,
?ilDBInterface  $db = null 
)

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

References $DIC.

34  {
35  global $DIC;
36 
37  $this->db = $db ?? $DIC->database();
38  }
global $DIC
Definition: shib_login.php:22

Member Function Documentation

◆ addToApprovedBuddies()

ilBuddySystemRelationRepository::addToApprovedBuddies ( ilBuddySystemRelation  $relation)
private

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

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

Referenced by save().

139  : void
140  {
141  $this->db->replace(
142  'buddylist',
143  [
144  'usr_id' => ['integer', $relation->getUsrId()],
145  'buddy_usr_id' => ['integer', $relation->getBuddyUsrId()]
146  ],
147  [
148  'ts' => ['integer', $relation->getTimestamp()]
149  ]
150  );
151 
152  $this->db->replace(
153  'buddylist',
154  [
155  'usr_id' => ['integer', $relation->getBuddyUsrId()],
156  'buddy_usr_id' => ['integer', $relation->getUsrId()]
157  ],
158  [
159  'ts' => ['integer', $relation->getTimestamp()]
160  ]
161  );
162  }
+ 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 179 of file class.ilBuddySystemRelationRepository.php.

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

Referenced by save().

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

◆ destroy()

ilBuddySystemRelationRepository::destroy ( )

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

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

◆ getAll()

ilBuddySystemRelationRepository::getAll ( )

Reads all items from database.

Returns
ilBuddySystemRelation[]

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

References $relation, $res, and getRelationByDatabaseRecord().

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

◆ getRelationByDatabaseRecord()

ilBuddySystemRelationRepository::getRelationByDatabaseRecord ( array  $row)
private

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

Referenced by getAll().

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

◆ removeFromApprovedBuddies()

ilBuddySystemRelationRepository::removeFromApprovedBuddies ( ilBuddySystemRelation  $relation)
private

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

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

Referenced by save().

164  : void
165  {
166  $this->db->manipulateF(
167  'DELETE FROM buddylist WHERE usr_id = %s AND buddy_usr_id = %s',
168  ['integer', 'integer'],
169  [$relation->getUsrId(), $relation->getBuddyUsrId()]
170  );
171 
172  $this->db->manipulateF(
173  'DELETE FROM buddylist WHERE buddy_usr_id = %s AND usr_id = %s',
174  ['integer', 'integer'],
175  [$relation->getUsrId(), $relation->getBuddyUsrId()]
176  );
177  }
+ 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 194 of file class.ilBuddySystemRelationRepository.php.

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

Referenced by save().

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

◆ save()

ilBuddySystemRelationRepository::save ( ilBuddySystemRelation  $relation)

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

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

209  : void
210  {
211  $ilAtomQuery = $this->db->buildAtomQuery();
212  $ilAtomQuery->addTableLock('buddylist_requests');
213  $ilAtomQuery->addTableLock('buddylist');
214 
215  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($relation): void {
216  if ($relation->isLinked()) {
217  $this->addToApprovedBuddies($relation);
218  } elseif ($relation->wasLinked()) {
219  $this->removeFromApprovedBuddies($relation);
220  }
221 
222  if ($relation->isRequested()) {
223  $this->addToRequestedBuddies($relation, false);
224  } elseif ($relation->isIgnored()) {
225  $this->addToRequestedBuddies($relation, true);
226  } elseif ($relation->wasRequested() || $relation->wasIgnored()) {
227  $this->removeFromRequestedBuddies($relation);
228  }
229  });
230 
231  $ilAtomQuery->run();
232  }
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.

◆ 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: