MDL-71915 mod_survey: Update tertiary nav

Update tertiary navigation for this activity.
Updated the behat tests for the change made.
This commit is contained in:
Sujith Haridasan 2021-08-03 16:34:05 +05:30
parent e0f584d64c
commit 222ab7b222
11 changed files with 266 additions and 80 deletions

View file

@ -0,0 +1,128 @@
<?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/>.
namespace mod_survey\output;
use moodle_url;
use renderable;
use renderer_base;
use templatable;
use url_select;
/**
* Output the rendered elements for the tertiary nav page action
*
* @package mod_survey
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class actionbar implements renderable, templatable {
/**
* The course id.
*
* @var int $id
*/
private $id;
/**
* The action decides the url to navigate to.
*
* @var string $action
*/
private $action;
/**
* Current url.
*
* @var moodle_url $currenturl
*/
private $currenturl;
/**
* actionbar constructor.
*
* @param int $id The course module id.
* @param string $action The action string.
* @param moodle_url $currenturl The current URL.
*/
public function __construct(int $id, string $action, moodle_url $currenturl) {
$this->id = $id;
$this->action = $action;
$this->currenturl = $currenturl;
}
/**
* Create select menu for the reports
*
* @return url_select url_select object.
*/
private function create_select_menu(): url_select {
$summarylink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'summary']);
$scaleslink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'scales']);
$questionslink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'questions']);
$participantslink = new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'students']);
$menu = [
$summarylink->out(false) => get_string('summary', 'survey'),
$scaleslink->out(false) => get_string('scales', 'survey'),
$questionslink->out(false) => get_string('questions', 'survey'),
$participantslink->out(false) => get_string('participants'),
];
switch ($this->action) {
case 'summary':
$activeurl = $summarylink;
break;
case 'scales':
$activeurl = $scaleslink;
break;
case 'questions':
$activeurl = $questionslink;
break;
case 'students':
$activeurl = $participantslink;
break;
default:
$activeurl = $this->currenturl;
}
return new url_select($menu, $activeurl->out(false), null, 'surveyresponseselect');
}
/**
* Data for the template.
*
* @param renderer_base $output renderer_base object.
* @return array data for the template
*/
public function export_for_template(renderer_base $output): array {
global $PAGE;
$selecturl = $this->create_select_menu();
$data = [
'urlselect' => $selecturl->export_for_template($output)
];
if (has_capability('mod/survey:download', $PAGE->cm->context)) {
$downloadlink = (new moodle_url('/mod/survey/report.php', ['id' => $this->id, 'action' => 'download']))->out(false);
$data['download'] = [
'link' => $downloadlink,
'text' => get_string('downloadresults', 'mod_survey'),
];
}
return $data;
}
}

View file

@ -31,7 +31,9 @@
$PAGE->set_title($strsurveys);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading($strsurveys);
}
if (! $surveys = get_all_instances_in_course("survey", $course)) {
notice(get_string('thereareno', 'moodle', $strsurveys), "../../course/view.php?id=$course->id");

View file

@ -0,0 +1,2 @@
clicktocontinue,mod_survey
viewsurveyresponses,mod_survey

View file

@ -96,7 +96,6 @@ $string['ciq4'] = 'What action from anyone in the forums did you find most puzzl
$string['ciq4short'] = 'Confusing moment';
$string['ciq5'] = 'What event surprised you most?';
$string['ciq5short'] = 'Suprising moment';
$string['clicktocontinue'] = 'Click here to continue';
$string['clicktocontinuecheck'] = 'Click here to check and continue';
$string['collesaintro'] = 'The purpose of this survey is to help us understand how well the online delivery of this unit enabled you to learn.
@ -281,6 +280,9 @@ $string['surveytype_help'] = 'There are 3 available survey types:
$string['surveytype_link'] = 'mod/survey/mod';
$string['thanksforanswers'] = 'Thanks for answering this survey, {$a}';
$string['time'] = 'Time';
$string['viewsurveyresponses'] = 'View {$a} survey responses';
$string['notyetanswered'] = 'Not yet answered';
$string['allquestionrequireanswer'] = 'All questions are required and must be answered.';
// Deprecated since Moodle 4.0.
$string['clicktocontinue'] = 'Click here to continue';
$string['viewsurveyresponses'] = 'View {$a} survey responses';

View file

@ -813,24 +813,8 @@ function survey_extend_settings_navigation($settings, $surveynode) {
global $PAGE;
if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) {
$responsesnode = $surveynode->add(get_string("responsereports", "survey"));
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary'));
$responsesnode->add(get_string("summary", "survey"), $url);
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'scales'));
$responsesnode->add(get_string("scales", "survey"), $url);
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'questions'));
$responsesnode->add(get_string("question", "survey"), $url);
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'students'));
$responsesnode->add(get_string('participants'), $url);
if (has_capability('mod/survey:download', $PAGE->cm->context)) {
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'download'));
$surveynode->add(get_string('downloadresults', 'survey'), $url);
}
$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action' => 'summary'));
$surveynode->add(get_string("responsereports", "survey"), $url);
}
}

