Browse Source

Display user summary in mobile app.

MOODLE_35_STABLE
Dan Marsden 6 years ago
parent
commit
6542eee57e
  1. 86
      classes/output/mobile.php
  2. 21
      classes/summary.php
  3. 51
      db/mobile.php
  4. 3
      export.php
  5. 3
      lib.php
  6. 19
      renderer.php
  7. 15
      renderhelpers.php
  8. 74
      templates/mobile_view_page.mustache

86
classes/output/mobile.php

@ -0,0 +1,86 @@
<?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/>.
/**
* Contains the mobile output class for the attendance
*
* @package mod_attendance
* @copyright 2018 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_attendance\output;
defined('MOODLE_INTERNAL') || die();
/**
* Mobile output class for the attendance.
*
* @copyright 2018 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mobile {
/**
* Returns the initial page when viewing the activity for the mobile app.
*
* @param array $args Arguments from tool_mobile_get_content WS
* @return array HTML, javascript and other data
*/
public static function mobile_view_activity($args) {
global $OUTPUT, $DB, $USER, $PAGE, $CFG;
require_once($CFG->dirroot.'/mod/attendance/locallib.php');
$args = (object) $args;
$cmid = $args->cmid;
$courseid = $args->courseid;
$groupid = empty($args->group) ? 0 : $args->group; // By default, group 0.
// Capabilities check.
$cm = get_coursemodule_from_id('attendance', $cmid);
require_login($courseid, false , $cm, true, true);
$context = \context_module::instance($cm->id);
require_capability('mod/attendance:view', $context);
$attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$pageparams = new \mod_attendance_view_page_params();
$pageparams->studentid = $USER->id;
$pageparams->mode = \mod_attendance_view_page_params::MODE_THIS_COURSE;
$pageparams->view = 5; // Show all sessions for this course?
$att = new \mod_attendance_structure($attendance, $cm, $course, $context, $pageparams);
$summary = new \mod_attendance_summary($att->id, array($USER->id), $att->pageparams->startdate,
$att->pageparams->enddate);
$data = array('attendance' => $attendance,
'summary' => $summary->get_all_sessions_summary_for($USER->id));
return [
'templates' => [
[
'id' => 'main',
'html' => $OUTPUT->render_from_template('mod_attendance/mobile_view_page', $data),
],
],
'javascript' => '',
'otherdata' => ''
];
}
}

21
classes/summary.php

@ -137,6 +137,11 @@ class mod_attendance_summary {
$usersummary->userstakensessionsbyacronym = array(); $usersummary->userstakensessionsbyacronym = array();
} }
$usersummary->pointssessionscompleted = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' .
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
$usersummary->percentagesessionscompleted = format_float($usersummary->takensessionspercentage * 100) . '%';
return $usersummary; return $usersummary;
} }
@ -168,11 +173,25 @@ class mod_attendance_summary {
} }
$usersummary->allsessionspercentage = attendance_calc_fraction($usersummary->takensessionspoints, $usersummary->allsessionspercentage = attendance_calc_fraction($usersummary->takensessionspoints,
$usersummary->allsessionsmaxpoints); $usersummary->allsessionsmaxpoints);
$usersummary->allsessionspercentage = format_float($usersummary->allsessionspercentage * 100) . '%';
$deltapoints = $usersummary->allsessionsmaxpoints - $usersummary->takensessionsmaxpoints; $deltapoints = $usersummary->allsessionsmaxpoints - $usersummary->takensessionsmaxpoints;
$usersummary->maxpossiblepoints = $usersummary->takensessionspoints + $deltapoints; $usersummary->maxpossiblepoints = $usersummary->takensessionspoints + $deltapoints;
$usersummary->maxpossiblepercentage = attendance_calc_fraction($usersummary->maxpossiblepoints, $usersummary->maxpossiblepoints = format_float($usersummary->maxpossiblepoints, 1, true, true) . ' / ' .
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
$usersummary->maxpossiblepercentage = attendance_calc_fraction(($usersummary->takensessionspoints + $deltapoints),
$usersummary->allsessionsmaxpoints); $usersummary->allsessionsmaxpoints);
$usersummary->maxpossiblepercentage = format_float($usersummary->maxpossiblepercentage * 100) . '%';
$usersummary->pointssessionscompleted = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' .
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
$usersummary->percentagesessionscompleted = format_float($usersummary->takensessionspercentage * 100) . '%';
$usersummary->pointsallsessions = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' .
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
return $usersummary; return $usersummary;
} }

51
db/mobile.php

@ -0,0 +1,51 @@
<?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/>.
/**
* Defines mobile handlers.
*
* @package mod_attendance
* @copyright 2018 Dan Marsdenb
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$addons = [
'mod_attendance' => [
'handlers' => [
'view' => [
'displaydata' => [
'icon' => $CFG->wwwroot . '/mod/attendance/pix/icon.png',
'class' => '',
],
'delegate' => 'CoreCourseModuleDelegate',
'method' => 'mobile_view_activity'
]
],
'lang' => [ // Language strings that are used in all the handlers.
['pluginname', 'attendance'],
['sessionscompleted', 'attendance'],
['pointssessionscompleted', 'attendance'],
['percentagesessionscompleted', 'attendance'],
['sessionstotal', 'attendance'],
['pointsallsessions', 'attendance'],
['percentageallsessions', 'attendance'],
['maxpossiblepoints', 'attendance'],
['maxpossiblepercentage', 'attendance'],
]
]
];

3
export.php

@ -181,8 +181,7 @@ if ($formdata = $mform->get_data()) {
} }
$data->table[$i][] = $usersummary->numtakensessions; $data->table[$i][] = $usersummary->numtakensessions;
$data->table[$i][] = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $data->table[$i][] = $usersummary->pointssessionscompleted;
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
$data->table[$i][] = format_float($usersummary->takensessionspercentage * 100); $data->table[$i][] = format_float($usersummary->takensessionspercentage * 100);
$i++; $i++;

3
lib.php

@ -285,8 +285,7 @@ function attendance_user_outline($course, $user, $mod, $attendance) {
$summary = new mod_attendance_summary($attendance->id, $user->id); $summary = new mod_attendance_summary($attendance->id, $user->id);
$usersummary = $summary->get_all_sessions_summary_for($user->id); $usersummary = $summary->get_all_sessions_summary_for($user->id);
$result->info = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $result->info = $usersummary->pointsallsessions;
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
} }
return $result; return $result;

19
renderer.php

@ -978,12 +978,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
$usersummary = $userdata->summary[$ca->attid]->get_all_sessions_summary_for($userdata->user->id); $usersummary = $userdata->summary[$ca->attid]->get_all_sessions_summary_for($userdata->user->id);
$row->cells[] = $usersummary->numtakensessions; $row->cells[] = $usersummary->numtakensessions;
$row->cells[] = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $row->cells[] = $usersummary->pointssessionscompleted;
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
if (empty($usersummary->numtakensessions)) { if (empty($usersummary->numtakensessions)) {
$row->cells[] = '-'; $row->cells[] = '-';
} else { } else {
$row->cells[] = format_float($usersummary->takensessionspercentage * 100) . '%'; $row->cells[] = $usersummary->percentagesessionscompleted;
} }
} }
@ -1438,24 +1437,20 @@ class mod_attendance_renderer extends plugin_renderer_base {
$contrast = $startwithcontrast; $contrast = $startwithcontrast;
$row = new html_table_row(); $row = new html_table_row();
$row->cells[] = $this->build_data_cell($usersummary->numtakensessions, $contrast); $row->cells[] = $this->build_data_cell($usersummary->numtakensessions, $contrast);
$text = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $row->cells[] = $this->build_data_cell($usersummary->pointssessionscompleted, $contrast);
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
$row->cells[] = $this->build_data_cell($text, $contrast);
$row->cells[] = $this->build_data_cell(format_float($usersummary->takensessionspercentage * 100) . '%', $contrast); $row->cells[] = $this->build_data_cell(format_float($usersummary->takensessionspercentage * 100) . '%', $contrast);
if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) { if ($reportdata->pageparams->view == ATT_VIEW_SUMMARY) {
$contrast = !$contrast; $contrast = !$contrast;
$row->cells[] = $this->build_data_cell($usersummary->numallsessions, $contrast); $row->cells[] = $this->build_data_cell($usersummary->numallsessions, $contrast);
$text = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $text = $usersummary->pointsallsessions;
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
$row->cells[] = $this->build_data_cell($text, $contrast); $row->cells[] = $this->build_data_cell($text, $contrast);
$row->cells[] = $this->build_data_cell(format_float($usersummary->allsessionspercentage * 100) . '%', $contrast); $row->cells[] = $this->build_data_cell($usersummary->allsessionspercentage, $contrast);
$contrast = !$contrast; $contrast = !$contrast;
$text = format_float($usersummary->maxpossiblepoints, 1, true, true) . ' / ' . $text = $usersummary->maxpossiblepoints;
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
$row->cells[] = $this->build_data_cell($text, $contrast); $row->cells[] = $this->build_data_cell($text, $contrast);
$row->cells[] = $this->build_data_cell(format_float($usersummary->maxpossiblepercentage * 100) . '%', $contrast); $row->cells[] = $this->build_data_cell($usersummary->maxpossiblepercentage, $contrast);
} }
$rows[] = $row; $rows[] = $row;

15
renderhelpers.php

@ -394,14 +394,13 @@ function construct_user_data_stat($usersummary, $view) {
$row = new html_table_row(); $row = new html_table_row();
$row->attributes['class'] = 'normal'; $row->attributes['class'] = 'normal';
$row->cells[] = get_string('pointssessionscompleted', 'attendance') . ':'; $row->cells[] = get_string('pointssessionscompleted', 'attendance') . ':';
$row->cells[] = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $row->cells[] = $usersummary->pointssessionscompleted;
format_float($usersummary->takensessionsmaxpoints, 1, true, true);
$stattable->data[] = $row; $stattable->data[] = $row;
$row = new html_table_row(); $row = new html_table_row();
$row->attributes['class'] = 'normal'; $row->attributes['class'] = 'normal';
$row->cells[] = get_string('percentagesessionscompleted', 'attendance') . ':'; $row->cells[] = get_string('percentagesessionscompleted', 'attendance') . ':';
$row->cells[] = format_float($usersummary->takensessionspercentage * 100) . '%'; $row->cells[] = $usersummary->percentagesessionscompleted;
$stattable->data[] = $row; $stattable->data[] = $row;
if ($view == ATT_VIEW_ALL) { if ($view == ATT_VIEW_ALL) {
@ -414,27 +413,25 @@ function construct_user_data_stat($usersummary, $view) {
$row = new html_table_row(); $row = new html_table_row();
$row->attributes['class'] = 'highlight'; $row->attributes['class'] = 'highlight';
$row->cells[] = get_string('pointsallsessions', 'attendance') . ':'; $row->cells[] = get_string('pointsallsessions', 'attendance') . ':';
$row->cells[] = format_float($usersummary->takensessionspoints, 1, true, true) . ' / ' . $row->cells[] = $usersummary->pointsallsessions;
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
$stattable->data[] = $row; $stattable->data[] = $row;
$row = new html_table_row(); $row = new html_table_row();
$row->attributes['class'] = 'highlight'; $row->attributes['class'] = 'highlight';
$row->cells[] = get_string('percentageallsessions', 'attendance') . ':'; $row->cells[] = get_string('percentageallsessions', 'attendance') . ':';
$row->cells[] = format_float($usersummary->allsessionspercentage * 100) . '%'; $row->cells[] = $usersummary->allsessionspercentage;
$stattable->data[] = $row; $stattable->data[] = $row;
$row = new html_table_row(); $row = new html_table_row();
$row->attributes['class'] = 'normal'; $row->attributes['class'] = 'normal';
$row->cells[] = get_string('maxpossiblepoints', 'attendance') . ':'; $row->cells[] = get_string('maxpossiblepoints', 'attendance') . ':';
$row->cells[] = format_float($usersummary->maxpossiblepoints, 1, true, true) . ' / ' . $row->cells[] = $usersummary->maxpossiblepoints;
format_float($usersummary->allsessionsmaxpoints, 1, true, true);
$stattable->data[] = $row; $stattable->data[] = $row;
$row = new html_table_row(); $row = new html_table_row();
$row->attributes['class'] = 'normal'; $row->attributes['class'] = 'normal';
$row->cells[] = get_string('maxpossiblepercentage', 'attendance') . ':'; $row->cells[] = get_string('maxpossiblepercentage', 'attendance') . ':';
$row->cells[] = format_float($usersummary->maxpossiblepercentage * 100) . '%'; $row->cells[] = $usersummary->maxpossiblepercentage;
$stattable->data[] = $row; $stattable->data[] = $row;
} }

74
templates/mobile_view_page.mustache

@ -0,0 +1,74 @@
{{=<% %>=}}
<div>
<core-course-module-description description="<% attendance.intro %>" component="mod_attendance" componentId="<% cmid %>"></core-course-module-description>
<ion-item>
<ion-grid>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.sessionscompleted' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.numtakensessions %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.pointssessionscompleted' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.pointssessionscompleted %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.percentagesessionscompleted' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.percentagesessionscompleted %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.sessionstotal' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.numallsessions %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.pointsallsessions' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.percentagesessionscompleted %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.percentageallsessions' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.allsessionspercentage %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.maxpossiblepoints' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.maxpossiblepoints %>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-9 class="text-left">
{{ 'plugin.mod_attendance.maxpossiblepercentage' | translate }}
</ion-col>
<ion-col col-2 class="text-left">
<% summary.maxpossiblepercentage %>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</div>
Loading…
Cancel
Save