Browse Source

New site-level/course category report for average course attendance.

MOODLE_33_STABLE
Dan Marsden 8 years ago
parent
commit
8d2967f4c6
  1. 104
      coursesummary.php
  2. 9
      db/access.php
  3. 3
      lang/en/attendance.php
  4. 3
      lib.php
  5. 48
      locallib.php
  6. 4
      version.php

104
coursesummary.php

@ -0,0 +1,104 @@
<?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/>.
/**
* Attendance course summary report.
*
* @package mod_attendance
* @copyright 2017 onwards Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot.'/mod/attendance/lib.php');
require_once($CFG->dirroot.'/mod/attendance/locallib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/coursecatlib.php');
$category = optional_param('category', 0, PARAM_INT);
$download = optional_param('download', '', PARAM_ALPHA);
$sort = optional_param('tsort', '', PARAM_ALPHA);
require_login();
if (empty($category)) {
$context = context_system::instance();
$courses = array(); // Show all courses.
} else {
$context = context_coursecat::instance($category);
$coursecat = coursecat::get($category);
$courses = $coursecat->get_courses(array('recursive' => true, 'idonly' => true));
}
// Check permissions.
require_capability('mod/attendance:viewsummaryreports', $context);
$exportfilename = 'attendancecoursesummary.csv';
$PAGE->set_url('/mod/attendance/coursesummary.php', array('category' => $category));
$PAGE->set_context(context_system::instance());
$PAGE->set_heading($SITE->fullname);
$table = new flexible_table('attendancecoursesummary');
$table->define_baseurl($PAGE->url);
if (!$table->is_downloading($download, $exportfilename)) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('coursesummary', 'mod_attendance'));
if (empty($category)) {
// Only show tabs if displaying via the admin page.
$tabmenu = attendance_print_settings_tabs('coursesummary');
echo $tabmenu;
}
}
$table->define_columns(array('course', 'percentage'));
$table->define_headers(array(get_string('course'),
get_string('averageattendance', 'attendance')));
$table->sortable(true);
$table->no_sorting('course');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'generaltable generalbox');
$table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$table->setup();
// Work out direction of sort required.
$sortcolumns = $table->get_sort_columns();
// Now do sorting if specified.
$orderby = ' ORDER BY percentage ASC';
if (!empty($sort)) {
$direction = ' DESC';
if (!empty($sortcolumns[$sort]) && $sortcolumns[$sort] == SORT_ASC) {
$direction = ' ASC';
}
$orderby = " ORDER BY $sort $direction";
}
$records = attendance_course_users_points($courses, $orderby);
foreach ($records as $record) {
if (!$table->is_downloading($download, $exportfilename)) {
$url = new moodle_url('/mod/attendance/index.php', array('id' => $record->courseid));
$name = html_writer::link($url, $record->coursename);
} else {
$name = $record->coursename;
}
$table->add_data(array($name, round($record->percentage * 100)."%"));
}
$table->finish_output();
if (!$table->is_downloading()) {
echo $OUTPUT->footer();
}

9
db/access.php

@ -132,4 +132,13 @@ $capabilities = array(
'manager' => CAP_ALLOW 'manager' => CAP_ALLOW
) )
), ),
// Allow access to site level reports.
'mod/attendance:viewsummaryreports' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSECAT,
'archetypes' => array(
'manager' => CAP_ALLOW
)
),
); );

3
lang/en/attendance.php

@ -57,6 +57,7 @@ $string['attendance:managetemporaryusers'] = 'Manage temporary users';
$string['attendance:takeattendances'] = 'Taking Attendances'; $string['attendance:takeattendances'] = 'Taking Attendances';
$string['attendance:view'] = 'Viewing Attendances'; $string['attendance:view'] = 'Viewing Attendances';
$string['attendance:viewreports'] = 'Viewing Reports'; $string['attendance:viewreports'] = 'Viewing Reports';
$string['attendance:viewsummaryreports'] = 'View course summary reports';
$string['attforblockdirstillexists'] = 'old mod/attforblock directory still exists - you must delete this directory on your server before running this upgrade.'; $string['attforblockdirstillexists'] = 'old mod/attforblock directory still exists - you must delete this directory on your server before running this upgrade.';
$string['attrecords'] = 'Attendances records'; $string['attrecords'] = 'Attendances records';
$string['calclose'] = 'Close'; $string['calclose'] = 'Close';
@ -396,3 +397,5 @@ $string['automark_help'] = 'When session closes, automatically set status for un
$string['studentmarking'] = 'Student recording'; $string['studentmarking'] = 'Student recording';
$string['automarktask'] = 'Check for closed attendance sessions that require auto marking'; $string['automarktask'] = 'Check for closed attendance sessions that require auto marking';
$string['autorecorded'] = 'system auto recorded'; $string['autorecorded'] = 'system auto recorded';
$string['coursesummary'] = 'Course summary report';
$string['averageattendance'] = 'Average attendance';

3
lib.php

@ -452,6 +452,9 @@ function attendance_print_settings_tabs($selected = 'settings') {
$tabs[] = new tabobject('defaultstatus', $CFG->wwwroot.'/mod/attendance/defaultstatus.php', $tabs[] = new tabobject('defaultstatus', $CFG->wwwroot.'/mod/attendance/defaultstatus.php',
get_string('defaultstatus', 'attendance'), get_string('defaultstatus', 'attendance'), false); get_string('defaultstatus', 'attendance'), get_string('defaultstatus', 'attendance'), false);
$tabs[] = new tabobject('coursesummary', $CFG->wwwroot.'/mod/attendance/coursesummary.php',
get_string('coursesummary', 'attendance'), get_string('coursesummary', 'attendance'), false);
ob_start(); ob_start();
print_tabs(array($tabs), $selected); print_tabs(array($tabs), $selected);
$tabmenu = ob_get_contents(); $tabmenu = ob_get_contents();

48
locallib.php

@ -649,3 +649,51 @@ function attendance_fill_groupid($formdata, &$sessions, $sess) {
} }
} }
} }
/**
* Generates a summary of points for the courses selected.
*
* @param array $courseids optional list of courses to return
* @param string $orderby - optional order by param
* @return stdClass
*/
function attendance_course_users_points($courseids = array(), $orderby = '') {
global $DB;
$where = '';
$params = array();
$where .= ' AND ats.sessdate < :enddate ';
$params['enddate'] = time();
$joingroup = 'LEFT JOIN {groups_members} gm ON (gm.userid = atl.studentid AND gm.groupid = ats.groupid)';
$where .= ' AND (ats.groupid = 0 or gm.id is NOT NULL)';
if (!empty($courseids)) {
list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$where .= ' AND c.id ' . $insql;
$params = array_merge($params, $inparams);
}
$sql = "SELECT courseid, coursename, sum(points) / sum(maxpoints) as percentage FROM (
SELECT a.id, a.course as courseid, c.fullname as coursename, atl.studentid AS userid, COUNT(DISTINCT ats.id) AS numtakensessions,
SUM(stg.grade) AS points, SUM(stm.maxgrade) AS maxpoints
FROM mdl_attendance_sessions ats
JOIN mdl_attendance a ON a.id = ats.attendanceid
JOIN mdl_course c ON c.id = a.course
JOIN mdl_attendance_log atl ON (atl.sessionid = ats.id)
JOIN mdl_attendance_statuses stg ON (stg.id = atl.statusid AND stg.deleted = 0 AND stg.visible = 1)
JOIN (SELECT attendanceid, setnumber, MAX(grade) AS maxgrade
FROM mdl_attendance_statuses
WHERE deleted = 0
AND visible = 1
GROUP BY attendanceid, setnumber) stm
ON (stm.setnumber = ats.statusset AND stm.attendanceid = ats.attendanceid)
{$joingroup}
WHERE ats.sessdate >= c.startdate
AND ats.lasttaken != 0
{$where}
GROUP BY a.id, a.course, c.fullname, atl.studentid
) p GROUP by courseid, coursename {$orderby}";
return $DB->get_records_sql($sql, $params);
}

4
version.php

@ -23,9 +23,9 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017050206; $plugin->version = 2017050207;
$plugin->requires = 2017042100; $plugin->requires = 2017042100;
$plugin->release = '3.3.6'; $plugin->release = '3.3.7';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0; $plugin->cron = 0;
$plugin->component = 'mod_attendance'; $plugin->component = 'mod_attendance';

Loading…
Cancel
Save