12 const TABLE_NAME =
"UserGroup";
18 public $CustomData =
"";
23 public function __construct($src = null, $stripSlashes =
false) {
29 $this->_loadByRow($src, $stripSlashes);
30 }
else if (is_numeric($src) && intval($src) > 0) {
32 $this->_loadFilter(self::GetTableName(__CLASS__),
"Id = " . intval($src));
43 $sql =
"IdOwner = " . $this->IdOwner .
" AND Name = '" . $Database->Escape($this->Name) .
"'";
45 $sql .=
" AND Id <> " . $this->Id;
46 $recs = self::_load(self::GetTableName(__CLASS__),
"", $sql);
63 public static function Load ($name = NULL, $idOwner = 0, $idAccount = 0, $limit = null, $offset = null, &$count = null, $returnArray =
false) {
65 $where =
"(Public = 1)";
67 $where .= ($where ?
" AND " :
"") . sprintf(
"(Name REGEXP '%s')", $Database->Escape($name));
68 if ($idOwner > 0 && $idOwner == $idAccount) {
69 $where .= ($where ?
" AND " :
"") .
"(" .
70 sprintf(
"(IdOwner = %d)", $idOwner) .
71 " OR " . sprintf(
"(Id IN (SELECT IdGroup FROM %s WHERE IdAccount = %d))", self::GetTableName(UserGroupAccount::class), $idAccount) .
75 $where .= ($where ?
" AND " :
"") . sprintf(
"(IdOwner = %d)", $idOwner);
77 $where .= ($where ?
" AND " :
"") . sprintf(
"(Id IN (SELECT IdGroup FROM %s WHERE IdAccount = %d))", self::GetTableName(UserGroupAccount::class), $idAccount);
79 return self::_load(self::GetTableName(__CLASS__), ($returnArray ?
"" : __CLASS__), $where,
"Name", $limit, $offset, $count);
90 $query = sprintf(
"UPDATE %s SET Name = '%s', IdOwner = %d, CustomData = '%s' WHERE Id = %d",
91 self::GetTableName(__CLASS__),
92 $Database->Escape($this->Name),
97 $query = sprintf(
"INSERT INTO %s (Name, IdOwner, Public, CustomData) VALUES ('%s', %d, %d, '%s')",
98 self::GetTableName(__CLASS__),
99 $Database->Escape($this->Name),
104 if ($Database->Query($query)) {
106 $this->Id = $Database->InsertedId();
120 if ($this->_Delete(self::GetTableName(__CLASS__),
"Id = " . $this->Id)) {
122 $this->_Delete(self::GetTableName(UserGroupAccount::class),
"IdGroup = " . $this->Id);
124 $this->_Delete(self::GetTableName(GameMail::class),
"IdGroup = " . $this->Id);
137 $members = UserGroupAccount::Load($this->Id);
148 $recs = $this->GetMembers();
149 foreach ($recs as $member) {
150 $user =
new Account($member->IdAccount);
162 $array = Utils::ObjectToArray($this);
163 $array[
"Owner"] =
new Account($this->IdOwner);
164 $array[
"Owner"] = $array[
"Owner"]->ToJson();
165 $array[
"Users"] = array();
166 $members = $this->GetMembersAccount();
167 foreach ($members as $user) {
168 $array[
"Users"][] = $user->ToArray();
__construct($src=null, $stripSlashes=false)
static Load($name=NULL, $idOwner=0, $idAccount=0, $limit=null, $offset=null, &$count=null, $returnArray=false)