• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP enrol_get_my_courses函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中enrol_get_my_courses函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_get_my_courses函数的具体用法?PHP enrol_get_my_courses怎么用?PHP enrol_get_my_courses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了enrol_get_my_courses函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_all_notes

 public function get_all_notes()
 {
     echo \html_writer::tag('p', get_string('viewallnote', 'local_note'), ['class' => 'lead']);
     $courses = enrol_get_my_courses('id');
     $courselist = [];
     foreach ($courses as $key => $nouse) {
         $courselist[] = $key;
     }
     if (empty($courselist)) {
         return \html_writer::div(get_string("nonotesavailable", "local_note"), 'alert alert-warning');
     }
     $sql = 'select * from {cli_note} where courseid in(' . implode(',', $courselist) . ') and status = 1 order by id DESC';
     $record = $this->db->get_records_sql($sql);
     if (!empty($record) && $record != null) {
         $table = new \html_table();
         $table->head = (array) get_strings(['serial', 'author', 'date', 'course', 'title', 'content', 'attachment', 'label', 'active', 'action'], 'local_note');
         $count = 1;
         foreach ($record as $key => $row) {
             $status = $row->status == true ? '<span class="label label-success">' . get_string('active', 'local_note') . '</span>' : '<span class="label label-warning">' . get_string('inactive', 'local_note') . '</span>';
             $action = '<i class="fa fa-lock" title="Access denied"></i>';
             $user = $this->db->get_record('user', ['id' => $row->publisherid], 'firstname, lastname');
             $author = $user->firstname . ' ' . $user->lastname;
             if ($this->userid == $row->publisherid) {
                 $action = \html_writer::link(new \moodle_url($this->cfg->wwwroot . '/local/note/edit_note.php?id=' . $row->id), '<i class="fa fa-edit"></i> ', ['title' => 'Edit note']);
                 $action .= \html_writer::link(new \moodle_url($this->cfg->wwwroot . '/local/note/delete_note.php?id=' . $row->id), ' <i class="fa fa-trash"></i>', ['title' => 'Delete note']);
             }
             $course = $this->db->get_record('course', array('id' => $row->courseid), 'fullname');
             $table->data[] = array($count++, $author, date('j M Y', $row->createdtime), \html_writer::link(new \moodle_url($this->cfg->wwwroot . '/course/view.php', ['id' => $row->courseid]), $course->fullname), '<a href="view_note.php?id=' . $row->id . '">' . $row->title . '</a>', strip_tags(substr($row->content, 0, 20)) . '&nbsp;<a href="view_note.php?id=' . $row->id . '">' . get_string('more', 'local_note') . '</a>', \html_writer::link(new \moodle_url($this->get_attachment($row->attachment)['url']), $this->get_attachment($row->attachment)['filename'], ['download' => 'download']), $row->label, $status, $action);
         }
         return \html_writer::table($table);
     } else {
         return \html_writer::div(get_string("nonotesavailable", "local_note"), 'alert alert-warning');
     }
 }
开发者ID:shambhukumar,项目名称:moodle-note,代码行数:34,代码来源:note.php


示例2: setup

 /**
  * Create basic setup for test cases
  * @return bool
  */
 public function setup()
 {
     global $CFG;
     $this->resetAfterTest(true);
     // Read settings from config.json.
     $configdata = file_get_contents($CFG->dirroot . '/local/onenote/tests/phpu_config_data.json');
     if (!$configdata) {
         echo 'Please provide PHPUnit testing configs in a config.json file';
         return false;
     }
     $this->config = json_decode($configdata, false);
     $this->user = $this->getDataGenerator()->create_user();
     $this->user1 = $this->getDataGenerator()->create_user();
     $this->course1 = $this->getDataGenerator()->create_course();
     $this->course2 = $this->getDataGenerator()->create_course();
     // Setting user and enrolling to the courses created with teacher role.
     $this->setUser($this->user->id);
     $c1ctx = context_course::instance($this->course1->id);
     $c2ctx = context_course::instance($this->course2->id);
     $this->getDataGenerator()->enrol_user($this->user->id, $this->course1->id, 3);
     $this->getDataGenerator()->enrol_user($this->user->id, $this->course2->id, 3);
     $this->assertCount(2, enrol_get_my_courses());
     $courses = enrol_get_my_courses();
     // Student enrollment.
     $this->setUser($this->user1->id);
     $this->getDataGenerator()->enrol_user($this->user1->id, $this->course1->id, 5);
     $this->getDataGenerator()->enrol_user($this->user1->id, $this->course2->id, 5);
     $this->assertCount(2, get_enrolled_users($c1ctx));
 }
开发者ID:jamesmcq,项目名称:o365-moodle,代码行数:33,代码来源:onenoteapi_test.php


示例3: get_glossaries_by_courses

 /**
  * Returns a list of glossaries in a provided list of courses.
  *
  * If no list is provided all glossaries that the user can view will be returned.
  *
  * @param array $courseids the course IDs.
  * @return array of glossaries
  * @since Moodle 3.1
  */
 public static function get_glossaries_by_courses($courseids = array())
 {
     $params = self::validate_parameters(self::get_glossaries_by_courses_parameters(), array('courseids' => $courseids));
     $warnings = array();
     $courses = array();
     $courseids = $params['courseids'];
     if (empty($courseids)) {
         $courses = enrol_get_my_courses();
         $courseids = array_keys($courses);
     }
     // Array to store the glossaries to return.
     $glossaries = array();
     // Ensure there are courseids to loop through.
     if (!empty($courseids)) {
         list($courses, $warnings) = external_util::validate_courses($courseids, $courses);
         // Get the glossaries in these courses, this function checks users visibility permissions.
         $glossaries = get_all_instances_in_courses('glossary', $courses);
         foreach ($glossaries as $glossary) {
             $context = context_module::instance($glossary->coursemodule);
             $glossary->name = external_format_string($glossary->name, $context->id);
             list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat, $context->id, 'mod_glossary', 'intro', null);
         }
     }
     $result = array();
     $result['glossaries'] = $glossaries;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:37,代码来源:external.php


