Exemplo n.º 1
0
 public function post_reservation()
 {
     $code = 0;
     $message = "ok";
     if ($this->auth_status) {
         $unixtime = strtotime(Input::post("date", "0000-00-00") . " " . Input::post("hour", 0) . ":00:00");
         $reservation = Model_Lessontime::find("first", ["where" => [["teacher_id", $this->user->id], ["freetime_at", $unixtime], ["deleted_at", 0]]]);
         if ($reservation != null) {
             if ($reservation->status == 0) {
                 $reservation->deleted_at = time();
                 $reservation->save();
                 $code = 201;
                 $message = "deleted";
             } else {
                 $code = 202;
                 $message = "reserved";
             }
         } else {
             $reservation = Model_Lessontime::forge();
             $reservation->teacher_id = $this->user->id;
             $reservation->edoo_tutor = $this->user->google_account;
             $reservation->student_id = 0;
             $reservation->status = 0;
             $reservation->freetime_at = $unixtime;
             $reservation->save();
             $code = 200;
         }
     } else {
         $code = 500;
         $message = "Auth error.";
     }
     $this->response(array('code' => $code, 'message' => $message));
 }
Exemplo n.º 2
0
 public function action_index()
 {
     // add
     if (Input::post("teacher_id", null) != null and Security::check_token()) {
         // save
         $reservation = Model_Lessontime::forge();
         $reservation->teacher_id = Input::post("teacher_id", 0);
         $reservation->student_id = 0;
         $reservation->status = 0;
         $reservation->freetime_at = strtotime(Input::post("year", 0) . "-" . Input::post("month", 0) . "-" . Input::post("day", 0) . " " . Input::post("hour", 0) . ":" . Input::post("min", 0) . ":00");
         $reservation->save();
     }
     $where = [["deleted_at", 0]];
     if (Input::get("search_teacher", 0) != 0) {
         array_push($where, ["teacher_id" => Input::get("search_teacher", 0)]);
     }
     if (Input::get("year", 0) != 0 && Input::get("month", 0) != 0 && Input::get("day", 0) != 0) {
         $y = Input::get("year", 0);
         $m = Input::get("month", 0);
         $d = Input::get("day", 0);
         array_push($where, ["freetime_at", ">=", strtotime("{$y}-{$m}-{$d} 00:00:00")]);
         array_push($where, ["freetime_at", "<=", strtotime("{$y}-{$m}-{$d} 23:59:59")]);
     }
     $data["reservations"] = Model_Lessontime::find("all", ["where" => $where, "order_by" => [["id", "desc"]]]);
     $config = array('pagination_url' => "?search_teacher=" . Input::get("search_teacher", 0), 'uri_segment' => "p", 'num_links' => 9, 'per_page' => 20, 'total_items' => count($data["reservations"]));
     $data["pager"] = Pagination::forge('mypagination', $config);
     $data["reservations"] = array_slice($data["reservations"], $data["pager"]->offset, $data["pager"]->per_page);
     $data["teachers"] = Model_User::find("all", ["where" => [["group_id", 10], ["deleted_at", 0]], "order_by" => [["id", "desc"]]]);
     $view = View::forge("admin/reservations/index", $data);
     $this->template->content = $view;
 }
Exemplo n.º 3
0
 public function action_add()
 {
     // add
     if (Input::post("year", null) != null and Security::check_token()) {
         // save
         $reservation = Model_Lessontime::forge();
         $reservation->teacher_id = $this->user->id;
         $reservation->edoo_tutor = $this->user->google_account;
         $reservation->student_id = 0;
         $reservation->status = 0;
         $reservation->freetime_at = strtotime(Input::post("year", 0) . "-" . Input::post("month", 0) . "-" . Input::post("day", 0) . " " . Input::post("hour", 0) . ":00:00");
         $reservation->save();
     }
     $data["reservations"] = Model_Lessontime::find("all", ["where" => [["deleted_at", 0], ["teacher_id", $this->user->id], ["freetime_at", ">=", time()]], "order_by" => [["id", "desc"]]]);
     $view = View::forge("teachers/lesson/add", $data);
     $this->template->content = $view;
 }