' . "\n";
echo '
' . $modulename . ' ' . $strviews . '
'."\n"
. $modulename . ' ' . $strposts . '
'."\n";
$table->initialbars($totalcount > $perpage);
$table->pagesize($perpage, $matchcount);
if ($uselegacyreader || $onlyuselegacyreader) {
list($actionsql, $actionparams) = report_participation_get_action_sql($action, $cm->modname);
$params = array_merge($params, $actionparams);
}
if (!$onlyuselegacyreader) {
list($crudsql, $crudparams) = report_participation_get_crud_sql($action);
$params = array_merge($params, $crudparams);
}
$usernamefields = get_all_user_name_fields(true, 'u');
$users = array();
// If using legacy log then get users from old table.
if ($uselegacyreader || $onlyuselegacyreader) {
$sql = "SELECT ra.userid, $usernamefields, u.idnumber, l.actioncount AS count
FROM (SELECT DISTINCT userid FROM {role_assignments} WHERE contextid $relatedctxsql AND roleid = :roleid ) ra
JOIN {user} u ON u.id = ra.userid
$groupsql
LEFT JOIN (
SELECT userid, COUNT(action) AS actioncount
FROM {log}
WHERE cmid = :instanceid
AND time > :timefrom " . $actionsql .
" GROUP BY userid) l ON (l.userid = ra.userid)";
if ($twhere) {
$sql .= ' WHERE '.$twhere; // Initial bar.
}
if ($table->get_sql_sort()) {
$sql .= ' ORDER BY '.$table->get_sql_sort();
}
if (!$users = $DB->get_records_sql($sql, $params, $table->get_page_start(), $table->get_page_size())) {
$users = array(); // Tablelib will handle saying 'Nothing to display' for us.
}
}
// Get record from sql_internal_table_reader and merge with records got from legacy log (if needed).
if (!$onlyuselegacyreader) {
$sql = "SELECT ra.userid, $usernamefields, u.idnumber, COUNT(DISTINCT l.timecreated) AS count
FROM {user} u
JOIN {role_assignments} ra ON u.id = ra.userid AND ra.contextid $relatedctxsql AND ra.roleid = :roleid
$groupsql
LEFT JOIN {" . $logtable . "} l
ON l.contextinstanceid = :instanceid
AND l.timecreated > :timefrom" . $crudsql ."
AND l.edulevel = :edulevel
AND l.anonymous = 0
AND l.contextlevel = :contextlevel
AND (l.origin = 'web' OR l.origin = 'ws')
AND l.userid = ra.userid";
// We add this after the WHERE statement that may come below.
$groupbysql = " GROUP BY ra.userid, $usernamefields, u.idnumber";
$params['edulevel'] = core\event\base::LEVEL_PARTICIPATING;
$params['contextlevel'] = CONTEXT_MODULE;
if ($twhere) {
$sql .= ' WHERE '.$twhere; // Initial bar.
}
$sql .= $groupbysql;
if ($table->get_sql_sort()) {
$sql .= ' ORDER BY '.$table->get_sql_sort();
}
if ($u = $DB->get_records_sql($sql, $params, $table->get_page_start(), $table->get_page_size())) {
if (empty($users)) {
$users = $u;
} else {
// Merge two users array.
foreach ($u as $key => $value) {
if (isset($users[$key]) && !empty($users[$key]->count)) {
if ($value->count) {
$users[$key]->count += $value->count;
}
} else {
$users[$key] = $value;
}
}
}
unset($u);
$u = null;
}
}
$data = array();
$a = new stdClass();
$a->count = $totalcount;
$a->items = format_string($role->name, true, array('context' => $context));
if ($matchcount != $totalcount) {
$a->count = $matchcount.'/'.$a->count;
}
echo '
'.get_string('counteditems', '', $a).'
'."\n";
if (!empty($CFG->messaging)) {
echo '
'."\n";
$options = new stdClass();
$options->courseid = $course->id;
$options->noteStateNames = note_get_state_names();
$options->stateHelpIcon = $OUTPUT->help_icon('publishstate', 'notes');
$PAGE->requires->js_call_amd('core_user/participants', 'init', [$options]);
}
echo '
'."\n";
}
echo $OUTPUT->footer();