Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 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;
 }
 /**
  * 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);
 }
    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;
    }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 /**
  * 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 -->';
     }
 }