Esempio n. 1
0
 public function action_war()
 {
     $war_id = $this->request->param('id', 0);
     $post = $this->request->post();
     $War = new Model_War();
     if ($post) {
         if ($war_id) {
             $War->edit($war_id, $post);
         } else {
             $post['endTime'] = now();
             $war_id = $War->add($post);
         }
         HTTP::redirect('panel/war/' . $war_id);
     }
     if ($war_id) {
         $war_entry = $War->find($war_id);
     } else {
         $war_entry = array();
     }
     $view = View::factory('panel/war_edit');
     $view->bind('war_id', $war_id)->bind('war_entry', $war_entry);
     $this->template->content = $view;
 }
Esempio n. 2
0
File: Api.php Progetto: korejwo/coc
 public function action_warclans()
 {
     //		Log::instance()->add(Log::ERROR, 'cron: war');
     $War = new Model_War();
     $wars = $War->get_wars_by_opponent_tag();
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_URL, 'https://api.clashofclans.com/v1/clans/%238PJ2CYU8/warlog');
     curl_setopt($curl, CURLOPT_HTTPHEADER, $this->config['auth']);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     $results = json_decode(curl_exec($curl), true);
     curl_close($curl);
     //		vd($results, 1);
     if (!isset($results['items'])) {
         die('API error');
     }
     $items = array_reverse($results['items']);
     //		vd($items);
     foreach ($items as $item) {
         $params = array("result" => $item['result'] == "win" ? 1 : 0, "teamSize" => $item['teamSize'], "attacks" => $item['clan']['attacks'], "stars" => $item['clan']['stars'], "destructionPercentage" => $item['clan']['destructionPercentage'], "expEarned" => $item['clan']['expEarned'], "opponent_tag" => $item['opponent']['tag'], "opponent_name" => $item['opponent']['name'], "opponent_stars" => $item['opponent']['stars'], "opponent_destructionPercentage" => $item['opponent']['destructionPercentage']);
         if (isset($wars[$item['opponent']['tag']])) {
             if ($wars[$item['opponent']['tag']]['result'] == null) {
                 $date = DateTime::createFromFormat("Ymd\\THis.u\\Z", $item['endTime']);
                 $date->modify('+2 hours');
                 $params['endTime'] = $date->format('Y-m-d H:i:s');
                 $War->edit($wars[$item['opponent']['tag']]['id'], $params);
             }
         } else {
             $date = DateTime::createFromFormat("Ymd\\THis.u\\Z", $item['endTime']);
             $date->modify('+2 hours');
             $params['endTime'] = $date->format('Y-m-d H:i:s');
             $War->add($params);
         }
     }
     exit;
 }