ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
Definition: saml.php:7

Member Function Documentation

◆ addToApprovedBuddies()

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

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

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

Referenced by save().

129  {
130  $this->db->replace(
131  'buddylist',
132  array(
133  'usr_id' => array('integer', $relation->getUserId()),
134  'buddy_usr_id' => array('integer', $relation->getBuddyUserId())
135  ),
136  array(
137  'ts' => array('integer', $relation->getTimestamp())
138  )
139  );
140 
141  $this->db->replace(
142  'buddylist',
143  array(
144  'usr_id' => array('integer', $relation->getBuddyUserId()),
145  'buddy_usr_id' => array('integer', $relation->getUserId())
146  ),
147  array(
148  'ts' => array('integer', $relation->getTimestamp())
149  )
150  );
151  }
+ 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 175 of file class.ilBuddySystemRelationRepository.php.

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

Referenced by save().

176  {
177  $this->db->replace(
178  'buddylist_requests',
179  array(
180  'usr_id' => array('integer', $relation->getUserId()),
181  'buddy_usr_id' => array('integer', $relation->getBuddyUserId())
182  ),
183  array(
184  'ts' => array('integer', $relation->getTimestamp()),
185  'ignored' => array('integer', (int) $ignored)
186  )
187  );
188  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

ilBuddySystemRelationRepository::destroy ( )

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

111  {
112  $this->db->queryF(
113  "DELETE FROM buddylist WHERE usr_id = %s OR buddy_usr_id = %s",
114  array('integer', 'integer'),
115  array($this->usr_id, $this->usr_id)
116  );
117 
118  $this->db->queryF(
119  "DELETE FROM buddylist_requests WHERE usr_id = %s OR buddy_usr_id = %s",
120  array('integer', 'integer'),
121  array($this->usr_id, $this->usr_id)
122  );
123  }

◆ getAll()

ilBuddySystemRelationRepository::getAll ( )

Reads all items from database.

Returns
ilBuddySystemRelation[]

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

References $key, $res, $row, $usr_id, 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  $relation = $this->getRelationByDatabaseRecord($row);
76  $relation->setUserId($row['usr_id']);
77  $relation->setBuddyUserId($row['buddy_usr_id']);
78  $relation->setTimestamp($row['ts']);
79  $relation->setIsOwnedByRequest($relation->getUserId() == $this->usr_id);
80  $key = $this->usr_id == $relation->getUserId() ? $relation->getBuddyUserId() : $relation->getUserId();
81  $relations[$key] = $relation;
82  }
83 
84  return $relations;
85  }
foreach($_POST as $key=> $value) $res
$row
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getDatabaseAdapter()

ilBuddySystemRelationRepository::getDatabaseAdapter ( )

◆ getRelationByDatabaseRecord()

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

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

References $row.

Referenced by getAll().

92  {
93  if (self::TYPE_APPROVED == $row['rel_type']) {
95  return $relation;
96  } else {
97  if (self::TYPE_IGNORED == $row['rel_type']) {
99  return $relation;
100  } else {
102  return $relation;
103  }
104  }
105  }
$row
Class ilBuddySystemRelation.
+ Here is the caller graph for this function:

◆ removeFromApprovedBuddies()

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

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

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

Referenced by save().

157  {
158  $this->db->manipulateF(
159  "DELETE FROM buddylist WHERE usr_id = %s AND buddy_usr_id = %s",
160  array('integer', 'integer'),
161  array($relation->getUserId(), $relation->getBuddyUserId())
162  );
163 
164  $this->db->manipulateF(
165  "DELETE FROM buddylist WHERE buddy_usr_id = %s AND usr_id = %s",
166  array('integer', 'integer'),
167  array($relation->getUserId(), $relation->getBuddyUserId())
168  );
169  }
+ 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 193 of file class.ilBuddySystemRelationRepository.php.

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

Referenced by save().

194  {
195  $this->db->manipulateF(
196  "DELETE FROM buddylist_requests WHERE usr_id = %s AND buddy_usr_id = %s",
197  array('integer', 'integer'),
198  array($relation->getUserId(), $relation->getBuddyUserId())
199  );
200 
201  $this->db->manipulateF(
202  "DELETE FROM buddylist_requests WHERE buddy_usr_id = %s AND usr_id = %s",
203  array('integer', 'integer'),
204  array($relation->getUserId(), $relation->getBuddyUserId())
205  );
206  }
+ 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 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().

212  {
213  $ilAtomQuery = $this->db->buildAtomQuery();
214  $ilAtomQuery->addTableLock('buddylist_requests');
215  $ilAtomQuery->addTableLock('buddylist');
216 
217  $ilAtomQuery->addQueryCallable(function (ilDBInterface $ilDB) use ($relation) {
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)
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: