/** * User leave table * * @param int $user_id * @param int $table_id * @param int $day( NORMAL DAY OR VEGAN DAY) * @return int */ function user_leave_table($user_id, $table_id, $day = NULL) { $result = LEAVE_TABLE_FAILED; if ($this->is_user_belongs_to_table($user_id, $table_id, $day)) { $this->load->model('users_model'); $is_vegan_table = $this->is_vegan_table($table_id); $is_user_want_vegan_meal = Users_model::is_user_want_vegan_meal($user_id); $res = $is_vegan_table ? $this->check_status_of_user_in_table($user_id, VEGAN_DAY) : $this->check_status_of_user_in_table($user_id, NORMAL_DAY); if ($is_user_want_vegan_meal && $is_vegan_table) { $result = $this->delete_user_in_table($user_id, $table_id, VEGAN_DAY) ? LEAVE_TABLE_SUCCESSFULLY : LEAVE_TABLE_FAILED; } else { if ($is_user_want_vegan_meal && !$is_vegan_table) { $result = $this->delete_user_in_table($user_id, $table_id, NORMAL_DAY) ? LEAVE_TABLE_SUCCESSFULLY : LEAVE_TABLE_FAILED; } else { if (!$is_user_want_vegan_meal && !$is_vegan_table) { $result = $this->delete_user_in_table($user_id, $table_id, NULL) ? LEAVE_TABLE_SUCCESSFULLY : LEAVE_TABLE_FAILED; } else { $result = LEAVE_TABLE_FAILED; } } } } else { $result = NO_SEAT_IN_TABLE; } return $result; }