function get_content() { global $CFG, $COURSE, $USER, $DB; if ($this->content !== NULL) { return $this->content; } $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $course = new GcrMdlCourse($COURSE, $CFG->current_app); $can_edit = has_capability('block/course_profile:edit', $context); $block_course_profile = $course->getBlockCourseProfile(); if (!$block_course_profile && $can_edit) { $parent_block_course_profile = $course->getRepresentativeBlockCourseProfile(); if ($parent_block_course_profile) { $this->copyFromBlock($parent_block_course_profile, $course); $block_course_profile = $course->getBlockCourseProfile(); } } if (!$block_course_profile) { if ($can_edit) { redirect($CFG->wwwroot . '/blocks/course_profile/edit.php?courseid=' . $COURSE->id); } else { return false; } } $img_src = $block_course_profile->getCourseIconUrl(); $instructor_text = 'Instructor: None'; $instructor = $block_course_profile->getInstructor(); if ($instructor) { $user = $instructor->getUserOnInstitution(); $institution = $CFG->current_app->getInstitution(); if ($user && $user->getApp()->getShortName() == $institution->getShortName()) { $user_obj = $user->getObject(); $user_profile_url = $institution->getAppUrl() . 'user/view.php?id=' . $user_obj->id; } else { $user = $instructor; $user_obj = $instructor->getObject(); $user_profile_url = $CFG->current_app->getAppUrl() . '/user/view?id=' . $user_obj->id . '&course=' . $COURSE->id; } $instructor_text = 'Instructor: <a href="' . $user_profile_url . '">' . $user->getFullnameString() . '</a>'; } $img = '<div class="gc_course_list_item_icon"><img src="' . $img_src . '" /></div>'; $this->content->items[] = $img; $this->content->items[] = $instructor_text; if ($can_edit) { $this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/course_profile/edit.php?courseid=' . $COURSE->id . '"><button style="cursor:pointer">Edit</button></a>'; } return $this->content; }
protected function compareHasIcon(GcrMdlCourse $course) { $result = 0; $course_block_course_profile = $course->getBlockCourseProfile(); $block_course_profile = $this->representative_course->getBlockCourseProfile(); $course_has_icon = $course_block_course_profile && $course_block_course_profile->getObject()->courseicon != ''; $has_icon = $block_course_profile && $block_course_profile->getObject()->courseicon != ''; if ($has_icon && !$course_has_icon) { $result = -1; } else { if ($course_has_icon && !$has_icon) { $result = 1; } } return $result; }