示例4: render_custom_menu

 protected function render_custom_menu(custom_menu $menu)
 {
     global $CFG;
     require_once $CFG->dirroot . '/course/lib.php';
     //navigation mycourses is no supported since 2.4
     if (isloggedin() && !isguestuser() && ($mycourses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC'))) {
         $branchlabel = get_string('mycourses');
         $branchurl = new moodle_url('/course/index.php');
         $branchtitle = $branchlabel;
         $branchsort = 8000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         foreach ($mycourses as $mycourse) {
             $branch->add($mycourse->shortname, new moodle_url('/course/view.php', array('id' => $mycourse->id)), $mycourse->fullname);
         }
     }
     $course_id = $this->page->course->id;
     if (isloggedin() && $course_id > 1) {
         $branchlabel = get_string('grades');
         $branchurl = new moodle_url('/grade/report/index.php?id=' . $this->page->course->id);
         $branchtitle = $branchlabel;
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
     }
     return parent::render_custom_menu($menu);
 }
开发者ID:sdc,项目名称:moodle-theme_archaius,代码行数:25,代码来源:renderers.php


示例5: render_custom_menu

 protected function render_custom_menu(custom_menu $menu)
 {
     /*
      * This code replaces adds the current enrolled
      * courses to the custommenu.
      */
     $hasdisplaymycourses = empty($this->page->theme->settings->displaymycourses) ? false : $this->page->theme->settings->displaymycourses;
     if (isloggedin() && !isguestuser() && $hasdisplaymycourses) {
         $mycoursetitle = $this->page->theme->settings->mycoursetitle;
         if ($mycoursetitle == 'module') {
             $branchtitle = get_string('mymodules', 'theme_evolved');
         } else {
             if ($mycoursetitle == 'unit') {
                 $branchtitle = get_string('myunits', 'theme_evolved');
             } else {
                 if ($mycoursetitle == 'class') {
                     $branchtitle = get_string('myclasses', 'theme_evolved');
                 } else {
                     $branchtitle = get_string('mycourses', 'theme_evolved');
                 }
             }
         }
         $branchlabel = '<i class="fa fa-briefcase"></i>' . $branchtitle;
         $branchurl = new moodle_url('/my/index.php');
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         if ($courses = enrol_get_my_courses(NULL, 'fullname ASC')) {
             foreach ($courses as $course) {
                 if ($course->visible) {
                     $branch->add(format_string($course->fullname), new moodle_url('/course/view.php?id=' . $course->id), format_string($course->shortname));
                 }
             }
         } else {
             $noenrolments = get_string('noenrolments', 'theme_evolved');
             $branch->add('<em>' . $noenrolments . '</em>', new moodle_url('/'), $noenrolments);
         }
     }
     /*
      * This code replaces adds the My Dashboard
      * functionality to the custommenu.
      */
     $hasdisplaymydashboard = empty($this->page->theme->settings->displaymydashboard) ? false : $this->page->theme->settings->displaymydashboard;
     if (isloggedin() && !isguestuser() && $hasdisplaymydashboard) {
         $branchlabel = '<i class="fa fa-dashboard"></i>' . get_string('mydashboard', 'theme_evolved');
         $branchurl = new moodle_url('/my/index.php');
         $branchtitle = get_string('mydashboard', 'theme_evolved');
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         $branch->add(get_string('profile') . '</em>', new moodle_url('/user/profile.php'), get_string('profile'));
         $branch->add(get_string('pluginname', 'block_calendar_month') . '</em>', new moodle_url('/calendar/view.php'), get_string('pluginname', 'block_calendar_month'));
         $branch->add(get_string('pluginname', 'block_messages') . '</em>', new moodle_url('/message/index.php'), get_string('pluginname', 'block_messages'));
         $branch->add(get_string('badges') . '</em>', new moodle_url('/badges/mybadges.php'), get_string('badges'));
         $branch->add(get_string('privatefiles', 'block_private_files') . '</em>', new moodle_url('/user/files.php'), get_string('privatefiles', 'block_private_files'));
         $branch->add(get_string('logout') . '</em>', new moodle_url('/login/logout.php'), get_string('logout'));
     }
     return parent::render_custom_menu($menu);
 }
开发者ID:robinleung,项目名称:moodle-theme_evolved,代码行数:57,代码来源:core_renderer.php


示例6: get_forums_by_courses

    /**
     * Returns a list of forums in a provided list of courses,
     * if no list is provided all forums that the user can view
     * will be returned.
     *
     * @param array $courseids the course ids
     * @return array the forum details
     * @since Moodle 2.5
     */
    public static function get_forums_by_courses($courseids = array()) {
        global $CFG, $DB, $USER;

        require_once($CFG->dirroot . "/mod/forum/lib.php");

        $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids));

        if (empty($params['courseids'])) {
            // Get all the courses the user can view.
            $courseids = array_keys(enrol_get_my_courses());
        } else {
            $courseids = $params['courseids'];
        }

        // Array to store the forums to return.
        $arrforums = array();

        // Ensure there are courseids to loop through.
        if (!empty($courseids)) {
            // Go through the courseids and return the forums.
            foreach ($courseids as $cid) {
                // Get the course context.
                $context = context_course::instance($cid);
                // Check the user can function in this context.
                self::validate_context($context);
                // Get the forums in this course.
                if ($forums = $DB->get_records('forum', array('course' => $cid))) {
                    // Get the modinfo for the course.
                    $modinfo = get_fast_modinfo($cid);
                    // Get the forum instances.
                    $foruminstances = $modinfo->get_instances_of('forum');
                    // Loop through the forums returned by modinfo.
                    foreach ($foruminstances as $forumid => $cm) {
                        // If it is not visible or present in the forums get_records call, continue.
                        if (!$cm->uservisible || !isset($forums[$forumid])) {
                            continue;
                        }
                        // Set the forum object.
                        $forum = $forums[$forumid];
                        // Get the module context.
                        $context = context_module::instance($cm->id);
                        // Check they have the view forum capability.
                        require_capability('mod/forum:viewdiscussion', $context);
                        // Format the intro before being returning using the format setting.
                        list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat,
                            $context->id, 'mod_forum', 'intro', 0);
                        // Add the course module id to the object, this information is useful.
                        $forum->cmid = $cm->id;
                        // Add the forum to the array to return.
                        $arrforums[$forum->id] = (array) $forum;
                    }
                }
            }
        }

        return $arrforums;
    }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:66,代码来源:externallib.php


示例7: get_surveys_by_courses

 /**
  * Returns a list of surveys in a provided list of courses,
  * if no list is provided all surveys that the user can view will be returned.
  *
  * @param array $courseids the course ids
  * @return array of surveys details
  * @since Moodle 3.0
  */
 public static function get_surveys_by_courses($courseids = array())
 {
     global $CFG, $USER, $DB;
     $returnedsurveys = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_surveys_by_courses_parameters(), array('courseids' => $courseids));
     $mycourses = array();
     if (empty($params['courseids'])) {
         $mycourses = enrol_get_my_courses();
         $params['courseids'] = array_keys($mycourses);
     }
     // Ensure there are courseids to loop through.
     if (!empty($params['courseids'])) {
         list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
         // Get the surveys in this course, this function checks users visibility permissions.
         // We can avoid then additional validate_context calls.
         $surveys = get_all_instances_in_courses("survey", $courses);
         foreach ($surveys as $survey) {
             $context = context_module::instance($survey->coursemodule);
             // Entry to return.
             $surveydetails = array();
             // First, we return information that any user can see in the web interface.
             $surveydetails['id'] = $survey->id;
             $surveydetails['coursemodule'] = $survey->coursemodule;
             $surveydetails['course'] = $survey->course;
             $surveydetails['name'] = external_format_string($survey->name, $context->id);
             if (has_capability('mod/survey:participate', $context)) {
                 $trimmedintro = trim($survey->intro);
                 if (empty($trimmedintro)) {
                     $tempo = $DB->get_field("survey", "intro", array("id" => $survey->template));
                     $survey->intro = get_string($tempo, "survey");
                 }
                 // Format intro.
                 list($surveydetails['intro'], $surveydetails['introformat']) = external_format_text($survey->intro, $survey->introformat, $context->id, 'mod_survey', 'intro', null);
                 $surveydetails['introfiles'] = external_util::get_area_files($context->id, 'mod_survey', 'intro', false, false);
                 $surveydetails['template'] = $survey->template;
                 $surveydetails['days'] = $survey->days;
                 $surveydetails['questions'] = $survey->questions;
                 $surveydetails['surveydone'] = survey_already_done($survey->id, $USER->id) ? 1 : 0;
             }
             if (has_capability('moodle/course:manageactivities', $context)) {
                 $surveydetails['timecreated'] = $survey->timecreated;
                 $surveydetails['timemodified'] = $survey->timemodified;
                 $surveydetails['section'] = $survey->section;
                 $surveydetails['visible'] = $survey->visible;
                 $surveydetails['groupmode'] = $survey->groupmode;
                 $surveydetails['groupingid'] = $survey->groupingid;
             }
             $returnedsurveys[] = $surveydetails;
         }
     }
     $result = array();
     $result['surveys'] = $returnedsurveys;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:64,代码来源:external.php


示例8: get_forums_by_courses

 /**
  * Returns a list of forums in a provided list of courses,
  * if no list is provided all forums that the user can view
  * will be returned.
  *
  * @param array $courseids the course ids
  * @return array the forum details
  * @since Moodle 2.5
  */
 public static function get_forums_by_courses($courseids = array())
 {
     global $CFG;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids));
     if (empty($params['courseids'])) {
         // Get all the courses the user can view.
         $courseids = array_keys(enrol_get_my_courses());
     } else {
         $courseids = $params['courseids'];
     }
     // Array to store the forums to return.
     $arrforums = array();
     // Ensure there are courseids to loop through.
     if (!empty($courseids)) {
         // Array of the courses we are going to retrieve the forums from.
         $dbcourses = array();
         // Mod info for courses.
         $modinfocourses = array();
         // Go through the courseids and return the forums.
         foreach ($courseids as $courseid) {
             // Check the user can function in this context.
             try {
                 $context = context_course::instance($courseid);
                 self::validate_context($context);
                 // Get the modinfo for the course.
                 $modinfocourses[$courseid] = get_fast_modinfo($courseid);
                 $dbcourses[$courseid] = $modinfocourses[$courseid]->get_course();
             } catch (Exception $e) {
                 continue;
             }
         }
         // Get the forums in this course. This function checks users visibility permissions.
         if ($forums = get_all_instances_in_courses("forum", $dbcourses)) {
             foreach ($forums as $forum) {
                 $course = $dbcourses[$forum->course];
                 $cm = $modinfocourses[$course->id]->get_cm($forum->coursemodule);
                 $context = context_module::instance($cm->id);
                 // Skip forums we are not allowed to see discussions.
                 if (!has_capability('mod/forum:viewdiscussion', $context)) {
                     continue;
                 }
                 // Format the intro before being returning using the format setting.
                 list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat, $context->id, 'mod_forum', 'intro', 0);
                 // Discussions count. This function does static request cache.
                 $forum->numdiscussions = forum_count_discussions($forum, $cm, $course);
                 $forum->cmid = $forum->coursemodule;
                 // Add the forum to the array to return.
                 $arrforums[$forum->id] = $forum;
             }
         }
     }
     return $arrforums;
 }
