Skip to content

Commit

Permalink
MDL-13525 role name aliases used in stat reports; merged from MOODLE_…
Browse files Browse the repository at this point in the history
…19_STABLE
  • Loading branch information
skodak committed Feb 23, 2008
1 parent f698601 commit ceceb9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
13 changes: 9 additions & 4 deletions course/report/stats/graph.php
Expand Up @@ -23,7 +23,7 @@

require_login();
$context = get_context_instance(CONTEXT_COURSE, $course->id);

if (!has_capability('moodle/site:viewreports', $context)) {
error('You need do not have the required permission to view reports for this course');
}
Expand Down Expand Up @@ -75,11 +75,11 @@
$graph->y_format['line1'] = array('colour' => 'blue','line' => 'line','legend' => $param->line1);
if (!empty($param->line2)) {
$graph->y_order[] = 'line2';
$graph->y_format['line2'] = array('colour' => 'green','line' => 'line','legend' => $param->line2);
$graph->y_format['line2'] = array('colour' => 'green','line' => 'line','legend' => $param->line2);
}
if (!empty($param->line3)) {
$graph->y_order[] = 'line3';
$graph->y_format['line3'] = array('colour' => 'red','line' => 'line','legend' => $param->line3);
$graph->y_format['line3'] = array('colour' => 'red','line' => 'line','legend' => $param->line3);
}
$graph->y_tick_labels = false;

Expand All @@ -88,14 +88,19 @@
$times = array();
$roles = array();
$missedlines = array();
$rolenames = get_all_roles();
foreach ($rolenames as $r) {
$rolenames[$r->id] = $r->name;
}
$rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id));
foreach ($stats as $stat) {
$data[$stat->roleid][$stat->timeend] = $stat->line1;
if (!empty($stat->zerofixed)) {
$missedlines[] = $stat->timeend;
}
if ($stat->roleid != 0) {
if (!array_key_exists($stat->roleid,$roles)) {
$roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
$roles[$stat->roleid] = $rolenames[$stat->roleid];
}
} else {
if (!array_key_exists($stat->roleid,$roles)) {
Expand Down
27 changes: 16 additions & 11 deletions course/report/stats/report.php
Expand Up @@ -10,7 +10,7 @@
$courseoptions[$c->id] = $c->shortname;
}
}

$reportoptions = stats_get_report_options($course->id, $mode);
$timeoptions = report_stats_timeoptions($mode);
if (empty($timeoptions)) {
Expand All @@ -22,22 +22,22 @@
if ($mode == STATS_MODE_DETAILED) {
$param = stats_get_parameters($time,null,$course->id,$mode); // we only care about the table and the time string (if we have time)

$sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber
FROM '.$CFG->prefix.'stats_user_'.$param->table.' s
JOIN '.$CFG->prefix.'user u ON u.id = s.userid
$sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber
FROM '.$CFG->prefix.'stats_user_'.$param->table.' s
JOIN '.$CFG->prefix.'user u ON u.id = s.userid
WHERE courseid = '.$course->id
. ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
. ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '')
.' ORDER BY u.lastname, u.firstname ASC';

if (!$us = get_records_sql($sql)) {
error('Cannot enter detailed view: No users found for this course.');
}

foreach ($us as $u) {
$users[$u->userid] = fullname($u, true);
}

$table->align = array('left','left','left','left','left','left','left','left');
$table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true),
get_string('users'),choose_from_menu($users,'userid',$userid,'','','',true),
Expand Down Expand Up @@ -128,7 +128,7 @@
if (empty($param->crosstab)) {
$table->head[] = $param->line1;
if (!empty($param->line2)) {
$table->head[] = $param->line2;
$table->head[] = $param->line2;
}
}
if (empty($param->crosstab)) {
Expand All @@ -150,14 +150,19 @@
$roles = array();
$times = array();
$missedlines = array();
$rolenames = get_all_roles();
foreach ($rolenames as $r) {
$rolenames[$r->id] = $r->name;
}
$rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id));
foreach ($stats as $stat) {
if (!empty($stat->zerofixed)) {
$missedlines[] = $stat->timeend;
}
$data[$stat->timeend][$stat->roleid] = $stat->line1;
if ($stat->roleid != 0) {
if (!array_key_exists($stat->roleid,$roles)) {
$roles[$stat->roleid] = get_field('role','name','id',$stat->roleid);
$roles[$stat->roleid] = $rolenames[$stat->roleid];
}
} else {
if (!array_key_exists($stat->roleid,$roles)) {
Expand All @@ -183,7 +188,7 @@
}
}
}
krsort($rolesdata);
krsort($rolesdata);
$row = array_merge(array($times[$time]),$rolesdata);
if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
$row[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='
Expand All @@ -193,7 +198,7 @@
}
$table->data[] = $row;
}
krsort($roles);
krsort($roles);
$table->head = array_merge($table->head,$roles);
}
$table->head[] = get_string('logs');
Expand All @@ -203,6 +208,6 @@
}
print_table($table);
}
}
}

?>

0 comments on commit ceceb9d

Please sign in to comment.