39
mod/survey/renderer.php Normal file
View file

@ -0,0 +1,39 @@
<?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/>.
/**
* Output the actionbar for this activity.
*
* @package mod_survey
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Renderer for the mod_survey tertiary nav
*/
class mod_survey_renderer extends plugin_renderer_base {
/**
* Renders the action bar for the mod_survey report page.
*
* @param \mod_survey\output\actionbar $actionbar Data for the template
* @return bool|string rendered HTML string from the template.
*/
public function response_actionbar( \mod_survey\output\actionbar $actionbar) {
return $this->render_from_template('mod_survey/response_action_bar', $actionbar->export_for_template($this));
}
}

View file

@ -92,33 +92,19 @@
$strseemoredetail = get_string("seemoredetail", "survey");
$strnotes = get_string("notes", "survey");
switch ($action) {
case 'download':
$PAGE->navbar->add(get_string('downloadresults', 'survey'));
break;
case 'summary':
case 'scales':
case 'questions':
$PAGE->navbar->add($strreport);
$PAGE->navbar->add(${'str'.$action});
break;
case 'students':
$PAGE->navbar->add($strreport);
$PAGE->navbar->add(get_string('participants'));
break;
case '':
$PAGE->navbar->add($strreport);
$PAGE->navbar->add($strsummary);
break;
default:
$PAGE->navbar->add($strreport);
break;
}
$PAGE->set_title("$course->shortname: ".format_string($survey->name));
$PAGE->set_heading($course->fullname);
// Activate the secondary nav tab.
navigation_node::override_active_url(new moodle_url('/mod/survey/report.php', ['id' => $id, 'action' => 'summary']));
$actionbar = new \mod_survey\output\actionbar($id, $action, $url);
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($survey->name));
}
$renderer = $PAGE->get_renderer('mod_survey');
echo $renderer->response_actionbar($actionbar);
/// Check to see if groups are being used in this survey
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
@ -152,30 +138,6 @@
$groupingid = $cm->groupingid;
echo $OUTPUT->box_start("generalbox boxaligncenter");
if ($showscales) {
echo "<a href=\"report.php?action=summary&amp;id=$id\">$strsummary</a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"report.php?action=scales&amp;id=$id\">$strscales</a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"report.php?action=questions&amp;id=$id\">$strquestions</a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"report.php?action=students&amp;id=$id\">".get_string('participants')."</a>";
if (has_capability('mod/survey:download', $context)) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"report.php?action=download&amp;id=$id\">$strdownload</a>";
}
if (empty($action)) {
$action = "summary";
}
} else {
echo "<a href=\"report.php?action=questions&amp;id=$id\">$strquestions</a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"report.php?action=students&amp;id=$id\">".get_string('participants')."</a>";
if (has_capability('mod/survey:download', $context)) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"report.php?action=download&amp;id=$id\">$strdownload</a>";
}
if (empty($action)) {
$action = "questions";
}
}
echo $OUTPUT->box_end();
echo $OUTPUT->spacer(array('height'=>30, 'width'=>30, 'br'=>true)); // should be done with CSS instead
@ -519,4 +481,3 @@
}
echo $OUTPUT->footer();

