protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null) { global $DB, $CFG; require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->dirroot . '/course/lib.php'; // Get grades as basic associative array. $gradeoptions = array(); $items = \grade_item::fetch_all(array('courseid' => $course->id)); // For some reason the fetch_all things return null if none. $items = $items ? $items : array(); foreach ($items as $id => $item) { // Don't include the grade item if it's linked with a module that is being deleted. if (course_module_instance_pending_deletion($item->courseid, $item->itemmodule, $item->iteminstance)) { continue; } // Do not include grades for current item. if ($cm && $cm->instance == $item->iteminstance && $cm->modname == $item->itemmodule && $item->itemtype == 'mod') { continue; } $gradeoptions[$id] = $item->get_name(true); } \core_collator::asort($gradeoptions); // Change to JS array format and return. $jsarray = array(); foreach ($gradeoptions as $id => $name) { $jsarray[] = (object) array('id' => $id, 'name' => $name); } return array($jsarray); }
/** * Returns the most descriptive field for this object. * * Determines what type of grade item it is then returns the appropriate string * * @param bool $fulltotal If the item is a category total, returns $categoryname."total" instead of "Category total" or "Course total" * @return string name */ public function get_name($fulltotal = false) { global $CFG; require_once $CFG->dirroot . '/course/lib.php'; if (strval($this->itemname) !== '') { // MDL-10557 // Make it obvious to users if the course module to which this grade item relates, is currently being removed. $deletionpending = course_module_instance_pending_deletion($this->courseid, $this->itemmodule, $this->iteminstance); $deletionnotice = get_string('gradesmoduledeletionprefix', 'grades'); return $deletionpending ? format_string($deletionnotice . ' ' . $this->itemname) : format_string($this->itemname); } else { if ($this->is_course_item()) { return get_string('coursetotal', 'grades'); } else { if ($this->is_category_item()) { if ($fulltotal) { $category = $this->load_parent_category(); $a = new stdClass(); $a->category = $category->get_name(); return get_string('categorytotalfull', 'grades', $a); } else { return get_string('categorytotal', 'grades'); } } else { return get_string('grade'); } } } }