Пример #1
0
 /**
  * Data provider for get_config.
  *
  * @return array
  */
 public function get_config_provider()
 {
     $allvalues = (object) ['some' => 'value', 'another' => 42, 'key' => ['somethingelse']];
     return ['No nitial config' => [null, null, null, (object) []], 'All values' => [$allvalues, null, null, $allvalues], 'Valid string value' => [$allvalues, 'some', null, 'value'], 'Valid array value' => [$allvalues, 'key', null, ['somethingelse']], 'Invalid value' => [$allvalues, 'notavalue', null, null], 'Configuration value' => [$allvalues, 'placement', null, \tool_usertours\configuration::get_default_value('placement')], 'Invalid value with default' => [$allvalues, 'notavalue', 'somedefault', 'somedefault']];
 }
Пример #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();
         }
     }
 }