Exemple #1
0
 /**
  * Reset the specified tour for the current user.
  *
  * @param   int     $tourid     The ID of the tour.
  * @param   int     $context    The Context ID of the current page.
  * @param   string  $pageurl    The path of the current page requesting the reset.
  * @return  array               As described in reset_tour_returns
  */
 public static function reset_tour($tourid, $context, $pageurl)
 {
     $params = self::validate_parameters(self::reset_tour_parameters(), ['tourid' => $tourid, 'context' => $context, 'pageurl' => $pageurl]);
     $context = \context_helper::instance_by_id($params['context']);
     self::validate_context($context);
     $tour = tourinstance::instance($params['tourid']);
     $tour->request_user_reset();
     $result = [];
     if ($tourinstance = \tool_usertours\manager::get_matching_tours(new \moodle_url($params['pageurl']))) {
         if ($tour->get_id() === $tourinstance->get_id()) {
             $result['startTour'] = $tour->get_id();
             \tool_usertours\event\tour_reset::create(['contextid' => $context->id, 'objectid' => $params['tourid'], 'other' => ['pageurl' => $params['pageurl']]])->trigger();
         }
     }
     return $result;
 }
Exemple #2
0
 /**
  * Tests for the get_matching_tours function.
  *
  * @dataProvider get_matching_tours_provider
  * @param   array   $alltours   The list of tours to insert
  * @param   string  $url        The URL to test
  * @param   string  $expected   The name of the expected matching tour
  */
 public function test_get_matching_tours($alltours, $url, $expected)
 {
     $this->resetAfterTest();
     foreach ($alltours as $tourconfig) {
         $tour = $this->helper_create_tour((object) $tourconfig);
         $this->helper_create_step((object) ['tourid' => $tour->get_id()]);
     }
     $match = \tool_usertours\manager::get_matching_tours(new moodle_url($url));
     if ($expected === null) {
         $this->assertNull($match);
     } else {
         $this->assertNotNull($match);
         $this->assertEquals($expected, $match->get_name());
     }
 }