Combu Server  3.1.1
PHP API Documentation
Friend.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class Friend extends DataClass {
11 
12  const TABLE_NAME = "Friend";
13 
14  public $IdAccount = 0;
15  public $IdFriend = 0;
16  public $State = FRIEND_STATE_ACCEPTED;
17 
21  public function __construct($src = null, $stripSlashes = false) {
22  if (!empty($src)) {
23  if (is_array($src)) {
24  // Load by array
25  $this->_loadByRow($src, $stripSlashes);
26  }
27  }
28  }
29 
37  public static function Load ($idAccount, $state = NULL, $limit = null, $offset = null, &$count = null, $returnArray = false) {
38  if ($state === FRIEND_STATE_REQUEST_PENDING) {
39  $where = sprintf("(IdFriend = %d) AND (State = %d)", $idAccount, FRIEND_STATE_REQUEST);
40  } else {
41  $where = sprintf("(IdAccount = %d)", $idAccount);
42  if ($state !== NULL) {
43  $where .= sprintf(" AND (State = %d)", $state);
44  }
45  }
46  return self::_load(self::GetTableName(__CLASS__), ($returnArray ? "" : __CLASS__), $where, NULL, $limit, $offset, $count);
47  }
48 
54  public function Save() {
55  global $Database;
56  $query = sprintf("REPLACE INTO %s (IdAccount, IdFriend, State) VALUES (%d, %d, %d)",
57  self::GetTableName(__CLASS__),
58  $this->IdAccount,
59  $this->IdFriend,
60  $this->State);
61  return $Database->Query($query);
62  }
63 
69  public function Delete() {
70  if ($this->IdAccount < 1 || $this->IdFriend < 1)
71  return FALSE;
72  return $this->_Delete(self::GetTableName(__CLASS__), sprintf("IdAccount = %d AND IdFriend = %d", $this->IdAccount, $this->IdFriend));
73  }
74 
82  public static function DeleteBoth($idUser1, $idUser2) {
83  if ($idUser1 > 0 && $idUser2 > 0) {
84  $where = sprintf("(IdAccount = %d AND IdFriend = %d) OR (IdAccount = %d AND IdFriend = %d)", $idUser1, $idUser2, $idUser2, $idUser1);
85  $self = new self();
86  return $self->_Delete(self::GetTableName(__CLASS__), $where);
87  }
88  return FALSE;
89  }
90 }
static DeleteBoth($idUser1, $idUser2)
Definition: Friend.php:82
Definition: Account.php:3
static Load($idAccount, $state=NULL, $limit=null, $offset=null, &$count=null, $returnArray=false)
Definition: Friend.php:37
__construct($src=null, $stripSlashes=false)
Definition: Friend.php:21