本文整理汇总了PHP中sort_by_roleassignment_authority函数的典型用法代码示例。如果您正苦于以下问题:PHP sort_by_roleassignment_authority函数的具体用法?PHP sort_by_roleassignment_authority怎么用?PHP sort_by_roleassignment_authority使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sort_by_roleassignment_authority函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: time
die;
}
// ALL CLEAR !
$DB->insert_record("enrol_paypal", $data);
if ($plugin_instance->enrolperiod) {
$timestart = time();
$timeend = $timestart + $plugin_instance->enrolperiod;
} else {
$timestart = 0;
$timeend = 0;
}
// Enrol user
$plugin->enrol_user($plugin_instance, $user->id, $plugin_instance->roleid, $timestart, $timeend);
// Pass $view=true to filter hidden caps if the user cannot see them
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
} else {
$teacher = false;
}
$mailstudents = $plugin->get_config('mailstudents');
$mailteachers = $plugin->get_config('mailteachers');
$mailadmins = $plugin->get_config('mailadmins');
$shortname = format_string($course->shortname, true, array('context' => $context));
if (!empty($mailstudents)) {
$a->coursename = format_string($course->fullname, true, array('context' => $coursecontext));
$a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}";
$eventdata = new stdClass();
$eventdata->modulename = 'moodle';
$eventdata->component = 'enrol_paypal';
$eventdata->name = 'paypal_enrolment';
示例2: cron
/**
* Notify users about enrolments that are going to expire soon!
* This function is run by admin/cron.php
* @return void
*/
function cron()
{
global $CFG, $USER, $SITE;
if (!isset($CFG->lastexpirynotify)) {
set_config('lastexpirynotify', 0);
}
// notify once a day only - TODO: add some tz handling here, maybe use timestamps
if ($CFG->lastexpirynotify == date('Ymd')) {
return;
}
if ($rs = get_recordset_select('course', 'enrolperiod > 0 AND expirynotify > 0 AND expirythreshold > 0')) {
$cronuser = clone $USER;
$admin = get_admin();
while ($course = rs_fetch_next_record($rs)) {
$a = new object();
$a->coursename = $course->shortname . '/' . $course->fullname;
// must be processed by format_string later
$a->threshold = $course->expirythreshold / 86400;
$a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id;
$a->current = array();
$a->past = array();
$expiry = time() + $course->expirythreshold;
$cname = $course->fullname;
/// Get all the manual role assignments for this course that have expired.
if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
continue;
}
if ($oldenrolments = get_records_sql("\n SELECT u.*, ra.timeend\n FROM {$CFG->prefix}user u\n JOIN {$CFG->prefix}role_assignments ra ON (ra.userid = u.id)\n WHERE ra.contextid = {$context->id}\n AND ra.timeend > 0 AND ra.timeend <= {$expiry}\n AND ra.enrol = 'manual'")) {
// inform user who can assign roles or admin
if ($teachers = get_users_by_capability($context, 'moodle/role:assign', '', '', '', '', '', '', false)) {
$teachers = sort_by_roleassignment_authority($teachers, $context);
$teacher = reset($teachers);
} else {
$teachers = array($admin);
$teacher = $admin;
}
$a->teacherstr = fullname($teacher, true);
foreach ($oldenrolments as $user) {
/// Email all users about to expire
$a->studentstr = fullname($user, true);
if ($user->timeend < $expiry - 86400) {
$a->past[] = fullname($user) . " <{$user->email}>";
} else {
$a->current[] = fullname($user) . " <{$user->email}>";
if ($course->notifystudents) {
// Send this guy notice
// setup global $COURSE properly - needed for languages
$USER = $user;
course_setup($course);
$a->coursename = format_string($cname);
$a->course = $a->coursename;
$strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a);
$strexpirynotify = get_string('expirynotify');
email_to_user($user, $teacher, format_string($SITE->fullname) . ' ' . $strexpirynotify, $strexpirynotifystudentsemail);
}
}
}
$a->current = implode("\n", $a->current);
$a->past = implode("\n", $a->past);
if ($a->current || $a->past) {
foreach ($teachers as $teacher) {
// setup global $COURSE properly - needed for languages
$USER = $teacher;
course_setup($course);
$a->coursename = format_string($cname);
$strexpirynotifyemail = get_string('expirynotifyemail', '', $a);
$strexpirynotify = get_string('expirynotify');
email_to_user($teacher, $admin, $a->coursename . ' ' . $strexpirynotify, $strexpirynotifyemail);
}
}
}
}
$USER = $cronuser;
course_setup($SITE);
// More environment
}
set_config('lastexpirynotify', date('Ymd'));
}
示例3: get_enroller
/**
* Returns the user who is responsible for self enrolments in given instance.
*
* Usually it is the first editing teacher - the person with "highest authority"
* as defined by sort_by_roleassignment_authority() having 'enrol/self:manage'
* capability.
*
* @param int $instanceid enrolment instance id
* @return stdClass user record
*/
protected function get_enroller($instanceid)
{
global $DB;
if ($this->lasternollerinstanceid == $instanceid and $this->lasternoller) {
return $this->lasternoller;
}
$instance = $DB->get_record('enrol', array('id' => $instanceid, 'enrol' => $this->get_name()), '*', MUST_EXIST);
$context = context_course::instance($instance->courseid);
if ($users = get_enrolled_users($context, 'enrol/self:manage')) {
$users = sort_by_roleassignment_authority($users, $context);
$this->lasternoller = reset($users);
unset($users);
} else {
$this->lasternoller = parent::get_enroller($instanceid);
}
$this->lasternollerinstanceid = $instanceid;
return $this->lasternoller;
}
示例4: enrol_page_hook
/**
* Creates course enrol form, checks if form submitted
* and enrols user if necessary. It can also redirect.
*
* @param stdClass $instance
* @return string html text, usually a form in a text box
*/
function enrol_page_hook(stdClass $instance)
{
global $CFG, $USER, $OUTPUT, $PAGE, $DB;
ob_start();
if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return ob_get_clean();
}
if ($instance->enrolstartdate != 0 && $instance->enrolstartdate > time()) {
return ob_get_clean();
}
if ($instance->enrolenddate != 0 && $instance->enrolenddate < time()) {
return ob_get_clean();
}
$course = $DB->get_record('course', array('id' => $instance->courseid));
$context = context_course::instance($course->id);
$shortname = format_string($course->shortname, true, array('context' => $context));
$strloginto = get_string("loginto", "", $shortname);
$strcourses = get_string("courses");
// Pass $view=true to filter hidden caps if the user cannot see them
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
} else {
$teacher = false;
}
if ((double) $instance->cost <= 0) {
$cost = (double) $this->get_config('cost');
} else {
$cost = (double) $instance->cost;
}
if (abs($cost) < 0.01) {
// no cost, other enrolment methods (instances) should be used
echo '<p>' . get_string('nocost', 'enrol_paypal') . '</p>';
} else {
// Calculate localised and "." cost, make sure we send PayPal the same value,
// please note PayPal expects amount with 2 decimal places and "." separator.
$localisedcost = format_float($cost, 2, true);
$cost = format_float($cost, 2, false);
if (isguestuser()) {
// force login only for guest user, not real users with guest role
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {
// This actually is not so secure ;-), 'cause we're
// in unencrypted connection...
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
echo '<div class="mdl-align"><p>' . get_string('paymentrequired') . '</p>';
echo '<p><b>' . get_string('cost') . ": {$instance->currency} {$localisedcost}" . '</b></p>';
echo '<p><a href="' . $wwwroot . '/login/">' . get_string('loginsite') . '</a></p>';
echo '</div>';
} else {
//Sanitise some fields before building the PayPal form
$coursefullname = format_string($course->fullname, true, array('context' => $context));
$courseshortname = $shortname;
$userfullname = fullname($USER);
$userfirstname = $USER->firstname;
$userlastname = $USER->lastname;
$useraddress = $USER->address;
$usercity = $USER->city;
$instancename = $this->get_instance_name($instance);
include $CFG->dirroot . '/enrol/paypal/enrol.html';
}
}
return $OUTPUT->box(ob_get_clean());
}
示例5: certificate_email_students
/**
* Sends the student their issued certificate from moddata as an email
* attachment.
*
* @param stdClass $user
* @param stdClass $course
* @param stdClass $certificate
* @param stdClass $certrecord
* @param stdClass $context
*/
function certificate_email_students($user, $course, $certificate, $certrecord, $context)
{
global $DB, $USER;
if ($certrecord->mailed > 0) {
return;
}
// Get teachers
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
}
// If we haven't found a teacher yet, look for a non-editing teacher in this course.
if (empty($teacher) && ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true))) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
}
$info = new stdClass();
$info->username = fullname($user);
$info->certificate = format_string($certificate->name, true);
$info->course = format_string($course->fullname, true);
$from = fullname($teacher);
$subject = $info->course . ': ' . $info->certificate;
$message = get_string('emailstudenttext', 'certificate', $info) . "\n";
// Make the HTML version more XHTML happy (&)
$messagehtml = text_to_html(get_string('emailstudenttext', 'certificate', $info));
$user->mailformat = 0;
// Always send HTML version as well
$filename = clean_filename($certificate->name . '.pdf');
// Get hashed pathname
$fs = get_file_storage();
$component = 'mod_certificate';
$filearea = 'issue';
$filepath = '/';
$files = $fs->get_area_files($context->id, $component, $filearea, $certrecord->id);
foreach ($files as $f) {
$filepathname = $f->get_contenthash();
}
$attachment = 'filedir/' . certificate_path_from_hash($filepathname) . '/' . $filepathname;
$attachname = $filename;
$DB->set_field('certificate_issues', 'mailed', '1', array('certificateid' => $certificate->id, 'userid' => $user->id));
return email_to_user($user, $from, $subject, $message, $messagehtml, $attachment, $attachname);
}
示例6: certificate_email_student
/**
* Sends the student their issued certificate from moddata as an email
* attachment.
*
* @param stdClass $course
* @param stdClass $certificate
* @param stdClass $certrecord
* @param stdClass $context
* @param string $filecontents the PDF file contents
* @param string $filename
* @return bool Returns true if mail was sent OK and false if there was an error.
*/
function certificate_email_student($course, $certificate, $certrecord, $context, $filecontents, $filename)
{
global $USER;
// Get teachers
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
}
// If we haven't found a teacher yet, look for a non-editing teacher in this course.
if (empty($teacher) && ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true))) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
}
// Ok, no teachers, use administrator name
if (empty($teacher)) {
$teacher = fullname(get_admin());
}
$info = new stdClass();
$info->username = fullname($USER);
$info->certificate = format_string($certificate->name, true);
$info->course = format_string($course->fullname, true);
$from = fullname($teacher);
$subject = $info->course . ': ' . $info->certificate;
$message = get_string('emailstudenttext', 'certificate', $info) . "\n";
// Make the HTML version more XHTML happy (&)
$messagehtml = text_to_html(get_string('emailstudenttext', 'certificate', $info));
$tempdir = make_temp_directory('certificate/attachment');
if (!$tempdir) {
return false;
}
$tempfile = $tempdir . '/' . md5(sesskey() . microtime() . $USER->id . '.pdf');
$fp = fopen($tempfile, 'w+');
fputs($fp, $filecontents);
fclose($fp);
$prevabort = ignore_user_abort(true);
$result = email_to_user($USER, $from, $subject, $message, $messagehtml, $tempfile, $filename);
@unlink($tempfile);
ignore_user_abort($prevabort);
return $result;
}
示例7: iomadcertificate_email_student
/**
* Sends the student their issued iomadcertificate from moddata as an email
* attachment.
*
* @param stdClass $course
* @param stdClass $iomadcertificate
* @param stdClass $certrecord
* @param stdClass $context
*/
function iomadcertificate_email_student($course, $iomadcertificate, $certrecord, $context)
{
global $DB, $USER;
// Get teachers
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
}
// If we haven't found a teacher yet, look for a non-editing teacher in this course.
if (empty($teacher) && ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true))) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
}
// Ok, no teachers, use administrator name
if (empty($teacher)) {
$teacher = fullname(get_admin());
}
$info = new stdClass();
$info->username = fullname($USER);
$info->iomadcertificate = format_string($iomadcertificate->name, true);
$info->course = format_string($course->fullname, true);
$from = fullname($teacher);
$subject = $info->course . ': ' . $info->iomadcertificate;
$message = get_string('emailstudenttext', 'iomadcertificate', $info) . "\n";
// Make the HTML version more XHTML happy (&)
$messagehtml = text_to_html(get_string('emailstudenttext', 'iomadcertificate', $info));
// Remove full-stop at the end if it exists, to avoid "..pdf" being created and being filtered by clean_filename
$certname = rtrim($iomadcertificate->name, '.');
$filename = clean_filename("{$certname}.pdf");
// Get hashed pathname
$fs = get_file_storage();
$component = 'mod_iomadcertificate';
$filearea = 'issue';
$filepath = '/';
$files = $fs->get_area_files($context->id, $component, $filearea, $certrecord->id);
foreach ($files as $f) {
$filepathname = $f->get_contenthash();
}
$attachment = 'filedir/' . iomadcertificate_path_from_hash($filepathname) . '/' . $filepathname;
$attachname = $filename;
return email_to_user($USER, $from, $subject, $message, $messagehtml, $attachment, $attachname);
}
示例8: enrol_page_hook
/**
* Creates course enrol form, checks if form submitted
* and enrols user if necessary. It can also redirect.
* It basically controls what the user sees it generates the enrollform e.t.c
*
*
* @param stdClass $instance
* @return string html text, usually a form in a text box
*/
function enrol_page_hook(stdClass $instance)
{
global $CFG, $USER, $OUTPUT, $PAGE, $DB;
ob_start();
$select = "userid = '" . $USER->id . "' AND enrolid ='" . $instance->id . "' AND timeend >'" . time() . "'";
if ($DB->record_exists_select('user_enrolments', $select, array($params = null))) {
return ob_get_clean();
}
if ($instance->enrolstartdate != 0 && $instance->enrolstartdate > time()) {
return ob_get_clean();
}
if ($instance->enrolenddate != 0 && $instance->enrolenddate < time()) {
return ob_get_clean();
}
$course = $DB->get_record('course', array('id' => $instance->courseid));
$context = context_course::instance($course->id);
$shortname = format_string($course->shortname, true, array('context' => $context));
$strloginto = get_string("loginto", "", $shortname);
$strcourses = get_string("courses");
// Pass $view=true to filter hidden caps if the user cannot see them.
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
//returns the first element in the array shifting the
//rest one position lower
} else {
$teacher = false;
}
if ((double) $instance->cost <= 0) {
$cost = (double) $this->get_config('cost');
//get_config fetches from the original configuration settings
} else {
$cost = (double) $instance->cost;
}
if (abs($cost) < 0.01) {
echo '<p>' . get_string('nocost', 'ipay') . '</p>';
} else {
//Calculate localised cost and "." cost, make sure we send Ipay the same value
//please note ipay expects ammount with 2 decimal places and "." seperator.
$localisedcost = format_float($cost, 2, true);
if (isguestuser()) {
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {
//This is not so secure ;-) cause we're
//in unencrypted connection
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
echo '<div class="mdl_align"><p>' . get_string('paymentrequired') . '</p>';
echo '<p><b>' . get_string('cost') . ": {$instance->currency} {$localisedcost}" . '</b></p>';
echo '<p><a href="' . $wwwroot . '/login/">' . get_string('loginsite') . '</a></p>';
echo "</div>";
} else {
$sql = "SELECT ud.data \n FROM {user_info_data} ud \n JOIN {user_info_field} uf ON uf.id = ud.fieldid\n WHERE ud.userid = :userid AND uf.shortname = :fieldname";
$params = array('userid' => $USER->id, 'fieldname' => 'Mobileno');
$mob = $DB->get_field_sql($sql, $params);
$coursefullname = format_string($course->fullname, true, array('context' => $context));
$courseshortname = $shortname;
$userfullname = fullname($USER);
$userfirstname = $USER->firstname;
$userlastname = $USER->lastname;
$useremail = $USER->email;
$userphonenumber = $USER->phone2;
$instancename = $this->get_instance_name($instance);
$businessname = $this->get_config('businessname');
//get businessname from configuration
$vendorid = $this->get_config('vendorid');
$enrolperiod = $instance->enrolperiod;
$curr = $this->get_config('currency');
include $CFG->dirroot . '/enrol/ipay/enrol.html';
}
}
return $OUTPUT->box(ob_get_clean());
}
示例9: get_teacher
/**
* Returns $user object of the main teacher for a course
*
* @uses $CFG
* @param int $courseid The course in question.
* @return user|false A {@link $USER} record of the main teacher for the specified course or false if error.
* @todo Finish documenting this function
*/
function get_teacher($courseid)
{
global $CFG;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
// Pass $view=true to filter hidden caps if the user cannot see them
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
return array_shift($users);
}
return false;
}
示例10: enrol_page_hook
/**
* Creates course enrol form, checks if form submitted
* and enrols user if necessary. It can also redirect.
*
* @param stdClass $instance
* @return string html text, usually a form in a text box
*/
function enrol_page_hook(stdClass $instance)
{
global $CFG, $USER, $OUTPUT, $PAGE, $DB;
ob_start();
if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return ob_get_clean();
}
if ($instance->enrolstartdate != 0 && $instance->enrolstartdate > time()) {
return ob_get_clean();
}
if ($instance->enrolenddate != 0 && $instance->enrolenddate < time()) {
return ob_get_clean();
}
$course = $DB->get_record('course', array('id' => $instance->courseid));
$strloginto = get_string("loginto", "", $course->shortname);
$strcourses = get_string("courses");
$context = get_context_instance(CONTEXT_COURSE, $course->id);
// Pass $view=true to filter hidden caps if the user cannot see them
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
} else {
$teacher = false;
}
if ((double) $instance->cost <= 0) {
$cost = (double) $this->get_config('cost');
} else {
$cost = (double) $instance->cost;
}
if (abs($cost) < 0.01) {
// no cost, other enrolment methods (instances) should be used
echo '<p>' . get_string('nocost', 'enrol_alipay') . '</p>';
} else {
if (isguestuser()) {
// force login only for guest user, not real users with guest role
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {
// This actually is not so secure ;-), 'cause we're
// in unencrypted connection...
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
echo '<div class="mdl-align"><p>' . get_string('paymentrequired') . '</p>';
echo '<p><b>' . get_string('cost') . ": {$instance->currency} {$cost}" . '</b></p>';
echo '<p><a href="' . $wwwroot . '/login/">' . get_string('loginsite') . '</a></p>';
echo '</div>';
} else {
//Sanitise some fields before building the alipay form
$coursefullname = format_string($course->fullname, true, array('context' => $context));
$courseshortname = $course->shortname;
$userfullname = fullname($USER);
$userfirstname = $USER->firstname;
$userlastname = $USER->lastname;
$useraddress = $USER->address;
$usercity = $USER->city;
$instancename = $this->get_instance_name($instance);
$data = $DB->get_record('enrol_alipay', array('courseid' => $instance->courseid, 'cost' => $cost, 'userid' => $USER->id, 'payment_status' => 0));
if (!$data) {
$data = new stdClass();
$newinsert = true;
$timearr = gettimeofday();
$data->trade_no = date('YmdHis', $timearr['sec']) . intval(substr($timearr['usec'], 0, 3)) . '2';
//网站订单系统中的唯一订单号
$data->courseid = $instance->courseid;
$data->userid = $USER->id;
$data->cost = $instance->cost;
}
$data->seller_email = $this->get_config('alipaybusiness');
$data->payment_status = 0;
$data->timeupdated = time();
if (isset($newinsert) && $newinsert) {
$DB->insert_record("enrol_alipay", $data);
} else {
$DB->update_record("enrol_alipay", $data);
}
include $CFG->dirroot . '/enrol/alipay/build_form.php';
include $CFG->dirroot . '/enrol/alipay/enrol.html';
}
}
return $OUTPUT->box(ob_get_clean());
}
示例11: fetch_unassigned_users
function fetch_unassigned_users($minstoshowusers, $courseid, $context)
{
global $CFG;
$timetoshowusers = $minstoshowusers * 60;
//Seconds default
$timefrom = 100 * floor((time() - $timetoshowusers) / 100);
// Round to nearest 100 seconds for better query cache
$selectsql = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, max(ul.timeaccess) as lastaccess ";
$from = "FROM {$CFG->prefix}user_lastaccess ul,\n {$CFG->prefix}user u ";
$where = "WHERE ul.timeaccess > {$timefrom}\n AND u.id = ul.userid\n AND ul.courseid = {$courseid} \n\t\t\t\t\t AND u.username not in \n\t\t\t\t\t (SELECT p.username FROM {$CFG->prefix}poodllpairwork_usermap p WHERE p.course = {$courseid})\n\t\t\t\t\t\tAND u.username not in \n\t\t\t\t\t\t (SELECT p.partnername FROM {$CFG->prefix}poodllpairwork_usermap p WHERE p.course = {$courseid})";
$order = "ORDER BY lastaccess DESC ";
$groupby = "GROUP BY u.id, u.username, u.firstname, u.lastname, u.picture ";
$SQL = $selectsql . $from . $where . $groupby . $order;
$students = array();
if ($users = get_records_sql($SQL)) {
//this puts students first and if we end up with an odd number of students , we add a teacher.
if (count($users) > 0) {
//these throw errors when noone is online , but Ido not know a better way ..
//we probably need to rewrite the sort function
$students = sort_by_roleassignment_authority($users, $context, array(5));
$nonstudents = sort_by_roleassignment_authority($users, $context, array(1, 2, 3, 4));
if (count($students) % 2 > 0 && count($nonstudents) > 0) {
$students[] = array_pop($nonstudents);
}
}
}
//We need to create pairs, so we return our students array, not the user array which contains all.
return $students;
}
示例12: newenrolmentemail
/**
* Send an email to the user when they are enroled.
*
* @param student $student The student object of for the enrolment.
* @return bool Success/Failure.
*/
public function newenrolmentemail(student $student)
{
global $DB;
if (!empty($student->no_moodle_enrol)) {
return false;
}
// Look for attached Moodle course, and get the course info.
$moodlecourseid = moodle_get_course($student->classid);
if (empty($moodlecourseid)) {
return false;
}
$course = $DB->get_record('course', array('id' => $moodlecourseid));
if (empty($course)) {
return false;
}
// Get the elis user and the moodle user.
$user = new user($student->userid);
$muser = $user->get_moodleuser();
if (empty($muser)) {
return false;
}
// Check whether emails are enabled.
$enabled = get_config('dhimport_version1elis', 'newenrolmentemailenabled');
if (empty($enabled)) {
return false;
}
// Check whether email text has been set.
$template = get_config('dhimport_version1elis', 'newenrolmentemailtemplate');
if (empty($template)) {
return false;
}
// Ensure Moodle user has an email address.
if (empty($muser->email)) {
return false;
}
// Get the email subject line, set an empty string if necessary.
$subject = get_config('dhimport_version1elis', 'newenrolmentemailsubject');
if (empty($subject) || !is_string($subject)) {
$subject = '';
}
// Get the user the email will be from.
$from = get_config('dhimport_version1elis', 'newenrolmentemailfrom');
if ($from === 'teacher') {
$context = context_course::instance($course->id);
$cap = 'moodle/course:update';
if ($users = get_users_by_capability($context, $cap, 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$from = current($users);
} else {
$from = get_admin();
}
} else {
$from = get_admin();
}
// Generate email.
$body = $this->newenrolmentemail_generate($template, $muser, $course);
// Send!
return $this->sendemail($muser, $from, $subject, $body);
}
示例13: enrol_page_hook
/**
* Creates course enrol form, checks if form submitted
* and enrols user if necessary. It can also redirect.
*
* @param stdClass $instance
* @return string html text, usually a form in a text box
*/
function enrol_page_hook(stdClass $instance)
{
global $CFG, $USER, $OUTPUT, $PAGE, $DB;
ob_start();
if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return ob_get_clean();
}
if ($instance->enrolstartdate != 0 && $instance->enrolstartdate > time()) {
return ob_get_clean();
}
if ($instance->enrolenddate != 0 && $instance->enrolenddate < time()) {
return ob_get_clean();
}
$course = $DB->get_record('course', array('id' => $instance->courseid));
$strloginto = get_string("loginto", "", $course->shortname);
$strcourses = get_string("courses");
$context = get_context_instance(CONTEXT_COURSE, $course->id);
// Pass $view=true to filter hidden caps if the user cannot see them
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$teacher = array_shift($users);
} else {
$teacher = false;
}
if ((double) $instance->cost <= 0) {
$cost = (double) $this->get_config('cost');
} else {
$cost = (double) $instance->cost;
}
if ($instance->customint3 > 0) {
// max enrol limit specified
$count = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
if ($count >= $instance->customint3) {
// bad luck, no more enrolments here
return $OUTPUT->notification(get_string('maxenrolledreached', 'enrol_globalclassroom'));
}
}
print '<div class="mdl-align"><h5>' . $course->fullname . '</h5>' . $course->summary . '</div>';
if (abs($cost) < 0.01 || $instance->customchar1 > 0 && $CFG->current_app->getCurrentUser()->isMember()) {
require_once "{$CFG->dirroot}/enrol/globalclassroom/locallib.php";
require_once "{$CFG->dirroot}/group/lib.php";
$form = new enrol_globalclassroom_enrol_form(NULL, $instance);
$instanceid = optional_param('instance', 0, PARAM_INT);
if ($instance->password) {
if ($instance->id == $instanceid) {
if ($data = $form->get_data()) {
$enrol = enrol_get_plugin('globalclassroom');
$CFG->current_app->enrolUserInCourse($course, $USER);
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id=' . $instance->courseid, $instance->courseid);
//there should be userid somewhere!
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
// it must be a group enrolment, let's assign group too
$groups = $DB->get_records('groups', array('courseid' => $instance->courseid), 'id', 'id, enrolmentkey');
foreach ($groups as $group) {
if (empty($group->enrolmentkey)) {
continue;
}
if ($group->enrolmentkey === $data->enrolpassword) {
groups_add_member($group->id, $USER->id);
break;
}
}
}
}
}
$form->display();
} else {
$CFG->current_app->enrolUserInCourse($course, $USER);
redirect($CFG->current_app->getAppUrl() . '/course/view.php?id=' . $course->id);
}
} else {
if (isguestuser()) {
// force login only for guest user, not real users with guest role
if (empty($CFG->loginhttps)) {
$wwwroot = $CFG->wwwroot;
} else {
// This actually is not so secure ;-), 'cause we're
// in unencrypted connection...
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
echo '<div class="mdl-align"><p>' . get_string('paymentrequired') . '</p>';
echo '<p><b>' . get_string('cost') . '$' . $cost . '</b></p>';
echo '<p><a href="' . $wwwroot . '/login/">' . get_string('loginsite') . '</a></p>';
echo '</div>';
} else {
//Sanitise some fields before building the PayPal form
$coursefullname = format_string($course->fullname, true, array('context' => $context));
$courseshortname = $course->shortname;
$userfullname = fullname($USER);
$userfirstname = $USER->firstname;
$userlastname = $USER->lastname;
$useraddress = $USER->address;
$usercity = $USER->city;
//.........这里部分代码省略.........
示例14: newenrolmentemail
/**
* Send an email to the user when they are enroled.
*
* @param int $user The user id being enroled.
* @param int $course The course id they're being enroled into.
* @return bool Success/Failure.
*/
public function newenrolmentemail($userid, $courseid)
{
global $DB;
if (empty($userid) || empty($courseid)) {
return false;
}
$user = $DB->get_record('user', array('id' => $userid));
$course = $DB->get_record('course', array('id' => $courseid));
if (empty($user) || empty($course)) {
return false;
}
$enabled = get_config('dhimport_version1', 'newenrolmentemailenabled');
if (empty($enabled)) {
// Emails disabled.
return false;
}
$template = get_config('dhimport_version1', 'newenrolmentemailtemplate');
if (empty($template)) {
// No text set.
return false;
}
if (empty($user->email)) {
// User has no email.
return false;
}
$subject = get_config('dhimport_version1', 'newenrolmentemailsubject');
if (empty($subject) || !is_string($subject)) {
$subject = '';
}
$from = get_config('dhimport_version1', 'newenrolmentemailfrom');
if ($from === 'teacher') {
$context = context_course::instance($courseid);
if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
$users = sort_by_roleassignment_authority($users, $context);
$from = current($users);
} else {
$from = get_admin();
}
} else {
$from = get_admin();
}
$body = $this->newenrolmentemail_generate($template, $user, $course);
return $this->sendemail($user, $from, $subject, $body);
}