本文整理汇总了PHP中get_default_course_role函数的典型用法代码示例。如果您正苦于以下问题:PHP get_default_course_role函数的具体用法?PHP get_default_course_role怎么用?PHP get_default_course_role使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_course_role函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: qcreate_student_q_access_sync
/**
* Called from cron and update_instance. Not called from add_instance as the contexts are not set up yet.
*/
function qcreate_student_q_access_sync($qcreate, $cmcontext = null, $course = null, $forcesync = false)
{
//check if a check is needed
$timenow = time();
$activityopen = ($qcreate->timeopen == 0 || $qcreate->timeopen < $timenow) && ($qcreate->timeclose == 0 || $qcreate->timeclose > $timenow);
$activitywasopen = ($qcreate->timeopen == 0 || $qcreate->timeopen < $qcreate->timesync) && ($qcreate->timeclose == 0 || $qcreate->timeclose > $qcreate->timesync);
$needsync = empty($qcreate->timesync) || $activitywasopen != $activityopen;
if ($forcesync || $needsync) {
if ($cmcontext == null) {
$cm = get_coursemodule_from_instance('qcreate', $qcreate->id);
$cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
if ($course == null) {
$course = get_record('course', 'id', $qcreate->course);
}
$studentrole = get_default_course_role($course);
if ($activityopen) {
$capabilitiestoassign = array(0 => array('moodle/question:add' => 1, 'moodle/question:usemine' => -1, 'moodle/question:viewmine' => -1, 'moodle/question:editmine' => -1), 1 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => -1, 'moodle/question:editmine' => -1), 2 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => 1, 'moodle/question:editmine' => -1), 3 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => 1, 'moodle/question:editmine' => 1));
foreach ($capabilitiestoassign[$qcreate->studentqaccess] as $capability => $permission) {
assign_capability($capability, $permission, $studentrole->id, $cmcontext->id, true);
}
} else {
$capabilitiestounassign = array('moodle/question:add', 'moodle/question:usemine', 'moodle/question:viewmine', 'moodle/question:editmine');
foreach ($capabilitiestounassign as $capability) {
unassign_capability($capability, $studentrole->id, $cmcontext->id);
}
}
set_field('qcreate', 'timesync', $timenow, 'id', $qcreate->id);
}
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:33,代码来源:lib.php
示例2: cron
/**
* This function is run by admin/cron.php every time if admin has enabled this plugin.
*
* Everyday at settlement time (default is 00:05), it cleans up some tables
* and sends email to admin/teachers about pending orders expiring if manual-capture has enabled.
*
* If admin set up 'Order review' and 'Capture day', it captures credits cards and enrols students.
*
* @access public
*/
function cron()
{
global $CFG;
require_once $CFG->dirroot . '/enrol/authorize/authorizenetlib.php';
$oneday = 86400;
$timenow = time();
$settlementtime = authorize_getsettletime($timenow);
$timediff30 = $settlementtime - 30 * $oneday;
$mconfig = get_config('enrol/authorize');
mtrace("Processing authorize cron...");
if (intval($mconfig->an_dailysettlement) < $settlementtime) {
set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
mtrace(" daily cron; some cleanups and sending email to admins the count of pending orders expiring", ": ");
$this->cron_daily();
mtrace("done");
}
mtrace(" scheduled capture", ": ");
if (empty($CFG->an_review) or !empty($CFG->an_test) or intval($CFG->an_capture_day) < 1 or !check_openssl_loaded()) {
mtrace("disabled");
return;
// order review disabled or test mode or manual capture or openssl wasn't loaded.
}
$timediffcnf = $settlementtime - intval($CFG->an_capture_day) * $oneday;
$select = "(status = '" . AN_STATUS_AUTH . "') AND (timecreated < '{$timediffcnf}') AND (timecreated > '{$timediff30}')";
if (!($ordercount = count_records_select('enrol_authorize', $select))) {
mtrace("no pending orders");
return;
}
$eachconn = intval($mconfig->an_eachconnsecs);
$eachconn = $eachconn > 60 ? 60 : ($eachconn <= 0 ? 3 : $eachconn);
if ($ordercount * $eachconn + intval($mconfig->an_lastcron) > $timenow) {
mtrace("blocked");
return;
}
set_config('an_lastcron', $timenow, 'enrol/authorize');
mtrace(" {$ordercount} orders are being processed now", ": ");
$faults = '';
$sendem = array();
$elapsed = time();
@set_time_limit(0);
$this->log = "AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate($timenow) . "\n";
$lastcourseid = 0;
for ($rs = get_recordset_select('enrol_authorize', $select, 'courseid'); $order = rs_fetch_next_record($rs);) {
$message = '';
$extra = NULL;
if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
if ($lastcourseid != $order->courseid) {
$lastcourseid = $order->courseid;
$course = get_record('course', 'id', $lastcourseid);
$role = get_default_course_role($course);
$context = get_context_instance(CONTEXT_COURSE, $lastcourseid);
}
$timestart = $timeend = 0;
if ($course->enrolperiod) {
$timestart = $timenow;
$timeend = $order->settletime + $course->enrolperiod;
}
$user = get_record('user', 'id', $order->userid);
if (role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, 'authorize')) {
$this->log .= "User({$user->id}) has been enrolled to course({$course->id}).\n";
if (!empty($CFG->enrol_mailstudents)) {
$sendem[] = $order->id;
}
} else {
$faults .= "Error while trying to enrol " . fullname($user) . " in '{$course->fullname}' \n";
foreach ($order as $okey => $ovalue) {
$faults .= " {$okey} = {$ovalue}\n";
}
}
} else {
$this->log .= "Error, Order# {$order->id}: " . $message . "\n";
}
}
rs_close($rs);
mtrace("processed");
$timenow = time();
$elapsed = $timenow - $elapsed;
$eachconn = ceil($elapsed / $ordercount);
set_config('an_eachconnsecs', $eachconn, 'enrol/authorize');
$this->log .= "AUTHORIZE.NET CRON FINISHED: " . userdate($timenow);
$adminuser = get_admin();
if (!empty($faults)) {
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON FAULTS", $faults);
}
if (!empty($CFG->enrol_mailadmins)) {
email_to_user($adminuser, $adminuser, "AUTHORIZE.NET CRON LOG", $this->log);
}
// Send emails to students about which courses have enrolled.
if (!empty($sendem)) {
mtrace(" sending welcome messages to students", ": ");
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:enrol.php
示例3: authorize_process_csv
//.........这里部分代码省略.........
$refund->status = AN_STATUS_CREDIT;
$refund->settletime = $settlementdate;
$DB->update_record('enrol_authorize_refunds', $refund);
$updated++;
} else {
$ignored++;
$ignoredlines .= $reftransid . ": Not our business(Reference Transaction ID)\n";
}
}
} else {
$ignored++;
$ignoredlines .= $reftransid . ": Not our business(Transaction ID)\n";
}
continue;
}
if (!($transstatus == 'Settled Successfully' && $transtype == 'Authorization w/ Auto Capture')) {
$ignored++;
$ignoredlines .= $transid . ": Not settled\n";
continue;
}
// TransactionId must match
$order = $DB->get_record('enrol_authorize', array('transid' => $transid));
if (!$order) {
$ignored++;
$ignoredlines .= $transid . ": Not our business\n";
continue;
}
// Authorized/Captured and Settled
$order->status = AN_STATUS_AUTHCAPTURE;
$order->settletime = $settlementdate;
$DB->update_record('enrol_authorize', $order);
$updated++;
// Updated order status and settlement date
if ($order->paymentmethod != AN_METHOD_ECHECK) {
$ignored++;
$ignoredlines .= $transid . ": The method must be echeck\n";
continue;
}
// Get course and context
$course = $DB->get_record('course', array('id' => $order->courseid));
if (!$course) {
$ignored++;
$ignoredlines .= $transid . ": Could not find this course: " . $order->courseid . "\n";
continue;
}
$coursecontext = context_course::instance($course->id, IGNORE_MISSING);
if (!$coursecontext) {
$ignored++;
$ignoredlines .= $transid . ": Could not find course context: " . $order->courseid . "\n";
continue;
}
// Get user
$user = $DB->get_record('user', array('id' => $order->userid));
if (!$user) {
$ignored++;
$ignoredlines .= $transid . ": Could not find this user: " . $order->userid . "\n";
continue;
}
// If user wasn't enrolled, enrol now. Ignore otherwise. Because admin user might submit this file again.
if ($role = get_default_course_role($course)) {
if (!user_has_role_assignment($user->id, $role->id, $coursecontext->id)) {
$timestart = $timeend = 0;
if ($course->enrolperiod) {
$timestart = time();
$timeend = $timestart + $course->enrolperiod;
}
// Enrol user
$pinstance = $DB->get_record('enrol', array('id' => $order->instanceid));
$plugin->enrol_user($pinstance, $user->id, $pinstance->roleid, $timestart, $timeend);
$imported++;
if ($plugin->get_config('enrol_mailstudents')) {
$sendem[] = $order->id;
}
}
}
}
fclose($handle);
/// Send email to admin
if (!empty($ignoredlines)) {
$admin = get_admin();
$eventdata = new stdClass();
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_authorize';
$eventdata->name = 'authorize_enrolment';
$eventdata->userfrom = $admin;
$eventdata->userto = $admin;
$eventdata->subject = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID))) . ': Authorize.net CSV ERROR LOG';
$eventdata->fullmessage = $ignoredlines;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
message_send($eventdata);
}
/// Send welcome messages to users
if (!empty($sendem)) {
send_welcome_messages($sendem);
}
/// Show result
notice("<b>Done...</b><br />Imported: {$imported}<br />Updated: {$updated}<br />Ignored: {$ignored}");
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:101,代码来源:uploadcsv.php
示例4: enrol_into_course
/**
* A convenience function to take care of the common case where you
* just want to enrol someone using the default role into a course
*
* @param object $course
* @param object $user
* @param string $enrol - the plugin used to do this enrolment
*/
function enrol_into_course($course, $user, $enrol)
{
$timestart = time();
// remove time part from the timestamp and keep only the date part
$timestart = make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0);
if ($course->enrolperiod) {
$timeend = $timestart + $course->enrolperiod;
} else {
$timeend = 0;
}
if ($role = get_default_course_role($course)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (!role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol)) {
return false;
}
// force accessdata refresh for users visiting this context...
mark_context_dirty($context->path);
email_welcome_message_to_user($course, $user);
add_to_log($course->id, 'course', 'enrol', 'view.php?id=' . $course->id, $course->id);
return true;
}
return false;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:31,代码来源:accesslib.php
示例5: sync_enrolments
/**
* sync enrolments with database, create courses if required.
*
* @param object The role to sync for. If no role is specified, defaults are
* used.
*/
function sync_enrolments($role = null)
{
global $CFG;
global $db;
error_reporting(E_ALL);
// Connect to the external database
$enroldb = $this->enrol_connect();
if (!$enroldb) {
notify("enrol/database cannot connect to server");
return false;
}
if (isset($role)) {
echo '=== Syncing enrolments for role: ' . $role->shortname . " ===\n";
} else {
echo "=== Syncing enrolments for default role ===\n";
}
// first, pack the sortorder...
fix_course_sortorder();
list($have_role, $remote_role_name, $remote_role_value) = $this->role_fields($enroldb, $role);
if (!$have_role) {
if (!empty($CFG->enrol_db_defaultcourseroleid) and $role = get_record('role', 'id', $CFG->enrol_db_defaultcourseroleid)) {
echo "=== Using enrol_db_defaultcourseroleid: {$role->id} ({$role->shortname}) ===\n";
} elseif (isset($role)) {
echo "!!! WARNING: Role specified by caller, but no (or invalid) role configuration !!!\n";
}
}
// get enrolments per-course
$sql = "SELECT DISTINCT {$CFG->enrol_remotecoursefield} " . " FROM {$CFG->enrol_dbtable} " . " WHERE {$CFG->enrol_remoteuserfield} IS NOT NULL" . (isset($remote_role_name, $remote_role_value) ? ' AND ' . $remote_role_name . ' = ' . $remote_role_value : '');
$rs = $enroldb->Execute($sql);
if (!$rs) {
trigger_error($enroldb->ErrorMsg() . ' STATEMENT: ' . $sql);
return false;
}
if ($rs->EOF) {
// no courses! outta here...
return true;
}
begin_sql();
$extcourses = array();
while ($extcourse_obj = rs_fetch_next_record($rs)) {
// there are more course records
$extcourse_obj = (object) array_change_key_case((array) $extcourse_obj, CASE_LOWER);
$extcourse = $extcourse_obj->{strtolower($CFG->enrol_remotecoursefield)};
array_push($extcourses, $extcourse);
// does the course exist in moodle already?
$course = false;
$course = get_record('course', $CFG->enrol_localcoursefield, $extcourse);
if (!is_object($course)) {
if (empty($CFG->enrol_db_autocreate)) {
// autocreation not allowed
if (debugging('', DEBUG_ALL)) {
error_log("Course {$extcourse} does not exist, skipping");
}
continue;
// next foreach course
}
// ok, now then let's create it!
// prepare any course properties we actually have
$course = new StdClass();
$course->{$CFG->enrol_localcoursefield} = $extcourse;
$course->fullname = $extcourse;
$course->shortname = $extcourse;
if (!($newcourseid = $this->create_course($course, true) and $course = get_record('course', 'id', $newcourseid))) {
error_log("Creating course {$extcourse} failed");
continue;
// nothing left to do...
}
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
// If we don't have a proper role setup, then we default to the default
// role for the current course.
if (!$have_role) {
$role = get_default_course_role($course);
}
// get a list of the student ids the are enrolled
// in the external db -- hopefully it'll fit in memory...
$extenrolments = array();
$sql = "SELECT {$CFG->enrol_remoteuserfield} " . " FROM {$CFG->enrol_dbtable} " . " WHERE {$CFG->enrol_remotecoursefield} = " . $enroldb->quote($extcourse) . ($have_role ? ' AND ' . $remote_role_name . ' = ' . $remote_role_value : '');
$crs = $enroldb->Execute($sql);
if (!$crs) {
trigger_error($enroldb->ErrorMsg() . ' STATEMENT: ' . $sql);
return false;
}
if ($crs->EOF) {
// shouldn't happen, but cover all bases
continue;
}
// slurp results into an array
while ($crs_obj = rs_fetch_next_record($crs)) {
$crs_obj = (object) array_change_key_case((array) $crs_obj, CASE_LOWER);
array_push($extenrolments, $crs_obj->{strtolower($CFG->enrol_remoteuserfield)});
}
rs_close($crs);
// release the handle
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:101,代码来源:enrol.php
示例6: cron
/**
* This function is run by admin/cron.php every time if admin has enabled this plugin.
*
* Everyday at settlement time (default is 00:05), it cleans up some tables
* and sends email to admin/teachers about pending orders expiring if manual-capture has enabled.
*
* If admin set up 'Order review' and 'Capture day', it captures credits cards and enrols students.
*
* @access public
*/
public function cron()
{
global $CFG, $DB;
$oneday = 86400;
$timenow = time();
$settlementtime = AuthorizeNet::getsettletime($timenow);
$timediff30 = $settlementtime - 30 * $oneday;
$mconfig = get_config('enrol/authorize');
mtrace("Processing authorize cron...");
if (intval($mconfig->an_dailysettlement) < $settlementtime) {
set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
mtrace(" Daily cron:");
$this->cron_daily();
mtrace(" Done");
}
mtrace(" Scheduled capture", ": ");
if (empty($CFG->an_review) or !empty($CFG->an_test) or intval($CFG->an_capture_day) < 1 or !check_curl_available()) {
mtrace("disabled");
return;
// order review disabled or test mode or manual capture or openssl wasn't loaded.
}
$timediffcnf = $settlementtime - intval($CFG->an_capture_day) * $oneday;
$select = "(status = ?) AND (timecreated < ?) AND (timecreated > ?)";
$params = array(AN_STATUS_AUTH, $timediffcnf, $timediff30);
if (!($ordercount = $DB->count_records_select('enrol_authorize', $select, $params))) {
mtrace("no pending orders");
return;
}
$eachconn = intval($mconfig->an_eachconnsecs);
$eachconn = $eachconn > 60 ? 60 : ($eachconn <= 0 ? 3 : $eachconn);
if ($ordercount * $eachconn + intval($mconfig->an_lastcron) > $timenow) {
mtrace("blocked");
return;
}
set_config('an_lastcron', $timenow, 'enrol/authorize');
mtrace(" {$ordercount} orders are being processed now", ": ");
$faults = '';
$sendem = array();
$elapsed = time();
@set_time_limit(0);
$this->log = "AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate($timenow) . "\n";
$lastcourseid = 0;
$rs = $DB->get_recordset_select('enrol_authorize', $select, $params, 'courseid');
foreach ($rs as $order) {
$message = '';
$extra = NULL;
if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_PRIOR_AUTH_CAPTURE)) {
if ($lastcourseid != $order->courseid) {
$lastcourseid = $order->courseid;
$course = $DB->get_record('course', array('id' => $lastcourseid));
$role = get_default_course_role($course);
$context = get_context_instance(CONTEXT_COURSE, $lastcourseid);
}
$timestart = $timeend = 0;
if ($course->enrolperiod) {
$timestart = $timenow;
$timeend = $order->settletime + $course->enrolperiod;
}
$user = $DB->get_record('user', array('id' => $order->userid));
if (role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, 'authorize')) {
$this->log .= "User({$user->id}) has been enrolled to course({$course->id}).\n";
if (!empty($CFG->enrol_mailstudents)) {
$sendem[] = $order->id;
}
} else {
$faults .= "Error while trying to enrol " . fullname($user) . " in '{$course->fullname}' \n";
foreach ($order as $okey => $ovalue) {
$faults .= " {$okey} = {$ovalue}\n";
}
}
} else {
$this->log .= "Error, Order# {$order->id}: " . $message . "\n";
}
}
$rs->close();
mtrace("processed");
$timenow = time();
$elapsed = $timenow - $elapsed;
$eachconn = ceil($elapsed / $ordercount);
set_config('an_eachconnsecs', $eachconn, 'enrol/authorize');
$this->log .= "AUTHORIZE.NET CRON FINISHED: " . userdate($timenow);
$adminuser = get_admin();
if (!empty($faults)) {
$eventdata = new object();
$eventdata->modulename = 'moodle';
$eventdata->userfrom = $adminuser;
$eventdata->userto = $adminuser;
$eventdata->subject = "AUTHORIZE.NET CRON FAULTS";
$eventdata->fullmessage = $faults;
$eventdata->fullmessageformat = FORMAT_PLAIN;
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:enrol.php
示例7: authorize_process_csv
//.........这里部分代码省略.........
$updated++;
// Updated order status
}
continue;
}
if (!empty($reftransid) && is_numeric($reftransid) && 'Settled Successfully' == $transstatus && 'Credit' == $transtype) {
if ($order = get_record('enrol_authorize', 'transid', $reftransid)) {
if (AN_METHOD_ECHECK == $order->paymentmethod) {
$refund = get_record('enrol_authorize_refunds', 'transid', $transid);
if ($refund) {
$refund->status = AN_STATUS_CREDIT;
$refund->settletime = $settlementdate;
update_record('enrol_authorize_refunds', $refund);
$updated++;
} else {
$ignored++;
$ignoredlines .= $reftransid . ": Not our business(Reference Transaction ID)\n";
}
}
} else {
$ignored++;
$ignoredlines .= $reftransid . ": Not our business(Transaction ID)\n";
}
continue;
}
if (!($transstatus == 'Settled Successfully' && $transtype == 'Authorization w/ Auto Capture')) {
$ignored++;
$ignoredlines .= $transid . ": Not settled\n";
continue;
}
// TransactionId must match
$order = get_record('enrol_authorize', 'transid', $transid);
if (!$order) {
$ignored++;
$ignoredlines .= $transid . ": Not our business\n";
continue;
}
// Authorized/Captured and Settled
$order->status = AN_STATUS_AUTHCAPTURE;
$order->settletime = $settlementdate;
update_record('enrol_authorize', $order);
$updated++;
// Updated order status and settlement date
if ($order->paymentmethod != AN_METHOD_ECHECK) {
$ignored++;
$ignoredlines .= $transid . ": The method must be echeck\n";
continue;
}
// Get course and context
$course = get_record('course', 'id', $order->courseid);
if (!$course) {
$ignored++;
$ignoredlines .= $transid . ": Could not find this course: " . $order->courseid . "\n";
continue;
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if (!$coursecontext) {
$ignored++;
$ignoredlines .= $transid . ": Could not find course context: " . $order->courseid . "\n";
continue;
}
// Get user
$user = get_record('user', 'id', $order->userid);
if (!$user) {
$ignored++;
$ignoredlines .= $transid . ": Could not find this user: " . $order->userid . "\n";
continue;
}
// If user wasn't enrolled, enrol now. Ignore otherwise. Because admin user might submit this file again.
if ($role = get_default_course_role($course)) {
if (!user_has_role_assignment($user->id, $role->id, $coursecontext->id)) {
$timestart = $timeend = 0;
if ($course->enrolperiod) {
$timestart = time();
$timeend = $timestart + $course->enrolperiod;
}
if (role_assign($role->id, $user->id, 0, $coursecontext->id, $timestart, $timeend, 0, 'authorize')) {
$imported++;
if (!empty($CFG->enrol_mailstudents)) {
$sendem[] = $order->id;
}
} else {
$ignoredlines .= $transid . ": Error while trying to enrol " . fullname($user) . " in '{$course->fullname}' \n";
}
}
}
}
fclose($handle);
/// Send email to admin
if (!empty($ignoredlines)) {
$admin = get_admin();
email_to_user($admin, $admin, "{$SITE->fullname}: Authorize.net CSV ERROR LOG", $ignoredlines);
}
/// Send welcome messages to users
if (!empty($sendem)) {
send_welcome_messages($sendem);
}
/// Show result
notice("<b>Done...</b><br />Imported: {$imported}<br />Updated: {$updated}<br />Ignored: {$ignored}");
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:101,代码来源:uploadcsv.php
示例8: add
//.........这里部分代码省略.........
}
$status = new Object();
$status->message = get_string('unsatisfiedprereqs', 'block_curr_admin');
$status->code = 'unsatisfiedprereqs';
return $status;
}
}
}
if (!empty($checks['waitlist'])) {
// check class enrolment limit
$cmclass = new cmclass($this->classid);
$limit = $cmclass->maxstudents;
if (!empty($limit) && $limit <= student::count_enroled($this->classid)) {
// class is full
// put student on wait list
$wait_list = new waitlist($this);
$wait_list->timecreated = time();
$wait_list->position = 0;
$wait_list->add();
if ($notify) {
$subject = get_string('user_waitlisted', 'block_curr_admin');
$a = new object();
$a->user = $this->user->idnumber;
$a->cmclass = $cmclass->idnumber;
$message = get_string('user_waitlisted_msg', 'block_curr_admin', $a);
$from = $user = get_admin();
notification::notify($message, $user, $from);
email_to_user($user, $from, $subject, $message);
}
$status = new Object();
$status->message = get_string('user_waitlisted', 'block_curr_admin');
$status->code = 'user_waitlisted';
return $status;
}
}
//set end time based on class duration
$studentclass = new cmclass($this->classid);
if (empty($this->endtime)) {
if (isset($studentclass->duration) && $studentclass->duration) {
$this->endtime = $this->enrolmenttime + $studentclass->duration;
} else {
// no class duration -> no end time
$this->endtime = 0;
}
}
$status = $this->data_insert_record();
// TBD: we should check this!
/// Get the Moodle user ID or create a new account for this user.
if (!($muserid = cm_get_moodleuserid($this->userid))) {
$user = new user($this->userid);
if (!($muserid = $user->synchronize_moodle_user(true, true))) {
$status = new Object();
$status->message = get_string('errorsynchronizeuser', 'block_curr_admin');
$muserid = false;
}
}
/// Enrol them into the Moodle class.
if ($moodlecourseid = moodle_get_course($this->classid)) {
if ($mcourse = get_record('course', 'id', $moodlecourseid)) {
$enrol = $mcourse->enrol;
if (!$enrol) {
$enrol = $CFG->enrol;
}
if ($CURMAN->config->restrict_to_elis_enrolment_plugin && $enrol != 'elis') {
$status = new Object();
$status->message = get_string('error_not_using_elis_enrolment', 'block_curr_admin');
return $status;
}
$timestart = $this->enrolmenttime;
$timeend = $this->endtime;
if ($role = get_default_course_role($mcourse)) {
$context = get_context_instance(CONTEXT_COURSE, $mcourse->id);
if (!empty($muserid)) {
if (!role_assign($role->id, $muserid, 0, $context->id, $timestart, $timeend, 0, 'manual')) {
$status = new Object();
$status->message = get_string('errorroleassign', 'block_curr_admin');
}
}
}
}
} else {
if (!empty($muserid)) {
$sturole = $CURMAN->config->enrolment_role_sync_student_role;
// ELIS-2776: must still trigger events for notifications
$ra = new stdClass();
$ra->roleid = !empty($sturole) ? $sturole : get_field('role', 'id', 'shortname', 'student');
$ra->contextid = context_level_base::get_custom_context_level('class', 'block_curr_admin');
// TBD
$ra->userid = $muserid;
$ra->component = '';
// TBD: 'enrol_elis'
$ra->itemid = $this->classid;
// TBD
$ra->timemodified = time();
$ra->modifierid = empty($USER->id) ? 0 : $USER->id;
events_trigger('role_assigned', $ra);
}
}
return $status;
}
开发者ID:remotelearner,项目名称:elis.cm,代码行数:101,代码来源:student.class.php
示例9: data_enrol_students
/**
* Enrol the students associated with the class into the attached Moodle
* course.
*
* @param none
* @return bool True on success, False otherwise.
*/
function data_enrol_students()
{
if (empty($this->classid) || empty($this->moodlecourseid) || !empty($this->siteconfig) && !file_exists($this->siteconfig)) {
return false;
}
$stu = new student();
if ($students = $stu->get_students($this->classid)) {
/// At this point we must switch over the other Moodle site's DB config, if needed
if (!empty($this->siteconfig)) {
$cfgbak = moodle_load_config($this->siteconfig);
}
/// This has to be put here in case we have a site config reload.
$CFG = $GLOBALS['CFG'];
$CURMAN = $GLOBALS['CURMAN'];
$db = $GLOBALS['db'];
$role = get_default_course_role($this->moodlecourseid);
if (!($context = get_context_instance(CONTEXT_COURSE, $this->moodlecourseid))) {
return false;
}
foreach ($students as $student) {
/// Make sure that a Moodle account exists for this user already.
$user = new user($student->id);
if (!($muser = $CURMAN->db->get_record('user', 'idnumber', addslashes($user->idnumber)))) {
$muser = addslashes_recursive($muser);
/// Create a new record.
$muser = new stdClass();
$muser->idnumber = $user->idnumber;
$muser->username = $user->uname;
$muser->passwword = $user->passwd;
$muser->firstname = $user->firstname;
$muser->lastname = $user->lastname;
$muser->auth = 'manual';
$muser->timemodified = time();
$muser->id = $CURMAN->db->insert_record('user', $muser);
}
/// If we have a vald Moodle user account, apply the role.
if (!empty($muser->id)) {
role_assign($role->id, $muser->id, 0, $context->id, 0, 0, 0, 'manual');
}
}
/// Reset $CFG object.
if (!empty($this->siteconfig)) {
moodle_load_config($cfgbak->dirroot . '/config.php');
}
}
return true;
}
开发者ID:remotelearner,项目名称:elis.cm,代码行数:54,代码来源:classmoodlecourse.class.php
示例10: fn_user_created_handler
/**
* This function is called when a 'user_created' event is triggered, and hopefully every time a new user
* is created. It will assign the defined user to the configured role at the front page level, so that
* the user can be added to site groups.
*
* @param object $eventdata The user object created.
* @return boolean Always return true so that the event gets cleared.
*
*/
function fn_user_created_handler($eventdata)
{
global $CFG;
/// If we aren't using site groups, do nothing.
if (empty($CFG->block_fn_site_groups_enabled)) {
return true;
}
/// If no specific role has been configured, use the default role for a course in the user policies.
if (empty($CFG->block_fn_site_groups_defaultroleid)) {
$course = get_site();
$role = get_default_course_role($course);
$defaultroleid = $role->id;
} else {
$defaultroleid = $CFG->block_fn_site_groups_defaultroleid;
}
/// If the role is empty, there's nothing else we can do.
if (!empty($defaultroleid)) {
$context = get_context_instance(CONTEXT_COURSE, SITEID);
role_assign($defaultroleid, $eventdata->id, false, $context->id);
}
return true;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:eventhandlers.php
示例11: notice_yesno
notice_yesno($confmsg, 'index.php', $return, $optionsyes, NULL, 'post', 'get');
admin_externalpage_print_footer();
die;
}
// action confirmed, perform it
if ($confirm) {
if (empty($SESSION->bulk_courses)) {
redirect($return);
}
// for each course, get the default role if needed and check the selected group
foreach ($SESSION->bulk_courses as $course) {
$context = get_context_instance(CONTEXT_COURSE, $course);
$in = implode(',', $SESSION->bulk_users);
$groupid = false;
if ($roleassign == 0) {
$defrole = get_default_course_role($context);
$roleassign = $defrole->id;
}
if (!empty($groupname)) {
$groupid = groups_get_group_by_name($course, stripslashes($groupname));
}
// for each user, enrol them to the course with the selected role,
// and add to the selected group if available
if ($rs = get_recordset_select('user', "id IN ({$in})")) {
while ($user = rs_fetch_next_record($rs)) {
role_assign($roleassign, $user->id, 0, $context->id, 0, 0, $hidden);
if ($groupid !== false) {
groups_add_member($groupid, $user->id);
}
}
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:index.php
示例12: assign_capability
assign_capability('block/fn_site_groups:managegroups', CAP_ALLOW, $gmroleid, $context->id);
assign_capability('block/fn_site_groups:managegroupmembers', CAP_ALLOW, $gmroleid, $context->id);
assign_capability('block/fn_site_groups:managestudents', CAP_ALLOW, $gmroleid, $context->id);
assign_capability('block/fn_site_groups:markallgroups', CAP_ALLOW, $gmroleid, $context->id);
assign_capability('block/fn_site_groups:assignallusers', CAP_INHERIT, $gmroleid, $context->id);
assign_capability('block/fn_site_groups:assignowngroupusers', CAP_ALLOW, $gmroleid, $context->id);
assign_capability('block/fn_site_groups:createnewgroups', CAP_ALLOW, $gmroleid, $context->id);
} else {
$gmroleid = $role->id;
}
$roles = get_records_menu('role', '', '', 'sortorder ASC', 'id,name');
if (empty($roles)) {
$roles = array();
}
$course = get_site();
$role = get_default_course_role($course);
$defaultroleid = $role->id;
$item = new admin_setting_configcheckbox('block_fn_site_groups_enabled', get_string('fn_site_groups_enabled', 'block_fn_site_groups'), get_string('fn_config_site_groups_enabled', 'block_fn_site_groups'), '0');
$item->set_updatedcallback('fn_sg_set_site_group_mode');
$settings->add($item);
$settings->add(new admin_setting_configselect('block_fn_site_groups_defaultroleid', get_string('fn_site_groups_defaultroleid', 'block_fn_site_groups'), get_string('fn_config_site_groups_defaultroleid', 'block_fn_site_groups'), $defaultroleid, $roles));
$settings->add(new admin_setting_configmulticheckbox('block_fn_site_groups_roles', get_string('fn_site_groups_roles', 'block_fn_site_groups'), get_string('fn_config_site_groups_roles', 'block_fn_site_groups'), '0', $roles));
/// These settings don't actually use the $CFG variable, but are used to manage capabilities.
$caps = role_context_capabilities($gmroleid, $context);
$sgusers = array();
if (!empty($caps['block/fn_site_groups:assignowngroupusers'])) {
$sgusers[] = 1;
}
if (!empty($caps['block/fn_site_groups:assignallusers'])) {
$sgusers[] = 2;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:settings.php
示例13: enrol_into_course
/**
* A convenience function to take care of the common case where you
* just want to enrol someone using the default role into a course
*
* @param object $course
* @param object $user
* @param string $enrol - the plugin used to do this enrolment
*/
function enrol_into_course($course, $user, $enrol)
{
if ($course->enrolperiod) {
$timestart = time();
$timeend = time() + $course->enrolperiod;
} else {
$timestart = $timeend = 0;
}
if ($role = get_default_course_role($course)) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
if (!role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol)) {
return false;
}
email_welcome_message_to_user($course, $user);
add_to_log($course->id, 'course', 'enrol', 'view.php?id=' . $course->id, $user->id);
return true;
}
return false;
}
开发者ID:veritech,项目名称:pare-project,代码行数:27,代码来源:accesslib.php
注:本文中的get_default_course_role函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论