protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // Display course overview files.
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::start_tag('div', array('class' => 'imagebox'));
             $images = html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image ' . $course->fullname, 'class' => 'courseimage'));
             $contentimages .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $images);
             $contentimages .= html_writer::end_tag('div');
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // Display course summary.
     if ($course->has_summary()) {
         $content .= $chelper->get_course_formatted_summary($course);
     }
     // Display course contacts. See course_in_list::get_course_contacts().
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // ...Teachers!.
     }
     return $content;
 }
 public function get_content()
 {
     global $CFG;
     if ($this->content !== null) {
         return $this->content;
     }
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $this->content->text = '';
     // The user/index.php expect course context, so get one if page has module context.
     $currentcontext = $this->page->context->get_course_context(false);
     if (empty($currentcontext)) {
         return $this->content;
     }
     if ($this->page->course->id == SITEID) {
         $courses = self::get_featured_courses();
         require_once $CFG->libdir . '/coursecatlib.php';
         $chelper = new coursecat_helper();
         foreach ($courses as $course) {
             $course = new course_in_list($course);
             $this->content->text .= '<div class="container-fluid coursebox">';
             $content = '';
             $coursename = $chelper->get_course_formatted_name($course);
             $coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursename, array('class' => $course->visible ? '' : 'dimmed'));
             $content .= html_writer::tag('div', $coursenamelink, array('class' => 'coursename'));
             if ($course->has_summary()) {
                 $content .= html_writer::start_tag('div', array('class' => 'summary'));
                 $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
                 $content .= html_writer::end_tag('div');
             }
             // Display course overview files.
             $contentimages = $contentfiles = '';
             foreach ($course->get_course_overviewfiles() as $file) {
                 $isimage = $file->is_valid_image();
                 $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
                 if ($isimage) {
                     $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url, 'style' => 'max-height: 150px')), array('class' => 'courseimage'));
                 } else {
                     $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
                     $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
                     $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
                 }
             }
             $content .= $contentimages . $contentfiles;
             $this->content->text .= $content . '</div>';
         }
     }
     return $this->content;
 }
Exemplo n.º 3
0
 /**
  * Returns HTML to display course content (summary, course contacts and optionally category name)
  *
  * This method is called from coursecat_coursebox() and may be re-used in AJAX
  *
  * @param coursecat_helper $chelper various display options
  * @param stdClass|course_in_list $course
  * @return string
  */
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // display course summary
     if ($course->has_summary()) {
         $content .= html_writer::start_tag('div', array('class' => 'summary'));
         $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
         $content .= html_writer::end_tag('div');
         // .summary
     }
     // display course overview files
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url)), array('class' => 'courseimage'));
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // display course contacts. See course_in_list::get_course_contacts()
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // .teachers
     }
     // display course category if necessary (for example in search results)
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // .coursecat
         }
     }
     return $content;
 }
Exemplo n.º 4
0
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     /*
      * We had to override this renderer to output the full category list for
      * a course : cat 1 / cat 2 / subcat / etc
      */
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // Display course overview files.
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::start_tag('div', array('class' => 'imagebox'));
             $images = html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image ' . $course->fullname, 'class' => 'courseimage'));
             $contentimages .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $images);
             $contentimages .= html_writer::end_tag('div');
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // Display course summary.
     if ($course->has_summary()) {
         $content .= $chelper->get_course_formatted_summary($course);
     }
     // Display course contacts. See course_in_list::get_course_contacts().
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // .teachers
     }
     // Display course category if necessary (for example in search results).
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             // $content .= get_string('category').': '.
             //         html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
             //                 $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $parents = coursecat::get_many($cat->get_parents());
             $linkydink = [];
             foreach ($parents as $parent) {
                 $linkydink[] = $parent->get_formatted_name();
             }
             $linkydink[] = $cat->get_formatted_name();
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), implode(" / ", $linkydink), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // .coursecat
         }
     }
     return $content;
 }
Exemplo n.º 5
0
 /**
  * Returns HTML to display course content (summary, course contacts and optionally category name)
  *
  * This method is called from coursecat_coursebox() and may be re-used in AJAX
  *
  * @param coursecat_helper $chelper various display options
  * @param stdClass|course_in_list $course
  * @return string
  */
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // display course summary
     if ($course->has_summary()) {
         $content .= html_writer::start_tag('div', array('class' => 'summary hideme'));
         $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
         $content .= html_writer::end_tag('div');
         // .summary
     }
     // display course contacts. See course_in_list::get_course_contacts()
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // .teachers
     }
     // display course category if necessary (for example in search results)
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // .coursecat
         }
     }
     return $content;
 }
Exemplo n.º 6
0
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course, $type = 1)
 {
     global $CFG, $OUTPUT, $PAGE;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // Display course overview files.
     $contentimages = '';
     $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             if ($type == 1) {
                 $contentimages .= html_writer::start_tag('div', array('class' => 'courseimage'));
                 $link = new moodle_url('/course/view.php', array('id' => $course->id));
                 $contentimages .= html_writer::link($link, html_writer::empty_tag('img', array('src' => $url)));
                 $contentimages .= html_writer::end_tag('div');
             } else {
                 $contentimages .= "<div class='cimbox' style='background: #FFF url({$url}) no-repeat center center; background-size: contain;'></div>";
             }
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     if (strlen($contentimages) == 0 && $type == 2) {
         // Default image
         $url = $PAGE->theme->setting_file_url('frontpagerendererdefaultimage', 'frontpagerendererdefaultimage');
         $contentimages .= "<div class='cimbox' style='background: #FFF url({$url}) no-repeat center center; background-size: contain;'></div>";
     }
     $content .= $contentimages . $contentfiles;
     if ($type == 2) {
         $content .= $this->coursecat_coursebox_enrolmenticons($course);
     }
     if ($type == 2) {
         $content .= html_writer::start_tag('div', array('class' => 'coursebox-content'));
         $coursename = $chelper->get_course_formatted_name($course);
         $content .= html_writer::tag('h3', html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursename, array('class' => $course->visible ? '' : 'dimmed', 'title' => $coursename)));
     }
     $content .= html_writer::start_tag('div', array('class' => 'summary'));
     if (isset($coursename)) {
         $content .= html_writer::tag('p', html_writer::tag('b', $coursename));
     }
     // Display course summary.
     if ($course->has_summary()) {
         $summs = $chelper->get_course_formatted_summary($course, array('overflowdiv' => false, 'noclean' => true, 'para' => false));
         $summs = strip_tags($summs);
         $truncsum = strlen($summs) > 70 ? substr($summs, 0, 70) . "..." : $summs;
         $content .= html_writer::tag('span', $truncsum, array('title' => $summs));
     }
     // Display course contacts. See course_in_list::get_course_contacts().
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // Teachers.
     }
     $content .= html_writer::end_tag('div');
     // Summary.
     // Display course category if necessary (for example in search results).
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // Coursecat.
         }
     }
     if ($type == 2) {
         $content .= html_writer::end_tag('div');
     }
     $content .= html_writer::tag('div', '', array('class' => 'boxfooter'));
     // Coursecat.
     return $content;
 }