/** * Returns the url of the first image contained in the course summary file area * @param int $id the course id * @return string the url to the image */ function block_my_course_progress_get_course_image_url($id) { global $CFG; require_once $CFG->libdir . "/filelib.php"; $course = get_course($id); if ($course instanceof stdClass) { require_once $CFG->libdir . '/coursecatlib.php'; $course = new course_in_list($course); } foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); if ($isimage) { return file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage); } } return false; }
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; }
protected function mycourses($CFG, $sidebar) { $mycourses = enrol_get_users_courses($_SESSION['USER']->id); $courselist = array(); foreach ($mycourses as $key => $val) { $courselist[] = $val->id; } $content = ''; for ($x = 1; $x <= sizeof($courselist); $x++) { $course = get_course($courselist[$x - 1]); $title = $course->fullname; if ($course instanceof stdClass) { require_once $CFG->libdir . '/coursecatlib.php'; $course = new course_in_list($course); } $url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg"; 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) { $url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg"; } } $content .= '<div class="view view-second view-mycourse ' . ($x % 3 == 0 ? 'view-nomargin' : '') . '"> <img src="' . $url . '" /> <div class="mask"> <h2>' . $title . '</h2> <a href="' . $CFG->wwwroot . '/course/view.php?id=' . $courselist[$x - 1] . '" class="info">Enter</a> </div> </div>'; } return $content; }
/** * Renderers actions for individual course actions. * * @param course_in_list $course The course to renderer actions for. * @return string */ public function search_listitem_actions(course_in_list $course) { $baseurl = new moodle_url('/course/managementsearch.php', array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => sesskey())); $actions = array(); // Edit. if ($course->can_access()) { if ($course->can_edit()) { $actions[] = $this->output->action_icon(new moodle_url('/course/edit.php', array('id' => $course->id)), new pix_icon('t/edit', get_string('edit')), null, array('class' => 'action-edit')); } // Show/Hide. if ($course->can_change_visibility()) { if ($course->visible) { $actions[] = $this->output->action_icon(new moodle_url($baseurl, array('action' => 'hidecourse')), new pix_icon('t/show', get_string('hide')), null, array('data-action' => 'hide', 'class' => 'action-hide')); } else { $actions[] = $this->output->action_icon(new moodle_url($baseurl, array('action' => 'showcourse')), new pix_icon('t/hide', get_string('show')), null, array('data-action' => 'show', 'class' => 'action-show')); } } } if (empty($actions)) { return ''; } return html_writer::span(join('', $actions), 'course-item-actions item-actions'); }
public function top_promoted_courses() { global $CFG, $OUTPUT, $DB, $PAGE; $featuredcontent = ''; /* Get Featured courses id from DB */ $featuredids = theme_pioneer_get_setting('toppromotedcourses'); $rcourseids = !empty($featuredids) ? explode(",", $featuredids, 10) : array(); if (empty($rcourseids)) { return false; } $hcourseids = theme_pioneer_hidden_courses_ids(); if (!empty($hcourseids)) { foreach ($rcourseids as $key => $val) { if (in_array($val, $hcourseids)) { unset($rcourseids[$key]); } } } foreach ($rcourseids as $key => $val) { $ccourse = $DB->get_record('course', array('id' => $val)); if (empty($ccourse)) { unset($rcourseids[$key]); continue; } } if (empty($rcourseids)) { return false; } $fcourseids = array_chunk($rcourseids, 10); $totalfcourse = count($fcourseids); $promotedtitle = theme_pioneer_get_setting('toppromotedtitle', 'format_text'); $promotedtitle = theme_pioneer_lang($promotedtitle); $closelisting = theme_pioneer_get_setting('topclosefeatured', 'format_text'); $topshowfeatured = theme_pioneer_get_setting('topshowfeatured', 'format_text'); $featuredheader = '<div class="custom-courses-list" id="topPromoted-Courses"> <div class="container-fluid"> <div class="promoted_courses" data-crow="' . $totalfcourse . '">'; $featuredfooter = ' </div> </div> </div>'; if (!empty($fcourseids)) { echo '<div id="featured-listing" class="collapse out">'; echo '<div data-toggle="collapse" data-target="#featured-listing" class="btn-link"style="text-align:center;">' . $closelisting . '</div>'; foreach ($fcourseids as $courseids) { $rowcontent = '<div><div class="row-fluid topcarousel">'; foreach ($courseids as $courseid) { $course = get_course($courseid); $no = get_config('theme_pioneer', 'toppatternselect'); $nimgp = empty($no) || $no == "default" ? 'no-image' : 'cs0' . $no . '/no-image'; $noimgurl = $OUTPUT->pix_url($nimgp, 'theme'); $courseurl = new moodle_url('/course/view.php', array('id' => $courseid)); if ($course instanceof stdClass) { require_once $CFG->libdir . '/coursecatlib.php'; $course = new course_in_list($course); } $imgurl = ''; $summary = theme_pioneer_strip_html_tags($course->summary); $summary = theme_pioneer_course_trim_char($summary, 125); $trimtitle = theme_pioneer_course_trim_char($course->fullname, 90); $context = context_course::instance($course->id); $nostudents = count_role_users(5, $context); foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $imgurl = 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) { $imgurl = $noimgurl; } } if (empty($imgurl)) { $imgurl = $PAGE->theme->setting_file_url('headerbackgroundimage', 'headerbackgroundimage', true); if (!$imgurl) { $imgurl = $noimgurl; } } $listitems = ' <div class="row-fluid"> <div class="span3"> <img src="' . $imgurl . '" width="100%" height="75px" alt="' . $course->fullname . '"> </div> <div class="span5"> <h5><a href="' . $courseurl . '" >' . $trimtitle . '</a></h5> </div> <div class="span4"> <p>' . $summary . '</p> </div> </div>'; $coursehtml = ' <div style="background-image: url(' . $imgurl . ');background-repeat: no-repeat;background-size:cover; background-position:center;" class="promowrap"> <div class="fp-coursebox"> <div class="fp-courseinfo"> <p style="font-size:24px;font-weight:bold;"><a href="' . $courseurl . '" id="button" data-toggle="tooltip" data-placement="bottom"title="' . $summary . '" >' . $trimtitle . '</a></p> <div class="titlebar"> <h5>' . $promotedtitle . '</h5> </div> <div data-toggle="collapse" data-target="#featured-listing" class="btn-link">' . $topshowfeatured . '</div> </div> </div> </div>'; $rowcontent .= $coursehtml; echo $listitems; } $rowcontent .= '</div></div> '; $featuredcontent .= $rowcontent; } echo "</div>"; } $featuredcourses = $featuredheader . $featuredcontent . $featuredfooter; return $featuredcourses; }
/** * Returns given course's summary with proper embedded files urls and formatted * * @param course_in_list $course * @param array|stdClass $options additional formatting options * @return string */ public function get_course_formatted_summary($course, $options = array()) { global $CFG; require_once $CFG->libdir . '/filelib.php'; if (!$course->has_summary()) { return ''; } $options = (array) $options; $context = context_course::instance($course->id); if (!isset($options['context'])) { // TODO see MDL-38521 // option 1 (current), page context - no code required // option 2, system context // $options['context'] = context_system::instance(); // option 3, course context: // $options['context'] = $context; // option 4, course category context: // $options['context'] = $context->get_parent_context(); } $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null); $summary = format_text($summary, $course->summaryformat, $options, $course->id); if (!empty($this->searchcriteria['search'])) { $summary = highlight($this->searchcriteria['search'], $summary); } return $summary; }
/** * Return the course information that is public (visible by every one) * * @param course_in_list $course course in list object * @param stdClass $coursecontext course context object * @return array the course information * @since Moodle 3.2 */ protected static function get_course_public_information(course_in_list $course, $coursecontext) { static $categoriescache = array(); // Category information. if (!array_key_exists($course->category, $categoriescache)) { $categoriescache[$course->category] = coursecat::get($course->category, IGNORE_MISSING); } $category = $categoriescache[$course->category]; // Retrieve course overview used files. $files = array(); foreach ($course->get_course_overviewfiles() as $file) { $fileurl = moodle_url::make_webservice_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename())->out(false); $files[] = array('filename' => $file->get_filename(), 'fileurl' => $fileurl, 'filesize' => $file->get_filesize(), 'filepath' => $file->get_filepath(), 'mimetype' => $file->get_mimetype(), 'timemodified' => $file->get_timemodified()); } // Retrieve the course contacts, // we need here the users fullname since if we are not enrolled can be difficult to obtain them via other Web Services. $coursecontacts = array(); foreach ($course->get_course_contacts() as $contact) { $coursecontacts[] = array('id' => $contact['user']->id, 'fullname' => $contact['username']); } // Allowed enrolment methods (maybe we can self-enrol). $enroltypes = array(); $instances = enrol_get_instances($course->id, true); foreach ($instances as $instance) { $enroltypes[] = $instance->enrol; } // Format summary. list($summary, $summaryformat) = external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null); $displayname = get_course_display_name_for_list($course); $coursereturns = array(); $coursereturns['id'] = $course->id; $coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id); $coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id); $coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id); $coursereturns['categoryid'] = $course->category; $coursereturns['categoryname'] = $category == null ? '' : $category->name; $coursereturns['summary'] = $summary; $coursereturns['summaryformat'] = $summaryformat; $coursereturns['summaryfiles'] = external_util::get_area_files($coursecontext->id, 'course', 'summary', false, false); $coursereturns['overviewfiles'] = $files; $coursereturns['contacts'] = $coursecontacts; $coursereturns['enrollmentmethods'] = $enroltypes; return $coursereturns; }
public function course_footer() { global $DB, $COURSE, $CFG, $PAGE; // Note: This check will be removed for Snap 2.7. if (empty($PAGE->theme->settings->coursefootertoggle)) { return false; } $context = context_course::instance($COURSE->id); $courseteachers = ''; $coursesummary = ''; $clist = new \course_in_list($COURSE); $teachers = $clist->get_course_contacts(); if (!empty($teachers)) { // Get all teacher user records in one go. $teacherids = array(); foreach ($teachers as $teacher) { $teacherids[] = $teacher['user']->id; } $teacherusers = $DB->get_records_list('user', 'id', $teacherids); // Create string for teachers. $courseteachers .= '<h6>' . get_string('coursecontacts', 'theme_snap') . '</h6><div id=course_teachers>'; foreach ($teachers as $teacher) { if (!isset($teacherusers[$teacher['user']->id])) { continue; } $teacheruser = $teacherusers[$teacher['user']->id]; $courseteachers .= $this->print_teacher_profile($teacheruser); } $courseteachers .= "</div>"; } // If user can edit add link to manage users. if (has_capability('moodle/course:enrolreview', $context)) { if (empty($courseteachers)) { $courseteachers = "<h6>" . get_string('coursecontacts', 'theme_snap') . "</h6>"; } $courseteachers .= '<a class="btn btn-default btn-sm" href="' . $CFG->wwwroot . '/enrol/users.php?id=' . $COURSE->id . '">' . get_string('enrolledusers', 'enrol') . '</a>'; } if (!empty($COURSE->summary)) { $coursesummary = '<h6>' . get_string('aboutcourse', 'theme_snap') . '</h6>'; $formatoptions = new stdClass(); $formatoptions->noclean = true; $formatoptions->overflowdiv = true; $formatoptions->context = $context; $coursesummarycontent = file_rewrite_pluginfile_urls($COURSE->summary, 'pluginfile.php', $context->id, 'course', 'summary', null); $coursesummarycontent = format_text($coursesummarycontent, $COURSE->summaryformat, $formatoptions); $coursesummary .= '<div id=course_about>' . $coursesummarycontent . '</div>'; } // If able to edit add link to edit summary. if (has_capability('moodle/course:update', $context)) { if (empty($coursesummary)) { $coursesummary = '<h6>' . get_string('aboutcourse', 'theme_snap') . '</h6>'; } $coursesummary .= '<a class="btn btn-default btn-sm" href="' . $CFG->wwwroot . '/course/edit.php?id=' . $COURSE->id . '#id_descriptionhdr">' . get_string('editsummary') . '</a>'; } // Get recent activities on mods in the course. $courserecentactivities = $this->get_mod_recent_activity($context); if ($courserecentactivities) { $courserecentactivity = '<h6>' . get_string('recentactivity') . '</h6>'; $courserecentactivity .= "<div id=course_recent_updates>"; if (!empty($courserecentactivities)) { $courserecentactivity .= $courserecentactivities; } $courserecentactivity .= "</div>"; } // If user can edit add link to moodle recent activity stuff. if (has_capability('moodle/course:update', $context)) { if (empty($courserecentactivities)) { $courserecentactivity = '<h6>' . get_string('recentactivity') . '</h6>'; $courserecentactivity .= get_string('norecentactivity'); } $courserecentactivity .= '<div><a class="btn btn-default btn-sm" href="' . $CFG->wwwroot . '/course/recent.php?id=' . $COURSE->id . '">' . get_string('showmore', 'form') . '</a></div>'; } if (!empty($courserecentactivity)) { $columns[] = $courserecentactivity; } if (!empty($courseteachers)) { $columns[] = $courseteachers; } if (!empty($coursesummary)) { $columns[] = $coursesummary; } // Logic for printing bootstrap grid. if (empty($columns)) { return ''; } else { if (count($columns) == 1) { $output = '<div class="col-md-12">' . $columns[0] . '</div>'; } else { if (count($columns) >= 2 && !empty($courserecentactivity)) { // Here we output recent updates any some other sections. if (count($columns) > 2) { $output = '<div class="col-md-6">' . $columns[1] . $columns[2] . '</div>'; } else { $output = '<div class="col-md-6">' . $columns[1] . '</div>'; } $output .= '<div class="col-md-6">' . $columns[0] . '</div>'; } else { if (count($columns) == 2) { $output = '<div class="col-md-6">' . $columns[1] . '</div>'; $output .= '<div class="col-md-6">' . $columns[0] . '</div>'; } } } } return $output; }
/** * 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; }
/** * Substitutes the certificate text variables * * @param stdClass $issuecert The issue certificate object * @param string $certtext The certificate text without substitutions * @return string Return certificate text with all substutions */ protected function get_certificate_text($issuecert, $certtext = null) { global $OUTPUT, $DB, $CFG; if (!($user = get_complete_user_data('id', $issuecert->userid))) { print_error('nousersfound', 'moodle'); } //If no text set get firstpage text if (empty($certtext)) { $certtext = $this->get_instance()->certificatetext; } $certtext = format_text($certtext, FORMAT_HTML, array('noclean' => true)); $a = new stdClass(); $a->username = fullname($user); $a->idnumber = $user->idnumber; $a->firstname = $user->firstname; $a->lastname = $user->lastname; $a->email = $user->email; $a->icq = $user->icq; $a->skype = $user->skype; $a->yahoo = $user->yahoo; $a->aim = $user->aim; $a->msn = $user->msn; $a->phone1 = $user->phone1; $a->phone2 = $user->phone2; $a->institution = $user->institution; $a->department = $user->department; $a->address = $user->address; $a->city = $user->city; //Add userimage url $a->userimage = $OUTPUT->user_picture($user, array('size' => 1, 'popup' => false)); if (!empty($user->country)) { $a->country = get_string($user->country, 'countries'); } else { $a->country = ''; } //Formatting URL, if needed $url = $user->url; if (strpos($url, '://') === false) { $url = 'http://' . $url; } $a->url = $url; //Getting user custom profiles fields $userprofilefields = $this->get_user_profile_fields($user->id); foreach ($userprofilefields as $key => $value) { $key = 'profile_' . $key; $a->{$key} = $value; } $a->coursename = format_string($this->get_instance()->coursename, true); $a->grade = $this->get_grade($user->id); $a->date = $this->get_date($issuecert, $user->id); $a->outcome = $this->get_outcome($user->id); $a->certificatecode = $issuecert->code; // this code stay here only beace legacy supporte, coursehours variable was removed //see issue 61 https://github.com/bozoh/moodle-mod_simplecertificate/issues/61 if (isset($this->get_instance()->coursehours)) { $a->hours = format_string($this->get_instance()->coursehours . ' ' . get_string('hours', 'simplecertificate'), true); } else { $a->hours = ''; } try { if ($course = $this->get_course()) { require_once $CFG->libdir . '/coursecatlib.php'; $courseinlist = new course_in_list($course); if ($courseinlist->has_course_contacts()) { $t = array(); foreach ($courseinlist->get_course_contacts() as $userid => $coursecontact) { $t[] = $coursecontact['rolename'] . ': ' . $coursecontact['username']; } $a->teachers = implode("<br>", $t); } else { $a->teachers = ''; } } else { $a->teachers = ''; } } catch (Exception $e) { $a->teachers = ''; } //Fetch user actitivy restuls $a->userresults = $this->get_user_results($issuecert->userid); //Get User role name in course if (!($a->userrolename = get_user_roles_in_course($user->id, $course->id))) { $a->userrolename = ''; } // Get user enrollment start date // see funtion enrol_get_enrolment_end($courseid, $userid), which get enddate, not start $sql = "SELECT ue.timestart\n FROM {user_enrolments} ue\n JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n JOIN {user} u ON u.id = ue.userid\n WHERE ue.userid = :userid AND e.status = :enabled AND u.deleted = 0"; $params = array('enabled' => ENROL_INSTANCE_ENABLED, 'userid' => $user->id, 'courseid' => $course->id); if ($timestart = $DB->get_field_sql($sql, $params)) { $a->timestart = userdate($timestart, $this->get_instance()->timestartdatefmt); } else { $a->timestart = ''; } $a = (array) $a; $search = array(); $replace = array(); foreach ($a as $key => $value) { $search[] = '{' . strtoupper($key) . '}'; //Some variables can't use format_string if (strtoupper($key) == 'USERIMAGE' || strtoupper($key) == 'URL') { $replace[] = $value; } else { $replace[] = format_string((string) $value, true); } } if ($search) { $certtext = str_replace($search, $replace, $certtext); } //Clear not setted custom profile fiedls {PROFILE_xxxx} return preg_replace('[\\{PROFILE_(.*)\\}]', "", $certtext); }
/** * Makes a course hidden given a \course_in_list object. * * @param \course_in_list $course * @return bool * @throws \moodle_exception */ public static function action_course_hide(\course_in_list $course) { if (!$course->can_change_visibility()) { throw new \moodle_exception('permissiondenied', 'error', '', null, 'course_in_list::can_change_visbility'); } return course_change_visibility($course->id, false); }
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; }
/** * Returns detailed info aboout a course * * @param int $id Course identifier */ function get_course_info($id, $username = '') { global $CFG, $DB; $username = utf8_decode($username); $username = strtolower($username); $query = "SELECT\n\t\t\tco.id AS remoteid,\n\t\t\tca.id AS cat_id,\n\t\t\tca.name AS cat_name,\n\t\t\tca.description AS cat_description,\n\t\t\tco.sortorder,\n\t\t\tco.fullname,\n\t\t\tco.shortname,\n\t\t\tco.idnumber,\n\t\t\tco.summary,\n\t\t\tco.startdate,\n\t\t\tco.lang\n\t\t\tFROM\n\t\t\t{$CFG->prefix}course_categories ca\n\t\t\tJOIN\n\t\t\t{$CFG->prefix}course co ON\n\t\t\tca.id = co.category\n\t\t\tWHERE\n\t\t\tco.id = ?\n\t\t\tORDER BY\n\t\t\tsortorder ASC"; $params = array($id); $record = $DB->get_record_sql($query, $params); $options['noclean'] = true; $course_info = get_object_vars($record); $course_info['fullname'] = format_string($course_info['fullname']); $course_info['cat_name'] = format_string($course_info['cat_name']); $context = context_coursecat::instance($course_info['cat_id']); $course_info['cat_description'] = file_rewrite_pluginfile_urls($course_info['cat_description'], 'pluginfile.php', $context->id, 'coursecat', 'description', NULL); $course_info['cat_description'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $course_info['cat_description']); $course_info['cat_description'] = format_text($course_info['cat_description'], FORMAT_MOODLE, $options); $context = context_course::instance($record->remoteid); $course_info['summary'] = file_rewrite_pluginfile_urls($course_info['summary'], 'pluginfile.php', $context->id, 'course', 'summary', NULL); $course_info['summary'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $course_info['summary']); $course_info['summary'] = format_text($course_info['summary'], FORMAT_MOODLE, $options); /* Get course cost if any */ $instances = enrol_get_instances($id, true); $params = array($id); $query = "SELECT count(*)\n FROM\n {$CFG->prefix}course_sections\n WHERE\n course = ? and section != 0 and visible=1\n "; $course_info['numsections'] = $DB->count_records_sql($query, $params); $course_info['self_enrolment'] = 0; $course_info['guest'] = 0; $in = true; $now = time(); foreach ($instances as $instance) { if ($instance->enrol == 'paypal' || $instance->enrol == 'joomdle') { $enrol = $instance->enrol; $query = "SELECT cost, currency\n\t\t\t\t\t\t\tFROM {$CFG->prefix}enrol\n\t\t\t\t\t\t\twhere courseid = ? and enrol = ?"; $params = array($id, $enrol); $record = $DB->get_record_sql($query, $params); $course_info['cost'] = (double) $record->cost; $course_info['currency'] = $record->currency; } /* Get enrolment dates. We get the last one, as good/bad as any other XXX */ if ($instance->enrolstartdate) { $course_info['enrolstartdate'] = $instance->enrolstartdate; } if ($instance->enrolenddate) { $course_info['enrolenddate'] = $instance->enrolenddate; } if ($instance->enrolperiod) { $course_info['enrolperiod'] = $instance->enrolperiod; } // Self-enrolment if ($instance->enrol == 'self') { $course_info['self_enrolment'] = 1; } // Guest access if ($instance->enrol == 'guest') { $course_info['guest'] = 1; } if ($instance->enrolstartdate && $instance->enrolenddate) { $in = false; if ($instance->enrolstartdate <= $now && $instance->enrolenddate >= $now) { $in = true; } } else { if ($instance->enrolstartdate) { $in = false; if ($instance->enrolstartdate <= $now) { $in = true; } } else { if ($instance->enrolenddate) { $in = false; if ($instance->enrolenddate >= $now) { $in = true; } } } } } $course_info['in_enrol_date'] = $in; $course_info['enroled'] = 0; if ($username) { $user = get_complete_user_data('username', $username); $courses = enrol_get_users_courses($user->id, true); $my_courses = array(); foreach ($courses as $course) { $my_courses[] = $course->id; } if (in_array($id, $my_courses)) { $course_info['enroled'] = 1; } } $course_info['summary_files'] = array(); $course = new course_in_list(get_course($id)); foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $url = file_encode_url("{$CFG->wwwroot}/auth/joomdle/pluginfile_joomdle.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage); $url_item = array(); $url_item['url'] = $url; $course_info['summary_files'][] = $url_item; } return $course_info; }
$table->align = array("left", "left", "left", "left", "center", "center", "center"); $table->width = "95%"; foreach ($companycourses as $companycourse) { //print_object($companycourse); $courselink = new moodle_url('/course/view.php', array('id' => $companycourse->id)); $coursecontext = context_course::instance($companycourse->id); $deletecoursebutton = ''; if (has_capability('moodle/course:delete', $coursecontext)) { $deletecoursebutton = html_writer::link(new moodle_url('/course/delete.php', array('id' => $companycourse->id, 'returntocompanycourse' => 1)), get_string('delete')); } $editcoursebutton = ''; if (has_capability('moodle/course:update', $coursecontext)) { $editcoursebutton = html_writer::link(new moodle_url('/course/edit.php', array('id' => $companycourse->id, 'returnto' => 'companycourse')), get_string('edit')); } $record = get_course($companycourse->id); $course = new course_in_list($record); $coursesuspendbutton = ''; if ($course->can_change_visibility()) { $action = $course->visible ? 'hidecourse' : 'showcourse'; $buttontext = $course->visible ? get_string('suspend', 'block_iomad_company_admin') : get_string('unsuspend', 'block_iomad_company_admin'); $coursesuspendbutton = html_writer::link(new moodle_url('companycourses.php', array('courseid' => $companycourse->id, 'action' => $action)), $buttontext); } $companycourse->fullname = '<a href=' . $courselink . '>' . $companycourse->fullname . '</a>'; $assigncourselink = ''; $companyrecord = $DB->get_record('company', array('id' => $companycourse->companyid)); if (iomad::has_capability('local/manage_company_dept_title:manage_courses', $context) && $companyrecord) { $assigncourselink = html_writer::link(new moodle_url('/local/manage_company_dept_title/addcoursetodepttitle.php', array('course' => $companycourse->id, 'companyid' => $companycourse->companyid)), get_string('assigncourse', 'local_manage_company_dept_title')); } $coursenotificationlink = ''; if (iomad::has_capability('local/course_notification:manage', $context) && $companyrecord) { $coursenotificationlink = html_writer::link(new moodle_url('/local/course_notification/manage_notification.php', array('courseid' => $companycourse->id, 'companyid' => $companycourse->companyid)), get_string('managenotification', 'block_iomad_company_admin'));
<div class="container-fluid"> <div class="row-fluid"> <div class="seal"> <?php /** * Display fullname and shortname of course * @author André Rodrigues <Math> * @date 2015/12/19 */ $actual_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; if (strpos($actual_link, $CFG->wwwroot . '/course') !== false) { // if ($PAGE->course->category != 0) { if (isset($_GET['id'])) { $courseid = $_GET['id']; $c = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $course = new course_in_list($c); $url = ''; 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); } echo '<div>'; echo '<img src="' . $url . '" />'; echo '</div>'; echo '<div>'; echo '<p>' . $PAGE->course->fullname . '</p>'; echo '<p>' . $PAGE->course->shortname . '</p>'; echo '</div>'; } } ?>
/** * Construct contents of course_overview block * * @param array $courses list of courses in sorted order * @param array $overviews list of course overviews * @return string html to be displayed in course_overview block */ public function course_overview($courses, $overviews) { global $CFG; $html = ''; $config = get_config('block_course_overview'); $ismovingcourse = false; $courseordernumber = 0; $maxcourses = count($courses); $userediting = false; // Intialise string/icon etc if user is editing and courses > 1 if ($this->page->user_is_editing() && count($courses) > 1) { $userediting = true; $this->page->requires->js_init_call('M.block_course_overview.add_handles'); // Check if course is moving $ismovingcourse = optional_param('movecourse', FALSE, PARAM_BOOL); $movingcourseid = optional_param('courseid', 0, PARAM_INT); } // Render first movehere icon. if ($ismovingcourse) { // Remove movecourse param from url. $this->page->ensure_param_not_in_url('movecourse'); // Show moving course notice, so user knows what is being moved. $html .= $this->output->box_start('notice'); $a = new stdClass(); $a->fullname = $courses[$movingcourseid]->fullname; $a->cancellink = html_writer::link($this->page->url, get_string('cancel')); $html .= get_string('movingcourse', 'block_course_overview', $a); $html .= $this->output->box_end(); $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => 0, 'courseid' => $movingcourseid)); // Create move icon, so it can be used. $movetofirsticon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('movetofirst', 'block_course_overview', $courses[$movingcourseid]->fullname), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movetofirsticon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } foreach ($courses as $key => $course) { // If moving course, then don't show course which needs to be moved. if ($ismovingcourse && $course->id == $movingcourseid) { continue; } $html .= $this->output->box_start('span6', "course-{$course->id}"); $html .= html_writer::start_tag('div', array('class' => 'coursebox')); $html .= html_writer::start_tag('div', array('class' => 'course_title')); // If user is editing, then add move icons. if ($userediting && !$ismovingcourse) { $moveicon = html_writer::empty_tag('img', array('src' => $this->pix_url('t/move')->out(false), 'alt' => get_string('movecourse', 'block_course_overview', $course->fullname), 'title' => get_string('move'))); $moveurl = new moodle_url($this->page->url, array('sesskey' => sesskey(), 'movecourse' => 1, 'courseid' => $course->id)); $moveurl = html_writer::link($moveurl, $moveicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'move')); } // No need to pass title through s() here as it will be done automatically by html_writer. $attributes = array('title' => $course->fullname); if ($course->id > 0) { if (empty($course->visible)) { $attributes['class'] = 'dimmed'; } $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); $coursefullname = format_string(get_course_display_name_for_list($course), true, $course->id); $link = html_writer::link($courseurl, $coursefullname, $attributes); $html .= $this->output->heading($link, 2, 'title'); } else { $html .= $this->output->heading(html_writer::link(new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id=' . $course->remoteid)), format_string($course->shortname, true), $attributes) . ' (' . format_string($course->hostname) . ')', 2, 'title'); } $html .= $this->output->box('', 'flush'); $html .= html_writer::end_tag('div'); if (!empty($config->showchildren) && $course->id > 0) { // List children here. if ($children = block_course_overview_get_child_shortnames($course->id)) { $html .= html_writer::tag('span', $children, array('class' => 'coursechildren')); } } // show summary and image require_once $CFG->libdir . '/coursecatlib.php'; global $DB; $coursesummary = $DB->get_field("course", "summary", array("id" => $course->id)); $html .= html_writer::tag('p', $coursesummary, array('class' => 'summary')); // If user is moving courses, then down't show overview. if (isset($overviews[$course->id]) && !$ismovingcourse) { $html .= $this->activity_display($course->id, $overviews[$course->id]); } $html .= $this->output->box('', 'flush'); $courseordernumber++; if ($ismovingcourse) { $moveurl = new moodle_url('/blocks/course_overview/move.php', array('sesskey' => sesskey(), 'moveto' => $courseordernumber, 'courseid' => $movingcourseid)); $a = new stdClass(); $a->movingcoursename = $courses[$movingcourseid]->fullname; $a->currentcoursename = $course->fullname; $movehereicon = html_writer::empty_tag('img', array('src' => $this->output->pix_url('movehere'), 'alt' => get_string('moveafterhere', 'block_course_overview', $a), 'title' => get_string('movehere'))); $moveurl = html_writer::link($moveurl, $movehereicon); $html .= html_writer::tag('div', $moveurl, array('class' => 'movehere')); } //show image $contentimages = ''; $thiscourse = new course_in_list($course); foreach ($thiscourse->get_course_overviewfiles() as $courseimage) { $isimage = $courseimage->is_valid_image(); $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $courseimage->get_contextid() . '/' . $courseimage->get_component() . '/' . $courseimage->get_filearea() . $courseimage->get_filepath() . $courseimage->get_filename()); if ($isimage) { $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url)), array('class' => 'courseimage')); } } $html .= $contentimages; $html .= html_writer::end_tag('div'); $html .= $this->output->box_end(); } // Wrap course list in a div and return. return html_writer::tag('div', $html, array('class' => 'course_list')); }
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::empty_tag('img', array('src' => $url, 'alt' => 'Course Image '. $course->fullname, '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')); } } /** * @updateDate 25/09/2014 * @author eFaktor (fbv) * * Description * Check if there is any image connected with the course. * Not Image --> Add an empty place */ if (!$contentimages) { $contentimages .= html_writer::start_tag('div', array('class' => 'not_courseimage')); $contentimages .= html_writer::end_div();//courseimage } $content .= $contentimages. $contentfiles; // display course summary if ($course->has_summary()) { $content .= html_writer::start_tag('div', array('class' => 'course-summary')); $content .= $course->summary; $content .= html_writer::end_div();//courseimage } // 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 promoted_courses() { global $CFG, $OUTPUT, $DB; $pcourseenable = theme_eguru_get_setting('pcourseenable'); if (!$pcourseenable) { return false; } $featuredcontent = ''; /* Get Featured courses id from DB */ $featuredids = theme_eguru_get_setting('promotedcourses'); $rcourseids = !empty($featuredids) ? explode(",", $featuredids) : array(); if (empty($rcourseids)) { return false; } $hcourseids = theme_eguru_hidden_courses_ids(); if (!empty($hcourseids)) { foreach ($rcourseids as $key => $val) { if (in_array($val, $hcourseids)) { unset($rcourseids[$key]); } } } foreach ($rcourseids as $key => $val) { $ccourse = $DB->get_record('course', array('id' => $val)); if (empty($ccourse)) { unset($rcourseids[$key]); continue; } } if (empty($rcourseids)) { return false; } $fcourseids = array_chunk($rcourseids, 6); $totalfcourse = count($fcourseids); $promotedtitle = theme_eguru_get_setting('promotedtitle', 'format_text'); $promotedtitle = theme_eguru_lang($promotedtitle); $featuredheader = '<div class="custom-courses-list" id="Promoted-Courses"> <div class="container-fluid"> <div class="titlebar with-felements"> <h2>' . $promotedtitle . '</h2> <div class="slidenav pagenav"> <button class="nav-item nav-prev slick-prev"> <i class="fa fa-chevron-right"></i><i class="fa fa-chevron-left"></i> </button> <button class="nav-item nav-next slick-next"> <i class="fa fa-chevron-right"></i><i class="fa fa-chevron-left"></i> </button> <div class="clearfix"></div> </div> <div class="clearfix"></div> </div> <div class="promoted_courses" data-crow="' . $totalfcourse . '">'; $featuredfooter = ' </div> </div> </div>'; if (!empty($fcourseids)) { foreach ($fcourseids as $courseids) { $rowcontent = '<div><div class="row-fluid">'; foreach ($courseids as $courseid) { $course = get_course($courseid); $no = get_config('theme_eguru', 'patternselect'); $nimgp = empty($no) || $no == "default" ? 'cs00/no-image' : 'cs0' . $no . '/no-image'; $noimgurl = $OUTPUT->pix_url($nimgp, 'theme'); $courseurl = new moodle_url('/course/view.php', array('id' => $courseid)); if ($course instanceof stdClass) { require_once $CFG->libdir . '/coursecatlib.php'; $course = new course_in_list($course); } $imgurl = ''; $summary = theme_eguru_strip_html_tags($course->summary); $summary = theme_eguru_course_trim_char($summary, 75); $context = context_course::instance($course->id); $nostudents = count_role_users(5, $context); foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $imgurl = 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) { $imgurl = $noimgurl; } } if (empty($imgurl)) { $imgurl = $noimgurl; } $coursehtml = '<div class="span2"> <div class="course-box"> <div class="thumb"><a href="' . $courseurl . '"> <img src="' . $imgurl . '" width="135" height="135" alt="' . $course->fullname . '"></a></div> <div class="info"> <h5><a href="' . $courseurl . '">' . $course->fullname . '</a></h5> </div> </div> </div>'; $rowcontent .= $coursehtml; } $rowcontent .= '</div></div>'; $featuredcontent .= $rowcontent; } } $featuredcourses = $featuredheader . $featuredcontent . $featuredfooter; return $featuredcourses; }
/** * Set course contact avatars; */ private function apply_contact_avatars() { global $DB, $OUTPUT; $clist = new \course_in_list($this->course); $teachers = $clist->get_course_contacts(); $avatars = []; $blankavatars = []; if (!empty($teachers)) { foreach ($teachers as $teacher) { $teacherids[] = $teacher['user']->id; } $teacherusers = $DB->get_records_list('user', 'id', $teacherids); foreach ($teachers as $teacher) { if (!isset($teacherusers[$teacher['user']->id])) { continue; } $teacheruser = $teacherusers[$teacher['user']->id]; $userpicture = new \user_picture($teacheruser); $userpicture->link = false; $userpicture->size = 100; $teacherpicture = $OUTPUT->render($userpicture); if (stripos($teacherpicture, 'defaultuserpic') === false) { $avatars[] = $teacherpicture; } else { $blankavatars[] = $teacherpicture; } } } // Let's put the interesting avatars first! $avatars = array_merge($avatars, $blankavatars); if (count($avatars) > 5) { // Show 4 avatars and link to show more. $this->visibleavatars = array_slice($avatars, 0, 4); $this->hiddenavatars = array_slice($avatars, 4); $this->showextralink = true; } else { $this->visibleavatars = $avatars; $this->hiddenavatars = []; } $this->hiddenavatarcount = count($this->hiddenavatars); }
/** * Print fixy (login or menu for signed in users) * */ public function print_fixed_menu() { global $CFG, $USER, $PAGE, $DB; $logout = get_string('logout'); $isguest = isguestuser(); if (!isloggedin() || $isguest) { $login = get_string('login'); $cancel = get_string('cancel'); $username = get_string('username'); $password = get_string('password'); $loginform = get_string('loginform', 'theme_snap'); $helpstr = ''; if (empty($CFG->forcelogin) || $isguest || !isloggedin() || !empty($CFG->registerauth) || is_enabled_auth('none') || !empty($CFG->auth_instructions)) { if ($isguest) { $helpstr = '<p class="text-center">' . get_string('loggedinasguest', 'theme_snap') . '</p>'; $helpstr .= '<p class="text-center">' . '<a class="btn btn-primary" href="' . s($CFG->wwwroot) . '/login/logout.php?sesskey=' . sesskey() . '">' . $logout . '</a></p>'; $helpstr .= '<p class="text-center">' . '<a href="' . s($CFG->wwwroot) . '/login/index.php">' . get_string('helpwithloginandguest', 'theme_snap') . '</a></p>'; } else { if (empty($CFG->forcelogin)) { $help = get_string('helpwithloginandguest', 'theme_snap'); } else { $help = get_string('helpwithlogin', 'theme_snap'); } $helpstr = "<p class='text-center'><a href='" . s($CFG->wwwroot) . "/login/index.php'>{$help}</a></p>"; } } echo $this->print_login_button(); echo "<form class=fixy action='{$CFG->wwwroot}/login/' method='post' id='login'>\n <a id='fixy-close' class='pull-right snap-action-icon' href='#'>\n <i class='icon icon-office-52'></i><small>{$cancel}</small>\n </a>\n <div class=fixy-inner>\n <legend>{$loginform}</legend>\n <label for='username'>{$username}</label>\n <input autocapitalize='off' type='text' name='username' id='username' placeholder='" . s($username) . "'>\n <label for='password'>{$password}</label>\n <input type='password' name='password' id='password' placeholder='" . s($password) . "'>\n <br>\n <input type='submit' id='loginbtn' value='" . s($login) . "'>\n {$helpstr}\n </div>\n </form>"; } else { $courselist = ""; $userpicture = new user_picture($USER); $userpicture->link = false; $userpicture->alttext = false; $userpicture->size = 100; $picture = $this->render($userpicture); $mycourses = enrol_get_my_courses(null, 'visible DESC, fullname ASC, id DESC'); $courselist .= "<section id='fixy-my-courses'><div class='clearfix'><h2>" . get_string('courses') . "</h2>"; foreach ($mycourses as $c) { $pubstatus = ""; if (!$c->visible) { $notpublished = get_string('notpublished', 'theme_snap'); $pubstatus = "<small class='published-status'>" . $notpublished . "</small>"; } $bgcolor = local::get_course_color($c->id); $courseimagecss = "background-color: #{$bgcolor};"; $bgimage = local::course_coverimage_url($c->id); if (!empty($bgimage)) { $courseimagecss .= "background-image: url({$bgimage});"; } $dynamicinfo = '<div data-courseid="' . $c->id . '" class=dynamicinfo></div>'; $teachers = ''; $courseteachers = ''; $clist = new course_in_list($c); $teachers = $clist->get_course_contacts(); if (!empty($teachers)) { $courseteachers = "<div class='sr-only'>" . get_string('coursecontacts', 'theme_snap') . "</div>"; // Get all teacher user records in one go. $teacherids = array(); foreach ($teachers as $teacher) { $teacherids[] = $teacher['user']->id; } $teacherusers = $DB->get_records_list('user', 'id', $teacherids); foreach ($teachers as $teacher) { if (!isset($teacherusers[$teacher['user']->id])) { continue; } $teacheruser = $teacherusers[$teacher['user']->id]; $userpicture = new user_picture($teacheruser); $userpicture->link = false; $userpicture->size = 100; $teacherpicture = $this->render($userpicture); $courseteachers .= $teacherpicture; } } $clink = '<div data-href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '" class="courseinfo" style="' . $courseimagecss . '"> <div class="courseinfo-body"><h3><a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . format_string($c->fullname) . '</a></h3>' . $dynamicinfo . $courseteachers . $pubstatus . '</div></div>'; $courselist .= $clink; } $courselist .= "</div>"; $courselist .= '<div class="row fixy-browse-search-courses"><br>'; if (has_capability('moodle/site:config', context_system::instance())) { $courserenderer = $PAGE->get_renderer('core', 'course'); $courselist .= '<div class="col-md-6">'; $courselist .= $courserenderer->course_search_form(null, 'fixy'); $courselist .= '</div>'; } $courselist .= '<div class="col-md-6">'; $courselist .= $this->print_view_all_courses(); $courselist .= '</div>'; $courselist .= '</div></section>'; // Close row. $menu = get_string('menu', 'theme_snap'); echo '<a href="#primary-nav" aria-haspopup="true" class="fixy-trigger" id="js-personal-menu-trigger" ' . 'aria-controls="primary-nav" title="' . get_string('sitenavigation', 'theme_snap') . '" data-toggle="tooltip" data-placement="bottom">' . $menu . $picture . $this->render_badge_count() . '</a>'; $close = get_string('close', 'theme_snap'); $viewyourprofile = get_string('viewyourprofile', 'theme_snap'); $realuserinfo = ''; if (\core\session\manager::is_loggedinas()) { $realuser = \core\session\manager::get_realuser(); $via = get_string('via', 'theme_snap'); $fullname = fullname($realuser, true); $realuserinfo = html_writer::span($via . ' ' . html_writer::span($fullname, 'real-user-name'), 'real-user-info'); } echo '<nav id="primary-nav" class="fixy toggle-details" tabindex="0"> <a id="fixy-close" class="pull-right snap-action-icon" href="#"> <i class="icon icon-office-52"></i><small>' . $close . '</small> </a> <div class=fixy-inner> <h1 id="fixy-profile-link"> <a title="' . s($viewyourprofile) . '" href="' . s($CFG->wwwroot) . '/user/profile.php" >' . $picture . '<span id="fixy-username">' . format_string(fullname($USER)) . '</span> </a> </h1>' . $realuserinfo . $courselist . $this->render_callstoaction() . ' <div class="fixy-logout-footer clearfix text-center"> <a class="btn btn-default logout" href="' . s($CFG->wwwroot) . '/login/logout.php?sesskey=' . sesskey() . '">' . $logout . '</a> </div> </div><!-- end fixy-inner --> </nav><!-- end primary nav -->'; } }
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; }
public function frontpage_available_courses() { /* available courses */ global $CFG, $OUTPUT; require_once $CFG->libdir . '/coursecatlib.php'; $chelper = new coursecat_helper(); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->set_courses_display_options(array('recursive' => true, 'limit' => $CFG->frontpagecourselimit, 'viewmoreurl' => new moodle_url('/course/index.php'), 'viewmoretext' => new lang_string('fulllistofcourses'))); $chelper->set_attributes(array('class' => 'frontpage-course-list-all')); $courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options()); $totalcount = coursecat::get(0)->get_courses_count($chelper->get_courses_display_options()); $course_ids = array_keys($courses); $new_course = get_string('availablecourses'); $header = '<div id="frontpage-course-list"> <h2>' . $new_course . '</h2> <div class="courses frontpage-course-list-all"> <div class="row-fluid">'; $footer = '</div> </div> </div>'; $co_cnt = 1; $content = ''; if ($ccc = get_courses('all', 'c.sortorder ASC', 'c.id,c.shortname,c.visible')) { foreach ($course_ids as $course_id) { $course = get_course($course_id); $noimg_url = $OUTPUT->pix_url('no-image', 'theme'); $course_url = new moodle_url('/course/view.php', array('id' => $course_id)); if ($course instanceof stdClass) { require_once $CFG->libdir . '/coursecatlib.php'; $course = new course_in_list($course); } $img_url = ''; $context = context_course::instance($course->id); foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $img_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) { $img_url = $noimg_url; } } if (empty($img_url)) { $img_url = $noimg_url; } $content .= '<div class="span3"> <div class="fp-coursebox"> <div class="fp-coursethumb"> <a href="' . $course_url . '"> <img src="' . $img_url . '" width="243" height="165" alt="' . $course->fullname . '"> </a> </div> <div class="fp-courseinfo"> <h5><a href="' . $course_url . '">' . $course->fullname . '</a></h5> <div class="readmore"><a href="' . $course_url . '">Readmore<i class="fa fa-angle-double-right"></i></a></div> </div> </div> </div>'; if ($co_cnt % 4 == "0") { $content .= '<div class="clearfix hidexs"></div>'; } $co_cnt++; } } $course_html = $header . $content . $footer; echo $course_html; if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) { // Print link to create a new course, for the 1st available category. echo $this->add_new_course_button(); } }