Beispiel #1
0
 /**
  * 获取活动列表
  */
 public function index()
 {
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $filter = $this->input->get('filter', 'all');
     $filter = explode(',', $filter);
     $end = (int) $this->input->get('end', 1);
     $city = (int) $this->input->get('city', 0);
     $sort = $this->input->get('sort', 'time');
     $pagesize = (int) $this->input->get('pagesize', 10);
     $page = (int) $this->input->get('page', 1);
     $start = abs($pagesize * ($page - 1));
     $type_array = Kohana::config('event.request_type');
     $sort_array = Kohana::config('event.sort');
     $result = array('total' => 0, 'data' => array());
     $apply_type = array();
     $private = 1;
     if (!array_key_exists($sort, $sort_array)) {
         $this->send_response(400, NULL, '400506:活动排序类型非法');
     }
     $sort = $sort_array[$sort];
     if (in_array('all', $filter)) {
         $private = 0;
     }
     if ($this->user_id > 0) {
         foreach ($filter as $type) {
             if (!in_array($type, $type_array)) {
                 $this->send_response(400, NULL, '400504:请求的活动类型非法');
             }
             switch ($type) {
                 case 'all':
                     $apply_type = '';
                     break;
                 case 'me_launch':
                     //我发起的活动
                     $apply_type[] = -1;
                     break;
                 case 'me_joined':
                     //我参加的活动
                     $apply_type[] = Kohana::config('event.apply_type.joined');
                     break;
                 case 'me_interested':
                     //我感兴趣的活动
                     $apply_type[] = Kohana::config('event.apply_type.interested');
                     break;
                 case 'me_not_join':
                 case 'me_refuse':
                     //我不参加的活动
                     $apply_type[] = Kohana::config('event.apply_type.refused');
                     break;
                 default:
                     break;
             }
         }
     }
     $count = $this->model->getEventNum($this->user_id, $apply_type, $end, $city, $private);
     $data = $this->model->getEventList($this->user_id, $apply_type, $end, $city, $start, $pagesize, $sort, $private);
     $event_list = $this->_arrange_event_list($data);
     $result['total'] = $count;
     $result['data'] = $event_list;
     $this->send_response(200, $result);
 }