开发者ID:educakanchay,项目名称:campus,代码行数:63,代码来源:externallib.php


示例9: get_wikis_by_courses

 /**
  * Returns a list of wikis in a provided list of courses,
  * if no list is provided all wikis that the user can view will be returned.
  *
  * @param array $courseids The courses IDs.
  * @return array Containing a list of warnings and a list of wikis.
  * @since Moodle 3.1
  */
 public static function get_wikis_by_courses($courseids = array())
 {
     $returnedwikis = array();
     $warnings = array();
     $params = self::validate_parameters(self::get_wikis_by_courses_parameters(), array('courseids' => $courseids));
     $mycourses = array();
     if (empty($params['courseids'])) {
         $mycourses = enrol_get_my_courses();
         $params['courseids'] = array_keys($mycourses);
     }
     // Ensure there are courseids to loop through.
     if (!empty($params['courseids'])) {
         list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
         // Get the wikis in this course, this function checks users visibility permissions.
         // We can avoid then additional validate_context calls.
         $wikis = get_all_instances_in_courses('wiki', $courses);
         foreach ($wikis as $wiki) {
             $context = context_module::instance($wiki->coursemodule);
             // Entry to return.
             $module = array();
             // First, we return information that any user can see in (or can deduce from) the web interface.
             $module['id'] = $wiki->id;
             $module['coursemodule'] = $wiki->coursemodule;
             $module['course'] = $wiki->course;
             $module['name'] = external_format_string($wiki->name, $context->id);
             $viewablefields = [];
             if (has_capability('mod/wiki:viewpage', $context)) {
                 list($module['intro'], $module['introformat']) = external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', $wiki->id);
                 $module['introfiles'] = external_util::get_area_files($context->id, 'mod_wiki', 'intro', false, false);
                 $viewablefields = array('firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend', 'section', 'visible', 'groupmode', 'groupingid');
             }
             // Check additional permissions for returning optional private settings.
             if (has_capability('moodle/course:manageactivities', $context)) {
                 $additionalfields = array('timecreated', 'timemodified');
                 $viewablefields = array_merge($viewablefields, $additionalfields);
             }
             foreach ($viewablefields as $field) {
                 $module[$field] = $wiki->{$field};
             }
             // Check if user can add new pages.
             $module['cancreatepages'] = wiki_can_create_pages($context);
             $returnedwikis[] = $module;
         }
     }
     $result = array();
     $result['wikis'] = $returnedwikis;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:57,代码来源:external.php


示例10: get_content

 function get_content()
 {
     global $CFG, $OUTPUT, $USER, $DB;
     //global $CFG, $SESSION, $USER, $COURSE, $SITE, $PAGE, $DB;
     if ($this->content !== null) {
         return $this->content;
     }
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     //show my incomplete courses
     //$completion = get_completion($USER->id);
     //print_object($completion);
     //complete courses
     //show the courses the user is enrolled.
     $this->content->text .= '<h2>Enrolled Courses</h2>';
     $mycourses = enrol_get_my_courses();
     /**
        TODO:
                 - Count how many courses the user is enrolled to
                 - Count how many courses are complete (if timecompleted is not null)
                 - 
     */
     //total courses
     $totalcourses = $DB->count_records('course_completions', array('userid' => $USER->id));
     //incomplete courses
     //$incompletecourses = $DB->count_records('course_completions', array('userid'=>$USER->id,'timecompleted'=>NULL));
     //inprogress courses
     $sql = "SELECT * FROM {course_completions} WHERE userid = :userid AND timestarted <> :timestarted AND timecompleted IS NULL";
     $inprogress_records = $DB->get_records_sql($sql, array('userid' => $USER->id, 'timestarted' => '0'));
     $inprogress_count = count($inprogress_records);
     //complete courses
     $sql = "SELECT * FROM {course_completions} WHERE userid = :userid AND timecompleted IS NOT :timecompleted";
     $complete_records = $DB->get_records_sql($sql, array('userid' => $USER->id, 'timecompleted' => NULL));
     $completecourses = count($complete_records);
     //print_object($inprogress_count);
     foreach ($mycourses as $course) {
         $this->content->text .= '<p><a href="">' . $course->shortname . '</a></p>';
     }
     //$this->content->text .= "Incomplete: " . $incompletecourses." / ".$totalcourses."<br>";
     $this->content->text .= "Inprogress: " . $inprogress_count . "<br>";
     $this->content->text .= "Complete: " . $completecourses . "<br>";
     $this->content->text .= "Total Courses: " . $totalcourses . "<br>";
     return $this->content;
 }
开发者ID:andrewmrg,项目名称:block_fulloverview,代码行数:49,代码来源:block_fulloverview.php


示例11: get_forums_by_courses

    /**
     * Returns a list of forums in a provided list of courses,
     * if no list is provided all forums that the user can view
     * will be returned.
     *
     * @param array $courseids the course ids
     * @return array the forum details
     * @since Moodle 2.5
     */
    public static function get_forums_by_courses($courseids = array()) {
        global $CFG;

        require_once($CFG->dirroot . "/mod/forum/lib.php");

        $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids));

        if (empty($params['courseids'])) {
            $params['courseids'] = array_keys(enrol_get_my_courses());
        }

        // Array to store the forums to return.
        $arrforums = array();
        $warnings = array();

        // Ensure there are courseids to loop through.
        if (!empty($params['courseids'])) {

            list($courses, $warnings) = external_util::validate_courses($params['courseids']);

            // Get the forums in this course. This function checks users visibility permissions.
            $forums = get_all_instances_in_courses("forum", $courses);
            foreach ($forums as $forum) {

                $course = $courses[$forum->course];
                $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
                $context = context_module::instance($cm->id);

                // Skip forums we are not allowed to see discussions.
                if (!has_capability('mod/forum:viewdiscussion', $context)) {
                    continue;
                }

                // Format the intro before being returning using the format setting.
                list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat,
                                                                                $context->id, 'mod_forum', 'intro', 0);
                // Discussions count. This function does static request cache.
                $forum->numdiscussions = forum_count_discussions($forum, $cm, $course);
                $forum->cmid = $forum->coursemodule;
                $forum->cancreatediscussions = forum_user_can_post_discussion($forum, null, -1, $cm, $context);

                // Add the forum to the array to return.
                $arrforums[$forum->id] = $forum;
            }
        }

        return $arrforums;
    }
