ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBuddySystemRelationRepository Class Reference

Class ilBuddySystemRelationRepository. More...

+ Collaboration diagram for ilBuddySystemRelationRepository:

Public Member Functions

 __construct ($usr_id)
 
 getDatabaseAdapter ()
 
 setDatabaseAdapter (ilDBInterface $db)
 
 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
 
 $usr_id
 

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 (   $usr_id)

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

References $DIC, and $usr_id.

29  {
30  global $DIC;
31 
32  $this->db = $DIC['ilDB'];
33  $this->usr_id = $usr_id;
34  }
global $DIC

Member Function Documentation

◆ addToApprovedBuddies()

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

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

References array, ilBuddySystemRelation\getBuddyUserId(), ilBuddySystemRelation\getTimestamp(), and ilBuddySystemRelation\getUserId().

Referenced by save().

136  {
137  $this->db->replace(
138  'buddylist',
139  array(
140  'usr_id' => array('integer', $relation->getUserId()),
141  'buddy_usr_id' => array('integer', $relation->getBuddyUserId())
142  ),
143  array(
144  'ts' => array('integer', $relation->getTimestamp())
145  )
146  );
147 
148  $this->db->replace(
149  'buddylist',
150  array(
151  'usr_id' => array('integer', $relation->getBuddyUserId()),
152  'buddy_usr_id' => array('integer', $relation->getUserId())
153  ),
154  array(
155  'ts' => array('integer', $relation->getTimestamp())
156  )
157  );
158  }
Create styles array
The data for the language used.
+ 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 182 of file class.ilBuddySystemRelationRepository.php.

References array, ilBuddySystemRelation\getBuddyUserId(), ilBuddySystemRelation\getTimestamp(), and ilBuddySystemRelation\getUserId().

Referenced by save().

