Beispiel #1
0
 /**
  * Form definition.
  */
 public function definition()
 {
     $mform = $this->_form;
     // ID of existing tour.
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     // Name of the tour.
     $mform->addElement('text', 'name', get_string('name', 'tool_usertours'));
     $mform->addRule('name', get_string('required'), 'required', null, 'client');
     $mform->setType('name', PARAM_TEXT);
     // Admin-only descriptions.
     $mform->addElement('textarea', 'description', get_string('description', 'tool_usertours'));
     $mform->setType('description', PARAM_RAW);
     // Application.
     $mform->addElement('text', 'pathmatch', get_string('pathmatch', 'tool_usertours'));
     $mform->setType('pathmatch', PARAM_RAW);
     $mform->addHelpButton('pathmatch', 'pathmatch', 'tool_usertours');
     $mform->addElement('checkbox', 'enabled', get_string('tourisenabled', 'tool_usertours'));
     // Configuration.
     $this->tour->add_config_to_form($mform);
     // Filters.
     $mform->addElement('header', 'filters', get_string('filter_header', 'tool_usertours'));
     $mform->addElement('static', 'filterhelp', '', get_string('filter_help', 'tool_usertours'));
     foreach (helper::get_all_filters() as $filterclass) {
         $filterclass::add_filter_to_form($mform);
     }
     $this->add_action_buttons();
 }
Beispiel #2
0
 /**
  * Print the edit tour page.
  *
  * @param   int         $id     The ID of the tour
  */
 protected function edit_tour($id = null)
 {
     global $PAGE;
     if ($id) {
         $tour = tour::instance($id);
         $PAGE->navbar->add($tour->get_name(), $tour->get_edit_link());
     } else {
         $tour = new tour();
         $PAGE->navbar->add(get_string('newtour', 'tool_usertours'), $tour->get_edit_link());
     }
     $form = new forms\edittour($tour);
     if ($form->is_cancelled()) {
         redirect(helper::get_list_tour_link());
     } else {
         if ($data = $form->get_data()) {
             // Creating a new tour.
             $tour->set_name($data->name);
             $tour->set_description($data->description);
             $tour->set_pathmatch($data->pathmatch);
             $tour->set_enabled(!empty($data->enabled));
             foreach (configuration::get_defaultable_keys() as $key) {
                 $tour->set_config($key, $data->{$key});
             }
             // Save filter values.
             foreach (helper::get_all_filters() as $filterclass) {
                 $filterclass::save_filter_values_from_form($tour, $data);
             }
             $tour->persist();
             redirect(helper::get_list_tour_link());
         } else {
             if (empty($tour)) {
                 $this->header('newtour');
             } else {
                 if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) {
                     notification::add(get_string('modifyshippedtourwarning', 'tool_usertours'), notification::WARNING);
                 }
                 $this->header($tour->get_name());
                 $data = $tour->prepare_data_for_form();
                 // Prepare filter values for the form.
                 foreach (helper::get_all_filters() as $filterclass) {
                     $filterclass::prepare_filter_values_for_form($tour, $data);
                 }
                 $form->set_data($data);
             }
             $form->display();
             $this->footer();
         }
     }
 }