/** * @before _secure */ public function profile() { $this->seo(array("title" => "Profile", "view" => $this->getLayoutView())); $view = $this->getActionView(); $user = $this->user; $view->set("errors", array()); if (RequestMethods::post("action") == "saveUser") { $user->name = RequestMethods::post("name"); $user->phone = RequestMethods::post("phone"); $password = RequestMethods::post("password"); if (!empty($password)) { $user->password = sha1($password); } $user->save(); $this->setUser($user); $view->set("success", "Info updated!!"); } $locations = Location::all(array("user_id = ?" => $this->user->id), array("*"), "created", "desc"); $family = Shared\Services\Patient::findFamily($this->user); $flocations = Shared\Services\Patient::familyLoc($family); if (RequestMethods::post("action") == "saveLocation") { $location_id = RequestMethods::post("location_id"); $location = $locations[$location_id]; $l = \Location::saveRecord(null, $location, array("validate" => true)); if (is_array($l)) { $view->set("success", "Fix the following errors")->set("errors", $l); } else { $locations[$location_id] = $l; $view->set("success", "Updated Location"); } } if (RequestMethods::post("addLocation")) { $user_id = (int) RequestMethods::post("user_id", $this->user->id); if ((int) $this->user->id == $user_id) { $u = $this->user; } else { $u = ArrayMethods::toObject(['id' => $family[$user_id]->user_id]); } $location = \Location::saveRecord($u, null, array("validate" => true)); if (is_array($location)) { $view->set("success", "Fix the following errors")->set("errors", $location); } else { $view->set("success", "Added New Location"); $arr = array($location->id => $location); $locations = array_merge($locations, $arr); } } $view->set("locations", $locations)->set("family", $family)->set("flocations", $flocations); }
/** * @before _secure */ public function checkout() { $this->seo(array("title" => "Cart", "view" => $this->getLayoutView())); $view = $this->getActionView(); $session = Registry::get("session"); $items = Cart::all(array("user_id = ?" => $this->user->id), array("service_id", "centre_id", "id")); $stored = $session->get('User\\Cart:$cart', array()); if (count($items) == 0 && count($stored) == 0) { $this->redirect("/profile"); } if (count($items) != count($stored)) { foreach ($stored as $s) { CartService::save($s, $this->user); } $items = Cart::all(array("user_id = ?" => $this->user->id), array("service_id", "centre_id", "id")); } $family = Shared\Services\Patient::findFamily($this->user); $locations = Location::all(array("user_id = ?" => $this->user->id), array("user_id", "id", "street", "area_id", "city_id")); $flocations = Shared\Services\Patient::familyLoc($family); $locations = array_merge($locations, $flocations); $view->set("items", $items); $view->set("family", $family); $view->set("locations", $locations); }