12 const TABLE_NAME =
"AppId";
17 public $DateCreated =
"";
19 public $Description =
"";
26 public function __construct($src = null, $stripSlashes =
false) {
33 $this->_loadByRow($src, $stripSlashes);
34 }
else if (is_numeric($src)) {
36 $this->_loadFilter(self::GetTableName(__CLASS__), sprintf(
"Id = %d", $src));
39 $this->_loadFilter(self::GetTableName(__CLASS__), sprintf(
"AppId = '%s'", $Database->Escape($src)));
50 $sql =
"SELECT Id FROM " . self::GetTableName(__CLASS__) .
" WHERE Name = '" . $Database->Escape($this->Name) .
"'";
52 $sql .=
" AND Id <> " . $this->Id .
"'";
54 $res = $Database->Query($sql);
56 $row = $Database->FetchAssoc($res);
65 return ($this->Active == 1);
69 return ($this->Id > 0 && strlen($this->
AppId) > 0 && strcasecmp($this->
AppId,
"new") != 0);
79 public static function GetApp($appId, $appSecret) {
81 if (!empty($appId) && !empty($appSecret)) {
82 $apps = DataClass::LoadRecords(sprintf(
"SELECT * FROM %s WHERE AppId = '%s'", self::GetTableName(__CLASS__), $Database->Escape($appId)), __CLASS__);
83 if (count($apps) > 0) {
85 if ($app->IsActive() && \strcmp($app->AppId, $appId) === 0 && \strcmp($app->Secret, $appSecret) === 0) {
102 public static function Load ($limit = null, $offset = null, &$count = null, $returnArray =
false) {
103 return self::_load(self::GetTableName(__CLASS__), ($returnArray ?
"" : __CLASS__), NULL,
"DateCreated DESC", $limit, $offset, $count);
114 $query = sprintf(
"UPDATE %s SET Active = %d, Name = '%s', Description = '%s' WHERE Id = %d",
115 self::GetTableName(__CLASS__),
117 $Database->Escape($this->Name),
118 $Database->Escape($this->Description),
122 $this->
AppId = Utils::NewGUID();
123 $this->Secret = Utils::NewGUID();
124 $this->DateCreated = Utils::GetCurrentDateTimeFormat();
125 $query = sprintf(
"INSERT INTO %s (Active, DateCreated, AppId, Secret, Name, Description) VALUES (%d, %s, '%s', '%s', '%s', '%s')",
126 self::GetTableName(__CLASS__),
128 $Database->EscapeDate($this->DateCreated),
129 $Database->Escape($this->
AppId),
130 $Database->Escape($this->Secret),
131 $Database->Escape($this->Name),
132 $Database->Escape($this->Description));
134 if ($Database->Query($query)) {
135 if ($this->Id <= 0) {
136 $this->Id = $Database->InsertedId();
149 if ($this->Id > 0 && $this->_Delete(self::GetTableName(__CLASS__), sprintf(
"Id = %d", $this->Id))) {
151 $this->_Delete(self::GetTableName(Account_App::class), sprintf(
"IdApp = %d", $this->Id));
152 $this->_Delete(self::GetTableName(News::class), sprintf(
"IdApp = %d", $this->Id));
153 $this->_Delete(self::GetTableName(AppCustomData::class), sprintf(
"IdApp = %d", $this->Id));
154 $this->_Delete(self::GetTableName(Inventory::class), sprintf(
"IdApp = %d", $this->Id));
155 $this->_Delete(self::GetTableName(SessionToken::class), sprintf(
"IdApp = %d", $this->Id));
156 $this->_Delete(self::GetTableName(IpBan::class), sprintf(
"IdApp = %d", $this->Id));
158 $achievements = Achievement::Load($this->Id);
159 foreach ($achievements as $achievement) {
160 if ($achievement->IdApp == $this->Id) {
161 $achievement->Delete();
165 $leaderboards = LeaderBoard::Load($this->Id);
166 foreach ($leaderboards as $leaderboard) {
167 if ($leaderboard->IdApp == $this->Id) {
168 $leaderboard->Delete();
172 $newsletters = Newsletter::Load($this->Id);
173 foreach ($newsletters as $newsletter) {
174 if ($newsletter->IdApp == $this->Id) {
175 $newsletter->Delete();
static Load($limit=null, $offset=null, &$count=null, $returnArray=false)
static GetApp($appId, $appSecret)
__construct($src=null, $stripSlashes=false)