Exemple #1
0
 /**
  * @before _secure, _vendor
  */
 public function editOffer($offer_id)
 {
     $this->seo(array("title" => "Edit Offer", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $offer = Offer::first(array("id = ?" => $offer_id, "organization_id = ?" => $this->organization->id));
     if (!$offer) {
         $this->redirect("/vendor");
     }
     $offer->start = array_shift(explode(' ', $offer->start));
     $offer->end = array_shift(explode(' ', $offer->end));
     $packages = Package::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $fields = $offer->render();
     $view->set("fields", $fields);
     $errors = array();
     if (RequestMethods::post("action") == "editOffer") {
         $offer->property_id = RequestMethods::post("package_id");
         foreach ($fields as $f) {
             $offer->{$f}['name'] = RequestMethods::post($f['name']);
         }
         if ($offer->validate()) {
             $offer->save();
             $view->set("message", "Offer Saved Successfully!!");
         } else {
             $errors = $offer->errors;
         }
     }
     $view->set("packages", $packages)->set("errors", $errors)->set("offer", $offer);
 }