diff --git a/password.php b/password.php
new file mode 100644
index 0000000..11f2724
--- /dev/null
+++ b/password.php
@@ -0,0 +1,50 @@
+.
+
+/**
+ * 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();
diff --git a/password_ajax.php b/password_ajax.php
new file mode 100644
index 0000000..47bb82a
--- /dev/null
+++ b/password_ajax.php
@@ -0,0 +1,49 @@
+.
+
+/**
+ * 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);
diff --git a/renderables.php b/renderables.php
index 0f2d483..dc3ced6 100644
--- a/renderables.php
+++ b/renderables.php
@@ -809,3 +809,61 @@ class url_helpers {
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;
+ }
+}
diff --git a/renderer.php b/renderer.php
index 039e01c..60e43c4 100644
--- a/renderer.php
+++ b/renderer.php
@@ -292,6 +292,15 @@ class mod_attendance_renderer extends plugin_renderer_base {
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.
*
@@ -306,12 +315,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
has_capability('mod/attendance:takeattendances', $sessdata->att->context) ||
has_capability('mod/attendance:changeattendances', $sessdata->att->context))) {
- $icon = new pix_icon('key', '', 'attendance');
- $attributes = array("class" => "btn-link p-a-0", "role" => "button",
- "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);
+ $icon = new attendance_password_icon($sess->studentpassword, $sess->id);
+ $actions .= $this->render($icon);
}
$date = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));
diff --git a/templates/attendance_password_icon.mustache b/templates/attendance_password_icon.mustache
new file mode 100644
index 0000000..2d1a928
--- /dev/null
+++ b/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"}
+ ]
+ }
+ }
+}}
+
+ {{#icon}}{{>core/pix_icon}}{{/icon}}{{#linktext}}{{.}}{{/linktext}}
+
\ No newline at end of file
diff --git a/templates/attendance_password_icon_boost.mustache b/templates/attendance_password_icon_boost.mustache
new file mode 100644
index 0000000..319b897
--- /dev/null
+++ b/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"}
+ ]
+ }
+ }
+}}
+
+ {{#pix}}key, attendance, {{alt}}{{/pix}}
+