MDL-72783 usertours: Create tours for the new navigation of Moodle 4.0

This commit is contained in:
Huong Nguyen 2022-01-24 15:06:20 +07:00 committed by Shamim Rezaie
parent c59d3d7496
commit 4a7caad272
18 changed files with 191 additions and 5 deletions

View File

@ -101,7 +101,10 @@ class step_list extends \flexible_table {
$content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $systemcontext->id,
'tool_usertours', 'stepcontent', $step->get_id());
return format_text(helper::get_string_from_input($content), $step->get_contentformat());
$content = helper::get_string_from_input($content);
$content = step::get_step_image_from_input($content);
return format_text($content, $step->get_contentformat());
}
/**

View File

@ -864,6 +864,10 @@ class manager {
// the format filename => version. The version value needs to
// be increased if the tour has been updated.
$shippedtours = [
'40_tour_navigation_dashboard.json' => 1,
'40_tour_navigation_mycourse.json' => 1,
'40_tour_navigation_course_teacher.json' => 1,
'40_tour_navigation_course_student.json' => 1,
];
// These are tours that we used to ship but don't ship any longer.

View File

@ -68,6 +68,9 @@ class step implements \renderable {
$content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $systemcontext->id,
'tool_usertours', 'stepcontent', $step->get_id());
$content = helper::get_string_from_input($content);
$content = $step::get_step_image_from_input($content);
$result = (object) [
'stepid' => $step->get_id(),
'title' => external_format_text(
@ -77,7 +80,7 @@ class step implements \renderable {
'tool_usertours'
)[0],
'content' => external_format_text(
helper::get_string_from_input($content),
$content,
$step->get_contentformat(),
$PAGE->context->id,
'tool_usertours'

View File

@ -817,4 +817,29 @@ class step {
return $string;
}
/**
* Attempt to replace PIXICON placeholder with the correct images for tour step content.
*
* @param string $content Tour content
* @return string Processed tour content
*/
public static function get_step_image_from_input(string $content): string {
global $OUTPUT;
if (preg_match('/(?<=@@PIXICON::).*?(?=@@)/', $content, $matches)) {
$bits = explode('::', $matches[0]);
$identifier = $bits[0];
$component = $bits[1];
if ($component == 'moodle') {
$component = 'core';
}
$image = \html_writer::img($OUTPUT->image_url($identifier, $component)->out(false),
'', ['class' => 'img-fluid']);
$contenttoreplace = '@@PIXICON::' . $matches[0] . '@@';
$content = str_replace($contenttoreplace, $image, $content);
}
return $content;
}
}

View File

