예제 #1
0
/**
 * Upgrade the user tours plugin.
 *
 * @param int $oldversion The old version of the user tours plugin
 * @return bool
 */
function xmldb_tool_usertours_upgrade($oldversion)
{
    global $CFG, $DB;
    if ($oldversion < 2016120501) {
        // Update the tours shipped with Moodle.
        manager::update_shipped_tours();
        upgrade_plugin_savepoint(true, 2016120501, 'tool', 'usertours');
    }
    // Automatically generated Moodle v3.2.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
예제 #2
0
/**
 * Perform the post-install procedures.
 */
function xmldb_tool_usertours_install()
{
    global $DB;
    $localplugin = core_plugin_manager::instance()->get_plugin_info('local_usertours');
    if ($localplugin) {
        // If the old local plugin was previously installed, copy over the data from the old tables.
        // The 'comment' field was renamed to 'description' in:
        // * 3.0 version 2015111604
        // * 3.1 version 2016052303
        // We need to attempt to fetch comment for these older versions.
        $hasdescription = $localplugin->versiondb < 2016052301 && $localplugin->versiondb >= 2015111604;
        $hasdescription = $hasdescription || $localplugin->versiondb > 2016052303;
        $tours = $DB->get_recordset('usertours_tours');
        $mapping = [];
        foreach ($tours as $tour) {
            if (!$hasdescription) {
                if (property_exists($tour, 'comment')) {
                    $tour->description = $tour->comment;
                    unset($tour->comment);
                } else {
                    $tour->description = '';
                }
            }
            $mapping[$tour->id] = $DB->insert_record('tool_usertours_tours', $tour);
        }
        $tours->close();
        $steps = $DB->get_recordset('usertours_steps');
        foreach ($steps as $step) {
            if (!isset($mapping[$step->tourid])) {
                // Skip this one. It has somehow become orphaned.
                continue;
            }
            $step->tourid = $mapping[$step->tourid];
            $DB->insert_record('tool_usertours_steps', $step);
        }
        $steps->close();
        // Delete the old records.
        $DB->delete_records('usertours_steps', null);
        $DB->delete_records('usertours_tours', null);
    }
    // Update the tours shipped with Moodle.
    manager::update_shipped_tours();
}
예제 #3
0
파일: tour.php 프로젝트: dg711/moodle
 /**
  * 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;
 }
예제 #4
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());
     }
 }