From 3eb3d916cbe046d5ba5e7f1db89559ffb6e3e2a3 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Tue, 29 Nov 2016 05:01:46 +0000 Subject: [PATCH 1/2] MDL-56553 tool_usertours: allow tours to be shipped with Moodle --- admin/tool/usertours/classes/manager.php | 86 +++++++++++++++++++ admin/tool/usertours/db/install.php | 5 ++ admin/tool/usertours/db/upgrade.php | 46 ++++++++++ .../tool/usertours/lang/en/tool_usertours.php | 1 + theme/boost/scss/moodle/tool_usertours.scss | 7 ++ 5 files changed, 145 insertions(+) create mode 100644 admin/tool/usertours/db/upgrade.php diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index f4ffa04beac..2c05b4c2610 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -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(); + } + } } diff --git a/admin/tool/usertours/db/install.php b/admin/tool/usertours/db/install.php index 3b6ab9dae86..e58154c8a90 100644 --- a/admin/tool/usertours/db/install.php +++ b/admin/tool/usertours/db/install.php @@ -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(); } diff --git a/admin/tool/usertours/db/upgrade.php b/admin/tool/usertours/db/upgrade.php new file mode 100644 index 00000000000..6f6208955ed --- /dev/null +++ b/admin/tool/usertours/db/upgrade.php @@ -0,0 +1,46 @@ +. + +/** + * Upgrade code for install + * + * @package tool_usertours + * @copyright 2016 Ryan Wyllie + * @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; +} diff --git a/admin/tool/usertours/lang/en/tool_usertours.php b/admin/tool/usertours/lang/en/tool_usertours.php index 87508d59228..f8767c8b6d8 100644 --- a/admin/tool/usertours/lang/en/tool_usertours.php +++ b/admin/tool/usertours/lang/en/tool_usertours.php @@ -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'; diff --git a/theme/boost/scss/moodle/tool_usertours.scss b/theme/boost/scss/moodle/tool_usertours.scss index b2ff962f1a0..de780f8dccc 100644 --- a/theme/boost/scss/moodle/tool_usertours.scss +++ b/theme/boost/scss/moodle/tool_usertours.scss @@ -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; +} From 10df630ee8ca32fb1dfbea6d24d7ad5018f31698 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Tue, 29 Nov 2016 05:03:42 +0000 Subject: [PATCH 2/2] MDL-56553 tool_usertours: add admin and course tours --- admin/tool/usertours/classes/manager.php | 5 ++- admin/tool/usertours/db/upgrade.php | 4 +-- .../tool/usertours/lang/en/tool_usertours.php | 32 +++++++++++++++++++ .../usertours/tours/boost_administrator.json | 2 ++ .../usertours/tours/boost_course_view.json | 2 ++ admin/tool/usertours/version.php | 2 +- 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 admin/tool/usertours/tours/boost_administrator.json create mode 100644 admin/tool/usertours/tours/boost_course_view.json diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index 2c05b4c2610..2a9c8ce39bc 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -786,7 +786,10 @@ class manager { // 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 = []; + $shippedtours = [ + 'boost_administrator.json' => 1, + 'boost_course_view.json' => 1, + ]; $existingtourrecords = $DB->get_recordset('tool_usertours_tours'); diff --git a/admin/tool/usertours/db/upgrade.php b/admin/tool/usertours/db/upgrade.php index 6f6208955ed..17d87fe9daf 100644 --- a/admin/tool/usertours/db/upgrade.php +++ b/admin/tool/usertours/db/upgrade.php @@ -35,11 +35,11 @@ use tool_usertours\manager; function xmldb_tool_usertours_upgrade($oldversion) { global $CFG, $DB; - if ($oldversion < 2016102002) { + if ($oldversion < 2016112900) { // Update the tours shipped with Moodle. manager::update_shipped_tours(); - upgrade_plugin_savepoint(true, 2016102002, 'tool', 'usertours'); + upgrade_plugin_savepoint(true, 2016112900, 'tool', 'usertours'); } return true; diff --git a/admin/tool/usertours/lang/en/tool_usertours.php b/admin/tool/usertours/lang/en/tool_usertours.php index f8767c8b6d8..858a93dd32d 100644 --- a/admin/tool/usertours/lang/en/tool_usertours.php +++ b/admin/tool/usertours/lang/en/tool_usertours.php @@ -137,3 +137,35 @@ $string['target_selector_targetvalue_help'] = 'A CSS selector can be used to tar $string['viewtour_info'] = 'This is the \'{$a->tourname}\' tour. It applies to the path \'{$a->path}\'.'; $string['viewtour_edit'] = 'You can edit the tour defaults and force the tour to be displayed to all users again.'; $string['tour_resetforall'] = 'The state of the tour has been reset. It will be displayed to all users again.'; + +// Boost - administrator tour. +$string['tour1_title_welcome'] = 'Welcome'; +$string['tour1_content_welcome'] = 'Welcome to the Boost theme for Moodle 3.2. If you\'ve used Moodle before you might find some things look a bit different.'; +$string['tour1_title_navigation'] = 'Navigation'; +$string['tour1_content_navigation'] = 'Major navigation is now though this nav drawer. The contents update depending on where you are in the site. Use the button at the top to hide or show it.'; +$string['tour1_title_customisation'] = 'Customisation'; +$string['tour1_content_customisation'] = 'To customise the look of your site and the front page, use the settings menu in the corner of this header. Try turning editing on right now.'; +$string['tour1_title_blockregion'] = 'Block region'; +$string['tour1_content_blockregion'] = 'There is still a block region over here. We recommend removing the Navigation and Settings blocks completely, as all the functionality is elsewhere in the Boost theme.'; +$string['tour1_title_addingblocks'] = 'Adding blocks'; +$string['tour1_content_addingblocks'] = 'In fact, think carefully about including any blocks on your pages. Blocks are not shown on the Moodle mobile app, so as a general rule it\'s much better to make sure your site works well without any blocks.'; +$string['tour1_title_end'] = 'End of tour'; +$string['tour1_content_end'] = 'This has been a user tour, a new feature in Moodle 3.2. It won\'t show again unless you reset it using the link in the footer. As an admin you can also create your own tours like this!'; + +// Boost - course view tour. +$string['tour2_title_welcome'] = 'Welcome'; +$string['tour2_content_welcome'] = 'Welcome to the Boost theme for Moodle 3.2. If you\'ve used Moodle before you might find things look a bit different here on the course page.'; +$string['tour2_title_customisation'] = 'Customisation'; +$string['tour2_content_customisation'] = 'To change any course settings, use the settings menu in the corner of this header. You will find a similar settings menu on the home page of every activity, too. Try turning editing on right now.'; +$string['tour2_title_navigation'] = 'Navigation'; +$string['tour2_content_navigation'] = 'Major navigation is now though this nav drawer. Use the button at the top to hide or show it. You will see that there are links for major sections of your course.'; +$string['tour2_title_opendrawer'] = 'Open the nav drawer'; +$string['tour2_content_opendrawer'] = 'Try opening the nav drawer now.'; +$string['tour2_title_participants'] = 'Course participants'; +$string['tour2_content_participants'] = 'View participants here. This is also where you go to add or remove students.'; +$string['tour2_title_addblock'] = 'Add a block'; +$string['tour2_content_addblock'] = 'If you enable editing mode you can add blocks from the nav drawer. However, think carefully about including any blocks on your pages. Blocks are not shown on Moodle mobile app, so for the best student experience it is much better to make sure your course works well without any blocks.'; +$string['tour2_title_addingblocks'] = 'Adding blocks'; +$string['tour2_content_addingblocks'] = 'You can add blocks to this page using this button. However, think carefully about including any blocks on your pages. Blocks are not shown on Moodle mobile app, so for the best student experience it is much better to make sure your course works well without any blocks.'; +$string['tour2_title_end'] = 'End of tour'; +$string['tour2_content_end'] = 'This has been a user tour, a new feature in Moodle 3.2. It won\'t show again unless you reset it using the link in the footer. The site admin can also create further tours for this site if required.'; diff --git a/admin/tool/usertours/tours/boost_administrator.json b/admin/tool/usertours/tours/boost_administrator.json new file mode 100644 index 00000000000..873293ffe10 --- /dev/null +++ b/admin/tool/usertours/tours/boost_administrator.json @@ -0,0 +1,2 @@ +{"name":"Boost - administrator","description":"A tour for Administrator's new to the Boost theme","pathmatch":"FRONTPAGE","enabled":"1","sortorder":"0","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"role\":[\"-1\"],\"theme\":[\"boost\"]},\"majorupdatetime\":1479366244,\"default_tour\":true,\"filename\":\"boost_administrator.json\",\"version\":1}","version":"2016102001","steps":[{"title":"tour1_title_welcome,tool_usertours","content":"tour1_content_welcome,tool_usertours","targettype":"2","targetvalue":"","sortorder":"0","configdata":"{}"},{"title":"tour1_title_navigation,tool_usertours","content":"tour1_content_navigation,tool_usertours","targettype":"0","targetvalue":"[data-region=\"drawer-toggle\"] button[data-action=\"toggle-drawer\"]","sortorder":"1","configdata":"{}"},{"title":"tour1_title_customisation,tool_usertours","content":"tour1_content_customisation,tool_usertours","targettype":"0","targetvalue":"body:not(.editing) #page-header .card-block","sortorder":"2","configdata":"{\"placement\":\"bottom\"}"},{"title":"tour1_title_blockregion,tool_usertours","content":"tour1_content_blockregion,tool_usertours","targettype":"0","targetvalue":"body.editing [data-region=\"blocks-column\"]","sortorder":"3","configdata":"{}"},{"title":"tour1_title_addingblocks,tool_usertours","content":"tour1_content_addingblocks,tool_usertours","targettype":"0","targetvalue":"body.editing [data-region=\"blocks-column\"]","sortorder":"4","configdata":"{\"placement\":\"bottom\"}"},{"title":"tour1_title_end,tool_usertours","content":"tour1_content_end,tool_usertours","targettype":"2","targetvalue":"","sortorder":"5","configdata":"{}"}]} + diff --git a/admin/tool/usertours/tours/boost_course_view.json b/admin/tool/usertours/tours/boost_course_view.json new file mode 100644 index 00000000000..b1684b4e3fe --- /dev/null +++ b/admin/tool/usertours/tours/boost_course_view.json @@ -0,0 +1,2 @@ +{"name":"Boost - course view","description":"A tour for introducing administrators and teachers to courses in the Boost theme","pathmatch":"\/course\/view.php%","enabled":"1","sortorder":"1","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"role\":[\"-1\",\"editingteacher\"],\"theme\":[\"boost\"]},\"majorupdatetime\":1480050104}","version":"2016102001","steps":[{"title":"tour2_title_welcome,tool_usertours","content":"tour2_content_welcome,tool_usertours","targettype":"2","targetvalue":"","sortorder":"0","configdata":"{}"},{"title":"tour2_title_customisation,tool_usertours","content":"tour2_content_customisation,tool_usertours","targettype":"0","targetvalue":"body:not(.editing) #page-header .card-block","sortorder":"1","configdata":"{}"},{"title":"tour2_title_navigation,tool_usertours","content":"tour2_content_navigation,tool_usertours","targettype":"0","targetvalue":"[data-region=\"drawer-toggle\"] button[data-action=\"toggle-drawer\"]","sortorder":"2","configdata":"{}"},{"title":"tour2_title_opendrawer,tool_usertours","content":"tour2_content_opendrawer,tool_usertours","targettype":"0","targetvalue":"body:not(.drawer-open-left) [data-region=\"drawer-toggle\"] button[data-action=\"toggle-drawer\"]","sortorder":"3","configdata":"{}"},{"title":"tour2_title_participants,tool_usertours","content":"tour2_content_participants,tool_usertours","targettype":"0","targetvalue":"body.drawer-open-left [data-region=\"drawer\"] [data-key=\"participants\"]","sortorder":"4","configdata":"{\"placement\":\"bottom\",\"backdrop\":\"0\"}"},{"title":"tour2_title_addblock,tool_usertours","content":"tour2_content_addblock,tool_usertours","targettype":"0","targetvalue":"body.drawer-open-left:not(.editing) [data-region=\"drawer\"]","sortorder":"5","configdata":"{\"placement\":\"top\",\"orphan\":\"0\",\"backdrop\":\"0\",\"reflex\":\"0\"}"},{"title":"tour2_title_addingblocks,tool_usertours","content":"tour2_content_addingblocks,tool_usertours","targettype":"0","targetvalue":"body.drawer-open-left.editing [data-region=\"drawer\"] [data-key=\"addblock\"]","sortorder":"6","configdata":"{\"backdrop\":\"0\",\"placement\":\"top\"}"},{"title":"tour2_title_end,tool_usertours","content":"tour2_content_end,tool_usertours","targettype":"2","targetvalue":"","sortorder":"7","configdata":"{}"}]} + diff --git a/admin/tool/usertours/version.php b/admin/tool/usertours/version.php index 6711935dd16..c185f6b3a11 100644 --- a/admin/tool/usertours/version.php +++ b/admin/tool/usertours/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016102001; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2016112900; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2016052300; // Requires this Moodle version. $plugin->component = 'tool_usertours'; // Full name of the plugin (used for diagnostics).