Exemple #1
0
 /**
  * Adding a new agenda item to the event
  * @param int $event_id
  */
 public function action_create($event_id = null)
 {
     is_null($event_id) and Response::redirect("event");
     $event = Model_Orm_Event::find($event_id);
     if (Input::method() == 'POST') {
         $val = Model_Orm_Agenda::validate('create');
         if ($val->run()) {
             $agenda = Model_Orm_Agenda::forge(array('title' => $val->validated('title')));
             $agenda->event = $event;
             if ($agenda and $agenda->save()) {
                 Session::set_flash('success', 'Added a new agenda item to the event "' . $event->title . '".');
                 Response::redirect('event/view/' . $event_id);
             } else {
                 Session::set_flash('error', 'Could not save the agenda item.');
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Adding agenda items to `" . $event->title . "`.";
     $this->template->content = View::forge('agenda/create');
 }
Exemple #2
0
 /**
  * demonstrates how ORM models can be used for loading 
  * DB information as well as creating new items or editing them.
  * @return view data
  */
 public function action_orm()
 {
     $demo_event = new Model_Orm_Event();
     $demo_event->title = "Lecture demo";
     $demo_event->description = "blabla";
     $demo_event->start = time();
     //$demo_event->save();
     $first_event = Model_Orm_Event::find(1);
     $first_event->title = "Modified title";
     $first_event->save();
     $events = Model_Orm_Event::find("all", array('related' => array('agendas', 'location')));
     $output = "";
     foreach ($events as $event) {
         $output .= "=======\r\n";
         $output .= $event->title . "\r\n";
         $output .= $event->description . "\r\n";
         if (isset($event->location) && isset($event->location->title)) {
             $output .= $event->location->title . $event->location->id . "\r\n";
         }
         foreach ($event->agendas as $agenda) {
             $output .= "-" . $agenda->title . "\r\n";
         }
     }
     $response = Response::forge($output);
     $response->set_header("Content-Type", "text/plain");
     return $response;
 }