ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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)
 ilBuddySystemRelationRepository constructor. More...
 
 getAll ()
 Reads all items from database. More...
 
 destroy ()
 
 save (ilBuddySystemRelation $relation)
 

Data Fields

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

Protected Attributes

 $db
 
 $usrId
 

Private Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBuddySystemRelationRepository::__construct ( int  $usrId)

ilBuddySystemRelationRepository constructor.

Parameters
int$usrId

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

References $DIC, and $usrId.

25  {
26  global $DIC;
27 
28  $this->db = $DIC['ilDB'];
29  $this->usrId = $usrId;
30  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ addToApprovedBuddies()

ilBuddySystemRelationRepository::addToApprovedBuddies ( ilBuddySystemRelation  $relation)
private
Parameters
ilBuddySystemRelation$relation

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

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

Referenced by save().

124  {
125  $this->db->replace(
126  'buddylist',
127  [
128  'usr_id' => ['integer', $relation->getUsrId()],
129  'buddy_usr_id' => ['integer', $relation->getBuddyUsrId()]
130  ],
131  [
132  'ts' => ['integer', $relation->getTimestamp()]
133  ]
134  );
135 
136  $this->db->replace(
137  'buddylist',
138  [
139  'usr_id' => ['integer', $relation->getBuddyUsrId()],
140  'buddy_usr_id' => ['integer', $relation->getUsrId()]
141  ],
142  [
143  'ts' => ['integer', $relation->getTimestamp()]
144  ]
145  );
146  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addToRequestedBuddies()

ilBuddySystemRelationRepository::addToRequestedBuddies ( ilBuddySystemRelation  $relation,
  $ignored 
)
private
Parameters
ilBuddySystemRelation$relation
boolean$ignored

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

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

Referenced by save().

171  {
172  $this->db->replace(
173  'buddylist_requests',
174  [
175  'usr_id' => ['integer', $relation->getUsrId()],
176  'buddy_usr_id' => ['integer', $relation->getBuddyUsrId()]
177  ],
178  [
179  'ts' => ['integer', $relation->getTimestamp()],
180  'ignored' => ['integer', (int) $ignored]
181  ]
182  );
183  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

ilBuddySystemRelationRepository::destroy ( )

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

106  {
107  $this->db->queryF(
108  "DELETE FROM buddylist WHERE usr_id = %s OR buddy_usr_id = %s",
109  ['integer', 'integer'],
110  [$this->usrId, $this->usrId]
111  );
112 
113  $this->db->queryF(
114  "DELETE FROM buddylist_requests WHERE usr_id = %s OR buddy_usr_id = %s",
115  ['integer', 'integer'],
116  [$this->usrId, $this->usrId]
117  );
118  }

◆ getAll()

ilBuddySystemRelationRepository::getAll ( )

Reads all items from database.

Returns
ilBuddySystemRelation[]

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

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

36  : array
37  {
38  $relations = [];
39 
40  $res = $this->db->queryF(
41  "
42  SELECT
43  buddylist.usr_id, buddylist.buddy_usr_id, buddylist.ts, %s rel_type
44  FROM buddylist
45  INNER JOIN usr_data ud
46  ON ud.usr_id = buddylist.usr_id
47  WHERE buddylist.usr_id = %s
48  UNION
49  SELECT
50  buddylist_requests.usr_id, buddylist_requests.buddy_usr_id, buddylist_requests.ts, (CASE WHEN ignored = 1 THEN %s ELSE %s END) rel_type
51  FROM buddylist_requests
52  INNER JOIN usr_data ud ON ud.usr_id = buddylist_requests.usr_id
53  INNER JOIN usr_data udbuddy ON udbuddy.usr_id = buddylist_requests.buddy_usr_id
54  WHERE buddylist_requests.usr_id = %s OR buddylist_requests.buddy_usr_id = %s
55  ",
56  [
57  'text',
58  'integer',
59  'text',
60  'text',
61  'integer',
62  'integer'
63  ],
64  [
65  self::TYPE_APPROVED,
66  $this->usrId,
67  self::TYPE_IGNORED,
68  self::TYPE_REQUESTED,
69  $this->usrId,
70  $this->usrId
71  ]
72  );
73 
74  while ($row = $this->db->fetchAssoc($res)) {
75  $relation = $this->getRelationByDatabaseRecord($row);
76  $relation->setUsrId((int) $row['usr_id']);
77  $relation->setBuddyUsrId((int) $row['buddy_usr_id']);
78  $relation->setTimestamp((int) $row['ts']);
79  $relation->setIsOwnedByActor($relation->getUsrId() === $this->usrId);
80  $key = $this->usrId === $relation->getUsrId() ? $relation->getBuddyUsrId() : $relation->getUsrId();
81  $relations[$key] = $relation;
82  }
83 
84  return $relations;
85  }
foreach($_POST as $key=> $value) $res
+ Here is the call graph for this function:

◆ getRelationByDatabaseRecord()

ilBuddySystemRelationRepository::getRelationByDatabaseRecord (   $row)
private
Parameters
$row
Returns
ilBuddySystemRelation

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

Referenced by getAll().

92  {
93  if (self::TYPE_APPROVED === $row['rel_type']) {
95  } elseif (self::TYPE_IGNORED === $row['rel_type']) {
97  }
98 
100  }
Class ilBuddySystemRequestedRelationState.
Class ilBuddySystemRelation.
+ Here is the caller graph for this function:

◆ removeFromApprovedBuddies()

ilBuddySystemRelationRepository::removeFromApprovedBuddies ( ilBuddySystemRelation  $relation)
private
Parameters
ilBuddySystemRelation$relation

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

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

Referenced by save().

152  {
153  $this->db->manipulateF(
154  "DELETE FROM buddylist WHERE usr_id = %s AND buddy_usr_id = %s",
155  ['integer', 'integer'],
156  [$relation->getUsrId(), $relation->getBuddyUsrId()]
157  );
158 
159  $this->db->manipulateF(
160  "DELETE FROM buddylist WHERE buddy_usr_id = %s AND usr_id = %s",
161  ['integer', 'integer'],
162  [$relation->getUsrId(), $relation->getBuddyUsrId()]
163  );
164  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeFromRequestedBuddies()

ilBuddySystemRelationRepository::removeFromRequestedBuddies ( ilBuddySystemRelation  $relation)
private
Parameters
ilBuddySystemRelation$relation

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

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

Referenced by save().

189  {
190  $this->db->manipulateF(
191  "DELETE FROM buddylist_requests WHERE usr_id = %s AND buddy_usr_id = %s",
192  ['integer', 'integer'],
193  [$relation->getUsrId(), $relation->getBuddyUsrId()]
194  );
195 
196  $this->db->manipulateF(
197  "DELETE FROM buddylist_requests WHERE buddy_usr_id = %s AND usr_id = %s",
198  ['integer', 'integer'],
199  [$relation->getUsrId(), $relation->getBuddyUsrId()]
200  );
201  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBuddySystemRelationRepository::save ( ilBuddySystemRelation  $relation)
Parameters
ilBuddySystemRelation$relation

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

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

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

Field Documentation

◆ $db

ilBuddySystemRelationRepository::$db
protected

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

◆ $usrId

ilBuddySystemRelationRepository::$usrId
protected

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

Referenced by __construct(), and getAll().

◆ TYPE_APPROVED

const ilBuddySystemRelationRepository::TYPE_APPROVED = 'app'

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

◆ TYPE_IGNORED

const ilBuddySystemRelationRepository::TYPE_IGNORED = 'ign'

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

◆ TYPE_REQUESTED

const ilBuddySystemRelationRepository::TYPE_REQUESTED = 'req'

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


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