From ab2968730a84b80da232f6935fc59353d08524cf Mon Sep 17 00:00:00 2001 From: Artem Andreev Date: Sat, 16 Jul 2011 13:23:54 +0400 Subject: [PATCH] Implemented attforblock_user_outline and attforblock_user_outline --- lib.php | 59 ++++++++++++++++++++++++++++++++++------------- renderer.php | 40 ++------------------------------ renderhelpers.php | 37 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 54 deletions(-) diff --git a/lib.php b/lib.php index 41a77eb..07cd786 100644 --- a/lib.php +++ b/lib.php @@ -164,17 +164,26 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) { /// Used for user activity reports. /// $return->time = the time they did it /// $return->info = a short text description + global $CFG; - require_once('locallib.php'); - - if (isstudent($course->id, $user->id)) { - if ($sescount = get_attendance($user->id,$course, $attforblock)) { - $strgrade = get_string('grade'); - $maxgrade = get_maxgrade($user->id, $course,$attforblock); - $usergrade = get_grade($user->id, $course,$attforblock); - $percent = get_percent($user->id,$course, $attforblock); - $result->info = "$strgrade: $usergrade / $maxgrade ($percent%)"; - } + require_once(dirname(__FILE__).'/locallib.php'); + require_once($CFG->libdir.'/gradelib.php'); + + $grades = grade_get_grades($course->id, 'mod', 'attforblock', $attforblock->id, $user->id); + + $result = new stdClass(); + if (!empty($grades->items[0]->grades)) { + $grade = reset($grades->items[0]->grades); + $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; @@ -183,14 +192,32 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) { function attforblock_user_complete($course, $user, $mod, $attforblock) { /// Print a detailed representation of what a user has done with /// 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 (! $cm = get_coursemodule_from_instance("attforblock", $attforblock->id, $course->id)) { -// error("Course Module ID was incorrect"); -// } - print_user_attendaces($user, $mod, $attforblock, $course); + if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { + $gradeable = $attforblock->grade > 0; + $statuses = get_statuses($attforblock->id); + $userstatusesstat = get_user_statuses_stat($attforblock->id, $course->startdate, $user->id); + $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; diff --git a/renderer.php b/renderer.php index 47717a6..81af246 100644 --- a/renderer.php +++ b/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) { $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); $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 .= $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->maxgrade[$ca->attid], $userdata->decimalpoints); } @@ -565,42 +565,6 @@ class mod_attforblock_renderer extends plugin_renderer_base { 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) { $table = new html_table(); $table->attributes['class'] = 'generaltable attwidth boxaligncenter'; diff --git a/renderhelpers.php b/renderhelpers.php index ef9ff84..7ac1226 100644 --- a/renderhelpers.php +++ b/renderhelpers.php @@ -168,4 +168,41 @@ function construct_session_full_date_time($datetime, $duration) { 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); +} + + ?>