/** * @before _secure, _vendor */ public function index() { $this->seo(array("title" => "Schedule Your Appointments", "view" => $this->getLayoutView())); $this->getLayoutView()->set("cal", true); $view = $this->getActionView(); if (RequestMethods::post("appointment_id")) { if (RequestMethods::post("job_id", "")) { $job = Job::first(array("appointment_id = ?" => RequestMethods::post("appointment_id"))); $job->user_id = RequestMethods::post("user_id"); } else { $job = new Job(array("user_id" => RequestMethods::post("user_id"), "muser_id" => RequestMethods::post("muser_id"), "puser_id" => RequestMethods::post("puser_id"), "appointment_id" => RequestMethods::post("appointment_id"), "location_id" => RequestMethods::post("location_id"), "centre_id" => RequestMethods::post("centre_id"), "organization_id" => RequestMethods::post("organization_id"))); } $job->save(); $view->set("message", "Runner Assigned Successfully"); } if (RequestMethods::post("action") == "capacity") { foreach (RequestMethods::post("slot") as $key => $value) { $slot = Slot::first(array("organization_id = ?" => $this->member->organization_id, "day = ?" => $key)); if (isset($slot)) { $slot->start = $value["start"]; $slot->day = $key; $slot->end = $value["end"]; $slot->capacity = $value["hlimit"]; } else { $slot = new Slot(array("user_id" => $this->user->id, "organization_id" => $this->member->organization_id, "day" => $key, "start" => $value["start"], "end" => $value["end"], "capacity" => $value["hlimit"])); } $slot->save(); } $view->set("message", "Slots Saved Successfully"); } $runners = Member::all(array("organization_id = ?" => $this->member->organization_id, "designation = ?" => "runner"), array("user_id", "id")); $view->set("runners", $runners); $view->set("day", array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")); $view->set("slots", Slot::all(array("organization_id = ?" => $this->member->organization_id), array("start", "end", "capacity", "day"))); }
public static function slots($user) { $slots = \Slot::all(["user_id = ?" => $user->id]); $result = []; foreach ($slots as $s) { if (array_key_exists($s->day, $result)) { $d = $result[$s->day][0]; $arr = time($d->start) < time($s->start) ? [$d, $s] : [$s, $d]; $result[$s->day] = $arr; } else { $result[$s->day] = [$s]; } } return $result; }