Browse Source

Implemented attforblock_user_outline and attforblock_user_outline

MOODLE_23_STABLE
Artem Andreev 14 years ago
parent
commit
ab2968730a
  1. 59
      lib.php
  2. 40
      renderer.php
  3. 37
      renderhelpers.php

59
lib.php

@ -164,17 +164,26 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) {
/// Used for user activity reports. /// Used for user activity reports.
/// $return->time = the time they did it /// $return->time = the time they did it
/// $return->info = a short text description /// $return->info = a short text description
global $CFG;
require_once('locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->libdir.'/gradelib.php');
if (isstudent($course->id, $user->id)) {
if ($sescount = get_attendance($user->id,$course, $attforblock)) { $grades = grade_get_grades($course->id, 'mod', 'attforblock', $attforblock->id, $user->id);
$strgrade = get_string('grade');
$maxgrade = get_maxgrade($user->id, $course,$attforblock); $result = new stdClass();
$usergrade = get_grade($user->id, $course,$attforblock); if (!empty($grades->items[0]->grades)) {
$percent = get_percent($user->id,$course, $attforblock); $grade = reset($grades->items[0]->grades);
$result->info = "$strgrade: $usergrade / $maxgrade ($percent%)"; $result->time = $grade->dategraded;
} }
else
$result->time = 0;
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) {
$statuses = get_statuses($attforblock->id);
$grade = get_user_grade(get_user_statuses_stat($attforblock->id, $course->startdate, $user->id), $statuses);
$maxgrade = get_user_max_grade(get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses);
$result->info = $grade.' / '.$maxgrade;
} }
return $result; return $result;
@ -183,14 +192,32 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) {
function attforblock_user_complete($course, $user, $mod, $attforblock) { function attforblock_user_complete($course, $user, $mod, $attforblock) {
/// Print a detailed representation of what a user has done with /// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports. /// a given particular instance of this module, for user activity reports.
global $CFG;
require_once('locallib.php'); require_once(dirname(__FILE__).'/renderhelpers.php');
require_once($CFG->libdir.'/gradelib.php');
if (isstudent($course->id, $user->id)) { if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) {
// if (! $cm = get_coursemodule_from_instance("attforblock", $attforblock->id, $course->id)) { $gradeable = $attforblock->grade > 0;
// error("Course Module ID was incorrect"); $statuses = get_statuses($attforblock->id);
// } $userstatusesstat = get_user_statuses_stat($attforblock->id, $course->startdate, $user->id);
print_user_attendaces($user, $mod, $attforblock, $course); $stat['completed'] = get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id);
$stat['statuses'] = $userstatusesstat;
if ($gradeable) {
$grade = get_user_grade($userstatusesstat, $statuses);
$maxgrade = get_user_max_grade(get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses);
if (!$decimalpoints = grade_get_setting($course->id, 'decimalpoints')) {
$decimalpoints = $CFG->grade_decimalpoints;
}
}
else {
$grade = 0;
$maxgrade = 0;
$decimalpoints = 0;
}
echo construct_user_data_stat($stat, $statuses,
$gradeable, $grade, $maxgrade, $decimalpoints);
} }
//return true; //return true;

40
renderer.php

@ -538,7 +538,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
if ($userdata->pageparams->mode == att_view_page_params::MODE_THIS_COURSE) { if ($userdata->pageparams->mode == att_view_page_params::MODE_THIS_COURSE) {
$o .= html_writer::empty_tag('hr'); $o .= html_writer::empty_tag('hr');
$o .= $this->construct_user_data_stat($userdata->stat, $userdata->statuses, $o .= construct_user_data_stat($userdata->stat, $userdata->statuses,
$userdata->gradable, $userdata->grade, $userdata->maxgrade, $userdata->decimalpoints); $userdata->gradable, $userdata->grade, $userdata->maxgrade, $userdata->decimalpoints);
$o .= $this->render_attforblock_filter_controls($userdata->filtercontrols); $o .= $this->render_attforblock_filter_controls($userdata->filtercontrols);
@ -556,7 +556,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
} }
$o .= html_writer::tag('h4', $ca->attname); $o .= html_writer::tag('h4', $ca->attname);
$o .= $this->construct_user_data_stat($userdata->stat[$ca->attid], $userdata->statuses[$ca->attid], $o .= construct_user_data_stat($userdata->stat[$ca->attid], $userdata->statuses[$ca->attid],
$userdata->gradable[$ca->attid], $userdata->grade[$ca->attid], $userdata->gradable[$ca->attid], $userdata->grade[$ca->attid],
$userdata->maxgrade[$ca->attid], $userdata->decimalpoints); $userdata->maxgrade[$ca->attid], $userdata->decimalpoints);
} }
@ -565,42 +565,6 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o; return $o;
} }
private function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade, $decimalpoints) {
$stattable = new html_table();
$stattable->attributes['class'] = 'list';
$row = new html_table_row();
$row->cells[] = get_string('sessionscompleted','attforblock').':';
$row->cells[] = $stat['completed'];
$stattable->data[] = $row;
foreach ($statuses as $st) {
$row = new html_table_row();
$row->cells[] = $st->description . ':';
$row->cells[] = array_key_exists($st->id, $stat['statuses']) ? $stat['statuses'][$st->id]->stcnt : 0;
$stattable->data[] = $row;
}
if ($gradable) {
$row = new html_table_row();
$row->cells[] = get_string('attendancegrade','attforblock') . ':';
$row->cells[] = $grade . ' / ' . $maxgrade;
$stattable->data[] = $row;
$row = new html_table_row();
$row->cells[] = get_string('attendancepercent','attforblock') . ':';
if ($maxgrade == 0) {
$percent = 0;
} else {
$percent = $grade / $maxgrade * 100;
}
$row->cells[] = sprintf("%0.{$decimalpoints}f", $percent);
$stattable->data[] = $row;
}
return html_writer::table($stattable);
}
private function construct_user_sessions_log(attforblock_user_data $userdata) { private function construct_user_sessions_log(attforblock_user_data $userdata) {
$table = new html_table(); $table = new html_table();
$table->attributes['class'] = 'generaltable attwidth boxaligncenter'; $table->attributes['class'] = 'generaltable attwidth boxaligncenter';

37
renderhelpers.php

@ -168,4 +168,41 @@ function construct_session_full_date_time($datetime, $duration) {
return $sessinfo; return $sessinfo;
} }
function construct_user_data_stat($stat, $statuses, $gradable, $grade, $maxgrade, $decimalpoints) {
$stattable = new html_table();
$stattable->attributes['class'] = 'list';
$row = new html_table_row();
$row->cells[] = get_string('sessionscompleted','attforblock').':';
$row->cells[] = $stat['completed'];
$stattable->data[] = $row;
foreach ($statuses as $st) {
$row = new html_table_row();
$row->cells[] = $st->description . ':';
$row->cells[] = array_key_exists($st->id, $stat['statuses']) ? $stat['statuses'][$st->id]->stcnt : 0;
$stattable->data[] = $row;
}
if ($gradable) {
$row = new html_table_row();
$row->cells[] = get_string('attendancegrade','attforblock') . ':';
$row->cells[] = $grade . ' / ' . $maxgrade;
$stattable->data[] = $row;
$row = new html_table_row();
$row->cells[] = get_string('attendancepercent','attforblock') . ':';
if ($maxgrade == 0) {
$percent = 0;
} else {
$percent = $grade / $maxgrade * 100;
}
$row->cells[] = sprintf("%0.{$decimalpoints}f", $percent);
$stattable->data[] = $row;
}
return html_writer::table($stattable);
}
?> ?>

Loading…
Cancel
Save