View file

@ -0,0 +1,72 @@
{{!
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/>.
}}
{{!
@template mod_survey/response_action_bar
Actions bar for the reports page UI.
Classes required for JS:
* none
Context variables required for this template:
* see mod/survey/classes/output/actionbar.php
Example context (json):
{
"download": {
"link": "http://foobar",
"text": "foobar site",
"urlselect": {
"id": "url_select123",
"sesskey": "sesskey",
"action": "http://localhost/moodle/course/jumpto.php",
"disabled": false,
"formid": "surveyresponseselect",
"classes": "urlselect",
"options": [
{
"name": "Summary",
"value": "/mod/survey/report.php?id=12&action=summary",
"selected": true
},
{
"name": "Scales",
"value": "/mod/survey/report.php?id=12&action=scales",
"selected": false
},
{
"name": "Questions",
"value": "/mod/survey/report.php?id=12&action=questions",
"selected": false
},
{
"name": "Participants",
"value": "/mod/survey/report.php?id=12&action=students",
"selected": false
}
]
}
}
}
}}
<div class="container-fluid">
<div class="row justify-content-between">
<div class="col-xs-6 float-left">
{{#urlselect}}
{{>core/url_select}}
{{/urlselect}}
</div>
{{#download}}
<div class="col-sm-6 float-right">
<a class="btn btn-secondary float-right" href="{{link}}">{{text}}</a>
</div>
{{/download}}
</div>
</div>

View file

@ -62,7 +62,7 @@ Feature: A teacher can use activity completion to track a student progress
And the "Submit answers" completion condition of "Test survey name" is displayed as "todo"
And I follow "Test survey name"
And the "Submit answers" completion condition of "Test survey name" is displayed as "todo"
And I press "Click here to continue"
And I press "Submit"
And I am on "Course 1" course homepage
And the "Submit answers" completion condition of "Test survey name" is displayed as "done"
And I follow "Test survey name"

View file

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

View file

@ -71,7 +71,9 @@ $strsurvey = get_string("modulename", "survey");
$PAGE->set_title($survey->name);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($survey->name));
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($survey->name));
}
// Render the activity information.
$completiondetails = \core_completion\cm_completion_details::get_instance($cm, $USER->id);
@ -90,11 +92,7 @@ if (has_capability('mod/survey:readresponses', $context) or ($groupmode == VISIB
$currentgroup = 0;
}
if (has_capability('mod/survey:readresponses', $context)) {
$numusers = survey_count_responses($survey->id, $currentgroup, $groupingid);
echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\">".
get_string("viewsurveyresponses", "survey", $numusers)."</a></div>";
} else if (!$cm->visible) {
if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
}
@ -103,9 +101,7 @@ if (!is_enrolled($context)) {
}
if ($surveyalreadydone) {
$numusers = survey_count_responses($survey->id, $currentgroup, $groupingid);
if ($showscales) {
// Ensure that graph.php will allow the user to see the graph.
if (has_capability('mod/survey:readresponses', $context) || !$groupmode || groups_is_member($currentgroup)) {
@ -183,7 +179,7 @@ if (!is_enrolled($context)) {
$PAGE->requires->js_call_amd('mod_survey/validation', 'ensureRadiosChosen', array('surveyform'));
echo '<br />';
echo '<input type="submit" class="btn btn-primary" value="'.get_string("clicktocontinue", "survey").'" />';
echo '<input type="submit" class="btn btn-primary" value="'. get_string("submit"). '" />';
echo '</div>';
echo "</form>";