/** * @param string $result * * @return bool */ public function doUpdate($result) { $return = true; $xml = $this->createXmlObject($result); $characters = $xml->result->rowset->row; foreach ($characters as $character) { $data = self::getXmlAttr($character); $character = Character::findOne(['apiID' => $this->apiID, 'characterID' => $data['characterID']]); if (!$character) { $character = new Character(); $character->apiID = $this->apiID; } $character->timeUpdated = time(); $character->characterID = $data['characterID']; $character->characterName = $data['name']; $character->corporationID = $data['corporationID']; $character->corporationName = $data['corporationName']; $character->allianceID = $data['allianceID'] ? $data['allianceID'] : null; $character->allianceName = $data['allianceName'] ? $data['allianceName'] : null; $character->factionID = $data['factionID'] ? $data['factionID'] : null; $character->factionName = $data['factionName'] ? $data['factionName'] : null; $return = $character->save() && $return; } return $return; }
/** * @param int $id * * @return Character * @throws NotFoundHttpException */ public function loadCharacter($id) { /** @var Character $character */ $model = Character::find()->joinWith('api')->where(['api_account_characters.characterID' => $id, 'api.userID' => \Yii::$app->user->id])->one(); if (!$model) { throw new NotFoundHttpException('Such character does not exist.'); } return $model; }
/** * @return \yii\db\ActiveQuery */ public function getCharacters() { return $this->hasMany(Character::className(), ['apiID' => 'id']); }
/** * @return string */ public function actionList() { $this->getView()->addBread('List'); $characters = Character::find()->joinWith('api')->where(['api.userID' => \Yii::$app->user->id])->all(); return $this->render('list', ['characters' => $characters]); }