183  {
184  $this->db->replace(
185  'buddylist_requests',
186  array(
187  'usr_id' => array('integer', $relation->getUserId()),
188  'buddy_usr_id' => array('integer', $relation->getBuddyUserId())
189  ),
190  array(
191  'ts' => array('integer', $relation->getTimestamp()),
192  'ignored' => array('integer', (int)$ignored)
193  )
194  );
195  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

ilBuddySystemRelationRepository::destroy ( )

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

References array.

118  {
119  $this->db->queryF(
120  "DELETE FROM buddylist WHERE usr_id = %s OR buddy_usr_id = %s",
121  array('integer', 'integer'),
122  array($this->usr_id, $this->usr_id)
123  );
124 
125  $this->db->queryF(
126  "DELETE FROM buddylist_requests WHERE usr_id = %s OR buddy_usr_id = %s",
127  array('integer', 'integer'),
128  array($this->usr_id, $this->usr_id)
129  );
130  }
Create styles array
The data for the language used.

◆ getAll()

ilBuddySystemRelationRepository::getAll ( )

Reads all items from database.

Returns
ilBuddySystemRelation[]

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

References $res, $row, $usr_id, array, and getRelationByDatabaseRecord().

57  {
58  $relations = array();
59 
60  $res = $this->db->queryF(
61  "
62  SELECT usr_id, buddy_usr_id, ts, %s rel_type FROM buddylist WHERE usr_id = %s
63  UNION
64  SELECT usr_id, buddy_usr_id, ts, (CASE WHEN ignored = 1 THEN %s ELSE %s END) rel_type FROM buddylist_requests WHERE usr_id = %s OR buddy_usr_id = %s
65  ",
66  array(
67  'text', 'integer', 'text', 'text', 'integer', 'integer'
68  ),
69  array(
70  self::TYPE_APPROVED, $this->usr_id, self::TYPE_IGNORED, self::TYPE_REQUESTED, $this->usr_id, $this->usr_id
71  )
72  );
73 
74  while($row = $this->db->fetchAssoc($res))
75  {
76  $relation = $this->getRelationByDatabaseRecord($row);
77  $relation->setUserId($row['usr_id']);
78  $relation->setBuddyUserId($row['buddy_usr_id']);
79  $relation->setTimestamp($row['ts']);
80  $relation->setIsOwnedByRequest($relation->getUserId() == $this->usr_id);
81  $key = $this->usr_id == $relation->getUserId() ? $relation->getBuddyUserId() : $relation->getUserId();
82  $relations[$key] = $relation;
83  }
84 
85  return $relations;
86  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getDatabaseAdapter()

ilBuddySystemRelationRepository::getDatabaseAdapter ( )

◆ getRelationByDatabaseRecord()

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

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

References $row.

Referenced by getAll().

93  {
94  if(self::TYPE_APPROVED == $row['rel_type'])
95  {
97  return $relation;
98  }
99  else
100  {
101  if(self::TYPE_IGNORED == $row['rel_type'])
102  {
104  return $relation;
105  }
106  else
107  {
109  return $relation;
110  }
111  }
112  }
Class ilBuddySystemRelation.
+ Here is the caller graph for this function:

◆ removeFromApprovedBuddies()

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

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

References array, ilBuddySystemRelation\getBuddyUserId(), and ilBuddySystemRelation\getUserId().

Referenced by save().

164  {
165  $this->db->manipulateF(
166  "DELETE FROM buddylist WHERE usr_id = %s AND buddy_usr_id = %s",
167  array('integer', 'integer'),
168  array($relation->getUserId(), $relation->getBuddyUserId())
169  );
170 
171  $this->db->manipulateF(
172  "DELETE FROM buddylist WHERE buddy_usr_id = %s AND usr_id = %s",
173  array('integer', 'integer'),
174  array($relation->getUserId(), $relation->getBuddyUserId())
175  );
176  }
Create styles array
The data for the language used.
+ 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 200 of file class.ilBuddySystemRelationRepository.php.

References array, ilBuddySystemRelation\getBuddyUserId(), and ilBuddySystemRelation\getUserId().

Referenced by save().

201  {
202  $this->db->manipulateF(
203  "DELETE FROM buddylist_requests WHERE usr_id = %s AND buddy_usr_id = %s",
204  array('integer', 'integer'),
205  array($relation->getUserId(), $relation->getBuddyUserId())
206  );
207 
208  $this->db->manipulateF(
209  "DELETE FROM buddylist_requests WHERE buddy_usr_id = %s AND usr_id = %s",
210  array('integer', 'integer'),
211  array($relation->getUserId(), $relation->getBuddyUserId())
212  );
213  }
Create styles array
The data for the language used.
+ 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 218 of file class.ilBuddySystemRelationRepository.php.

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

219  {
220  $ilAtomQuery = $this->db->buildAtomQuery();
221  $ilAtomQuery->addTableLock('buddylist_requests');
222  $ilAtomQuery->addTableLock('buddylist');
223 
224  $ilAtomQuery->addQueryCallable(function(ilDBInterface $ilDB) use ($relation) {
225  if($relation->isLinked())
226  {
227  $this->addToApprovedBuddies($relation);
228  }
229  else if($relation->wasLinked())
230  {
231  $this->removeFromApprovedBuddies($relation);
232  }
233 
234  if($relation->isRequested())
235  {
236  $this->addToRequestedBuddies($relation, false);
237  }
238  else if($relation->isIgnored())
239  {
240  $this->addToRequestedBuddies($relation, true);
241  }
242  else if($relation->wasRequested() || $relation->wasIgnored())
243  {
244  $this->removeFromRequestedBuddies($relation);
245  }
246  });
247 
248  $ilAtomQuery->run();
249  }
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:

◆ setDatabaseAdapter()

ilBuddySystemRelationRepository::setDatabaseAdapter ( ilDBInterface  $db)
Parameters
ilDBInterface$db

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

References $db.

Field Documentation

◆ $db

ilBuddySystemRelationRepository::$db
protected

◆ $usr_id

int ilBuddySystemRelationRepository::$usr_id
protected

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

Referenced by __construct(), and getAll().

◆ TYPE_APPROVED

const ilBuddySystemRelationRepository::TYPE_APPROVED = 'app'

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

◆ TYPE_IGNORED

const ilBuddySystemRelationRepository::TYPE_IGNORED = 'ign'

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

◆ TYPE_REQUESTED

const ilBuddySystemRelationRepository::TYPE_REQUESTED = 'req'

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


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