/** * * @global <type> $CURMAN */ public function add() { global $CURMAN; if (empty($this->position)) { //SELECT MIN(userid) FROM eli_crlm_wait_list WHERE 1 $sql = 'SELECT ' . sql_max('position') . ' as max FROM ' . $CURMAN->db->prefix_table(WATLSTTABLE) . ' as wl WHERE wl.classid = ' . $this->classid; $max_record = get_record_sql($sql); $max = $max_record->max; $this->position = $max + 1; } $subject = get_string('waitlist', 'block_curr_admin'); $cmclass = new cmclass($this->classid); $message = get_string('added_to_waitlist_message', 'block_curr_admin', $cmclass->idnumber); $user = cm_get_moodleuser($this->userid); $from = get_admin(); // Send a notification and e-mail only if the Moodle user exists if ($user != null) { notification::notify($message, $user, $from); email_to_user($user, $from, $subject, $message); } parent::add(); }
/** * When called resets all custom roles as per definition set down in /local/roles.php * * Note that this uses the non-core role.custom field to isolate roles to remove. * * Utilise the $path parameter to allow for localisation (i.e. different roles defintion than core). * * Sort order is reset based on the order listed in the defintion. * * WARNING: as long as you retain the same shortname existing user role assigments will * be retained. if you change the shortname they will be lost. * * KNOWN ISSUE: we rely on shortname being unique, but this is not enforced by the db. * this is more a problem with moodle. * * @param text $path * */ function tao_reset_custom_roles($path = 'local') { global $CFG; if (!get_site()) { // not finished installing, skip return true; } // get latest role definition from roles file $rolespath = $CFG->dirroot . '/' . $path . '/roles.php'; if (!file_exists($rolespath)) { debugging("Local caps reassignment called with invalid path {$path}"); return false; } require_once $rolespath; if (!isset($customroles)) { return true; // nothing to do. } $undeletableroles = array(); $undeletableroles[$CFG->notloggedinroleid] = 1; $undeletableroles[$CFG->guestroleid] = 1; $undeletableroles[$CFG->defaultuserroleid] = 1; $undeletableroles[$CFG->defaultcourseroleid] = 1; // If there is only one admin role, add that to $undeletableroles too. $adminroles = get_admin_roles(); if (count($adminroles) == 1) { $undeletableroles[reset($adminroles)->id] = 1; } // get recordset of existing custom roles $sql = "SELECT id, name, shortname, description, sortorder, custom\n FROM {$CFG->prefix}role\n WHERE custom IS NOT NULL"; $roles = get_records_sql($sql); // remove custom roles that are not in the latest definition foreach ($roles as $role) { // check whether this role is in the latest definition if (array_key_exists($role->shortname, $customroles)) { continue; } // extra safety: check undeletable roles if (isset($undeletableroles[$role->id])) { continue; } delete_role($role->id); } // hack to avoid sortorder unique constraint execute_sql("UPDATE {$CFG->prefix}role SET sortorder = (sortorder+1000) WHERE custom IS NOT NULL"); // set sortorder to current highest value $sortorder = get_field_sql("SELECT " . sql_max('sortorder') . " FROM {$CFG->prefix}role WHERE custom IS NULL"); // now loop through the new settings foreach ($customroles as $shortname => $role) { $sortorder++; // get the roleid $roleid = get_field('role', 'id', 'shortname', $shortname); // if exists then make updates if (!empty($roleid)) { // only update fields that have been set if (isset($role['name'])) { set_field('role', 'name', $role['name'], 'shortname', $shortname); } if (isset($role['description'])) { set_field('role', 'description', $role['description'], 'shortname', $shortname); } // reset sortorder set_field('role', 'sortorder', $sortorder, 'shortname', $shortname); // else create record } else { $newrole = new stdclass(); $newrole->name = $role['name']; $newrole->shortname = $shortname; $newrole->description = $role['description']; $newrole->sortorder = $sortorder; $newrole->custom = 1; $roleid = insert_record('role', $newrole); } // remove any previously set legacy roles $legacyroles = get_legacy_roles(); foreach ($legacyroles as $ltype => $lcap) { unassign_capability($lcap, $roleid); } // reset legacy role if (isset($role['legacy'])) { $legacycap = $legacyroles[$role['legacy']]; $context = get_context_instance(CONTEXT_SYSTEM); assign_capability($legacycap, CAP_ALLOW, $roleid, $context->id); } // update the context settings set_role_contextlevels($roleid, $role['context']); // e.g. array(CONTEXT_SYSTEM, CONTEXT_COURSECAT) // set allow assigns if (is_array($role['canassign'])) { // delete existing delete_records('role_allow_assign', 'allowassign', $roleid); foreach ($role['canassign'] as $canassign) { $canassignid = get_field('role', 'id', 'shortname', $canassign); allow_assign($canassignid, $roleid); } } } // reset custom capabilities to keep up with changes return tao_reset_capabilities(); }
function action_savewaitlist() { global $USER, $CURMAN; $classid = cm_get_param('id', 0, PARAM_INT); $form = $this->create_waitlistform($classid); if ($form->is_cancelled()) { $this->action_available(); } else { if ($data = $form->get_data()) { $class = new cmclass($classid); $userid = cm_get_crlmuserid($USER->id); $position = $CURMAN->db->get_field(WATLSTTABLE, sql_max('position'), 'classid', $classid) + 1; $wait_record = new object(); $wait_record->userid = $userid; $wait_record->classid = $classid; $wait_record->enrolmenttime = $class->startdate; $wait_record->timecraeted = time(); $wait_record->position = $position; $wait_list = new waitlist($wait_record); $wait_list->add(); $this->action_waitlist(); } } }