Ejemplo n.º 1
0
 /**
  * A validation function which checks if the number passed 
  * to it is a valid location ID.
  * @param type $val
  * @return boolean
  */
 public static function _validation_valid_location($val)
 {
     if (Model_Orm_Location::find($val) == null) {
         Validation::active()->set_message('valid_location', 'The field "location" must refer to a valid location.');
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 public function action_edit($id = null)
 {
     //looks up the even in the database
     //if anything is not OK - redirects back to the list of events
     is_null($id) and Response::redirect('event');
     $event = Model_Orm_Event::find($id, array("related" => array("location")));
     is_null($event) and Response::redirect('Event');
     //not POST = just read from database
     if (Input::method() == 'POST') {
         $val = Model_Orm_Event::validate("edit");
         if ($val->run()) {
             //validation is OK!
             $event->title = $val->validated("title");
             $event->description = $val->validated("description");
             $event->start = $val->validated("start");
             $event->location = Model_Orm_Location::find(Input::post("location"));
             if ($event->save()) {
                 Session::set_flash("success", "Changes saved successfuly!");
             } else {
                 Session::set_flash("error", "Somehow could not save the item.");
             }
             Response::redirect("event/view/" . $event->id);
         } else {
             //POST data passed, but something wrong with validation
             Session::set_flash("error", $val->error());
         }
     }
     $data["event"] = $event;
     $data["locations"] = Model_Orm_Location::get_locations();
     $this->add_rich_form_scripts();
     $this->template->title = "Editing the event " . $event->title;
     $this->template->page_content = View::forge("event/edit", $data);
 }