Ejemplo n.º 1
0
 /**
  * 
  * @param WotClan $clan
  */
 public static function updateClanInfo($clan)
 {
     $url = strtr(self::$wotApiClanUrl, array('{applicationId}' => self::getApplicationId(), '{clanId}' => $clan->clan_id));
     $jsonString = self::getContent($url);
     if ($jsonString != false) {
         $jsonData = json_decode($jsonString, true);
         if ($jsonData['status'] == 'ok') {
             if (isset($jsonData['data'][$clan->clan_id])) {
                 $data = $jsonData['data'][$clan->clan_id];
                 $clan->clan_descr = $data['description'];
                 $clan->updated_at = date('Y-m-d H:i', $data['updated_at']);
                 $clan->clan_name = $data['abbreviation'];
                 $clan->clan_fullname = $data['name'];
                 $clan->clan_descr_html = $data['description_html'];
                 $clan->clan_created = date('Y-m-d', $data['created_at']);
                 $clan->clan_ico = $data['emblems']['large'];
                 $clan->clan_motto = $data['motto'];
                 $clan->clan_owner_id = $data['owner_id'];
                 $clan->save(false);
                 $members = $data['members'];
                 //	foreach ($data['members'] as $member) {
                 //		$members[$member['account_id']]=$member;
                 //	}
             }
             $tran = Yii::app()->db->beginTransaction();
             $clanPlayers = $clan->playersRec;
             foreach ($clanPlayers as $playerId => $clanPlayerRec) {
                 if (!isset($members[$playerId])) {
                     $clanPlayerRec->escape_date = new CDbExpression('now()');
                     $clanPlayerRec->save(false);
                     continue;
                 }
                 if ($clanPlayerRec->clan_role_id != $members[$playerId]['role']) {
                     $clanPlayerRec->clan_role_id = WotClanRole::getRoleId($members[$playerId]['role'], $members[$playerId]['role_i18n']);
                     $clanPlayerRec->save(false);
                 }
             }
             foreach ($members as $playerId => $playerData) {
                 if (!isset($clanPlayers[$playerId])) {
                     $player = WotPlayer::model()->findByPk($playerId);
                     if (empty($player)) {
                         $player = new WotPlayer();
                         $player->player_id = $playerId;
                         $player->player_name = $playerData['account_name'];
                         $player->save(false);
                     }
                     $playerClan = WotPlayerClan::model()->findByPk(array('player_id' => $playerId, 'clan_id' => $clan->clan_id, 'entry_date' => date('Y-m-d', $playerData['created_at'])));
                     if (empty($playerClan)) {
                         $playerClan = new WotPlayerClan();
                         $playerClan->clan_id = $clan->clan_id;
                         $playerClan->player_id = $playerId;
                         $playerClan->entry_date = date('Y-m-d', $playerData['created_at']);
                         $playerClan->clan_role_id = WotClanRole::getRoleId($playerData['role'], $playerData['role_i18n']);
                     } else {
                         if (!empty($playerClan->escape_date)) {
                             $playerClan->escape_date = null;
                         }
                     }
                     $playerClan->save(false);
                 }
             }
             $tran->commit();
         } else {
             Yii::log($jsonString, 'error');
         }
         //var_dump($jsonData);
     }
 }
Ejemplo n.º 2
0
 public static function isClanPlayer($playerId)
 {
     $player = WotPlayerClan::model()->findByAttributes(array('clan_id' => WotClan::currentClan()->clan_id, 'player_id' => $playerId), 'escape_date is null');
     return !empty($player);
 }