コード例 #1
0
ファイル: WotMap.php プロジェクト: joelsantosjunior/wotdb
 /**
  * @return WotMap the static model class
  */
 public static function getByName($mapName)
 {
     $model = self::model()->findByAttributes(array('map_name' => $mapName));
     if (empty($model)) {
         $model = new WotMap();
         $model->map_name = $mapName;
         $model->save(false);
     }
     return $model;
 }
コード例 #2
0
ファイル: WotService.php プロジェクト: joelsantosjunior/wotdb
 /**
  * 
  * @param WotClan $clan
  */
 public static function updateClanProvinces($clan)
 {
     $clanId = $clan->clan_id . '-' . $clan->clan_name;
     $data = self::ajaxRequest("http://worldoftanks.ru/community/clans/{$clanId}/provinces/list/");
     $currentProvinces = array();
     if (!empty($data)) {
         if ($data['status'] == 'ok') {
             foreach ($data['request_data']['items'] as $item) {
                 $province = WotProvince::getByAttributes($item['name'], $item['id']);
                 $map = WotMap::getByName($item['arena_name']);
                 $currentProvinces[$item['name']] = $item['id'];
                 $clanProvince = WotClanProvince::model()->findByAttributes(array('province_id' => $province->province_id, 'clan_id' => $clan->clan_id, 'date_end' => null));
                 if (empty($clanProvince)) {
                     $clanProvince = new WotClanProvince();
                     $clanProvince->clan_id = $clan->clan_id;
                     $clanProvince->province_id = $province->province_id;
                     $clanProvince->prime_time = $item['prime_time'];
                     $clanProvince->map_id = $map->map_id;
                     $clanProvince->revenue = $item['revenue'];
                     $clanProvince->type = $item['type'];
                     $days = intval($item['occupancy_time']);
                     if ($days > 0) {
                         $clanProvince->date_start = new CDbExpression("date_add(curdate(), interval -{$days} DAY)");
                     } else {
                         $clanProvince->date_start = new CDbExpression('curdate()');
                     }
                     $clanProvince->save(false);
                 }
             }
             foreach ($clan->clanProvinces as $clanProvince) {
                 if (!isset($currentProvinces[$clanProvince->province->province_name])) {
                     $clanProvince->date_end = new CDbExpression('now()');
                     $clanProvince->save(false);
                 }
             }
         }
     }
 }