12 const TABLE_NAME =
"Account_Platform";
14 public $IdAccount = 0;
15 public $PlatformKey =
"";
16 public $PlatformId =
"";
21 public function __construct($src = null, $stripSlashes =
false) {
26 $this->_loadByRow($src, $stripSlashes);
36 public static function Load($idAccount) {
38 $where = sprintf(
"IdAccount = %d", $idAccount);
39 return self::_load(self::GetTableName(__CLASS__), __CLASS__, $where);
42 public static function LoadAccount ($platformKey, $platformId, &$accountPlatform = NULL) {
45 $accountPlatform = NULL;
46 $query = sprintf(
"SELECT IdAccount FROM %s WHERE PlatformKey = '%s' AND PlatformId = '%s'",
47 self::GetTableName(__CLASS__),
48 $Database->Escape($platformKey),
49 $Database->Escape($platformId));
50 $rows = self::LoadRecords($query, __CLASS__);
51 if (count($rows) > 0) {
52 $accountPlatform = $rows[0];
54 $account =
new Account($accountPlatform->IdAccount);
55 if ($account->Id < 1) {
72 public static function LoadOrCreateAccount ($platformKey, $platformId, &$accountPlatform = NULL, &$justCreated = FALSE) {
75 $accountPlatform = NULL;
76 $account = self::LoadAccount($platformKey, $platformId, $accountPlatform);
77 if ($account == NULL) {
78 if ($accountPlatform) {
80 $accountPlatform->Delete();
81 $accountPlatform = NULL;
85 $account->Username = $platformKey .
"_" . $platformId;
86 $account->Enabled = 1;
87 if ($account->Save()) {
89 $accountPlatform->PlatformKey = $platformKey;
90 $accountPlatform->PlatformId = $platformId;
91 $accountPlatform->IdAccount = $account->Id;
92 if ($accountPlatform->Save()) {
95 $accountPlatform = NULL;
116 if ($this->IdAccount < 1 || !$this->PlatformKey || !$this->PlatformId) {
119 $query = sprintf(
"REPLACE INTO %s (IdAccount, PlatformKey, PlatformId) VALUES (%d, '%s', '%s')",
120 self::GetTableName(__CLASS__),
122 $Database->Escape($this->PlatformKey),
123 $Database->Escape($this->PlatformId));
124 return $Database->Query($query);
134 $where = sprintf(
"IdAccount = %d AND PlatformKey = '%s' AND PlatformId = '%s'",
136 $Database->Escape($this->PlatformKey),
137 $Database->Escape($this->PlatformId));
138 return $this->_Delete(self::GetTableName(__CLASS__), $where);