/** * 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) { if (!$this->enablecategoryicon) { return parent::coursecat_coursebox_content($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 = ''; $coursehascontacts = $course->has_course_contacts(); // Display course summary. if ($course->has_summary()) { $summaryclass = 'summary'; if ($coursehascontacts == false) { $summaryclass .= ' noteachers'; } $content .= html_writer::start_tag('div', array('class' => $summaryclass)); $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false)); $content .= html_writer::end_tag('div'); // Class .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 ($coursehascontacts) { $content .= html_writer::start_tag('ul', array('class' => 'teachers')); foreach ($course->get_course_contacts() as $userid => $coursecontact) { $faiconsetting = \theme_essential\toolbox::get_setting('courselistteachericon'); $faiconsettinghtml = empty($faiconsetting) ? '' : '<i class="fa fa-' . $faiconsetting . '"></i> '; $name = $faiconsettinghtml . $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'); // Class .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'); // Class .coursecat. } } return $content; }
/** * Set a css class to each activity item in course module choose lightbox form because parent selector does not exists in css3 * @param mixed $modules array of objects for each available modules (activities & resources) * @param mixed $course object for the current course * @return string HTML containing the list of available modules */ public function course_modchooser($modules, $course) { $content = parent::course_modchooser($modules, $course); // Could be done with one call to array_filter(), but we need to keep the same modules order than in parent method $modulesfiltered = array_merge(array_filter($modules, create_function('$mod', 'return ($mod->archetype !== MOD_ARCHETYPE_RESOURCE && $mod->archetype !== MOD_ARCHETYPE_SYSTEM);')), array_filter($modules, create_function('$mod', 'return ($mod->archetype === MOD_ARCHETYPE_RESOURCE);'))); if (count($modulesfiltered)) { $html = $content; foreach ($modulesfiltered as $modulename => $module) { if (!isset($module->types)) { $html = preg_replace('/<div class="option">/', !empty($modulename) ? '<div class="option div_module_' . $modulename . '">' : '<div class="option div_module_unknown">', $html, 1); } else { $html = preg_replace('/<div class="nonoption">/', !empty($modulename) ? '<div class="nonoption div_module_' . $modulename . '">' : '<div class="nonoption div_module_unknown">', $html, 1); $html = preg_replace('/<div class="option subtype">/', !empty($modulename) ? '<div class="option subtype div_module_' . $modulename . '">' : '<div class="option subtype div_module_unknown">', $html, count($module->types)); } } return $html; } return str_replace('<div class="option subtype">', '<div class="option subtype div_module_unknown">', str_replace('<div class="nonoption">', '<div class="nonoption div_module_unknown">', str_replace('<div class="option">', '<div class="option div_module_unknown">', $content))); }
protected function coursecat_coursebox_content(coursecat_helper $chelper, $course, $type = 3) { 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); } if ($type == 3 || $OUTPUT->body_id() != 'page-site-index') { return parent::coursecat_coursebox_content($chelper, $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)); } $coursecontacts = theme_bcu_get_setting('tilesshowcontacts'); if ($coursecontacts) { $coursecontacttitle = theme_bcu_get_setting('tilescontactstitle'); // 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 = ($coursecontacttitle ? $coursecontact['rolename'] . ': ' : html_writer::tag('i', ' ', array('class' => 'fa fa-graduation-cap'))) . 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; }
/** * Yes, this looks like it should be part of core renderer but moodles crazy ia means its part of course. */ public function course_search_form($value = '', $format = 'plain') { if ($format !== 'fixy') { // For now only handle search in fixy menu. return parent::course_search_form($value, $format); } 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::tag('label', $strsearchcourses, array('for' => $inputid, 'class' => 'sr-only')); $output .= html_writer::start_div('input-group'); $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); $button = array('type' => 'submit', 'class' => 'btn btn-default'); $output .= html_writer::start_span('input-group-btn'); $output .= html_writer::tag('button', get_string('go'), $button); $output .= html_writer::end_span(); $output .= html_writer::end_div(); // Close form-group. $output .= html_writer::end_tag('form'); return $output; }
protected function course_modchooser_module($module, $classes = array('option')) { global $PAGE; if (empty($PAGE->theme->settings->usemodchoosertiles)) { return parent::course_modchooser_module($module, $classes); } $output = ''; $output .= html_writer::start_tag('div', array('class' => implode(' ', $classes))); $output .= html_writer::start_tag('label', array('for' => 'module_' . $module->name)); if (!isset($module->types)) { $output .= html_writer::tag('input', '', array('type' => 'radio', 'name' => 'jumplink', 'id' => 'module_' . $module->name, 'value' => $module->link)); } $attributes = array('class' => 'modicon'); if (isset($module->icon)) { // Add an icon if we have one $attributes['style'] = 'background-image:url(' . $this->pix_url('icon', $module->name) . ');'; } $output .= html_writer::tag('span', '', $attributes); $output .= html_writer::tag('span', $module->title, array('class' => 'typename')); if (!isset($module->help)) { // Add help if found $module->help = get_string('nohelpforactivityorresource', 'moodle'); } // Format the help text using markdown with the following options $options = new stdClass(); $options->trusted = false; $options->noclean = false; $options->smiley = false; $options->filter = false; $options->para = true; $options->newlines = false; $options->overflowdiv = false; $module->help = format_text($module->help, FORMAT_MARKDOWN, $options); $output .= html_writer::tag('span', $module->help, array('class' => 'typesummary')); $output .= html_writer::end_tag('label'); $output .= html_writer::end_tag('div'); return $output; }
protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') { global $CFG, $OUTPUT; $type = theme_bcu_get_setting('frontpagerenderer'); $additionalcss = ''; if ($type == 2) { $additionalcss = 'hover'; } if ($OUTPUT->body_id() != 'page-site-index') { return parent::coursecat_coursebox($chelper, $course, $additionalclasses = ''); } 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' => 'span4 panel panel-default coursebox ' . $additionalcss)); $urlb = new moodle_url('/course/view.php', array('id' => $course->id)); $content .= "<a href='{$urlb}'>"; $coursename = $chelper->get_course_formatted_name($course); $content .= html_writer::start_tag('div', array('class' => 'panel-heading')); if ($type == 1) { $content .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursename, array('class' => $course->visible ? '' : 'dimmed', 'title' => $coursename)); } // 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')); } } if ($type == 1) { $content .= $this->coursecat_coursebox_enrolmenticons($course, $type); } $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 clearfix')); // This gets the course image or files. $content .= $this->coursecat_coursebox_content($chelper, $course, $type); 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' => 'fa fa-chevron-' . $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 submit 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; }
/** * Override the constructor so that we can initialise the string cache * * @param moodle_page $page * @param string $target */ public function __construct(moodle_page $page, $target) { $this->strings = new stdClass(); parent::__construct($page, $target); //add_modchoosertoggle(); }