示例#1
0
 public function up()
 {
     //we'll need some places where the events can take place
     $locations = array('Rīga', 'Valmiera', 'Ventspils');
     foreach ($locations as $location) {
         $loc = \Model_Orm_Location::forge();
         $loc->title = $location;
         $loc->save();
     }
     //and let's create at least one event as well
     $demo_event = \Model_Orm_Event::forge();
     $demo_event->title = "Notikums pēc nedēļas";
     $demo_event->description = "Kaut kas, kam jānotiek nedēļu vēlāk nekā šī skripta izpilde.";
     $startdate = \Fuel\Core\Date::forge(time() + 7 * 24 * 60 * 60);
     $demo_event->start = $startdate->format('mysql', false);
     //'2013-11-27 07:00:00';
     $demo_event->location_id = 1;
     //pieņemsim, ka Rīgā;
     $demo_event->save();
     //the event shouldn't be empty - some agenda items
     $agenda_items = array('Notikuma pats, pats sākums', 'Kaut kad drusku vēlāk', 'Vēl mazliet vēlāk', 'Un nu jau arī beigas');
     foreach ($agenda_items as $agenda_item) {
         $demo_agenda = \Model_Orm_Agenda::forge();
         $demo_agenda->title = $agenda_item;
         $demo_agenda->event = $demo_event;
         $demo_agenda->save();
     }
     //we also need some users. at least two.
     \Auth::instance()->create_user("*****@*****.**", "fuel_dev", "*****@*****.**", 100, array("verified" => true, "verification_key" => md5(mt_rand(0, mt_getrandmax()))));
     \Auth::instance()->create_user("*****@*****.**", "fuel_dev", "*****@*****.**", 1, array("verified" => true, "verification_key" => md5(mt_rand(0, mt_getrandmax()))));
 }
示例#2
0
 /**
  * Automatic creation of input forms.
  * @return view data
  */
 public function action_fieldset()
 {
     $output = "";
     //the generated output will be collected here
     $eventinstance = new Model_Orm_Event();
     //a new form which is identified as "eventform"
     //in current view
     $inputform = Fuel\Core\Fieldset::forge("eventform");
     //the fieldset class loads field information from our model
     $inputform->add_model($eventinstance);
     //since the location field should be a drop-down select box,
     //we add it manually.
     //The actual list of locations is loaded by the Model_Orm_Location model
     $inputform->add("location", "Select a location", array("type" => "select", "name" => "location_id", "options" => Model_Orm_Location::get_locations()));
     //the Fieldset does not automatically add buttons, hence we do
     $inputform->add("submit", "", array("type" => "submit", "value" => "Add", "class" => "btn medium primary"));
     //this re-loads data from $_POST array if the form is re-submitted.
     $inputform->repopulate();
     //execute validations described in the model class
     if ($inputform->validation()->run()) {
         //this is the good case!
         $new_event = Model_Orm_Event::forge();
         $fields = $inputform->validated();
         $new_event->title = $fields["title"];
         $new_event->description = $fields["description"];
         $new_event->start = time();
         $new_event->save();
         //always do a redirect after saving an item!
         Response::redirect("event/orm");
     } else {
         //there have been some problems, output them to the client
         foreach ($inputform->validation()->error() as $error) {
             $output .= "<p>" . $error . "</p>";
         }
     }
     //the 'build' actually generates all HTML code
     $output .= $inputform->build();
     return Response::forge($output);
 }