Skip to content

Commit

Permalink
Merge branch 'MDL-72557-master' of git://github.com/rezaies/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Oct 6, 2021
2 parents af94d5b + 912a580 commit 6f7e5cf
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 18 deletions.
2 changes: 1 addition & 1 deletion admin/tool/usertours/classes/external/tour.php
Expand Up @@ -104,7 +104,7 @@ public static function fetch_and_start_tour_returns() {
'tourconfig' => new external_single_structure([
'name' => new external_value(PARAM_RAW, 'Tour Name'),
'steps' => new external_multiple_structure(self::step_structure_returns()),
'onesteptour' => new external_value(PARAM_BOOL, 'Is a one step tour', VALUE_DEFAULT, false),
'endtourlabel' => new external_value(PARAM_RAW, 'Label of the end tour button'),
], 'Tour config', VALUE_OPTIONAL)
]);
}
Expand Down
4 changes: 4 additions & 0 deletions admin/tool/usertours/classes/local/forms/edittour.php
Expand Up @@ -79,6 +79,10 @@ public function definition() {

$mform->addElement('checkbox', 'enabled', get_string('tourisenabled', 'tool_usertours'));

$mform->addElement('text', 'endtourlabel', get_string('endtourlabel', 'tool_usertours'));
$mform->setType('endtourlabel', PARAM_TEXT);
$mform->addHelpButton('endtourlabel', 'endtourlabel', 'tool_usertours');

// Configuration.
$this->tour->add_config_to_form($mform);

Expand Down
1 change: 1 addition & 0 deletions admin/tool/usertours/classes/manager.php
Expand Up @@ -370,6 +370,7 @@ protected function edit_tour($id = null) {
$tour->set_description($data->description);
$tour->set_pathmatch($data->pathmatch);
$tour->set_enabled(!empty($data->enabled));
$tour->set_endtourlabel($data->endtourlabel);

foreach (configuration::get_defaultable_keys() as $key) {
$tour->set_config($key, $data->$key);
Expand Down
7 changes: 1 addition & 6 deletions admin/tool/usertours/classes/output/tour.php
Expand Up @@ -60,18 +60,13 @@ public function export_for_template(\renderer_base $output) {
$result = (object) [
'name' => $this->tour->get_tour_key(),
'steps' => [],
'onesteptour' => false,
'endtourlabel' => $this->tour->get_endtourlabel(),
];

foreach ($this->tour->get_steps() as $step) {
$result->steps[] = (new step($step))->export_for_template($output);
}

// Check if its a only one step tour.
if (count($result->steps) == 1) {
$result->onesteptour = true;
}

return $result;
}
}
37 changes: 37 additions & 0 deletions admin/tool/usertours/classes/tour.php
Expand Up @@ -89,6 +89,11 @@ class tour {
*/
protected $enabled;

/**
* @var $endtourlabel The end tour label.
*/
protected $endtourlabel;

/**
* @var $sortorder The sort order.
*/
Expand Down Expand Up @@ -187,6 +192,7 @@ protected function reload_from_record($record, $clean = false) {
if (isset($record->sortorder)) {
$this->sortorder = $record->sortorder;
}
$this->endtourlabel = $record->endtourlabel ?? null;
$this->config = json_decode($record->configdata);
$this->dirty = false;
$this->steps = [];
Expand Down Expand Up @@ -322,6 +328,36 @@ public function set_enabled($value) {
return $this;
}

/**
* The end tour label for the tour.
*
* @return string
*/
public function get_endtourlabel(): string {
if ($this->endtourlabel) {
$label = $this->endtourlabel;
} else if ($this->count_steps() == 1) {
$label = get_string('endonesteptour', 'tool_usertours');
} else {
$label = get_string('endtour', 'tool_usertours');
}

return $label;
}

/**
* Set the endtourlabel of the tour to the specified value.
*
* @param string $value
* @return $this
*/
public function set_endtourlabel(string $value): tour {
$this->endtourlabel = $value;
$this->dirty = true;

return $this;
}

/**
* The link to view this tour.
*
Expand Down Expand Up @@ -389,6 +425,7 @@ public function to_record() {
'pathmatch' => $this->pathmatch,
'enabled' => $this->enabled,
'sortorder' => $this->sortorder,
'endtourlabel' => $this->endtourlabel,
'configdata' => json_encode($this->config),
);
}
Expand Down
3 changes: 2 additions & 1 deletion admin/tool/usertours/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/usertours/db" VERSION="20160830" COMMENT="XMLDB file for Moodle tool/usertours"
<XMLDB PATH="admin/tool/usertours/db" VERSION="20210923" COMMENT="XMLDB file for Moodle tool/usertours"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -12,6 +12,7 @@
<FIELD NAME="pathmatch" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="endtourlabel" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Custom label for the end tour button"/>
<FIELD NAME="configdata" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
Expand Down
16 changes: 16 additions & 0 deletions admin/tool/usertours/db/upgrade.php
Expand Up @@ -36,6 +36,8 @@
function xmldb_tool_usertours_upgrade($oldversion) {
global $CFG, $DB;

$dbman = $DB->get_manager();

// Automatically generated Moodle v3.6.0 release upgrade line.
// Put any upgrade step following this.

Expand Down Expand Up @@ -83,5 +85,19 @@ function xmldb_tool_usertours_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2021052508, 'tool', 'usertours');
}

if ($oldversion < 2021092300) {
// Define field endtourlabel to be added to tool_usertours_tours.
$table = new xmldb_table('tool_usertours_tours');
$field = new xmldb_field('endtourlabel', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'sortorder');

// Conditionally launch add field endtourlabel.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Usertours savepoint reached.
upgrade_plugin_savepoint(true, 2021092300, 'tool', 'usertours');
}

return true;
}
2 changes: 2 additions & 0 deletions admin/tool/usertours/lang/en/tool_usertours.php
Expand Up @@ -49,6 +49,8 @@
$string['editstep'] = 'Editing "{$a}"';
$string['tourisenabled'] = 'Tour is enabled';
$string['enabled'] = 'Enabled';
$string['endtourlabel'] = 'End tour button\'s label';
$string['endtourlabel_help'] = 'You can optionally specify a custom label for the end tour button. The default label is "Got it!" for single-step, and "End tour" for multiple-step tours.';
$string['event_tour_started'] = 'Tour started';
$string['event_tour_reset'] = 'Tour reset';
$string['event_tour_ended'] = 'Tour ended';
Expand Down
9 changes: 2 additions & 7 deletions admin/tool/usertours/templates/tourstep.mustache
Expand Up @@ -43,7 +43,7 @@
Example context (json):
{
"name" : "tour_activity_completion",
"onesteptour" : true,
"endtourlabel" : "Got it!",
"steps": [
{
"stepid": 10,
Expand All @@ -68,12 +68,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-role="previous">{{# str }} previousstep, tool_usertours {{/ str }}</button>
<button type="button" class="btn btn-primary" data-role="next">{{# str }} nextstep, tool_usertours {{/ str }}</button>
{{#onesteptour}}
<button class="btn btn-secondary" data-role="end"> {{# str }} endonesteptour, tool_usertours {{/ str }} </button>
{{/onesteptour}}
{{^onesteptour}}
<button class="btn btn-secondary" data-role="end"> {{# str }} endtour, tool_usertours {{/ str }} </button>
{{/onesteptour}}
<button class="btn btn-secondary" data-role="end"> {{endtourlabel}} </button>
</div>
</div>
</div>
18 changes: 18 additions & 0 deletions admin/tool/usertours/tests/behat/tour_navigation.feature
Expand Up @@ -60,3 +60,21 @@ Feature: Steps can be navigated within a tour
And I should see "Next"
And I click on "Next" "button"
And I should see "End tour"

@javascript
Scenario: Customised 'end tour' button text for one step tours
Given I log in as "admin"
And I add a new user tour with:
| Name | Calendar tour |
| Description | Calendar tour |
| Apply to URL match | /my/% |
| Tour is enabled | 1 |
| End tour button's label | CustomText |
And I add steps to the "Calendar tour" tour:
| targettype | Block | Title | Content |
| Block | Calendar | Calendar events | This is the calendar block |
And I change window size to "large"
And I follow "Dashboard" in the user menu
And I wait until the page is ready
And I should see "This is the calendar block"
Then I should see "CustomText"
4 changes: 2 additions & 2 deletions admin/tool/usertours/upgrade.txt
Expand Up @@ -2,8 +2,8 @@ This files describes API changes in the tool_usertours code.

=== 4.0 ===
* The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour`
external method has also a `onsteptour` property to differentiate between
one step tours and multiple step tours.
external method has also an `endtourlabel` property that contains the label to be used
for the end tour button.

=== 3.9 ===
* The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour`
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/usertours/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021052508; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2021092300; // 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).

0 comments on commit 6f7e5cf

Please sign in to comment.