Ejemplo n.º 1
0
 /**
  * Listing all tables of shift
  * url: http://localhost/shift/<number_of_shift>/tables?[for_vegans=]
  * Method: GET
  * @param       int  $shift_id
  * @param       int  $for_vegans
  * @return      json
  */
 function tables_of_shift_get($shift_id)
 {
     $this->authenticate();
     $messages_lang = $this->common->set_language_for_server_api('tables_api', array('get_tables_of_shift_success', 'get_tables_of_shift_failure', 'variables_not_valid'));
     $for_vegans = NULL;
     $day = NULL;
     if (NULL != $this->input->get('for_vegans')) {
         $for_vegans = strtolower($this->input->get('for_vegans'));
     }
     if ($for_vegans == 'true') {
         $day = $for_vegans = VEGAN_DAY;
     } else {
         if ($for_vegans == 'false') {
             $day = $for_vegans = NORMAL_DAY;
         }
     }
     $result = Tables_model::get_tables_by_shift($shift_id, $for_vegans, $day);
     $tables = array();
     $response = array();
     if ($result != NULL) {
         foreach ($result as $key => $temp) {
             $table = array();
             $table['id'] = (int) $temp->id;
             $table['name'] = $temp->name;
             $table['for_vegans'] = (bool) $temp->for_vegans;
             $table['description'] = $temp->description;
             $table['seats'] = (int) $temp->seats;
             $table['available_seats'] = (int) $temp->seats - (int) $temp->occupied_seats;
             $table['shift_id'] = (int) $temp->shift_id;
             $table['shift'] = $temp->shift;
             $table['start_time'] = $temp->start_time;
             $table['end_time'] = $temp->end_time;
             $users = array();
             $result = Tables_model::get_users_in_table($temp->id, $day);
             if ($result != NULL) {
                 foreach ($result as $key => $temp) {
                     $user = array();
                     $user['id'] = (int) $temp->id;
                     $user['email'] = $temp->email;
                     $user['first_name'] = $temp->first_name;
                     $user['last_name'] = $temp->last_name;
                     $user['want_vegan_meal'] = (bool) $temp->want_vegan_meal;
                     $user['avatar_content_file'] = $temp->avatar_content_file;
                     array_push($users, $user);
                 }
                 $table['users'] = $users;
             }
             array_push($tables, $table);
         }
         $response['status'] = $messages_lang['success'];
         $response['message'] = $messages_lang['get_tables_of_shift_success'];
         $response['data'] = $tables;
     } else {
         $response['status'] = $messages_lang['failure'];
         $response['message'] = $messages_lang['get_tables_of_shift_failure'];
     }
     $this->response($response, 200);
 }
Ejemplo n.º 2
0
 public function list_users_from_table($table_id)
 {
     $this->common->authenticate();
     $day = $this->input->get('day');
     echo json_encode(Tables_model::get_users_in_table($table_id, $day));
 }
 public function store_announcement()
 {
     $this->load->model('users_model');
     $data['user_id'] = (int) $this->session->userdata('logged_in')['user_id'];
     $data['title'] = $this->input->post('subject');
     $data['content'] = $this->input->post('content');
     $data['meal_date'] = $this->input->post('lunch_date');
     $announcement_for = $this->input->post('announcement_for');
     $users = array();
     switch ($announcement_for) {
         case ANNOUNCEMENT_USER:
             $data['user'] = $this->input->post('user');
             $users[] = Users_model::get_user_by('id', $data['user']);
             break;
         case ANNOUNCEMENT_TABLE:
             $data['table'] = $this->input->post('table');
             $this->load->model('tables_model');
             $users = Tables_model::get_users_in_table($data['table']);
             break;
         case ANNOUNCEMENT_SHIFT:
             $data['shift'] = $this->input->post('shift');
             $this->load->model('shifts_model');
             $users = Shifts_model::get_users_by_shift($data['shift']);
             break;
         default:
             $data['user'] = '******';
             $users = Users_model::get_all_users();
             break;
     }
     list($result, $announcement_id) = Announcements_model::insert_announcement($data);
     if ($result) {
         $registation_ids = array();
         if ($users != NULL) {
             foreach ($users as $user) {
                 if ($user->gcm_regid != NULL) {
                     $registation_ids[] = $user->gcm_regid;
                 }
             }
         }
         $user = array();
         $user['avatar_content_file'] = $this->session->userdata('logged_in')['avatar_content_file'];
         $user['email'] = $this->session->userdata('logged_in')['email'];
         $user['id'] = (int) $this->session->userdata('logged_in')['user_id'];
         if ($registation_ids != NULL) {
             $send_notification['data'] = array('type' => 'announcement', 'announcement' => array('id' => (int) $announcement_id, 'title' => $data['title'], 'content' => $data['content'], 'meal_date' => $data['meal_date'], 'read_flag' => FALSE, 'number_of_replies' => 0, 'number_of_have_read_replies' => 0, 'created_at' => date('Y-m-d H:i:s'), 'email' => $user['email'], 'avatar_content_file' => $user['avatar_content_file'], 'user_id' => $user['id']));
             $this->common->send_notification($registation_ids, $send_notification);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }