Exemplo n.º 1
0
 public function get_weathers()
 {
     if (!$this->is_ajax(false)) {
         return show_error("It's not Ajax request!<br/>Please confirm your program again.");
     }
     $north_east = $this->input_post('NorthEast');
     $south_west = $this->input_post('SouthWest');
     if (!(isset($north_east['latitude']) && isset($south_west['latitude']) && isset($north_east['longitude']) && isset($south_west['longitude']))) {
         return $this->output_json(array('status' => true, 'weathers' => array()));
     }
     $weathers = array_map(function ($weather) {
         return array('id' => $weather->id, 'lat' => $weather->latitude, 'lng' => $weather->longitude, 'title' => $weather->title);
     }, Weather::find('all', array('limit' => 50, 'conditions' => array('latitude < ? AND latitude > ? AND longitude < ? AND longitude > ?', $north_east['latitude'], $south_west['latitude'], $north_east['longitude'], $south_west['longitude']))));
     return $this->output_json(array('status' => true, 'weathers' => $weathers));
 }
Exemplo n.º 2
0
 public function index($offset = 0)
 {
     $columns = array('title' => 'string', 'latitude' => 'string', 'longitude' => 'string', 'temperature' => 'string');
     $configs = array('admin', 'weathers', '%s');
     $conditions = conditions($columns, $configs, 'Weather', $this->input_gets());
     $conditions = array(implode(' AND ', $conditions));
     $limit = 25;
     $total = Weather::count(array('conditions' => $conditions));
     $offset = $offset < $total ? $offset : 0;
     $this->load->library('pagination');
     $configs = array_merge(array('total_rows' => $total, 'num_links' => 5, 'per_page' => $limit, 'uri_segment' => 0, 'base_url' => '', 'page_query_string' => false, 'first_link' => '第一頁', 'last_link' => '最後頁', 'prev_link' => '上一頁', 'next_link' => '下一頁', 'full_tag_open' => '<ul class="pagination">', 'full_tag_close' => '</ul>', 'first_tag_open' => '<li>', 'first_tag_close' => '</li>', 'prev_tag_open' => '<li>', 'prev_tag_close' => '</li>', 'num_tag_open' => '<li>', 'num_tag_close' => '</li>', 'cur_tag_open' => '<li class="active"><a href="#">', 'cur_tag_close' => '</a></li>', 'next_tag_open' => '<li>', 'next_tag_close' => '</li>', 'last_tag_open' => '<li>', 'last_tag_close' => '</li>'), $configs);
     $this->pagination->initialize($configs);
     $pagination = $this->pagination->create_links();
     $weathers = Weather::find('all', array('offset' => $offset, 'limit' => $limit, 'order' => 'id DESC', 'include' => array('log'), 'conditions' => $conditions));
     $message = identity()->get_session('_flash_message', true);
     $this->add_js(base_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'jquery.timeago.js'))->add_js(base_url('resource', 'javascript', 'jquery-timeago_v1.3.1', 'locales', 'jquery.timeago.zh-TW.js'))->load_view(array('message' => $message, 'pagination' => $pagination, 'weathers' => $weathers, 'columns' => $columns));
 }