Fixed group mode
This commit is contained in:
parent
6821122c30
commit
ba12c4d42b
3 changed files with 59 additions and 45 deletions
81
locallib.php
81
locallib.php
|
@ -402,6 +402,11 @@ function customcert_get_issues($customcertid, $groupmode, $cm, $page, $perpage)
|
||||||
// Get the conditional SQL.
|
// Get the conditional SQL.
|
||||||
list($conditionssql, $conditionsparams) = customcert_get_conditional_issues_sql($cm, $groupmode);
|
list($conditionssql, $conditionsparams) = customcert_get_conditional_issues_sql($cm, $groupmode);
|
||||||
|
|
||||||
|
// If it is empty then return an empty array.
|
||||||
|
if (empty($conditionsparams)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
// Add the conditional SQL and the customcertid to form all used parameters.
|
// Add the conditional SQL and the customcertid to form all used parameters.
|
||||||
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
||||||
|
|
||||||
|
@ -431,6 +436,11 @@ function customcert_get_number_of_issues($customcertid, $cm, $groupmode) {
|
||||||
// Get the conditional SQL.
|
// Get the conditional SQL.
|
||||||
list($conditionssql, $conditionsparams) = customcert_get_conditional_issues_sql($cm, $groupmode);
|
list($conditionssql, $conditionsparams) = customcert_get_conditional_issues_sql($cm, $groupmode);
|
||||||
|
|
||||||
|
// If it is empty then return 0.
|
||||||
|
if (empty($conditionsparams)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Add the conditional SQL and the customcertid to form all used parameters.
|
// Add the conditional SQL and the customcertid to form all used parameters.
|
||||||
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
$allparams = $conditionsparams + array('customcertid' => $customcertid);
|
||||||
|
|
||||||
|
@ -453,55 +463,58 @@ function customcert_get_number_of_issues($customcertid, $cm, $groupmode) {
|
||||||
* @return array the conditional variables
|
* @return array the conditional variables
|
||||||
*/
|
*/
|
||||||
function customcert_get_conditional_issues_sql($cm, $groupmode) {
|
function customcert_get_conditional_issues_sql($cm, $groupmode) {
|
||||||
global $CFG, $DB;
|
global $DB, $USER;
|
||||||
|
|
||||||
// Get all users that can manage this customcert to exclude them from the report.
|
// Get all users that can manage this customcert to exclude them from the report.
|
||||||
$context = context_module::instance($cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
$conditionssql = '';
|
$conditionssql = '';
|
||||||
$conditionsparams = array();
|
$conditionsparams = array();
|
||||||
if ($certmanagers = array_keys(get_users_by_capability($context, 'mod/customcert:manage', 'u.id'))) {
|
|
||||||
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
|
|
||||||
$conditionssql .= "AND NOT u.id $sql \n";
|
|
||||||
$conditionsparams += $params;
|
|
||||||
}
|
|
||||||
|
|
||||||
$restricttogroup = false;
|
// Get all users that can manage this certificate to exclude them from the report.
|
||||||
|
$certmanagers = array_keys(get_users_by_capability($context, 'mod/certificate:manage', 'u.id'));
|
||||||
|
$certmanagers = array_merge($certmanagers, array_keys(get_admins()));
|
||||||
|
list($sql, $params) = $DB->get_in_or_equal($certmanagers, SQL_PARAMS_NAMED, 'cert');
|
||||||
|
$conditionssql .= "AND NOT u.id $sql \n";
|
||||||
|
$conditionsparams += $params;
|
||||||
|
|
||||||
if ($groupmode) {
|
if ($groupmode) {
|
||||||
|
$canaccessallgroups = has_capability('moodle/site:accessallgroups', $context);
|
||||||
$currentgroup = groups_get_activity_group($cm);
|
$currentgroup = groups_get_activity_group($cm);
|
||||||
|
|
||||||
|
// If we are viewing all participants and the user does not have access to all groups then return nothing.
|
||||||
|
if (!$currentgroup && !$canaccessallgroups) {
|
||||||
|
return array('', array());
|
||||||
|
}
|
||||||
|
|
||||||
if ($currentgroup) {
|
if ($currentgroup) {
|
||||||
$restricttogroup = true;
|
if (!$canaccessallgroups) {
|
||||||
|
// Guest users do not belong to any groups.
|
||||||
|
if (isguestuser()) {
|
||||||
|
return array('', array());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the user belongs to the group we are viewing.
|
||||||
|
$usersgroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid);
|
||||||
|
if ($usersgroups) {
|
||||||
|
if (!isset($usersgroups[$currentgroup])) {
|
||||||
|
return array('', array());
|
||||||
|
}
|
||||||
|
} else { // They belong to no group, so return an empty array.
|
||||||
|
return array('', array());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$groupusers = array_keys(groups_get_members($currentgroup, 'u.*'));
|
$groupusers = array_keys(groups_get_members($currentgroup, 'u.*'));
|
||||||
if (empty($groupusers)) {
|
if (empty($groupusers)) {
|
||||||
return array();
|
return array('', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list($sql, $params) = $DB->get_in_or_equal($groupusers, SQL_PARAMS_NAMED, 'grp');
|
||||||
|
$conditionssql .= "AND u.id $sql ";
|
||||||
|
$conditionsparams += $params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$restricttogrouping = false;
|
|
||||||
|
|
||||||
// If groupmembersonly used, remove users who are not in any group.
|
|
||||||
if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
|
|
||||||
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
|
|
||||||
$restricttogrouping = true;
|
|
||||||
} else {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($restricttogroup || $restricttogrouping) {
|
|
||||||
if ($restricttogroup) {
|
|
||||||
$allowedusers = $groupusers;
|
|
||||||
} else if ($restricttogroup && $restricttogrouping) {
|
|
||||||
$allowedusers = array_intersect($groupusers, $groupingusers);
|
|
||||||
} else {
|
|
||||||
$allowedusers = $groupingusers;
|
|
||||||
}
|
|
||||||
|
|
||||||
list($sql, $params) = $DB->get_in_or_equal($allowedusers, SQL_PARAMS_NAMED, 'grp');
|
|
||||||
$conditionssql .= "AND u.id $sql \n";
|
|
||||||
$conditionsparams += $params;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($conditionssql, $conditionsparams);
|
return array($conditionssql, $conditionsparams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,10 @@ $context = context_module::instance($cm->id);
|
||||||
require_capability('mod/customcert:manage', $context);
|
require_capability('mod/customcert:manage', $context);
|
||||||
|
|
||||||
// Get the users who have been issued.
|
// Get the users who have been issued.
|
||||||
$users = customcert_get_issues($customcert->id, groups_get_activity_groupmode($cm), $cm, $page, $perpage);
|
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||||
|
groups_get_activity_group($cm, true);
|
||||||
|
}
|
||||||
|
$users = customcert_get_issues($customcert->id, $groupmode, $cm, $page, $perpage);
|
||||||
|
|
||||||
if ($download) {
|
if ($download) {
|
||||||
customcert_generate_report_file($customcert, $users, $download);
|
customcert_generate_report_file($customcert, $users, $download);
|
||||||
|
|
18
view.php
18
view.php
|
@ -58,22 +58,19 @@ if ($customcert->requiredtime && !has_capability('mod/certificate:manage', $cont
|
||||||
// Check that no action was passed, if so that means we are not outputting to PDF.
|
// Check that no action was passed, if so that means we are not outputting to PDF.
|
||||||
if (empty($action)) {
|
if (empty($action)) {
|
||||||
// Get the current groups mode.
|
// Get the current groups mode.
|
||||||
groups_print_activity_menu($cm, $pageurl);
|
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||||
$currentgroup = groups_get_activity_group($cm);
|
groups_get_activity_group($cm, true);
|
||||||
$groupmode = groups_get_activity_groupmode($cm);
|
}
|
||||||
|
|
||||||
// Generate the link to the report if there are issues to display.
|
// Generate the link to the report if there are issues to display.
|
||||||
$reportlink = '';
|
$reportlink = '';
|
||||||
if (has_capability('mod/customcert:manage', $context)) {
|
if (has_capability('mod/customcert:manage', $context)) {
|
||||||
// Get the total number of issues.
|
// Get the total number of issues.
|
||||||
$numissues = customcert_get_number_of_issues($customcert->id, $cm, $groupmode);
|
$numissues = customcert_get_number_of_issues($customcert->id, $cm, $groupmode);
|
||||||
// If the number of issues is greater than 0 display a link to the report.
|
$href = new moodle_urL('/mod/customcert/report.php', array('id' => $cm->id));
|
||||||
if ($numissues > 0) {
|
$url = html_writer::tag('a', get_string('viewcustomcertissues', 'customcert', $numissues),
|
||||||
$href = new moodle_urL('/mod/customcert/report.php', array('id' => $cm->id));
|
array('href' => $href->out()));
|
||||||
$url = html_writer::tag('a', get_string('viewcustomcertissues', 'customcert', $numissues),
|
$reportlink = html_writer::tag('div', $url, array('class' => 'reportlink'));
|
||||||
array('href' => $href->out()));
|
|
||||||
$reportlink = html_writer::tag('div', $url, array('class' => 'reportlink'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the intro content if it exists.
|
// Generate the intro content if it exists.
|
||||||
|
@ -111,6 +108,7 @@ if (empty($action)) {
|
||||||
|
|
||||||
// Output all the page data.
|
// Output all the page data.
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
groups_print_activity_menu($cm, $pageurl);
|
||||||
echo $reportlink;
|
echo $reportlink;
|
||||||
echo $intro;
|
echo $intro;
|
||||||
echo $issuelist;
|
echo $issuelist;
|
||||||
|
|
Loading…
Reference in a new issue