function hotpot_get_report_users($course, $formdata) { $users = array(); /// Check to see if groups are being used in this module $groupmode = groupmode($course, $cm); //TODO: there is no $cm defined! $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=simple"); $sort = "u.lastname ASC"; switch ($formdata['reportusers']) { case 'students': if ($currentgroup) { $users = get_group_students($currentgroup, $sort); } else { $users = get_course_students($course->id, $sort); } break; case 'all': if ($currentgroup) { $users = get_group_users($currentgroup, $sort); } else { $users = get_course_users($course->id, $sort); } break; } return $users; }
//get the effective groupmode of this course and module $groupmode = groupmode($course, $cm); //get students in conjunction with groupmode if ($groupmode > 0) { if ($SESSION->lstgroupid == -2) { if (isadmin()) { $mygroupid = false; $SESSION->lstgroupid = false; } else { $mygroupid = mygroupid($course->id); } } else { $mygroupid = $SESSION->lstgroupid; } if ($mygroupid) { $students = get_group_students($mygroupid, 'u.lastname ASC'); } else { $students = get_course_students($course->id, $sort = "u.lastname", $dir = "ASC"); } } else { $students = get_course_students($course->id, $sort = "u.lastname", $dir = "ASC"); } $mygroupid = isset($mygroupid) ? $mygroupid : NULL; $completedFeedbackCount = get_completeds_group_count($feedback, $mygroupid); echo '<div align="center"><a href="analysis.php?id=' . $id . '">'; echo get_string('analysis', 'feedback') . ' (' . get_string('completed_feedbacks', 'feedback') . ': ' . $completedFeedbackCount . ')</a>'; echo '</div>'; } echo '<p>'; print_simple_box_start('center'); if (isteacher($course->id) || isadmin()) {
function grade_download($download, $id) { global $CFG; require_login(); if (!($course = get_record("course", "id", $id))) { error("Course ID was incorrect"); } require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id)); $strgrades = get_string("grades"); $strgrade = get_string("grade"); $strmax = get_string("maximumshort"); $stractivityreport = get_string("activityreport"); /// Check to see if groups are being used in this course $currentgroup = get_current_group($course->id); if (($currentgroup = get_current_group($course->id)) && groupmode($course) != 0) { $students = get_group_students($currentgroup, "u.lastname ASC"); } else { $students = grade_get_course_students($course->id); } if (!empty($students)) { foreach ($students as $student) { $grades[$student->id] = array(); // Collect all grades in this array $gradeshtml[$student->id] = array(); // Collect all grades html formatted in this array $totals[$student->id] = array(); // Collect all totals in this array } } $columns = array(); // Accumulate column names in this array. $columnhtml = array(); // Accumulate column html in this array. /// Collect modules data get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); /// Search through all the modules, pulling out grade data $sections = get_all_sections($course->id); // Sort everything the same as the course for ($i = 0; $i <= $course->numsections; $i++) { if (isset($sections[$i])) { // should always be true $section = $sections[$i]; if ($section->sequence) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $sectionmod) { $mod = $mods[$sectionmod]; $instance = get_record("{$mod->modname}", "id", "{$mod->instance}"); $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php"; if (file_exists($libfile)) { require_once $libfile; $gradefunction = $mod->modname . "_grades"; if (function_exists($gradefunction)) { // Skip modules without grade function if ($modgrades = $gradefunction($mod->instance)) { if (!empty($modgrades->maxgrade)) { if ($mod->visible) { $maxgrade = "{$strmax}: {$modgrades->maxgrade}"; } else { $maxgrade = "{$strmax}: {$modgrades->maxgrade}"; } } else { $maxgrade = ""; } $columns[] = "{$mod->modfullname}: " . format_string($instance->name, true) . " - {$maxgrade}"; if (!empty($students)) { foreach ($students as $student) { if (!empty($modgrades->grades[$student->id])) { $grades[$student->id][] = $currentstudentgrade = $modgrades->grades[$student->id]; } else { $grades[$student->id][] = $currentstudentgrade = ""; $gradeshtml[$student->id][] = ""; } if (!empty($modgrades->maxgrade)) { $totals[$student->id] = (double) $totals[$student->id] + (double) $currentstudentgrade; } else { $totals[$student->id] = (double) $totals[$student->id] + 0; } } } } } } } } } } // a new Moodle nesting record? ;-) /// OK, we have all the data, now present it to the user /// OK, we have all the data, now present it to the user if ($download == "ods" and confirm_sesskey()) { require_once "../lib/odslib.class.php"; /// Calculate file name $downloadfilename = clean_filename("{$course->shortname} {$strgrades}.ods"); /// Creating a workbook $workbook = new MoodleODSWorkbook("-"); /// Sending HTTP headers $workbook->send($downloadfilename); /// Adding the worksheet $myxls =& $workbook->add_worksheet($strgrades); /// Print names of all the fields $myxls->write_string(0, 0, get_string("firstname")); $myxls->write_string(0, 1, get_string("lastname")); $myxls->write_string(0, 2, get_string("idnumber")); $myxls->write_string(0, 3, get_string("institution")); $myxls->write_string(0, 4, get_string("department")); $myxls->write_string(0, 5, get_string("email")); $pos = 6; foreach ($columns as $column) { $myxls->write_string(0, $pos++, strip_tags($column)); } $myxls->write_string(0, $pos, get_string("total")); /// Print all the lines of data. $i = 0; if (!empty($grades)) { foreach ($grades as $studentid => $studentgrades) { $i++; $student = $students[$studentid]; if (empty($totals[$student->id])) { $totals[$student->id] = ''; } $myxls->write_string($i, 0, $student->firstname); $myxls->write_string($i, 1, $student->lastname); $myxls->write_string($i, 2, $student->idnumber); $myxls->write_string($i, 3, $student->institution); $myxls->write_string($i, 4, $student->department); $myxls->write_string($i, 5, $student->email); $j = 6; foreach ($studentgrades as $grade) { if (is_numeric($grade)) { $myxls->write_number($i, $j++, strip_tags($grade)); } else { $myxls->write_string($i, $j++, strip_tags($grade)); } } $myxls->write_number($i, $j, $totals[$student->id]); } } /// Close the workbook $workbook->close(); exit; } else { if ($download == "xls" and confirm_sesskey()) { require_once "../lib/excellib.class.php"; /// Calculate file name $downloadfilename = clean_filename("{$course->shortname} {$strgrades}.xls"); /// Creating a workbook $workbook = new MoodleExcelWorkbook("-"); /// Sending HTTP headers $workbook->send($downloadfilename); /// Adding the worksheet $myxls =& $workbook->add_worksheet($strgrades); /// Print names of all the fields $myxls->write_string(0, 0, get_string("firstname")); $myxls->write_string(0, 1, get_string("lastname")); $myxls->write_string(0, 2, get_string("idnumber")); $myxls->write_string(0, 3, get_string("institution")); $myxls->write_string(0, 4, get_string("department")); $myxls->write_string(0, 5, get_string("email")); $pos = 6; foreach ($columns as $column) { $myxls->write_string(0, $pos++, strip_tags($column)); } $myxls->write_string(0, $pos, get_string("total")); /// Print all the lines of data. $i = 0; if (!empty($grades)) { foreach ($grades as $studentid => $studentgrades) { $i++; $student = $students[$studentid]; if (empty($totals[$student->id])) { $totals[$student->id] = ''; } $myxls->write_string($i, 0, $student->firstname); $myxls->write_string($i, 1, $student->lastname); $myxls->write_string($i, 2, $student->idnumber); $myxls->write_string($i, 3, $student->institution); $myxls->write_string($i, 4, $student->department); $myxls->write_string($i, 5, $student->email); $j = 6; foreach ($studentgrades as $grade) { if (is_numeric($grade)) { $myxls->write_number($i, $j++, strip_tags($grade)); } else { $myxls->write_string($i, $j++, strip_tags($grade)); } } $myxls->write_number($i, $j, $totals[$student->id]); } } /// Close the workbook $workbook->close(); exit; } else { if ($download == "txt" and confirm_sesskey()) { /// Print header to force download header("Content-Type: application/download\n"); $downloadfilename = clean_filename("{$course->shortname} {$strgrades}"); header("Content-Disposition: attachment; filename=\"{$downloadfilename}.txt\""); /// Print names of all the fields echo get_string("firstname") . "\t" . get_string("lastname") . "\t" . get_string("idnumber") . "\t" . get_string("institution") . "\t" . get_string("department") . "\t" . get_string("email"); foreach ($columns as $column) { $column = strip_tags($column); echo "\t{$column}"; } echo "\t" . get_string("total") . "\n"; /// Print all the lines of data. foreach ($grades as $studentid => $studentgrades) { $student = $students[$studentid]; if (empty($totals[$student->id])) { $totals[$student->id] = ''; } echo "{$student->firstname}\t{$student->lastname}\t{$student->idnumber}\t{$student->institution}\t{$student->department}\t{$student->email}"; foreach ($studentgrades as $grade) { $grade = strip_tags($grade); echo "\t{$grade}"; } echo "\t" . $totals[$student->id]; echo "\n"; } exit; } else { if ($download == '' and confirm_sesskey()) { error("No file type specified"); exit; } } } } }
function wiki_grade_get_users_info($courseid, $wikiid) { global $CFG; $USERS_PER_PAGE = 18; $group = optional_param('group', -1, PARAM_INT); if ($group >= 0) { $users = get_group_students($group); $groups = groups_get_all_groups($courseid); $groupname = $groups[$group]->name; $a->of = 'of group ' . $groupname; } else { $users = get_course_users($courseid, 'u.lastname', '', 'u.id, u.firstname, u.lastname, u.idnumber'); $a->of = ''; } $users = array_values($users); $num_users = count($users); $num_pages = wiki_grade_get_num_userpages($num_users, $USERS_PER_PAGE); $userlistpage = optional_param('userlistpage', 0, PARAM_INT); if ($userlistpage >= $num_pages) { $userlistpage = 0; } $from = $userlistpage * $USERS_PER_PAGE; if ($userlistpage == $num_pages - 1) { $to = $from + $num_users % $USERS_PER_PAGE; } else { $to = $from + $USERS_PER_PAGE; } $output = print_box_start('generalbox', '', true); $output .= '<div style="float:left">'; $a->from = $from + 1; $a->to = $to; $a->total = $num_users; $output .= get_string('eval_show_userlist', 'wiki', $a); $output .= '</div>'; $output .= '<div style="float:right">'; $output .= '<table><tr><td><i>' . get_string('legend', 'wiki') . ': </i></td>'; $output .= '<td class="borderred">' . get_string('eval_legend_user_nograde', 'wiki') . '</td>'; $output .= '<td> </td>'; $output .= '<td class="bordergreen">' . get_string('eval_legend_user_grade', 'wiki') . '</td>'; $output .= '</tr></table>'; $output .= '</div>'; $output .= '<div style="clear:both"> </div>'; if (!$users) { echo 'grades.lib.php: there is not any user in this course'; } else { $wikimanager = wiki_manager_get_instance(); $output .= '<ul class="userlist">'; $output .= "\n\n" . '<div class="container"><br/>'; for ($i = $from; $i < $to; $i++) { $myuser = $users[$i]; $output .= '<li>'; $info = $wikimanager->get_user_info_by_id($myuser->id); $grade = grade_get_grades($courseid, 'mod', 'wiki', $wikiid, $myuser->id); if (isset($grade->items[0]->grades[$myuser->id])) { $grade = $grade->items[0]->grades[$myuser->id]->str_grade; } else { $grade = null; } $output .= "\n" . wiki_grade_get_user_info($info, $courseid, $grade); $output .= '</li>'; } $output .= '</ul>' . "\n\n"; $output .= wiki_grade_get_userpages($num_users, $userlistpage, $courseid, $USERS_PER_PAGE); $output .= '</tr></td></table>'; $output .= print_box_end(true); echo $output; } }
$changegroup = optional_param('group', -1, PARAM_INT); require_login(); if (!($course = get_record("course", "id", $id))) { error("Course ID was incorrect"); } require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id)); $strgrades = get_string("grades"); $strgrade = get_string("grade"); $strmax = get_string("maximumshort"); $stractivityreport = get_string("activityreport"); /// Check to see if groups are being used in this course $groupmode = groupmode($course); $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); /// Get a list of all students if ($currentgroup) { if (!($students = get_group_students($currentgroup, "u.lastname ASC"))) { print_header("{$course->shortname}: {$strgrades}", $course->fullname, "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> \n -> {$strgrades}"); setup_and_print_groups($course, $groupmode, "grades.php?id={$course->id}"); notice(get_string("nostudentsingroup"), "{$CFG->wwwroot}/course/view.php?id={$course->id}"); print_footer($course); exit; } } else { if (!($students = get_course_students($course->id, "u.lastname ASC"))) { print_header("{$course->shortname}: {$strgrades}", $course->fullname, "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> \n -> {$strgrades}"); notice(get_string("nostudentsyet"), "{$CFG->wwwroot}/course/view.php?id={$course->id}"); print_footer($course); exit; } } foreach ($students as $student) {