Skip to content

Commit

Permalink
Breadrumbs and company
Browse files Browse the repository at this point in the history
The original target of this work was the normalisation of breadcrumbs.
At the end of this work, the only aspect that has not yet been definitively put in order is the normalisation of breadcrumbs. The MDL-80602 solution will probably show how to deal with this problem correctly.

Using the classic theme, all pages in the module when selected are now highlighted in bold in the navigation block and the administration block.

Surveypro logical structure is, as known:
[Spro area] surveypro (managed in view.php)
    - [Area section] cover
    - [Area section] submissionslist
    - [Area section] submissionform
    - [Area section] searchsubmissions
[Spro area] layout (managed in layout.php)
    - [Area section] itemslist
    - [Area section] itemsetup
    - [Area section] branchingvalidation
    - [Area section] preview
[Spro area] reports (managed in reports.php)
    - [report] attachement overview
    - [report] frequency distribution
    - [report] late users
    - [report] responses per user
    - [report] users per count of responses
[Spro area] tools (managed in tools.php)
    - [Area section] export
    - [Area section] import
[Spro area] user templates (managed in utemplates.php)
    - [Area section] manage
    - [Area section] save
    - [Area section] import
    - [Area section] apply
[Spro area] master templates (managed in mtemplates.php)
    - [Area section] save
    - [Area section] apply

Page highlighting in the two blocks is extended to each section of each area. The links of the blocks in 'standard' conditions refer to each area in its default section. For the definition of the area default section I introduced the function: surveypro_get_defaults_section_per_area on lib.php.

To realise this highlighting I needed to introduce the two variables $area and $section throughout all the code.

While writing this code, I realised that the reports listed in the page of [area]: surveypro [section]: cover were different from those listed in the jump menu of [area]: report. I therefore standardised the procedure for identifying the reports allowed based on the user's capability. The definition is in $reportman->is_report_allowed().

In order to prevent any past or future errors from introducing data into the reports that the generic user is not supposed to see (GDPR, EU regulation 2016/679), I introduced at the level of reportbase class the property $onlypersonaldata. This property is true if the user does not have the capability 'mod/surveypro:accessreports' but does have the capability 'mod/surveypro:accessownreports'.

A report, with this correction, is shown IF AND ONLY IF the user requesting it has one of these two capabilities: 'mod/surveypro:accessreports' or 'mod/surveypro:accessownreports'.
The truth table for accessing reports is the following:

|                    | accessownreports: yes    | accessownreports: no   |
| accessreports: yes | display general report   | display general report |
| accessreports: no  | $onlypersonaldata = true | reports are denied     |

If $onlypersonaldata == true, a report is shown using as referring database ONLY THE SUBMISSIONS OF THE USER.

Because of the introduction of $onlypersonaldata I removed the method $reportman->get_hasstudentreport() as it has not any more a meaning. Each report is accessible to students. In the worst case students will see the report of their own submissions only if $onlypersonaldata = true.
  • Loading branch information