@ -114,11 +114,12 @@ function xmldb_tool_usertours_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2021101300, 'tool', 'usertours');
}
if ($oldversion < 2021101301) {
if ($oldversion < 2021101302) {
// Update shipped tours.
// Normally, we just bump the version numbers because we need to call update_shipped_tours only once.
manager::update_shipped_tours();
upgrade_plugin_savepoint(true, 2021101301, 'tool', 'usertours');
upgrade_plugin_savepoint(true, 2021101302, 'tool', 'usertours');
}
return true;

View File

@ -266,6 +266,28 @@ $string['tour_activityinfo_course_student_content'] = 'Activity dates and/or wha
$string['tour_activityinfo_course_teacher_title'] = 'New: Activity information';
$string['tour_activityinfo_course_teacher_content'] = 'New course settings \'Show completion conditions\' and \'Show activity dates\' enable you to choose whether activity completion conditions (if set) and/or dates are displayed for students on the course page.';
// 4.0 New navigation tour.
$string['tour_navigation_course_announcements_teacher_content'] = '@@PIXICON::tour/tour_course_admin_3::tool_usertours@@<br>Post important news here.';
$string['tour_navigation_course_announcements_teacher_title'] = 'Something to tell everyone?';
$string['tour_navigation_course_edit_teacher_content'] = '@@PIXICON::tour/tour_course_admin_1::tool_usertours@@<br>Add new content or edit existing content.';
$string['tour_navigation_course_edit_teacher_title'] = 'Activate edit mode';
$string['tour_navigation_course_index_student_content'] = '@@PIXICON::tour/tour_course_student::tool_usertours@@<br>Browse through activities and track your progress.';
$string['tour_navigation_course_index_student_title'] = 'Find your way around';
$string['tour_navigation_course_index_teacher_content'] = '@@PIXICON::tour/tour_course_admin_2::tool_usertours@@<br>Drag and drop activities to re-order course content.';
$string['tour_navigation_course_index_teacher_title'] = 'Course index';
$string['tour_navigation_course_student_tour_des'] = 'Where to browse through activities in a course';
$string['tour_navigation_course_student_tour_name'] = 'Course index';
$string['tour_navigation_course_teacher_tour_des'] = 'Edit mode, drag and drop of activities and posting announcements in a course';
$string['tour_navigation_course_teacher_tour_name'] = 'Course editing';
$string['tour_navigation_dashboard_content'] = '@@PIXICON::tour/tour_dashboard::tool_usertours@@<br>This side panel can contain more features.';
$string['tour_navigation_dashboard_title'] = 'Expand to explore!';
$string['tour_navigation_dashboard_tour_des'] = 'Where blocks can be found on the Dashboard';
$string['tour_navigation_dashboard_tour_name'] = 'Block drawer';
$string['tour_navigation_mycourses_content'] = '@@PIXICON::tour/tour_mycourses::tool_usertours@@<br>Add, copy, delete and hide courses from this menu.';
$string['tour_navigation_mycourses_title'] = 'Courses and categories';
$string['tour_navigation_mycourses_tour_des'] = 'Course management options on the My courses page';
$string['tour_navigation_mycourses_tour_name'] = 'Course management';
$string['tour_final_step_title'] = 'End of tour';
$string['tour_final_step_content'] = 'This is the end of your user tour. It won\'t show again unless you reset it using the link in the footer.';

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -823,4 +823,26 @@ class step_testcase extends advanced_testcase {
$this->assertEquals($value, $step->$getter());
}
/**
* Ensure that the get_step_image_from_input function replace PIXICON placeholder with the correct images correctly.
*/
public function test_get_step_image_from_input() {
$stepcontent = '@@PIXICON::tour/tour_mycourses::tool_usertours@@<br>Test';
$stepcontent = \tool_usertours\step::get_step_image_from_input($stepcontent);
// If the format is correct, PIXICON placeholder will be replaced with the img tag.
$this->assertStringStartsWith('<img', $stepcontent);
$this->assertStringEndsWith('Test', $stepcontent);
$this->assertStringNotContainsString('PIXICON', $stepcontent);
$stepcontent = '@@PIXICON::tour/tour_mycourses<br>Test';
$stepcontent = \tool_usertours\step::get_step_image_from_input($stepcontent);
// If the format is not correct, PIXICON placeholder will not be replaced with the img tag.
$this->assertStringStartsNotWith('<img', $stepcontent);
$this->assertStringStartsWith('@@PIXICON', $stepcontent);
$this->assertStringEndsWith('Test', $stepcontent);
$this->assertStringContainsString('PIXICON', $stepcontent);
}
}

View File

@ -0,0 +1,22 @@
{
"name": "tour_navigation_course_student_tour_name,tool_usertours",
"description": "tour_navigation_course_student_tour_des,tool_usertours",
"pathmatch": "\/course\/view.php%",
"enabled": "1",
"sortorder": "3",
"endtourlabel": "",
"configdata": "{\"placement\":\"right\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"student\"],\"theme\":[\"boost\"],\"cssselector\":[]},\"majorupdatetime\":1641972472,\"shipped_tour\":true,\"shipped_filename\":\"40_tour_navigation_course_student.json\",\"shipped_version\":1}",
"displaystepnumbers": true,
"version": "2021101301",
"steps": [
{
"title": "tour_navigation_course_index_student_title,tool_usertours",
"content": "tour_navigation_course_index_student_content,tool_usertours",
"contentformat": "1",
"targettype": "0",
"targetvalue": "#theme_boost-drawers-courseindex .drawercontent",
"sortorder": "0",
"configdata": "{}"
}
]
}

