public function get_options() { global $CFG, $USER, $COURSE; if (!isset($this->user)) { require_once $CFG->dirroot . '/blocks/courseprefs/classes/CoursePrefsUser.php'; $this->user = CoursePrefsUser::findByUnique($USER->username); } if (!isset($this->course)) { $this->course = $COURSE->id == 1 ? null : $COURSE; } if (isset($this->callback)) { $sections = call_user_func($this->callback, $this); } if (empty($sections) and is_siteadmin($USER->id) and $this->course) { $sections = cps_sections($this->course); } if (empty($sections) and $this->user) { $sections = $this->user->getSectionsForMoodleCourse($this->course, false); } $this->sections = $sections; return $sections ? array_map(array($this, 'transform_section'), $sections) : array(); }
function get_content() { if ($this->content !== NULL) { return $this->content; } global $CFG, $COURSE, $USER; $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; // Does the user have the right capability? // Line 4354 of lib/weblib.php suggests that a teacher // is defined by one being able to view details of other users $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); if (!has_capability('moodle/user:viewdetails', $context)) { return $this->content; } $user = CoursePrefsUser::findByUnique($USER->username); // No Atheletes in the course means this block is hidden if (get_athelete_count($COURSE) == 0) { // If in Edit mode: display the no athletes text $edit = optional_param('edit', 0, PARAM_INT); if ($edit) { $this->content->text = '<span>' . get_string('no_atheletes', 'block_athelete_reporting') . '</span>'; } return $this->content; } // Check course's grade to pass $this->courseitem = grade_item::fetch_course_item($COURSE->id); if (is_siteadmin($USER->id)) { $sections = cps_sections($COURSE); } else { if ($user) { $sections = $user->getSectionsForMoodleCourse($COURSE); } else { return $this->content; } } $out = '<div class="block_athelete_reporting_body"> <form method="POST" action="' . $CFG->wwwroot . '/blocks/athelete_reporting/report.php">'; foreach ($sections as $section) { $atheletes = get_atheletes($section); if (!$atheletes) { continue; } $id = 'block_athelete_reporting_section_' . $section->id; $out .= '<div class="block_athelete_reporting_header"> <input type="image" src="' . $CFG->pixpath . '/t/switch_plus.gif" onclick="elementToggleHide(this, true, function(el) { return document.getElementById(\'' . $id . '\');}, \'Show Section\', \'Hide Section\'); return false;"> ' . get_string('format_section', 'block_courseprefs', $section) . ' </div> <div id="' . $id . '" class="block_athelete_reporting_section_body hidden"> ' . array_reduce($atheletes, array($this, 'reduce_athelete')) . ' </div>'; } if (!empty($sections)) { $out .= ' <input type="hidden" name="id" value="' . $COURSE->id . '"> <input type="submit" value="' . get_string('report', 'block_athelete_reporting') . '"> </form>'; } $out .= '<a href="' . $CFG->wwwroot . '/blocks/student_gradeviewer/analysis.php?id=' . $COURSE->id . '">' . get_string('analysis', 'block_student_gradeviewer') . '</a>'; $user = CoursePrefsUser::findByUnique($USER->username); if (!empty($CFG->cas_email) and $user and $user->getSectionsInfoAsTeacher(false, null, true)) { $out .= '<br/><span class="athlete_small_text"> <a href="' . $CFG->wwwroot . '/blocks/student_gradeviewer/options.php?id=' . $COURSE->id . '">' . get_string('options', 'block_student_gradeviewer') . '</a> </span>'; } $out .= '</div>'; $this->content->text = $out; return $this->content; }
$navigation = array(array('name' => $course->shortname, 'link' => $CFG->wwwroot . '/course/view.php?id=' . $courseid, 'type' => 'title'), array('name' => $blockname, 'link' => '', 'type' => 'title'), array('name' => $heading, 'link' => '', 'type' => 'title')); print_header_simple($heading, '', build_navigation($navigation)); print_heading_with_help($heading, 'select', 'block_student_reporting'); $filters = cps_user_component::build_filters('select.php', array('id' => $courseid), array('section' => array('course' => $course))); $filters->display(); // Permission and dependencies aside, let's get to the logic // Obtain CPS sections tied to this course idnumber $user = CoursePrefsUser::findByUnique($USER->username); $where = $filters->where_clause(create_function('$k,$w', ' switch($k) { case "section": return "s." . $w; default: return "cpsu." . $w; } ')); if (is_siteadmin($USER->id)) { $sections = cps_sections($course, $where['section']); } else { if ($user) { $sections = $user->getSectionsForMoodleCourse($course); } else { echo '<span class="error">' . get_string('no_permission', 'block_student_gradeviewer') . '</span>'; print_footer(); die; } } echo '<form method="POST" action="report.php"> <div class="report_wrap">'; // Grab the course item $course_item = grade_item::fetch_course_item($courseid); unset($where['section']); $printed = false;