Пример #1
0
 /**
  * update character data from CCPs CREST API
  * @return array (some status messages)
  */
 public function updateFromCrest()
 {
     $status = [];
     if ($accessToken = $this->getAccessToken()) {
         // et basic character data
         // -> this is required for "ownerHash" hash check (e.g. character was sold,..)
         // -> the "id" check is just for security and should NEVER fail!
         $ssoController = new Sso();
         if (!is_null($verificationCharacterData = $ssoController->verifyCharacterData($accessToken)) && $verificationCharacterData->CharacterID === $this->_id) {
             // get character data from CREST
             $characterData = $ssoController->getCharacterData($accessToken);
             if (isset($characterData->character)) {
                 $characterData->character['ownerHash'] = $verificationCharacterData->CharacterOwnerHash;
                 $corporation = null;
                 $alliance = null;
                 if (isset($characterData->corporation)) {
                     /**
                      * @var $corporation CorporationModel
                      */
                     $corporation = $this->rel('corporationId');
                     $corporation->getById($characterData->corporation['id'], 0);
                     $corporation->copyfrom($characterData->corporation, ['id', 'name', 'isNPC']);
                     $corporation->save();
                 }
                 if (isset($characterData->alliance)) {
                     /**
                      * @var $alliance AllianceModel
                      */
                     $alliance = $this->rel('allianceId');
                     $alliance->getById($characterData->alliance['id'], 0);
                     $alliance->copyfrom($characterData->alliance, ['id', 'name']);
                     $alliance->save();
                 }
                 $this->copyfrom($characterData->character, ['name', 'ownerHash']);
                 $this->set('corporationId', is_object($corporation) ? $corporation->get('id') : null);
                 $this->set('allianceId', is_object($alliance) ? $alliance->get('id') : null);
                 $this->save();
             }
         } else {
             $status[] = sprintf(Sso::ERROR_VERIFY_CHARACTER, $this->name);
         }
     } else {
         $status[] = sprintf(Sso::ERROR_ACCESS_TOKEN, $this->name);
     }
     return $status;
 }