libdir.'/gradelib.php'); require_once($CFG->dirroot.'/grade/querylib.php'); require_once($CFG->dirroot.'/blocks/gradelevel/lib.php'); use block_gradelevel; class block_gradelevel extends block_base { public $levelset; public function init() { global $PAGE; global $COURSE; $this->title = get_config('gradelevel', 'blocktitle'); if(empty($this->title)) { $this->title = get_string('title', 'block_gradelevel'); } // include javascript and run badge renderer when page loading is complete $PAGE->requires->js_call_amd('block_gradelevel/renderbadge', 'init'); // find or create the levelset for this course $this->levelset = block_gradelevel_levelset::find_by_course($COURSE->id); } // The PHP tag and the curly bracket for the class definition // will only be closed after there is another function added in the next section. public function html_attributes() { $attributes = parent::html_attributes(); // Get default values $attributes['class'] .= ' block_'. $this->name(); // Append our class to class attribute return $attributes; } public function get_content() { global $CFG; global $USER; global $COURSE; if ($this->content !== null) { return $this->content; } $this->content = new stdClass; if(empty($this->levelset)) { $this->content->text = ""; $this->content->footer = get_string("unattached_course",'block_gradelevel'); } else { // below can be a single call to $this->levelset->get_user_leveldata() once the need for debugging (fixed point total) is gone $pointstotal = $this->levelset->get_levelset_grade($USER->id); $level_info = $this->levelset->calculate_level($pointstotal); $this->content->text = $this->levelset->render_badge($pointstotal); if($level_info->levelup_total > 0) { $this->content->footer = "