Browse Source

Improve password-pop-up handling.

MOODLE_32_STABLE
Dan Marsden 8 years ago
parent
commit
39644e9476
  1. 50
      password.php
  2. 49
      password_ajax.php
  3. 58
      renderables.php
  4. 17
      renderer.php
  5. 22
      templates/attendance_password_icon.mustache
  6. 28
      templates/attendance_password_icon_boost.mustache

50
password.php

@ -0,0 +1,50 @@
<?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/>.
/**
* Displays help via AJAX call or in a new page
*
* Use {@link core_renderer::help_icon()} or {@link addHelpButton()} to display
* the help icon.
*
* @copyright 2002 onwards Martin Dougiamas
* @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__).'/../../config.php');
$session = required_param('session', PARAM_INT);
$session = $DB->get_record('attendance_sessions', array('id' => $session), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('attendance', $session->attendanceid);
$context = context_module::instance($cm->id);
$capabilities = array('mod/attendance:manageattendances', 'mod/attendance:takeattendances','mod/attendance:changeattendances');
if (!has_any_capability($capabilities, $context)) {
exit;
}
$PAGE->set_url('/mod/attendance/password.php');
$PAGE->set_pagelayout('popup');
$PAGE->set_context(context_system::instance());
$PAGE->set_title(get_string('password', 'attendance'));
echo $OUTPUT->header();
echo html_writer::span($session->studentpassword, 'student-password');
echo $OUTPUT->footer();

49
password_ajax.php

@ -0,0 +1,49 @@
<?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/>.
/**
* Displays help via AJAX call or in a new page
*
* Use {@link core_renderer::help_icon()} or {@link addHelpButton()} to display
* the help icon.
*
* @copyright 2002 onwards Martin Dougiamas
* @package core
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once(dirname(__FILE__).'/../../config.php');
$session = required_param('session', PARAM_INT);
$session = $DB->get_record('attendance_sessions', array('id' => $session), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('attendance', $session->attendanceid);
$context = context_module::instance($cm->id);
$capabilities = array('mod/attendance:manageattendances', 'mod/attendance:takeattendances','mod/attendance:changeattendances');
if (!has_any_capability($capabilities, $context)) {
exit;
}
$PAGE->set_url('/mod/attendance/password.php');
$PAGE->set_pagelayout('popup');
$PAGE->set_context(context_system::instance());
$data->heading = '';
$data->text = html_writer::span($session->studentpassword, 'student-password');
echo json_encode($data);

58
renderables.php

@ -809,3 +809,61 @@ class url_helpers {
return $att->url_view($params); return $att->url_view($params);
} }
} }
/**
* Data structure representing an attendance password icon.
* copied from help_icon class
*
* @copyright 2017 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class attendance_password_icon implements renderable, templatable {
/**
* @var string text to show
*/
public $text;
/**
* @var string Extra descriptive text next to the icon
*/
public $linktext = null;
/**
* Constructor
*
* @param string $identifier string for help page title,
* string with _help suffix is used for the actual help text.
* string with _link suffix is used to create a link to further info (if it exists)
* @param string $component
*/
public function __construct($text, $sessionid) {
$this->text = $text;
$this->sessionid = $sessionid;
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return array
*/
public function export_for_template(renderer_base $output) {
$title = get_string('password', 'attendance');
$data = new stdClass();
$data->heading = '';
$data->text = $this->text;
$data->alt = $title;
$data->icon = (new pix_icon('key', '', 'attendance'))->export_for_template($output);
$data->linktext = '';
$data->title = $title;
$data->url = (new moodle_url('/mod/attendance/password.php', [
'session' => $this->sessionid]))->out(false);
$data->ltr = !right_to_left();
return $data;
}
}

17
renderer.php

@ -292,6 +292,15 @@ class mod_attendance_renderer extends plugin_renderer_base {
return html_writer::table($table); return html_writer::table($table);
} }
/**
* Implementation of user image rendering.
*
* @param help_icon $helpicon A help icon instance
* @return string HTML fragment
*/
protected function render_attendance_password_icon(attendance_password_icon $helpicon) {
return $this->render_from_template('attendance/attendance_password_icon', $helpicon->export_for_template($this));
}
/** /**
* Construct date time actions. * Construct date time actions.
* *
@ -306,12 +315,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
has_capability('mod/attendance:takeattendances', $sessdata->att->context) || has_capability('mod/attendance:takeattendances', $sessdata->att->context) ||
has_capability('mod/attendance:changeattendances', $sessdata->att->context))) { has_capability('mod/attendance:changeattendances', $sessdata->att->context))) {
$icon = new pix_icon('key', '', 'attendance'); $icon = new attendance_password_icon($sess->studentpassword, $sess->id);
$attributes = array("class" => "btn-link p-a-0", "role" => "button", $actions .= $this->render($icon);
"data-toggle" => "popover", "data-placement" => "left", "data-html" => "true",
"tabindex" => "0", "data-trigger" => "manual");
$attributes['data-content'] = html_writer::span($sess->studentpassword, 'student-pass');
$actions .= html_writer::tag('a', $this->output->render($icon), $attributes);
} }
$date = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance')); $date = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));

22
templates/attendance_password_icon.mustache

@ -0,0 +1,22 @@
{{!
@template attendance/attendance_password_icon
attendance_password icon.
Example context (json):
{
"title": "Help with something",
"url": "http://example.org/help",
"linktext": "",
"icon":{
"attributes": [
{"name": "class", "value": "iconhelp"},
{"name": "src", "value": "../../../pix/help.svg"},
{"name": "alt", "value": "Help icon"}
]
}
}
}}
<span class="helptooltip">
<a href="{{url}}" title={{#quote}}{{title}}{{/quote}} aria-haspopup="true" target="_blank">{{#icon}}{{>core/pix_icon}}{{/icon}}{{#linktext}}{{.}}{{/linktext}}</a>
</span>

28
templates/attendance_password_icon_boost.mustache

@ -0,0 +1,28 @@
{{!
@template attendance/attendance_password_icon Boost Example.
This is an example of a template you could copy into a boost based theme to use proper popover.
At the moment we cannot specify different templates to use in plugin so we use
a cross-compatible link based pop-up for the password.
attendance_password icon.
Example context (json):
{
"title": "Help with something",
"url": "http://example.org/help",
"linktext": "",
"icon":{
"attributes": [
{"name": "class", "value": "iconhelp"},
{"name": "src", "value": "../../../pix/help.svg"},
{"name": "alt", "value": "Help icon"}
]
}
}
}}
<a class="btn btn-link p-a-0" role="button"
data-container="body" data-toggle="popover"
data-placement="{{#ltr}}left{{/ltr}}{{^ltr}}right{{/ltr}}" data-content="<span class='student-pass'>{{text}}</span> {{completedoclink}}"
data-html="true" tabindex="0" data-trigger="focus">
{{#pix}}key, attendance, {{alt}}{{/pix}}
</a>
Loading…
Cancel
Save