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

PHP enrol_get_plugins函数代码示例

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

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



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

示例1: disable_plugin

 protected function disable_plugin()
 {
     $enabled = enrol_get_plugins(true);
     unset($enabled['meta']);
     $enabled = array_keys($enabled);
     set_config('enrol_plugins_enabled', implode(',', $enabled));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:7,代码来源:plugin_test.php


示例2: test_get_enrolment_plugins

 public function test_get_enrolment_plugins()
 {
     $this->resetAfterTest(true);
     $actual = tool_uploadcourse_helper::get_enrolment_plugins();
     $this->assertSame(array_keys(enrol_get_plugins(false)), array_keys($actual));
     // This should be identical as cached.
     $secondactual = tool_uploadcourse_helper::get_enrolment_plugins();
     $this->assertEquals($actual, $secondactual);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:9,代码来源:helper_test.php


示例3: get_enrolment_plugins

 /**
  * Gets all of the enrolment plugins that are active for this course.
  *
  * @return array
  */
 public function get_enrolment_plugins() {
     if ($this->_plugins === null) {
         $this->_plugins = enrol_get_plugins(true);
     }
     return $this->_plugins;
 }
开发者ID:nuckey,项目名称:moodle,代码行数:11,代码来源:locallib.php


示例4: reset_course_userdata

/**
 * This function will empty a course of user data.
 * It will retain the activities and the structure of the course.
 *
 * @param object $data an object containing all the settings including courseid (without magic quotes)
 * @return array status array of array component, item, error
 */
function reset_course_userdata($data)
{
    global $CFG, $USER, $DB;
    require_once $CFG->libdir . '/gradelib.php';
    require_once $CFG->libdir . '/completionlib.php';
    require_once $CFG->dirroot . '/group/lib.php';
    $data->courseid = $data->id;
    $context = get_context_instance(CONTEXT_COURSE, $data->courseid);
    // calculate the time shift of dates
    if (!empty($data->reset_start_date)) {
        // time part of course startdate should be zero
        $data->timeshift = $data->reset_start_date - usergetmidnight($data->reset_start_date_old);
    } else {
        $data->timeshift = 0;
    }
    // result array: component, item, error
    $status = array();
    // start the resetting
    $componentstr = get_string('general');
    // move the course start time
    if (!empty($data->reset_start_date) and $data->timeshift) {
        // change course start data
        $DB->set_field('course', 'startdate', $data->reset_start_date, array('id' => $data->courseid));
        // update all course and group events - do not move activity events
        $updatesql = "UPDATE {event}\n                         SET timestart = timestart + ?\n                       WHERE courseid=? AND instance=0";
        $DB->execute($updatesql, array($data->timeshift, $data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
    }
    if (!empty($data->reset_logs)) {
        $DB->delete_records('log', array('course' => $data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('deletelogs'), 'error' => false);
    }
    if (!empty($data->reset_events)) {
        $DB->delete_records('event', array('courseid' => $data->courseid));
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteevents', 'calendar'), 'error' => false);
    }
    if (!empty($data->reset_notes)) {
        require_once $CFG->dirroot . '/notes/lib.php';
        note_delete_all($data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('deletenotes', 'notes'), 'error' => false);
    }
    if (!empty($data->delete_blog_associations)) {
        require_once $CFG->dirroot . '/blog/lib.php';
        blog_remove_associations_for_course($data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('deleteblogassociations', 'blog'), 'error' => false);
    }
    if (!empty($data->reset_course_completion)) {
        // Delete course completion information
        $course = $DB->get_record('course', array('id' => $data->courseid));
        $cc = new completion_info($course);
        $cc->delete_course_completion_data();
        $status[] = array('component' => $componentstr, 'item' => get_string('deletecoursecompletiondata', 'completion'), 'error' => false);
    }
    $componentstr = get_string('roles');
    if (!empty($data->reset_roles_overrides)) {
        $children = get_child_contexts($context);
        foreach ($children as $child) {
            $DB->delete_records('role_capabilities', array('contextid' => $child->id));
        }
        $DB->delete_records('role_capabilities', array('contextid' => $context->id));
        //force refresh for logged in users
        mark_context_dirty($context->path);
        $status[] = array('component' => $componentstr, 'item' => get_string('deletecourseoverrides', 'role'), 'error' => false);
    }
    if (!empty($data->reset_roles_local)) {
        $children = get_child_contexts($context);
        foreach ($children as $child) {
            role_unassign_all(array('contextid' => $child->id));
        }
        //force refresh for logged in users
        mark_context_dirty($context->path);
        $status[] = array('component' => $componentstr, 'item' => get_string('deletelocalroles', 'role'), 'error' => false);
    }
    // First unenrol users - this cleans some of related user data too, such as forum subscriptions, tracking, etc.
    $data->unenrolled = array();
    if (!empty($data->unenrol_users)) {
        $plugins = enrol_get_plugins(true);
        $instances = enrol_get_instances($data->courseid, true);
        foreach ($instances as $key => $instance) {
            if (!isset($plugins[$instance->enrol])) {
                unset($instances[$key]);
                continue;
            }
            if (!$plugins[$instance->enrol]->allow_unenrol($instance)) {
                unset($instances[$key]);
            }
        }
        $sqlempty = $DB->sql_empty();
        foreach ($data->unenrol_users as $withroleid) {
            $sql = "SELECT DISTINCT ue.userid, ue.enrolid\n                      FROM {user_enrolments} ue\n                      JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n                      JOIN {context} c ON (c.contextlevel = :courselevel AND c.instanceid = e.courseid)\n                      JOIN {role_assignments} ra ON (ra.contextid = c.id AND ra.roleid = :roleid AND ra.userid = ue.userid)";
            $params = array('courseid' => $data->courseid, 'roleid' => $withroleid, 'courselevel' => CONTEXT_COURSE);
            $rs = $DB->get_recordset_sql($sql, $params);
            foreach ($rs as $ue) {
//.........这里部分代码省略.........
开发者ID:hitphp,项目名称:moodle,代码行数:101,代码来源:moodlelib.php


示例5: output_html

 /**
  * Builds the XHTML to display the control
  *
  * @param string $data Unused
  * @param string $query
  * @return string
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT, $DB;
     // display strings
     $strup = get_string('up');
     $strdown = get_string('down');
     $strsettings = get_string('settings');
     $strenable = get_string('enable');
     $strdisable = get_string('disable');
     $struninstall = get_string('uninstallplugin', 'admin');
     $strusage = get_string('enrolusage', 'enrol');
     $enrols_available = enrol_get_plugins(false);
     $active_enrols = enrol_get_plugins(true);
     $allenrols = array();
     foreach ($active_enrols as $key => $enrol) {
         $allenrols[$key] = true;
     }
     foreach ($enrols_available as $key => $enrol) {
         $allenrols[$key] = true;
     }
     // now find all borked plugins and at least allow then to uninstall
     $borked = array();
     $condidates = $DB->get_fieldset_sql("SELECT DISTINCT enrol FROM {enrol}");
     foreach ($condidates as $candidate) {
         if (empty($allenrols[$candidate])) {
             $allenrols[$candidate] = true;
         }
     }
     $return = $OUTPUT->heading(get_string('actenrolshhdr', 'enrol'), 3, 'main', true);
     $return .= $OUTPUT->box_start('generalbox enrolsui');
     $table = new html_table();
     $table->head = array(get_string('name'), $strusage, $strenable, $strup . '/' . $strdown, $strsettings, $struninstall);
     $table->align = array('left', 'center', 'center', 'center', 'center', 'center');
     $table->width = '90%';
     $table->data = array();
     // iterate through enrol plugins and add to the display table
     $updowncount = 1;
     $enrolcount = count($active_enrols);
     $url = new moodle_url('/admin/enrol.php', array('sesskey' => sesskey()));
     $printed = array();
     foreach ($allenrols as $enrol => $unused) {
         if (get_string_manager()->string_exists('pluginname', 'enrol_' . $enrol)) {
             $name = get_string('pluginname', 'enrol_' . $enrol);
         } else {
             $name = $enrol;
         }
         //usage
         $ci = $DB->count_records('enrol', array('enrol' => $enrol));
         $cp = $DB->count_records_select('user_enrolments', "enrolid IN (SELECT id FROM {enrol} WHERE enrol = ?)", array($enrol));
         $usage = "{$ci} / {$cp}";
         // hide/show link
         if (isset($active_enrols[$enrol])) {
             $aurl = new moodle_url($url, array('action' => 'disable', 'enrol' => $enrol));
             $hideshow = "<a href=\"{$aurl}\">";
             $hideshow .= "<img src=\"" . $OUTPUT->pix_url('i/hide') . "\" class=\"icon\" alt=\"{$strdisable}\" /></a>";
             $enabled = true;
             $displayname = "<span>{$name}</span>";
         } else {
             if (isset($enrols_available[$enrol])) {
                 $aurl = new moodle_url($url, array('action' => 'enable', 'enrol' => $enrol));
                 $hideshow = "<a href=\"{$aurl}\">";
                 $hideshow .= "<img src=\"" . $OUTPUT->pix_url('i/show') . "\" class=\"icon\" alt=\"{$strenable}\" /></a>";
                 $enabled = false;
                 $displayname = "<span class=\"dimmed_text\">{$name}</span>";
             } else {
                 $hideshow = '';
                 $enabled = false;
                 $displayname = '<span class="notifyproblem">' . $name . '</span>';
             }
         }
         // up/down link (only if enrol is enabled)
         $updown = '';
         if ($enabled) {
             if ($updowncount > 1) {
                 $aurl = new moodle_url($url, array('action' => 'up', 'enrol' => $enrol));
                 $updown .= "<a href=\"{$aurl}\">";
                 $updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"{$strup}\" /></a>&nbsp;";
             } else {
                 $updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"icon\" alt=\"\" />&nbsp;";
             }
             if ($updowncount < $enrolcount) {
                 $aurl = new moodle_url($url, array('action' => 'down', 'enrol' => $enrol));
                 $updown .= "<a href=\"{$aurl}\">";
                 $updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"{$strdown}\" /></a>";
             } else {
                 $updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"icon\" alt=\"\" />";
             }
             ++$updowncount;
         }
         // settings link
         if (isset($active_enrols[$enrol]) or file_exists($CFG->dirroot . '/enrol/' . $enrol . '/settings.php')) {
             $surl = new moodle_url('/admin/settings.php', array('section' => 'enrolsettings' . $enrol));
             $settings = "<a href=\"{$surl}\">{$strsettings}</a>";
//.........这里部分代码省略.........
开发者ID:raymondAntonio,项目名称:moodle,代码行数:101,代码来源:adminlib.php


示例6: cron_run


//.........这里部分代码省略.........
        $authplugin = get_auth_plugin($auth);
        if (method_exists($authplugin, 'cron')) {
            mtrace("Running cron for auth/{$auth}...");
            $authplugin->cron();
            if (!empty($authplugin->log)) {
                mtrace($authplugin->log);
            }
        }
        unset($authplugin);
    }
    // Generate new password emails for users - ppl expect these generated asap
    if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
        mtrace('Creating passwords for new users...');
        $usernamefields = get_all_user_name_fields(true, 'u');
        $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email,\n                                                 {$usernamefields}, u.username, u.lang,\n                                                 p.id as prefid\n                                            FROM {user} u\n                                            JOIN {user_preferences} p ON u.id=p.userid\n                                           WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin' AND u.deleted = 0");
        // note: we can not send emails to suspended accounts
        foreach ($newusers as $newuser) {
            // Use a low cost factor when generating bcrypt hash otherwise
            // hashing would be slow when emailing lots of users. Hashes
            // will be automatically updated to a higher cost factor the first
            // time the user logs in.
            if (setnew_password_and_mail($newuser, true)) {
                unset_user_preference('create_password', $newuser);
                set_user_preference('auth_forcepasswordchange', 1, $newuser);
            } else {
                trigger_error("Could not create and mail new user password!");
            }
        }
        $newusers->close();
    }
    // It is very important to run enrol early
    // because other plugins depend on correct enrolment info.
    mtrace("Running enrol crons if required...");
    $enrols = enrol_get_plugins(true);
    foreach ($enrols as $ename => $enrol) {
        // do this for all plugins, disabled plugins might want to cleanup stuff such as roles
        if (!$enrol->is_cron_required()) {
            continue;
        }
        mtrace("Running cron for enrol_{$ename}...");
        cron_trace_time_and_memory();
        $enrol->cron();
        $enrol->set_config('lastcron', time());
    }
    // Run all cron jobs for each module
    mtrace("Starting activity modules");
    get_mailer('buffer');
    if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
        foreach ($mods as $mod) {
            $libfile = "{$CFG->dirroot}/mod/{$mod->name}/lib.php";
            if (file_exists($libfile)) {
                include_once $libfile;
                $cron_function = $mod->name . "_cron";
                if (function_exists($cron_function)) {
                    mtrace("Processing module function {$cron_function} ...", '');
                    cron_trace_time_and_memory();
                    $pre_dbqueries = null;
                    $pre_dbqueries = $DB->perf_get_queries();
                    $pre_time = microtime(1);
                    if ($cron_function()) {
                        $DB->set_field("modules", "lastcron", $timenow, array("id" => $mod->id));
                    }
                    if (isset($pre_dbqueries)) {
                        mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
                        mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
                    }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:67,代码来源:cronlib.php


示例7: display_savenew

 function display_savenew()
 {
     // action_savenew()
     global $USER, $CFG, $DB;
     $clsid = cm_get_param('clsid', 0);
     $class = new pmclass($clsid);
     $now = time();
     if (!$class->is_enrollable()) {
         print_error('notenrollable', 'enrol');
         // TBD
     }
     // check if class is full
     if (!empty($class->maxstudents) && student::count_enroled($class->id) >= $class->maxstudents) {
         $form = $this->create_waitlistform($classid);
         $form->display();
         return;
     }
     // call the Moodle enrolment plugin if attached to a Moodle course, and
     // it's not the elis plugin
     //todo: check Moodle enrolment plugins here
     $cuserid = cm_get_crlmuserid($USER->id);
     $sturecord = array();
     $sturecord['classid'] = $class->id;
     $sturecord['userid'] = $cuserid;
     // Set the enrolment time from class startdate if it's in the future or just set
     // current time if class has an associated Moodle course that has already started
     $enrolmenttime = $class->startdate;
     if ($moodlecourseid = moodle_get_course($clsid)) {
         if ($startdate = $DB->get_field('course', 'startdate', array('id' => $moodlecourseid))) {
             $enrolmenttime = $startdate < $now ? $now : $class->startdate;
         }
     }
     $sturecord['enrolmenttime'] = max($now, $enrolmenttime);
     $sturecord['completetime'] = 0;
     $newstu = new student($sturecord);
     $courseid = $class->get_moodle_course_id();
     if ($courseid) {
         $course = $DB->get_record('course', array('id' => $courseid));
         // check that the elis plugin allows for enrolments from the course
         // catalog -- if not, see if there are other plugins that allow
         // self-enrolment.
         $plugin = enrol_get_plugin('elis');
         $enrol = $plugin->get_or_create_instance($course);
         if (!$enrol->{enrol_elis_plugin::ENROL_FROM_COURSE_CATALOG_DB}) {
             // get course enrolment plugins, and see if any of them allow self-enrolment
             $enrols = enrol_get_plugins(true);
             $enrolinstances = enrol_get_instances($course->id, true);
             foreach ($enrolinstances as $instance) {
                 if (!isset($enrols[$instance->enrol])) {
                     continue;
                 }
                 $form = $enrols[$instance->enrol]->enrol_page_hook($instance);
                 if ($form) {
                     // at least one plugin allows self-enrolment -- send
                     // the user to the course enrolment page, and prevent
                     // automatic enrolment
                     $newstu->no_moodle_enrol = true;
                     $newstu->save();
                     redirect("{$CFG->wwwroot}/course/enrol.php?id={$courseid}");
                     return;
                 }
             }
         }
     }
     $newstu->save();
     $tmppage = new coursecatalogpage(array('action' => 'default'));
     redirect($tmppage->url);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:68,代码来源:coursecatalogpage.class.php


示例8: process_enrol

    /**
     * Create enrolment instances.
     *
     * This has to be called after creation of roles
     * and before adding of role assignments.
     *
     * @param mixed $data
     * @return void
     */
    public function process_enrol($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id; // We'll need this later

        $restoretype = plugin_supports('enrol', $data->enrol, ENROL_RESTORE_TYPE, null);

        if ($restoretype !== ENROL_RESTORE_EXACT and $restoretype !== ENROL_RESTORE_NOUSERS) {
            // TODO: add complex restore support via custom class
            debugging("Skipping '{$data->enrol}' enrolment plugin. Will be implemented before 2.0 release", DEBUG_DEVELOPER);
            $this->set_mapping('enrol', $oldid, 0);
            return;
        }

        // Perform various checks to decide what to do with the enrol plugin
        if (!array_key_exists($data->enrol, enrol_get_plugins(false))) {
            // TODO: decide if we want to switch to manual enrol - we need UI for this
            debugging("Enrol plugin data can not be restored because it is not installed");
            $this->set_mapping('enrol', $oldid, 0);
            return;

        }
        if (!enrol_is_enabled($data->enrol)) {
            // TODO: decide if we want to switch to manual enrol - we need UI for this
            debugging("Enrol plugin data can not be restored because it is not enabled");
            $this->set_mapping('enrol', $oldid, 0);
            return;
        }

        // map standard fields - plugin has to process custom fields from own restore class
        $data->roleid = $this->get_mappingid('role', $data->roleid);
        //TODO: should we move the enrol start and end date here?

        // always add instance, if the course does not support multiple instances it just returns NULL
        $enrol = enrol_get_plugin($data->enrol);
        $courserec = $DB->get_record('course', array('id' => $this->get_courseid())); // Requires object, uses only id!!
        if ($newitemid = $enrol->add_instance($courserec, (array)$data)) {
            // ok
        } else {
            if ($instances = $DB->get_records('enrol', array('courseid'=>$courserec->id, 'enrol'=>$data->enrol))) {
                // most probably plugin that supports only one instance
                $newitemid = key($instances);
            } else {
                debugging('Can not create new enrol instance or reuse existing');
                $newitemid = 0;
            }
        }

        if ($restoretype === ENROL_RESTORE_NOUSERS) {
            // plugin requests to prevent restore of any users
            $newitemid = 0;
        }

        $this->set_mapping('enrol', $oldid, $newitemid);
    }
开发者ID:nottmoo,项目名称:moodle,代码行数:65,代码来源:restore_stepslib.php


示例9: cron_run


//.........这里部分代码省略.........
        mtrace('Cleaned cache flags');
        // If you suspect that the context paths are somehow corrupt
        // replace the line below with: build_context_path(true);
        build_context_path();
        mtrace('Built context paths');
        if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
            $notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
            $DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime' => $notificationdeletetime));
            mtrace('Cleaned up read notifications');
        }
        mtrace("Finished clean-up tasks...");
    }
    // End of occasional clean-up tasks
    // Run automated backups if required.
    require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
    require_once $CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php';
    backup_cron_automated_helper::run_automated_backup();
    /// Run the auth cron, if any
    /// before enrolments because it might add users that will be needed in enrol plugins
    $auths = get_enabled_auth_plugins();
    mtrace("Running auth crons if required...");
    foreach ($auths as $auth) {
        $authplugin = get_auth_plugin($auth);
        if (method_exists($authplugin, 'cron')) {
            mtrace("Running cron for auth/{$auth}...");
            $authplugin->cron();
            if (!empty($authplugin->log)) {
                mtrace($authplugin->log);
            }
        }
        unset($authplugin);
    }
    mtrace("Running enrol crons if required...");
    $enrols = enrol_get_plugins(true);
    foreach ($enrols as $ename => $enrol) {
        // do this for all plugins, disabled plugins might want to cleanup stuff such as roles
        if (!$enrol->is_cron_required()) {
            continue;
        }
        mtrace("Running cron for enrol_{$ename}...");
        $enrol->cron();
        $enrol->set_config('lastcron', time());
    }
    if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
        require_once $CFG->dirroot . '/lib/statslib.php';
        // check we're not before our runtime
        $timetocheck = stats_get_base_daily() + $CFG->statsruntimestarthour * 60 * 60 + $CFG->statsruntimestartminute * 60;
        if (time() > $timetocheck) {
            // process configured number of days as max (defaulting to 31)
            $maxdays = empty($CFG->statsruntimedays) ? 31 : abs($CFG->statsruntimedays);
            if (stats_cron_daily($maxdays)) {
                if (stats_cron_weekly()) {
                    if (stats_cron_monthly()) {
                        stats_clean_old();
                    }
                }
            }
            @set_time_limit(0);
        } else {
            mtrace('Next stats run after:' . userdate($timetocheck));
        }
    }
    // run gradebook import/export/report cron
    if ($gradeimports = get_plugin_list('gradeimport')) {
        foreach ($gradeimports as $gradeimport => $plugindir) {
            if (file_exists($plugindir . '/lib.php')) {
开发者ID:vuchannguyen,项目名称:web,代码行数:67,代码来源:cronlib.php


示例10: redirect

// Everybody is enrolled on the frontpage
if ($course->id == SITEID) {
    redirect("{$CFG->wwwroot}/");
}
if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
    print_error('coursehidden');
}
$PAGE->set_course($course);
$PAGE->set_pagelayout('course');
$PAGE->set_url('/enrol/index.php', array('id' => $course->id));
// do not allow enrols when in login-as session
if (\core\session\manager::is_loggedinas() and $USER->loginascontext->contextlevel == CONTEXT_COURSE) {
    print_error('loginasnoenrol', '', $CFG->wwwroot . '/course/view.php?id=' . $USER->loginascontext->instanceid);
}
// get all enrol forms available in this course
$enrols = enrol_get_plugins(true);
$enrolinstances = enrol_get_instances($course->id, true);
$forms = array();
foreach ($enrolinstances as $instance) {
    if (!isset($enrols[$instance->enrol])) {
        continue;
    }
    $form = $enrols[$instance->enrol]->enrol_page_hook($instance);
    if ($form) {
        $forms[$instance->id] = $form;
    }
}
// Check if user already enrolled
if (is_enrolled($context, $USER, '', true)) {
    if (!empty($SESSION->wantsurl)) {
        $destination = $SESSION->wantsurl;
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:index.php


示例11: can_access_course

/**
 * Returns true if the user is able to access the course.
 *
 * This function is in no way, shape, or form a substitute for require_login.
 * It should only be used in circumstances where it is not possible to call require_login
 * such as the navigation.
 *
 * This function checks many of the methods of access to a course such as the view
 * capability, enrollments, and guest access. It also makes use of the cache
 * generated by require_login for guest access.
 *
 * The flags within the $USER object that are used here should NEVER be used outside
 * of this function can_access_course and require_login. Doing so WILL break future
 * versions.
 *
 * @global moodle_database $DB
 * @param stdClass $context
 * @param stdClass|null $user
 * @param string $withcapability Check for this capability as well.
 * @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
 * @param boolean $trustcache If set to false guest access will always be checked
 *                             against the enrolment plugins from the course, rather
 *                             than the cache generated by require_login.
 * @return boolean Returns true if the user is able to access the course
 */
function can_access_course($context, $user = null, $withcapability = '', $onlyactive = false, $trustcache = true)
{
    global $DB, $USER;
    $coursecontext = get_course_context($context);
    $courseid = $coursecontext->instanceid;
    // First check the obvious, is the user viewing or is the user enrolled.
    if (is_viewing($coursecontext, $user, $withcapability) || is_enrolled($coursecontext, $user, $withcapability, $onlyactive)) {
        // How easy was that!
        return true;
    }
    $access = false;
    if (!isset($USER->enrol)) {
        // Cache hasn't been generated yet so we can't trust it
        $trustcache = false;
        /**
         * These flags within the $USER object should NEVER be used outside of this
         * function can_access_course and the function require_login.
         * Doing so WILL break future versions!!!!
         */
        $USER->enrol = array();
        $USER->enrol['enrolled'] = array();
        $USER->enrol['tempguest'] = array();
    }
    // If we don't trust the cache we need to check with the courses enrolment
    // plugin instances to see if the user can access the course as a guest.
    if (!$trustcache) {
        // Ok, off to the database we go!
        $instances = $DB->get_records('enrol', array('courseid' => $courseid, 'status' => ENROL_INSTANCE_ENABLED), 'sortorder, id ASC');
        $enrols = enrol_get_plugins(true);
        foreach ($instances as $instance) {
            if (!isset($enrols[$instance->enrol])) {
                continue;
            }
            $until = $enrols[$instance->enrol]->try_guestaccess($instance);
            if ($until !== false) {
                // Never use me anywhere but here and require_login
                $USER->enrol['tempguest'][$courseid] = $until;
                $access = true;
                break;
            }
        }
    }
    // If we don't already have access (from above) check the cache and see whether
    // there is record of it in there.
    if (!$access && isset($USER->enrol['tempguest'][$courseid])) {
        // Never use me anywhere but here and require_login
        if ($USER->enrol['tempguest'][$courseid] == 0) {
            $access = true;
        } else {
            if ($USER->enrol['tempguest'][$courseid] > time()) {
                $access = true;
            } else {
                //expired
                unset($USER->enrol['tempguest'][$courseid]);
            }
        }
    }
    return $access;
}
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-lib,代码行数:84,代码来源:accesslib.php


示例12: execute

 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     global $CFG, $DB;
     $timenow = time();
     // Run the auth cron, if any before enrolments
     // because it might add users that will be needed in enrol plugins.
     $auths = get_enabled_auth_plugins();
     mtrace("Running auth crons if required...");
     foreach ($auths as $auth) {
         $authplugin = get_auth_plugin($auth);
         if (method_exists($authplugin, 'cron')) {
             mtrace("Running cron for auth/{$auth}...");
             $authplugin->cron();
             if (!empty($authplugin->log)) {
                 mtrace($authplugin->log);
             }
         }
         unset($authplugin);
     }
     // It is very important to run enrol early
     // because other plugins depend on correct enrolment info.
     mtrace("Running enrol crons if required...");
     $enrols = enrol_get_plugins(true);
     foreach ($enrols as $ename => $enrol) {
         // Do this for all plugins, disabled plugins might want to cleanup stuff such as roles.
         if (!$enrol->is_cron_required()) {
             continue;
         }
         mtrace("Running cron for enrol_{$ename}...");
         $enrol->cron();
         $enrol->set_config('lastcron', time());
     }
     // Run all cron jobs for each module.
     mtrace("Starting activity modules");
     if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
         foreach ($mods as $mod) {
             $libfile = "{$CFG->dirroot}/mod/{$mod->name}/lib.php";
             if (file_exists($libfile)) {
                 include_once $libfile;
                 $cronfunction = $mod->name . "_cron";
                 if (function_exists($cronfunction)) {
                     mtrace("Processing module function {$cronfunction} ...\n", '');
                     $predbqueries = null;
                     $predbqueries = $DB->perf_get_queries();
                     $pretime = microtime(1);
                     if ($cronfunction()) {
                         $DB->set_field("modules", "lastcron", $timenow, array("id" => $mod->id));
                     }
                     if (isset($predbqueries)) {
                         mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
                         mtrace("... used " . (microtime(1) - $pretime) . " seconds");
                     }
                     // Reset possible changes by modules to time_limit. MDL-11597.
                     \core_php_time_limit::raise();
                     mtrace("done.");
                 }
             }
         }
     }
     mtrace("Finished activity modules");
     mtrace("Starting blocks");
     if ($blocks = $DB->get_records_select("block", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
         // We will need the base class.
         require_once $CFG->dirroot . '/blocks/moodleblock.class.php';
         foreach ($blocks as $block) {
             $blockfile = $CFG->dirroot . '/blocks/' . $block->name . '/block_' . $block->name . '.php';
             if (file_exists($blockfile)) {
                 require_once $blockfile;
                 $classname = '\\block_' . $block->name;
                 $blockobj = new $classname();
                 if (method_exists($blockobj, 'cron')) {
                     mtrace("Processing cron function for " . $block->name . '....', '');
                     if ($blockobj->cron()) {
                         $DB->set_field('block', 'lastcron', $timenow, array('id' => $block->id));
                     }
                     // Reset possible changes by blocks to time_limit. MDL-11597.
                     \core_php_time_limit::raise();
                     mtrace('done.');
                 }
             }
         }
     }
     mtrace('Finished blocks');
     mtrace('Starting admin reports');
     cron_execute_plugin_type('report');
     mtrace('Finished admin reports');
     mtrace('Starting course reports');
     cron_execute_plugin_type('coursereport');
     mtrace('Finished course reports');
     // Run gradebook import/export/report cron.
     mtrace('Starting gradebook plugins');
     cron_execute_plugin_type('gradeimport');
     cron_execute_plugin_type('gradeexport');
     cron_execute_plugin_type('gradereport');
     mtrace('Finished gradebook plugins');
     // All other plugins.
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:legacy_plugin_cron_task.php


示例13: local_ltiprovider_duplicate_course


//.........这里部分代码省略.........
    foreach ($backupsettings as $name => $value) {
        $setting = $rc->get_plan()->get_setting($name);
        if ($setting->get_status() == backup_setting::NOT_LOCKED) {
            $setting->set_value($value);
        }
    }
    if (!$rc->execute_precheck()) {
        $precheckresults = $rc->get_precheck_results();
        if (is_array($precheckresults) && !empty($precheckresults['errors'])) {
            if (empty($CFG->keeptempdirectoriesonbackup)) {
                fulldelete($backupbasepath);
            }
            $errorinfo = '';
            foreach ($precheckresults['errors'] as $error) {
                $errorinfo .= $error;
            }
            if (array_key_exists('warnings', $precheckresults)) {
                foreach ($precheckresults['warnings'] as $warning) {
                    $errorinfo .= $warning;
                }
            }
            throw new moodle_exception('backupprecheckerrors', 'webservice', '', $errorinfo);
        }
    }
    $rc->execute_plan();
    $rc->destroy();
    $course = $DB->get_record('course', array('id' => $newcourse->id), '*', MUST_EXIST);
    $course->visible = $visible;
    $course->fullname = $newcourse->fullname;
    $course->shortname = $newcourse->shortname;
    $course->idnumber = $newcourse->idnumber;
    // Set shortname and fullname back.
    $DB->update_record('course', $course);
    if (empty($CFG->keeptempdirectoriesonbackup)) {
        fulldelete($backupbasepath);
    }
    // Delete the course backup file created by this WebService. Originally located in the course backups area.
    $file->delete();
    // We have to unenroll all the user except the one that create the course.
    if (get_config('local_ltiprovider', 'duplicatecourseswithoutusers') and $useridcreating) {
        require_once $CFG->dirroot . '/group/lib.php';
        // Previous to unenrol users, we assign some type of activities to the user that created the course.
        if ($user = $DB->get_record('user', array('id' => $useridcreating))) {
            if ($databases = $DB->get_records('data', array('course' => $course->id))) {
                foreach ($databases as $data) {
                    $DB->execute("UPDATE {data_records} SET userid = ? WHERE dataid = ?", array($user->id, $data->id));
                }
            }
            if ($glossaries = $DB->get_records('glossary', array('course' => $course->id))) {
                foreach ($glossaries as $glossary) {
                    $DB->execute("UPDATE {glossary_entries} SET userid = ? WHERE glossaryid = ?", array($user->id, $glossary->id));
                }
            }
            // Same for questions.
            $newcoursecontextid = context_course::instance($course->id);
            if ($qcategories = $DB->get_records('question_categories', array('contextid' => $newcoursecontextid->id))) {
                foreach ($qcategories as $qcategory) {
                    $DB->execute("UPDATE {question} SET createdby = ?, modifiedby = ? WHERE category = ?", array($user->id, $user->id, $qcategory->id));
                }
            }
            // Enrol the user.
            if ($tool = $DB->get_record('local_ltiprovider', array('contextid' => $newcoursecontextid->id))) {
                $roles = explode(',', strtolower($context->info['roles']));
                local_ltiprovider_enrol_user($tool, $user, $roles, true);
            }
            // Now, we unenrol all the users except the one who created the course.
            $plugins = enrol_get_plugins(true);
            $instances = enrol_get_instances($course->id, true);
            foreach ($instances as $key => $instance) {
                if (!isset($plugins[$instance->enrol])) {
                    unset($instances[$key]);
                    continue;
                }
            }
            $sql = "SELECT ue.*\n                          FROM {user_enrolments} ue\n                          JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n                          JOIN {context} c ON (c.contextlevel = :courselevel AND c.instanceid = e.courseid)";
            $params = array('courseid' => $course->id, 'courselevel' => CONTEXT_COURSE);
            $rs = $DB->get_recordset_sql($sql, $params);
            foreach ($rs as $ue) {
                if ($ue->userid == $user->id) {
                    continue;
                }
                if (!isset($instances[$ue->enrolid])) {
                    continue;
                }
                $instance = $instances[$ue->enrolid];
                $plugin = $plugins[$instance->enrol];
                if (!$plugin->allow_unenrol($instance) and !$plugin->allow_unenrol_user($instance, $ue)) {
                    continue;
                }
                $plugin->unenrol_user($instance, $ue->userid);
            }
            $rs->close();
            groups_delete_group_members($course->id);
            groups_delete_groups($course->id, false);
            groups_delete_groupings_groups($course->id, false);
            groups_delete_groupings($course->id, false);
        }
    }
    return $course;
}
开发者ID:gabrielrosset,项目名称:moodle-local_ltiprovider,代码行数:101,代码来源:locallib.php


示例14: appendices

 /**
  * generate list of course tools
  *
  * @author Guy Thomas
  * @date 2014-04-23
  * @return string
  */
 public static function appendices()
 {
     global $CFG, $COURSE, $PAGE, $OUTPUT;
     $links = array();
     $localplugins = core_component::get_plugin_list('local');
     $coursecontext = context_course::instance($COURSE->id);
     // Turn editing on.
     $iconsrc = $OUTPUT->pix_url('icon', 'label');
     $editcourseicon = '<img class="svg-icon" alt="" title="" src="' . $iconsrc . '">';
     $url = new moodle_url('/course/view.php', ['id' => $COURSE->id, 'sesskey' => sesskey()]);
     if ($PAGE->user_is_editing()) {
         $url->param('edit', 'off');
         $editstring = get_string('turneditingoff');
     } else {
         $url->param('edit', 'on');
         $editstring = get_string('editcoursecontent', 'theme_snap');
     }
     $links[] = array('link' => $url, 'title' => $editcourseicon . $editstring, 'capability' => 'moodle/course:update');
     // Course settings.
     $settingsicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-settings"></use></svg>';
     $links[] = array('link' => 'course/edit.php?id=' . $COURSE->id, 'title' => $settingsicon . get_string('editcoursesettings', 'theme_snap'), 'capability' => 'moodle/course:update');
     // Participants.
     $participanticon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-participants"></use></svg>';
     $links[] = array('link' => 'user/index.php?id=' . $COURSE->id . '&mode=1', 'title' => $participanticon . get_string('participants'), 'capability' => 'moodle/course:viewparticipants');
     // Gradebook.
     $gradebookicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-gradbook"></use></svg>';
     if (self::gradebook_accessible($coursecontext)) {
         // Gradebook.
         $links[] = array('link' => 'grade/index.php?id=' . $COURSE->id, 'title' => $gradebookicon . get_string('gradebook', 'grades'));
     }
     // Only show if joule grader is installed.
     if (array_key_exists('joulegrader', $localplugins)) {
         if (has_capability('local/joulegrader:grade', $coursecontext) || has_capability('local/joulegrader:view', $coursecontext)) {
             $links[] = array('link' => 'local/joulegrader/view.php?courseid=' . $COURSE->id, 'title' => $gradebookicon . get_string('pluginname', 'local_joulegrader'));
         }
     }
     // Only show Norton grader if installed.
     if (array_key_exists('nortongrader', $localplugins)) {
         if (has_capability('local/nortongrader:grade', $coursecontext) || has_capability('local/nortongrader:view', $coursecontext)) {
             $links[] = array('link' => $CFG->wwwroot . '/local/nortongrader/view.php?courseid=' . $COURSE->id, 'title' => $gradebookicon . get_string('pluginname', 'local_nortongrader'));
         }
     }
     // Only show core outcomes if enabled.
     $outcomesicon = '<svg viewBox="0 0 100 100" class="svg-icon">
     <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#coursetools-outcomes"></use></svg>';
     if (!empty($CFG->core_outcome_enable) && has_capability('moodle/grade:edit', $coursecontext)) {
         $links[] = array('link' => 'outcome/course.php?contextid=' . $coursecontext->id, 'title' => $outcomesicon . g 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP enrol_get_shared_courses函数代码示例发布时间:2022-05-15
下一篇:
PHP enrol_get_plugin函数代码示例发布时间: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