course_renderer.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. // This file is part of The Bootstrap 3 Moodle theme
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Renderers to align Moodle's HTML with that expected by Bootstrap
  18. *
  19. * @package theme_bootstrap
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. defined('MOODLE_INTERNAL') || die();
  23. require_once($CFG->dirroot . "/course/renderer.php");
  24. class theme_bootstrap_core_course_renderer extends core_course_renderer {
  25. protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
  26. global $CFG, $OUTPUT;
  27. if (!isset($this->strings->summary)) {
  28. $this->strings->summary = get_string('summary');
  29. }
  30. if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) {
  31. return '';
  32. }
  33. if ($course instanceof stdClass) {
  34. require_once($CFG->libdir. '/coursecatlib.php');
  35. $course = new course_in_list($course);
  36. }
  37. $content = '';
  38. $classes = trim($additionalclasses);
  39. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
  40. $classes .= ' collapsed';
  41. }
  42. $content .= html_writer::start_tag('div', array('class' => 'panel panel-default coursebox'));
  43. $content .= html_writer::start_tag('div', array('class' => 'panel-heading'));
  44. // Course name.
  45. $coursename = $chelper->get_course_formatted_name($course);
  46. $content .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)),
  47. $coursename, array('class' => $course->visible ? '' : 'dimmed'));
  48. // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page.
  49. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
  50. if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles()) {
  51. $url = new moodle_url('/course/info.php', array('id' => $course->id));
  52. $arrow = html_writer::tag('span', '', array('class'=>'glyphicon glyphicon-info-sign'));
  53. $content .= html_writer::link('#coursecollapse' . $course->id , '&nbsp;' . $arrow, array('data-toggle' => 'collapse', 'data-parent' => '#frontpage-category-combo'));
  54. }
  55. }
  56. // print enrolmenticons
  57. if ($icons = enrol_get_course_info_icons($course)) {
  58. $content .= html_writer::start_tag('div', array('class' => 'enrolmenticons'));
  59. foreach ($icons as $pix_icon) {
  60. $content .= $this->render($pix_icon);
  61. }
  62. $content .= html_writer::end_tag('div'); // .enrolmenticons
  63. }
  64. $content .= html_writer::end_tag('div'); // End .panel-heading.
  65. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
  66. $content .= html_writer::start_tag('div', array('id' => 'coursecollapse' . $course->id, 'class' => 'panel-collapse collapse'));
  67. }
  68. $content .= html_writer::start_tag('div', array('class' => 'panel-body'));
  69. // This gets the course image or files
  70. $content .= $this->coursecat_coursebox_content($chelper, $course);
  71. if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) {
  72. $icondirection = 'left';
  73. if ('ltr' === get_string('thisdirection', 'langconfig')) {
  74. $icondirection = 'right';
  75. }
  76. $arrow = html_writer::tag('span','', array('class' => ' glyphicon glyphicon-arrow-'.$icondirection));
  77. $btn = html_writer::tag('span', get_string('course') . ' ' . $arrow, array('class' => 'coursequicklink'));
  78. $content .= html_writer::link(new moodle_url('/course/view.php',
  79. array('id' => $course->id)), $btn, array('class' => 'coursebtn btn btn-info btn-sm pull-right'));
  80. }
  81. $content .= html_writer::end_tag('div'); // End .panel-body.
  82. if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
  83. $content .= html_writer::end_tag('div'); // End .collapse.
  84. }
  85. $content .= html_writer::end_tag('div'); // End .panel.
  86. return $content;
  87. }
  88. protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
  89. global $CFG;
  90. // if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
  91. // return '';
  92. // }
  93. if ($course instanceof stdClass) {
  94. require_once($CFG->libdir. '/coursecatlib.php');
  95. $course = new course_in_list($course);
  96. }
  97. $content = '';
  98. // display course overview files
  99. $contentimages = $contentfiles = '';
  100. foreach ($course->get_course_overviewfiles() as $file) {
  101. $isimage = $file->is_valid_image();
  102. $url = file_encode_url("$CFG->wwwroot/pluginfile.php",
  103. '/'. $file->get_contextid(). '/'. $file->get_component(). '/'.
  104. $file->get_filearea(). $file->get_filepath(). $file->get_filename(), !$isimage);
  105. if ($isimage) {
  106. $contentimages .= html_writer::tag('div',
  107. html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image '. $course->fullname)),
  108. array('class' => 'courseimage'));
  109. } else {
  110. $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
  111. $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')).
  112. html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
  113. $contentfiles .= html_writer::tag('span',
  114. html_writer::link($url, $filename),
  115. array('class' => 'coursefile fp-filename-icon'));
  116. }
  117. }
  118. $content .= $contentimages. $contentfiles;
  119. // display course summary
  120. if ($course->has_summary()) {
  121. $content .= html_writer::start_tag('div', array('class' => 'summary'));
  122. $content .= $chelper->get_course_formatted_summary($course,
  123. array('overflowdiv' => true, 'noclean' => true, 'para' => false));
  124. $content .= html_writer::end_tag('div'); // .summary
  125. }
  126. // display course contacts. See course_in_list::get_course_contacts()
  127. if ($course->has_course_contacts()) {
  128. $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
  129. foreach ($course->get_course_contacts() as $userid => $coursecontact) {
  130. $name = $coursecontact['rolename'].': '.
  131. html_writer::link(new moodle_url('/user/view.php',
  132. array('id' => $userid, 'course' => SITEID)),
  133. $coursecontact['username']);
  134. $content .= html_writer::tag('li', $name);
  135. }
  136. $content .= html_writer::end_tag('ul'); // .teachers
  137. }
  138. // display course category if necessary (for example in search results)
  139. if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
  140. require_once($CFG->libdir. '/coursecatlib.php');
  141. if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
  142. $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
  143. $content .= get_string('category').': '.
  144. html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
  145. $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
  146. $content .= html_writer::end_tag('div'); // .coursecat
  147. }
  148. }
  149. $content .= html_writer::tag('div', '', array('class' => 'boxfooter')); // .coursecat
  150. return $content;
  151. }
  152. public function course_search_form($value = '', $format = 'plain') {
  153. static $count = 0;
  154. $formid = 'coursesearch';
  155. if ((++$count) > 1) {
  156. $formid .= $count;
  157. }
  158. $inputid = 'coursesearchbox';
  159. $inputsize = 30;
  160. if ($format === 'navbar') {
  161. $formid = 'coursesearchnavbar';
  162. $inputid = 'navsearchbox';
  163. }
  164. $strsearchcourses = get_string("searchcourses");
  165. $searchurl = new moodle_url('/course/search.php');
  166. $form = array('id' => $formid, 'action' => $searchurl, 'method' => 'get', 'class' => "form-inline", 'role' => 'form');
  167. $output = html_writer::start_tag('form', $form);
  168. $output .= html_writer::start_div('form-group');
  169. $output .= html_writer::tag('label', $strsearchcourses, array('for' => $inputid, 'class' => 'sr-only'));
  170. $search = array('type' => 'text', 'id' => $inputid, 'size' => $inputsize, 'name' => 'search',
  171. 'class' => 'form-control', 'value' => s($value), 'placeholder' => $strsearchcourses);
  172. $output .= html_writer::empty_tag('input', $search);
  173. $output .= html_writer::end_div(); // Close form-group.
  174. $button = array('type' => 'submit', 'class' => 'btn btn-default');
  175. $output .= html_writer::tag('button', get_string('go'), $button);
  176. $output .= html_writer::end_tag('form');
  177. return $output;
  178. }
  179. }