mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-56553 tool_usertours: allow tours to be shipped with Moodle
This commit is contained in:
parent
3eabedbb92
commit
3eb3d916cb
@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use tool_usertours\local\forms;
|
||||
use tool_usertours\local\table;
|
||||
use core\notification;
|
||||
|
||||
/**
|
||||
* Tour manager.
|
||||
@ -117,6 +118,21 @@ class manager {
|
||||
*/
|
||||
const ACTION_RESETFORALL = 'resetforall';
|
||||
|
||||
/**
|
||||
* @var CONFIG_SHIPPED_TOUR
|
||||
*/
|
||||
const CONFIG_SHIPPED_TOUR = 'shipped_tour';
|
||||
|
||||
/**
|
||||
* @var CONFIG_SHIPPED_FILENAME
|
||||
*/
|
||||
const CONFIG_SHIPPED_FILENAME = 'shipped_filename';
|
||||
|
||||
/**
|
||||
* @var CONFIG_SHIPPED_VERSION
|
||||
*/
|
||||
const CONFIG_SHIPPED_VERSION = 'shipped_version';
|
||||
|
||||
/**
|
||||
* This is the entry point for this controller class.
|
||||
*
|
||||
@ -349,6 +365,10 @@ class manager {
|
||||
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();
|
||||
|
||||
@ -646,6 +666,11 @@ class manager {
|
||||
}
|
||||
|
||||
$tour = $step->get_tour();
|
||||
|
||||
if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) {
|
||||
notification::add(get_string('modifyshippedtourwarning', 'tool_usertours'), notification::WARNING);
|
||||
}
|
||||
|
||||
$PAGE->navbar->add($tour->get_name(), $tour->get_view_link());
|
||||
if (isset($id)) {
|
||||
$PAGE->navbar->add($step->get_title(), $step->get_edit_link());
|
||||
@ -750,4 +775,65 @@ class manager {
|
||||
$step->remove();
|
||||
redirect($tour->get_view_link());
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure all of the default tours that are shipped with Moodle are created
|
||||
* and up to date with the latest version.
|
||||
*/
|
||||
public static function update_shipped_tours() {
|
||||
global $DB, $CFG;
|
||||
|
||||
// A list of tours that are shipped with Moodle. They are in
|
||||
// the format filename => version. The version value needs to
|
||||
// be increased if the tour has been updated.
|
||||
$shippedtours = [];
|
||||
|
||||
$existingtourrecords = $DB->get_recordset('tool_usertours_tours');
|
||||
|
||||
// Get all of the existing shipped tours and check if they need to be
|
||||
// updated.
|
||||
foreach ($existingtourrecords as $tourrecord) {
|
||||
$tour = tour::load_from_record($tourrecord);
|
||||
|
||||
if (!empty($tour->get_config(self::CONFIG_SHIPPED_TOUR))) {
|
||||
$filename = $tour->get_config(self::CONFIG_SHIPPED_FILENAME);
|
||||
$version = $tour->get_config(self::CONFIG_SHIPPED_VERSION);
|
||||
|
||||
// If we know about this tour (otherwise leave it as is).
|
||||
if (isset($shippedtours[$filename])) {
|
||||
// And the version in the DB is an older version.
|
||||
if ($version < $shippedtours[$filename]) {
|
||||
// Remove the old version because it's been updated
|
||||
// and needs to be recreated.
|
||||
$tour->remove();
|
||||
} else {
|
||||
// The tour has not been updated so we don't need to
|
||||
// do anything with it.
|
||||
unset($shippedtours[$filename]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$existingtourrecords->close();
|
||||
|
||||
foreach ($shippedtours as $filename => $version) {
|
||||
$filepath = $CFG->dirroot . '/admin/tool/usertours/tours/' . $filename;
|
||||
$tourjson = file_get_contents($filepath);
|
||||
$tour = self::import_tour_from_json($tourjson);
|
||||
|
||||
// Set some additional config data to record that this tour was
|
||||
// added as a shipped tour.
|
||||
$tour->set_config(self::CONFIG_SHIPPED_TOUR, true);
|
||||
$tour->set_config(self::CONFIG_SHIPPED_FILENAME, $filename);
|
||||
$tour->set_config(self::CONFIG_SHIPPED_VERSION, $version);
|
||||
|
||||
if (defined('BEHAT_SITE_RUNNING') || (defined('PHPUNIT_TEST') && PHPUNIT_TEST)) {
|
||||
// Disable this tour if this is behat or phpunit.
|
||||
$tour->set_enabled(false);
|
||||
}
|
||||
|
||||
$tour->persist();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
use tool_usertours\manager;
|
||||
|
||||
/**
|
||||
* Perform the post-install procedures.
|
||||
*/
|
||||
@ -71,4 +73,7 @@ function xmldb_tool_usertours_install() {
|
||||
$DB->delete_records('usertours_steps', null);
|
||||
$DB->delete_records('usertours_tours', null);
|
||||
}
|
||||
|
||||
// Update the tours shipped with Moodle.
|
||||
manager::update_shipped_tours();
|
||||
}
|
||||
|
46
admin/tool/usertours/db/upgrade.php
Normal file
46
admin/tool/usertours/db/upgrade.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Upgrade code for install
|
||||
*
|
||||
* @package tool_usertours
|
||||
* @copyright 2016 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use tool_usertours\manager;
|
||||
|
||||
/**
|
||||
* 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 < 2016102002) {
|
||||
// Update the tours shipped with Moodle.
|
||||
manager::update_shipped_tours();
|
||||
|
||||
upgrade_plugin_savepoint(true, 2016102002, 'tool', 'usertours');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -60,6 +60,7 @@ $string['filter_role'] = 'Role';
|
||||
$string['filter_role_help'] = 'A tour may be restricted to users with selected roles in the context where the tour is shown. For example, restricting a Dashboard tour to users with the role of student won\'t work if users have the role of student in a course (as is generally the case). A Dashboard tour can only be restricted to users with a system role.';
|
||||
$string['importtour'] = 'Import tour';
|
||||
$string['left'] = 'Left';
|
||||
$string['modifyshippedtourwarning'] = 'This is a user tour that has shipped with Moodle. Any modifications you make may be overridden during your next site upgrade.';
|
||||
$string['movestepdown'] = 'Move step down';
|
||||
$string['movestepup'] = 'Move step up';
|
||||
$string['movetourdown'] = 'Move tour down';
|
||||
|
@ -103,3 +103,10 @@ span[data-flexitour="container"] {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hack the bone! Hack the bone!
|
||||
[data-region="drawer"] [data-flexitour="container"] {
|
||||
/*rtl:ignore*/
|
||||
margin-left: -15px;
|
||||
width: $drawer-width - 10px;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user