Inheritance: extends CI_Model
Exemplo 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);
 }
Exemplo n.º 2
0
 function get_tables_from_shift()
 {
     $this->common->authenticate();
     $shift_id = $this->input->post('shift_id');
     $day = $this->input->post('day');
     $for_vegans = $day == NORMAL_DAY ? 0 : NULL;
     $this->load->model('tables_model');
     $this->load->model('shifts_model');
     $tables = Tables_model::get_tables_by_shift($shift_id, $for_vegans, $day);
     $data['tables'] = $tables;
     $data['shift'] = Shifts_model::get_shift_by_id($shift_id);
     echo json_encode($data);
 }
 /**
  * Get announcements for user
  *
  * @param       int  $user_id
  * @param       date(Y-m-d)  $start_time
  * @param       date(Y-m-d)  $end_time
  * @return      array
  */
 function get_announcements_for_user($user_id, $start_time, $end_time)
 {
     $messages = array();
     $this->load->model('users_model');
     $user = Users_model::get_user_by('id', $user_id);
     // Get all messages from admin
     $result = $this->get_announcements(NULL, NULL, $start_time, $end_time);
     if ($result != NULL) {
         foreach ($result as $message) {
             if ($message->user == 'all') {
                 $messages = $this->add_a_annoucement_in_announcements($user, $messages, $message);
             } elseif ($message->user == $user_id) {
                 $messages = $this->add_a_annoucement_in_announcements($user, $messages, $message);
             } else {
                 $this->load->model('tables_model');
                 // Get shift and table of user
                 $shift_and_tables = Tables_model::get_shift_and_tables_of_user($user_id);
                 if ($shift_and_tables != NULL) {
                     $shift_id = $shift_and_tables[0]->shift_id;
                     if (!is_null($message->shift)) {
                         if ($message->shift == $shift_id) {
                             $messages = $this->add_a_annoucement_in_announcements($user, $messages, $message);
                         }
                     } elseif (!is_null($message->table)) {
                         foreach ($shift_and_tables as $table) {
                             if ($message->table == $table->table_id) {
                                 $messages = $this->add_a_annoucement_in_announcements($user, $messages, $message);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $messages;
 }
Exemplo n.º 4
0
 public function store_or_edit_table($request, $table_id = NULL)
 {
     $table = array('name' => $this->input->post('table'), 'description' => $this->input->post('description'), 'seats' => $this->input->post('seats'), 'shift_id' => $this->input->post('shift'), 'for_vegans' => !empty($this->input->post('for_vegans')) ? 1 : 0);
     if ($request == 'add') {
         return Tables_model::insert_table($table);
     } else {
         return $this->tables_model->update_table($table_id, $table);
     }
 }
 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;
     }
 }