View File

@ -0,0 +1,40 @@
{
"name": "tour_navigation_course_teacher_tour_name,tool_usertours",
"description": "tour_navigation_course_teacher_tour_des,tool_usertours",
"pathmatch": "\/course\/view.php%",
"enabled": "1",
"sortorder": "2",
"endtourlabel": "",
"configdata": "{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"-1\",\"coursecreator\",\"manager\",\"teacher\",\"editingteacher\"],\"theme\":[\"boost\"],\"cssselector\":[]},\"majorupdatetime\":1641972470,\"shipped_tour\":true,\"shipped_filename\":\"40_tour_navigation_course_teacher.json\",\"shipped_version\":1}",
"displaystepnumbers": true,
"version": "2021101301",
"steps": [
{
"title": "tour_navigation_course_edit_teacher_title,tool_usertours",
"content": "tour_navigation_course_edit_teacher_content,tool_usertours",
"contentformat": "1",
"targettype": "0",
"targetvalue": "form.editmode-switch-form",
"sortorder": "0",
"configdata": "{}"
},
{
"title": "tour_navigation_course_index_teacher_title,tool_usertours",
"content": "tour_navigation_course_index_teacher_content,tool_usertours",
"contentformat": "1",
"targettype": "0",
"targetvalue": "#theme_boost-drawers-courseindex .drawercontent",
"sortorder": "1",
"configdata": "{\"placement\":\"right\"}"
},
{
"title": "tour_navigation_course_announcements_teacher_title,tool_usertours",
"content": "tour_navigation_course_announcements_teacher_content,tool_usertours",
"contentformat": "1",
"targettype": "0",
"targetvalue": ".course-content .course-content-item-content .activity-item[data-activityname=\"Announcements\"]",
"sortorder": "2",
"configdata": "{\"placement\":\"left\"}"
}
]
}

View File

@ -0,0 +1,22 @@
{
"name": "tour_navigation_dashboard_tour_name,tool_usertours",
"description": "tour_navigation_dashboard_tour_des,tool_usertours",
"pathmatch": "FRONTPAGE",
"enabled": "1",
"sortorder": "0",
"endtourlabel": "",
"configdata": "{\"placement\":\"left\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[],\"theme\":[\"boost\"],\"cssselector\":[]},\"majorupdatetime\":1641972465,\"shipped_tour\":true,\"shipped_filename\":\"40_tour_navigation_dashboard.json\",\"shipped_version\":1}",
"displaystepnumbers": true,
"version": "2021101301",
"steps": [
{
"title": "tour_navigation_dashboard_title,tool_usertours",
"content": "tour_navigation_dashboard_content,tool_usertours",
"contentformat": "1",
"targettype": "0",
"targetvalue": ".drawer-toggles .drawer-toggler.drawer-right-toggle",
"sortorder": "0",
"configdata": "{\"placement\":\"left\"}"
}
]
}

View File

@ -0,0 +1,22 @@
{
"name": "tour_navigation_mycourses_tour_name,tool_usertours",
"description": "tour_navigation_mycourses_tour_des,tool_usertours",
"pathmatch": "\/my\/courses.php",
"enabled": "1",
"sortorder": "1",
"endtourlabel": "I understand",
"configdata": "{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[],\"theme\":[\"boost\"],\"cssselector\":[]},\"majorupdatetime\":1641972468,\"shipped_tour\":true,\"shipped_filename\":\"40_tour_navigation_mycourse.json\",\"shipped_version\":1}",
"displaystepnumbers": true,
"version": "2021101301",
"steps": [
{
"title": "tour_navigation_mycourses_title,tool_usertours",
"content": "tour_navigation_mycourses_content,tool_usertours",
"contentformat": "1",
"targettype": "0",
"targetvalue": ".header-actions-container .btn-group",
"sortorder": "0",
"configdata": "{}"
}
]
}

View File

@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2021101301; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2021101302; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'tool_usertours'; // Full name of the plugin (used for diagnostics).