. /** * Renderers to align Moodle's HTML with that expected by Bootstrap * * @package theme_bootstrap * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . "/course/renderer.php"); class theme_bootstrap_core_course_renderer extends core_course_renderer { protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') { global $CFG, $OUTPUT; if (!isset($this->strings->summary)) { $this->strings->summary = get_string('summary'); } if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) { return ''; } if ($course instanceof stdClass) { require_once($CFG->libdir. '/coursecatlib.php'); $course = new course_in_list($course); } $content = ''; $classes = trim($additionalclasses); if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { $classes .= ' collapsed'; } $content .= html_writer::start_tag('div', array('class' => 'panel panel-default coursebox')); $content .= html_writer::start_tag('div', array('class' => 'panel-heading')); // Course name. $coursename = $chelper->get_course_formatted_name($course); $content .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursename, array('class' => $course->visible ? '' : 'dimmed')); // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()) { $url = new moodle_url('/course/info.php', array('id' => $course->id)); $arrow = html_writer::tag('span', '', array('class'=>'glyphicon glyphicon-info-sign')); $content .= html_writer::link('#coursecollapse' . $course->id , ' ' . $arrow, array('data-toggle' => 'collapse', 'data-parent' => '#frontpage-category-combo')); } } // print enrolmenticons if ($icons = enrol_get_course_info_icons($course)) { $content .= html_writer::start_tag('div', array('class' => 'enrolmenticons')); foreach ($icons as $pix_icon) { $content .= $this->render($pix_icon); } $content .= html_writer::end_tag('div'); // .enrolmenticons } $content .= html_writer::end_tag('div'); // End .panel-heading. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { $content .= html_writer::start_tag('div', array('id' => 'coursecollapse' . $course->id, 'class' => 'panel-collapse collapse')); } $content .= html_writer::start_tag('div', array('class' => 'panel-body')); // This gets the course image or files $content .= $this->coursecat_coursebox_content($chelper, $course); if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) { $icondirection = 'left'; if ('ltr' === get_string('thisdirection', 'langconfig')) { $icondirection = 'right'; } $arrow = html_writer::tag('span','', array('class' => ' glyphicon glyphicon-arrow-'.$icondirection)); $btn = html_writer::tag('span', get_string('course') . ' ' . $arrow, array('class' => 'coursequicklink')); $content .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $btn, array('class' => 'coursebtn btn btn-info btn-sm pull-right')); } $content .= html_writer::end_tag('div'); // End .panel-body. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { $content .= html_writer::end_tag('div'); // End .collapse. } $content .= html_writer::end_tag('div'); // End .panel. return $content; } 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::tag('div', html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image '. $course->fullname)), 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 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 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 } } $content .= html_writer::tag('div', '', array('class' => 'boxfooter')); // .coursecat return $content; } public function course_search_form($value = '', $format = 'plain') { static $count = 0; $formid = 'coursesearch'; if ((++$count) > 1) { $formid .= $count; } $inputid = 'coursesearchbox'; $inputsize = 30; if ($format === 'navbar') { $formid = 'coursesearchnavbar'; $inputid = 'navsearchbox'; } $strsearchcourses = get_string("searchcourses"); $searchurl = new moodle_url('/course/search.php'); $form = array('id' => $formid, 'action' => $searchurl, 'method' => 'get', 'class' => "form-inline", 'role' => 'form'); $output = html_writer::start_tag('form', $form); $output .= html_writer::start_div('form-group'); $output .= html_writer::tag('label', $strsearchcourses, array('for' => $inputid, 'class' => 'sr-only')); $search = array('type' => 'text', 'id' => $inputid, 'size' => $inputsize, 'name' => 'search', 'class' => 'form-control', 'value' => s($value), 'placeholder' => $strsearchcourses); $output .= html_writer::empty_tag('input', $search); $output .= html_writer::end_div(); // Close form-group. $button = array('type' => 'submit', 'class' => 'btn btn-default'); $output .= html_writer::tag('button', get_string('go'), $button); $output .= html_writer::end_tag('form'); return $output; } }