kordan authored and stronk7 committed Feb 25, 2024
1 parent fbd1491 commit 7a531c5
Show file tree
Hide file tree
Showing 36 changed files with 557 additions and 354 deletions.
7 changes: 5 additions & 2 deletions classes/cover.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function display_cover() {
$paramurl = [];
$paramurl['s'] = $this->cm->instance;
$paramurl['mode'] = SURVEYPRO_NEWRESPONSEMODE;
$paramurl['area'] = 'surveypro';
$paramurl['section'] = 'submissionform';
$paramurl['begin'] = 1;
$url = new \moodle_url('/mod/surveypro/view.php', $paramurl);
Expand Down Expand Up @@ -192,13 +193,14 @@ public function display_cover() {

// Begin of: report section.
$surveyproreportlist = get_plugin_list('surveyproreport');
$paramurl = ['s' => $this->cm->instance];
$paramurl = ['s' => $this->cm->instance, 'area' => 'reports', 'section' => 'apply'];

foreach ($surveyproreportlist as $reportname => $pluginpath) {
$classname = 'surveyproreport_'.$reportname.'\report';
$reportman = new $classname($this->cm, $this->context, $this->surveypro);
$reportman->setup();

if ($reportman->is_report_allowed($reportname)) {
if ($reportman->is_report_allowed()) {
if ($childrenreports = $reportman->get_haschildrenreports()) {
$linklabel = get_string('pluginname', 'surveyproreport_'.$reportname);
$this->add_report_link($childrenreports, $reportname, $messages, $linklabel);
Expand All @@ -217,6 +219,7 @@ public function display_cover() {
// End of: report section.

// Begin of: user templates section.
$paramurl = ['s' => $this->cm->instance, 'area' => 'utemplates'];
if ($canmanageusertemplates) {
$paramurl['section'] = 'manage';
$url = new \moodle_url('/mod/surveypro/utemplates.php', $paramurl);
Expand Down
6 changes: 6 additions & 0 deletions classes/layout_itemsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public function display_items_table() {
if ($reserved) {
$paramurl['act'] = SURVEYPRO_MAKEAVAILABLE;
$paramurl['sortindex'] = $sortindex;
$paramurl['area'] = 'layout';
$paramurl['section'] = 'itemslist';
$paramurl['sesskey'] = sesskey();

Expand All @@ -412,6 +413,7 @@ public function display_items_table() {
} else {
$paramurl['act'] = SURVEYPRO_MAKERESERVED;
$paramurl['sortindex'] = $sortindex;
$paramurl['area'] = 'layout';
$paramurl['section'] = 'itemslist';
$paramurl['sesskey'] = sesskey();

Expand Down Expand Up @@ -487,6 +489,7 @@ public function display_items_table() {
// SURVEYPRO_EDITITEM.
$paramurl = $paramurlbase;
$paramurl['mode'] = SURVEYPRO_EDITITEM;
$paramurl['area'] = 'layout';
$paramurl['section'] = 'itemsetup';

$link = new \moodle_url('/mod/surveypro/layout.php', $paramurl);
Expand Down Expand Up @@ -517,6 +520,7 @@ public function display_items_table() {
$paramurl = $paramurlbase;
$paramurl['act'] = SURVEYPRO_DELETEITEM;
$paramurl['sortindex'] = $sortindex;
$paramurl['area'] = 'layout';
$paramurl['section'] = 'itemslist';
$paramurl['sesskey'] = sesskey();

Expand Down Expand Up @@ -551,6 +555,7 @@ public function display_items_table() {
if ($currentindent !== false) { // It may be false like for labels with fullwidth == 1.
$paramurl = $paramurlbase;
$paramurl['act'] = SURVEYPRO_CHANGEINDENT;
$paramurl['area'] = 'layout';
$paramurl['section'] = 'itemslist';
$paramurl['sesskey'] = sesskey();

Expand Down Expand Up @@ -604,6 +609,7 @@ public function display_items_table() {
if (!empty($drawmoveherebox)) {
$paramurl = $paramurlmove;
$paramurl['lib'] = $sortindex;
$paramurl['area'] = 'layout';
$paramurl['section'] = 'itemslist';
$paramurl['sesskey'] = sesskey();

Expand Down
47 changes: 23 additions & 24 deletions classes/output/action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public function draw_view_action_bar(): string {

$canview = has_capability('mod/surveypro:view', $this->context);
$cansearch = has_capability('mod/surveypro:searchsubmissions', $this->context);

$utilitylayoutman = new utility_layout($this->cm, $this->surveypro);

$paramurl = ['s' => $this->surveypro->id];
$paramurl = ['s' => $this->surveypro->id, 'area' => 'surveypro'];

// View -> cover.
if ($canview) {
Expand Down Expand Up @@ -167,7 +168,7 @@ public function draw_layout_action_bar(): string {
$wheresql = 'surveyproid = :surveyproid AND parentid <> :parentid';
$countparents = $DB->count_records_select('surveypro_item', $wheresql, $whereparams);

$paramurl = ['s' => $this->surveypro->id];
$paramurl = ['s' => $this->surveypro->id, 'area' => 'layout'];

// Layout -> itemslist.
if ($canmanageitems) {
Expand Down Expand Up @@ -243,18 +244,18 @@ public function draw_tools_action_bar(): string {
$canimportresponses = has_capability('mod/surveypro:importresponses', $this->context);
$canexportresponses = has_capability('mod/surveypro:exportresponses', $this->context);

$paramurl = ['s' => $this->surveypro->id];
$paramurl = ['s' => $this->surveypro->id, 'area' => 'tools'];

// Begin of definition for urlselect.
// Tools -> export.
if ($canexportresponses) {
// Tools -> import.
if ($canimportresponses) {
$paramurl['section'] = 'import';
$linktoimport = new moodle_url('/mod/surveypro/tools.php', $paramurl);
$menu[$linktoimport->out(false)] = get_string('tools_import', 'mod_surveypro');
}

// Tools -> import.
if ($canimportresponses) {
// Tools -> export.
if ($canexportresponses) {
$paramurl['section'] = 'export';
$linktoexport = new moodle_url('/mod/surveypro/tools.php', $paramurl);
$menu[$linktoexport->out(false)] = get_string('tools_export', 'mod_surveypro');
Expand Down Expand Up @@ -298,7 +299,7 @@ public function draw_utemplates_action_bar(): string {

$riskyediting = ($this->surveypro->riskyeditdeadline > time());

$paramurl = ['s' => $this->surveypro->id];
$paramurl = ['s' => $this->surveypro->id, 'area' => 'utemplates'];

// Begin of definition for urlselect.
// Utemplates -> manage.
Expand Down Expand Up @@ -371,7 +372,7 @@ public function draw_mtemplates_action_bar(): string {

$riskyediting = ($this->surveypro->riskyeditdeadline > time());

$paramurl = ['s' => $this->surveypro->id];
$paramurl = ['s' => $this->surveypro->id, 'area' => 'mtemplates'];

// Begin of definition for urlselect.
// Mtemplates -> save.
Expand Down Expand Up @@ -424,28 +425,26 @@ public function draw_reports_action_bar(): string {
foreach ($surveyproreportlist as $reportname => $reportpath) {
$classname = 'surveyproreport_'.$reportname.'\report';
$reportman = new $classname($this->cm, $this->context, $this->surveypro);

$condition = $canaccessreports;
$condition = $condition || ($canaccessownreports && $reportman->get_hasstudentreport());
$condition = $condition && $reportman->report_applies_to($this->surveypro->template);

// GDPR condition.
$othercondition = !$reportman->get_displayusernames() || (empty($this->surveypro->anonymous) || $canalwaysseeowner);
$condition = $condition && $othercondition;
if ($condition) {
$linktoreport = new \moodle_url('/mod/surveypro/report/'.$reportname.'/view.php', ['s' => $this->cm->instance]);
$reportman->setup();
if ($reportman->is_report_allowed()) {
$paramurl = ['s' => $this->cm->instance, 'area' => 'reports', 'section' => 'view', 'report' => $reportname];
$linktoreport = new \moodle_url('/mod/surveypro/reports.php', $paramurl);
$menu[$linktoreport->out(false)] = get_string('pluginname', 'surveyproreport_'.$reportname);
}
}
}

$pageparams = $PAGE->url->params();

// Select the menu item according to the currenturl.
$regex = '~report=([a-z]*)$~';
if (preg_match($regex, $this->currenturl->out(true), $match)) {
$activeurl = new \moodle_url('/mod/surveypro/report/'.$match[1].'/view.php', ['s' => $this->cm->instance]);
$paramurl = ['s' => $this->surveypro->id, 'area' => 'reports', 'section' => 'view'];
if (isset($pageparams['report'])) {
$paramurl['report'] = $pageparams['report'];
$activeurl = new \moodle_url('/mod/surveypro/reports.php', $paramurl);
} else {
$reportname = reset($surveyproreportlist);
$activeurl = new \moodle_url('/mod/surveypro/report/'.$reportname.'/view.php', ['s' => $this->cm->instance]);
$report = reset($surveyproreportlist);
$paramurl['report'] = $report;
$activeurl = new \moodle_url('/mod/surveypro/reports.php', $paramurl);
}

$urlselect = new url_select($menu, $activeurl->out(false), null, 'viewactionselect');
Expand Down
37 changes: 25 additions & 12 deletions classes/reportbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ abstract class reportbase {
*/
public $additionalparams;

/**
* @var bool $onlypersonaldata
* The report I am asking should refer to my personal submissions only.
*/
public $onlypersonaldata;

/**
* Class constructor.
*
Expand All @@ -72,19 +78,24 @@ public function __construct($cm, $context, $surveypro) {
}

/**
* Does the current report apply to the passed mastertemplates?
* Setup.
*
* @param string $mastertemplate
* @return boolean
* Set $this->onlypersonaldata;
*/
abstract public function report_applies_to($mastertemplate);
public function setup() {
$canaccessreports = has_capability('mod/surveypro:accessreports', $this->context);
$canaccessownreports = has_capability('mod/surveypro:accessownreports', $this->context);

$this->onlypersonaldata = (!$canaccessreports && $canaccessownreports) ? true : false;
}

/**
* Returns if this report was created for student too.
* Does the current report apply to the passed mastertemplates?
*
* @param string $mastertemplate
* @return boolean
*/
abstract public static function get_hasstudentreport();
abstract public function report_applies_to($mastertemplate);

/**
* Does this report display user names.
Expand All @@ -111,16 +122,16 @@ public function prevent_direct_user_input() {
*/
public function is_report_allowed() {
$canaccessreports = has_capability('mod/surveypro:accessreports', $this->context);
$canalwaysseeowner = has_capability('mod/surveypro:alwaysseeowner', $this->context);
$canaccessownreports = has_capability('mod/surveypro:accessownreports', $this->context);
$canalwaysseeowner = has_capability('mod/surveypro:alwaysseeowner', $this->context);

$condition = $canaccessreports;
$condition = $condition || ($canaccessownreports && $this->get_hasstudentreport());
// General condition.
$condition = $canaccessreports || $canaccessownreports;
$condition = $condition && $this->report_applies_to($this->surveypro->template);

// GDPR condition.
$othercondition = !$this->get_displayusernames() || (empty($this->surveypro->anonymous) || $canalwaysseeowner);
$condition = $condition && $othercondition;
$gdprcondition = !$this->get_displayusernames() || (empty($this->surveypro->anonymous) || $canalwaysseeowner);
$condition = $condition && $gdprcondition;

return $condition;
}
Expand Down Expand Up @@ -349,7 +360,9 @@ public function get_paramurl(): array {

foreach ($this->additionalparams['optional'] as $variable => $type) {
$value = optional_param($variable, '', $type);
$paramurl[$variable] = $value;
if (!empty($value)) {
$paramurl[$variable] = $value;
}
}
foreach ($this->additionalparams['required'] as $variable => $type) {
$value = required_param($variable, $type);
Expand Down
7 changes: 4 additions & 3 deletions classes/submissions_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ public function display_submissions_table() {
$table->initialbars(true);
}

$paramurl = ['s' => $this->cm->instance, 'section' => 'submissionslist'];
$paramurl = ['s' => $this->cm->instance, 'area' => 'surveypro', 'section' => 'submissionslist'];
if ($this->searchquery) {
$paramurl['searchquery'] = $this->searchquery;
}
Expand Down Expand Up @@ -788,7 +788,7 @@ public function display_submissions_table() {
}

$tablerowcounter = 0;
$paramurlbase = ['s' => $this->cm->instance];
$paramurlbase = ['s' => $this->cm->instance, 'area' => 'surveypro', 'section' => 'submissionslist'];

foreach ($submissions as $submission) {
// Count each submission.
Expand Down Expand Up @@ -1018,6 +1018,7 @@ public function show_action_buttons($tifirst, $tilast) {
if ($addnew) {
$paramurl['mode'] = SURVEYPRO_NEWRESPONSEMODE;
$paramurl['begin'] = 1;
$paramurl['area'] = 'surveypro';
$paramurl['section'] = 'submissionform';

$addurl = new \moodle_url('/mod/surveypro/view.php', $paramurl);
Expand Down Expand Up @@ -1049,7 +1050,7 @@ public function show_action_buttons($tifirst, $tilast) {
}
} else {
$class = ['class' => 'buttons'];
$addbutton = new \single_button($addurl, get_string('addnewsubmission', 'mod_surveypro'), 'post', 'primary');
$addbutton = new \single_button($addurl, get_string('addnewsubmission', 'mod_surveypro'), 'get', 'primary');
$class = ['class' => 'buttons btn-secondary'];
$deleteallbutton = new \single_button($deleteurl, get_string('deleteallsubmissions', 'mod_surveypro'));

Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
$PAGE->set_heading($course->fullname);
// Is it useful? $PAGE->add_body_class('mediumwidth');.

// Output starts here.
echo $OUTPUT->header();
echo $OUTPUT->heading($strdataplural, 2);

Expand Down
Loading

0 comments on commit 7a531c5

Please sign in to comment.