开发者ID:uniedpa,项目名称:moodle,代码行数:57,代码来源:externallib.php


示例12: block_my_course_progress_get_sorted_courses

/**
 * Return sorted list of user courses
 *
 * @return array                courses
 */
function block_my_course_progress_get_sorted_courses()
{
    global $USER;
    $courses = enrol_get_my_courses();
    if (array_key_exists($site->id, $courses)) {
        unset($courses[$site->id]);
    }
    foreach ($courses as $c) {
        if (isset($USER->lastcourseaccess[$c->id])) {
            $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
        } else {
            $courses[$c->id]->lastaccess = 0;
        }
    }
    return $courses;
}
开发者ID:Regaez,项目名称:moodle-block_my_course_progress,代码行数:21,代码来源:locallib.php


示例13: render_custom_menu

 protected function render_custom_menu(custom_menu $menu)
 {
     global $CFG;
     $hasdisplaymycourses = theme_lambda_get_setting('mycourses_dropdown');
     if (isloggedin() && !isguestuser() && $hasdisplaymycourses) {
         $branchlabel = get_string('mycourses');
         $branchurl = new moodle_url('#');
         $branchtitle = $branchlabel;
         $branchsort = 10000;
         $branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
         if ($mycourses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {
             foreach ($mycourses as $mycourse) {
                 $branch->add($mycourse->shortname, new moodle_url('/course/view.php', array('id' => $mycourse->id)), $mycourse->fullname);
             }
         } else {
             $hometext = get_string('myhome');
             $homelabel = $hometext;
             $branch->add($homelabel, new moodle_url('/my/index.php'), $hometext);
         }
     }
     return parent::render_custom_menu($menu);
 }
开发者ID:sirromas,项目名称:medical,代码行数:22,代码来源:core_renderer.php


示例14: block_resources_get_all_resources

/**
* get all resources!
* 
*/
function block_resources_get_all_resources()
{
    global $DB;
    // get courses list in wich logged user was enrolled
    $courses = enrol_get_my_courses();
    if (empty($courses)) {
        return false;
    }
    $ids = implode(',', array_keys($courses));
    // --------- cycle by courses
    foreach ($courses as $key => $course) {
        if (!isset($courses[$key]->resources)) {
            $courses[$key]->resources = array();
        }
        // get videoresources list from courses and then render it
        // * link to videoresource = link to course modules
        $courses[$key]->videoresources = get_coursemodules_in_course('videoresource', $course->id);
    }
    // get resources list from all courses with AVG rating
    $resources = $DB->get_records_sql('
        SELECT DISTINCT rl.course * 10000 + si.id as id, si.id as section_id, rl.course, r.id as resource_id, r.url, r.title, r.internal_title, r.description, r.author, r.source
               , (SELECT AVG(t.rating) FROM mdl_rating t 
                    LEFT JOIN mdl_resource_section_items si ON si.id = t.itemid WHERE si.resource_item_id = r.id) as avgrate
        FROM mdl_resourcelib rl
             RIGHT JOIN mdl_resourcelib_content rc ON rl.id = rc.resourcelib_id
             RIGHT JOIN mdl_resource_lists l ON rc.instance_id = l.id
             RIGHT JOIN mdl_resource_list_sections ls ON l.id = ls.resource_list_id
             RIGHT JOIN mdl_resource_section_items si ON ls.resource_section_id = si.resource_section_id
             RIGHT JOIN mdl_resource_items r ON r.id = si.resource_item_id
        WHERE rl.course IN (' . $ids . ')
        ORDER BY ls.sort_order, si.sort_order');
    foreach ($resources as $key => $resource) {
        if (!isset($courses[$resource->course]->resources[$resource->resource_id])) {
            $courses[$resource->course]->resources[$resource->resource_id] = $resource;
        }
    }
    return $courses;
}
开发者ID:TheFridayInstitute,项目名称:moodle_block_resources,代码行数:42,代码来源:locallib.php


示例15: setup

 /**
  * Create basic setup for test cases
  * @return bool
  */
 public function setup()
 {
     global $CFG;
     return true;
     // Need to update tests to not contact external services.
     $this->resetAfterTest(true);
     $this->user = $this->getDataGenerator()->create_user();
     $this->user1 = $this->getDataGenerator()->create_user();
     $this->course1 = $this->getDataGenerator()->create_course();
     $this->course2 = $this->getDataGenerator()->create_course();
     // Setting user and enrolling to the courses created with teacher role.
     $this->setUser($this->user->id);
     $c1ctx = context_course::instance($this->course1->id);
     $c2ctx = context_course::instance($this->course2->id);
     $this->getDataGenerator()->enrol_user($this->user->id, $this->course1->id, 3);
     $this->getDataGenerator()->enrol_user($this->user->id, $this->course2->id, 3);
     $this->assertCount(2, enrol_get_my_courses());
     $courses = enrol_get_my_courses();
     // Student enrollment.
     $this->setUser($this->user1->id);
     $this->getDataGenerator()->enrol_user($this->user1->id, $this->course1->id, 5);
     $this->getDataGenerator()->enrol_user($this->user1->id, $this->course2->id, 5);
     $this->assertCount(2, get_enrolled_users($c1ctx));
 }
开发者ID:eugeneventer,项目名称:o365-moodle,代码行数:28,代码来源:onenoteapi_test.php


示例16: block_elabel_get_my_courses

/**
 * Is used to fetch all user courses he is a teacher in and he can request a label for
 */
function block_elabel_get_my_courses()
{
    global $DB, $USER;
    $courses = enrol_get_my_courses();
    $data = array();
    foreach ($courses as $course) {
        //skip course if the is not a teacher
        if (!has_capability('block/elabel:audit', context_course::instance($course->id), $USER)) {
            unset($course);
            continue;
        }
        $request = $DB->get_record('block_elabel_request', array('courseid' => $course->id));
        if (!$request) {
            $course->status = STATUS_NEW;
            $course->requestid = 0;
        } else {
            $course->status = $request->state;
            $course->requestid = $request->id;
        }
        list($faculty, $department, $center) = block_elabel_get_coursecat_infos($course->id);
        $data[] = array('title' => $course->fullname, 'faculty' => $faculty, 'user' => fullname($USER), 'status' => $course->status, 'requestid' => $course->requestid, 'courseid' => $course->id, 'timecreated' => isset($request->timecreated) ? date("d.m.Y", $request->timecreated) : '', 'timegranted' => isset($request->timegranted) ? date("d.m.Y", $request->timegranted) : '');
    }
    return $data;
}
开发者ID:gtn,项目名称:elabel,代码行数:27,代码来源:lib.php


示例17: getCourseList

 public function getCourseList()
 {
     $fieldMap = ["id" => "course_id", "shortname" => "short_name", "fullname" => "display_name"];
     $retval = [];
     $sortorder = 'visible DESC, sortorder ASC';
     if ($courses = enrol_get_my_courses(NULL, $sortorder)) {
         foreach ($courses as $k => $course) {
             $this->mark($course->id . " " . $course->visible);
             if ($course->visible < 1) {
                 next;
             }
             $c = [];
             foreach ($fieldMap as $k => $v) {
                 if (property_exists($course, $k)) {
                     $c[$v] = $course->{$k};
                 }
             }
             // ignore course files/images
             // FIXME: add references to icons and images.
             $retval[] = $c;
         }
     }
     return $retval;
 }
开发者ID:phish108,项目名称:PowerTLA,代码行数:24,代码来源:Course.class.php


示例18: forum_get_optional_subscribed_forums

/**
 * Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from
 *
 * @return array An array of unsubscribable forums
 */
function forum_get_optional_subscribed_forums() {
    global $USER, $DB;

    // Get courses that $USER is enrolled in and can see
    $courses = enrol_get_my_courses();
    if (empty($courses)) {
        return array();
    }

    $courseids = array();
    foreach($courses as $course) {
        $courseids[] = $course->id;
    }
    list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'c');

    // get all forums from the user's courses that they are subscribed to and which are not set to forced
    $sql = "SELECT f.id, cm.id as cm, cm.visible
              FROM {forum} f
                   JOIN {course_modules} cm ON cm.instance = f.id
                   JOIN {modules} m ON m.name = :modulename AND m.id = cm.module
                   LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
             WHERE f.forcesubscribe <> :forcesubscribe AND fs.id IS NOT NULL
                   AND cm.course $coursesql";
    $params = array_merge($courseparams, array('modulename'=>'forum', 'userid'=>$USER->id, 'forcesubscribe'=>FORUM_FORCESUBSCRIBE));
    if (!$forums = $DB->get_records_sql($sql, $params)) {
        return array();
    }

    $unsubscribableforums = array(); // Array to return

    foreach($forums as $forum) {

        if (empty($forum->visible)) {
            // the forum is hidden
            $context = context_module::instance($forum->cm);
            if (!has_capability('moodle/course:viewhiddenactivities', $context)) {
                // the user can't see the hidden forum
                continue;
            }
        }

        // subscribe.php only requires 'mod/forum:managesubscriptions' when
        // unsubscribing a user other than yourself so we don't require it here either

        // A check for whether the forum has subscription set to forced is built into the SQL above

        $unsubscribableforums[] = $forum;
    }

    return $unsubscribableforums;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:56,代码来源:lib.php


示例19: render_custom_menu


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP enrol_get_plugin函数代码示例发布时间:2022-05-15
下一篇:
PHP enrol_get_instances函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap