本文整理汇总了PHP中course_enrolment_manager::get_context方法的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager::get_context方法的具体用法?PHP course_enrolment_manager::get_context怎么用?PHP course_enrolment_manager::get_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_enrolment_manager
的用法示例。
在下文中一共展示了course_enrolment_manager::get_context方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_user_enrolment_actions
/**
* Gets an array of the user enrolment actions
*
* @param course_enrolment_manager $manager
* @param stdClass $ue A user enrolment object
* @return array An array of user_enrolment_actions
*/
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
$actions = array();
$context = $manager->get_context();
$instance = $ue->enrolmentinstance;
$params = $manager->get_moodlepage()->url->params();
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/database:unenrol', $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
}
return $actions;
}
示例2: stdClass
require_login($course);
require_capability('moodle/course:enrolreview', $context);
require_sesskey();
echo $OUTPUT->header();
// send headers
$manager = new course_enrolment_manager($PAGE, $course);
$outcome = new stdClass();
$outcome->success = true;
$outcome->response = new stdClass();
$outcome->error = '';
$searchanywhere = get_user_preferences('userselector_searchanywhere', false);
switch ($action) {
case 'unenrol':
$ue = $DB->get_record('user_enrolments', array('id' => required_param('ue', PARAM_INT)), '*', MUST_EXIST);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$instance || !$plugin || !enrol_is_enabled($instance->enrol) || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/{$instance->enrol}:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
throw new enrol_ajax_exception('unenrolnotpermitted');
}
break;
case 'unassign':
$role = required_param('role', PARAM_INT);
$user = required_param('user', PARAM_INT);
if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->unassign_role_from_user($user, $role)) {
throw new enrol_ajax_exception('unassignnotpermitted');
}
break;
case 'assign':
$user = $DB->get_record('user', array('id' => required_param('user', PARAM_INT)), '*', MUST_EXIST);
$roleid = required_param('roleid', PARAM_INT);
if (!array_key_exists($roleid, $manager->get_assignable_roles())) {
throw new enrol_ajax_exception('invalidrole');
示例3: initialise_javascript
public function initialise_javascript()
{
if (has_capability('moodle/role:assign', $this->manager->get_context())) {
$this->moodlepage->requires->strings_for_js(array('assignroles', 'confirmunassign', 'confirmunassigntitle', 'confirmunassignyes', 'confirmunassignno'), 'role');
$modules = array('moodle-enrol-rolemanager', 'moodle-enrol-rolemanager-skin');
$function = 'M.enrol.rolemanager.init';
$arguments = array('containerId' => $this->id, 'userIds' => array_keys($this->users), 'courseId' => $this->manager->get_course()->id, 'otherusers' => isset($this->otherusers));
$this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
}
示例4: get_bulk_operations
/**
* The manual plugin has several bulk operations that can be performed.
* @param course_enrolment_manager $manager
* @return array
*/
public function get_bulk_operations(course_enrolment_manager $manager)
{
global $CFG;
require_once $CFG->dirroot . '/enrol/manual/locallib.php';
$context = $manager->get_context();
$bulkoperations = array();
if (has_capability("enrol/manual:manage", $context)) {
$bulkoperations['editselectedusers'] = new enrol_manual_editselectedusers_operation($manager, $this);
}
if (has_capability("enrol/manual:unenrol", $context)) {
$bulkoperations['deleteselectedusers'] = new enrol_manual_deleteselectedusers_operation($manager, $this);
}
return $bulkoperations;
}
示例5: get_manual_enrol_button
/**
* Returns a button to enrol a cohort or its users through the manual enrolment plugin.
*
* This function also adds a quickenrolment JS ui to the page so that users can be enrolled
* via AJAX.
*
* @param course_enrolment_manager $manager
* @return enrol_user_button
*/
public function get_manual_enrol_button(course_enrolment_manager $manager)
{
$course = $manager->get_course();
if (!$this->can_add_new_instances($course->id)) {
return false;
}
$cohorturl = new moodle_url('/enrol/cohort/edit.php', array('courseid' => $course->id));
$button = new enrol_user_button($cohorturl, get_string('enrolcohort', 'enrol'), 'get');
$button->class .= ' enrol_cohort_plugin';
$button->strings_for_js(array('enrol', 'synced', 'enrolcohort', 'enrolcohortusers'), 'enrol');
$button->strings_for_js(array('ajaxmore', 'cohortsearch'), 'enrol_cohort');
$button->strings_for_js('assignroles', 'role');
$button->strings_for_js('cohort', 'cohort');
$button->strings_for_js('users', 'moodle');
// No point showing this at all if the user cant manually enrol users.
$hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual');
$modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin');
$function = 'M.enrol_cohort.quickenrolment.init';
$arguments = array('courseid' => $course->id, 'ajaxurl' => '/enrol/cohort/ajax.php', 'url' => $manager->get_moodlepage()->url->out(false), 'manualEnrolment' => $hasmanualinstance);
$button->require_yui_module($modules, $function, array($arguments));
return $button;
}
示例6: enrol_cohort_search_cohorts
/**
* Gets cohorts the user is able to view.
*
* @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
*
* @global moodle_database $DB
* @param course_enrolment_manager $manager
* @param int $offset limit output from
* @param int $limit items to output per load
* @param string $search search string
* @return array Array(more => bool, offset => int, cohorts => array)
*/
function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '')
{
global $CFG;
debugging('enrol_cohort_search_cohorts() is deprecated. This functionality is moved to enrol_manual.', DEBUG_DEVELOPER);
require_once $CFG->dirroot . '/cohort/lib.php';
$context = $manager->get_context();
$cohorts = array();
$instances = $manager->get_enrolment_instances();
$enrolled = array();
foreach ($instances as $instance) {
if ($instance->enrol === 'cohort') {
$enrolled[] = $instance->customint1;
}
}
$rawcohorts = cohort_get_available_cohorts($context, COHORT_COUNT_MEMBERS, $offset, $limit, $search);
// Produce the output respecting parameters.
foreach ($rawcohorts as $c) {
$cohorts[$c->id] = array('cohortid' => $c->id, 'name' => shorten_text(format_string($c->name, true, array('context' => context::instance_by_id($c->contextid))), 35), 'users' => $c->memberscnt, 'enrolled' => in_array($c->id, $enrolled));
}
return array('more' => !(bool) $limit, 'offset' => $offset, 'cohorts' => $cohorts);
}
示例7: array
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
// Check if there is an action to take
if ($action) {
// Check if the page is confirmed (and sesskey is correct)
$confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
$actiontaken = false;
$pagetitle = '';
$pageheading = '';
$mform = null;
$pagecontent = null;
switch ($action) {
/**
* Removes a role from the user with this course
*/
case 'unassign':
if (has_capability('moodle/role:assign', $manager->get_context())) {
$role = required_param('roleid', PARAM_INT);
$user = required_param('user', PARAM_INT);
if ($confirm && $manager->unassign_role_from_user($user, $role)) {
redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id' => $user), '*', MUST_EXIST);
$allroles = $manager->get_all_roles();
$role = $allroles[$role];
$yesurl = new moodle_url($PAGE->url, array('action' => 'unassign', 'roleid' => $role->id, 'user' => $user->id, 'confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unassignconfirm', 'role', array('user' => fullname($user, true), 'role' => $role->localname));
$pagetitle = get_string('unassignarole', 'role', $role->localname);
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
示例8: process
/**
* Processes the bulk operation request for the given userids with the provided properties.
*
* @global moodle_database $DB
* @param course_enrolment_manager $manager
* @param array $userids
* @param stdClass $properties The data returned by the form.
*/
public function process(course_enrolment_manager $manager, array $users, stdClass $properties)
{
global $DB;
if (!has_capability("enrol/manual:unenrol", $manager->get_context())) {
return false;
}
foreach ($users as $user) {
foreach ($user->enrolments as $enrolment) {
$plugin = $enrolment->enrolmentplugin;
$instance = $enrolment->enrolmentinstance;
if ($plugin->allow_unenrol_user($instance, $enrolment)) {
$plugin->unenrol_user($instance, $user->id);
}
}
}
return true;
}
示例9: array
$PAGE->set_url('/enrol/otherusers.php', $manager->get_url_params() + $table->get_url_params());
$userdetails = array('picture' => false, 'firstname' => get_string('firstname'), 'lastname' => get_string('lastname'));
$extrafields = get_extra_user_fields($context);
foreach ($extrafields as $field) {
$userdetails[$field] = get_user_field_name($field);
}
$fields = array('userdetails' => $userdetails, 'lastseen' => get_string('lastaccess'), 'role' => get_string('roles', 'role'));
// Remove hidden fields if the user has no access
if (!has_capability('moodle/course:viewhiddenuserfields', $context)) {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
if (isset($hiddenfields['lastaccess'])) {
unset($fields['lastseen']);
}
}
$table->set_fields($fields, $OUTPUT);
//$users = $manager->get_other_users($table->sort, $table->sortdirection, $table->page, $table->perpage);
$renderer = $PAGE->get_renderer('core_enrol');
$canassign = has_capability('moodle/role:assign', $manager->get_context());
$users = $manager->get_other_users_for_display($renderer, $PAGE->url, $table->sort, $table->sortdirection, $table->page, $table->perpage);
$assignableroles = $manager->get_assignable_roles(true);
foreach ($users as $userid => &$user) {
$user['picture'] = $OUTPUT->render($user['picture']);
$user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $PAGE->url);
}
$table->set_total_users($manager->get_total_other_users());
$table->set_users($users);
$PAGE->set_title($course->fullname . ': ' . get_string('totalotherusers', 'enrol', $manager->get_total_other_users()));
$PAGE->set_heading($PAGE->title);
echo $OUTPUT->header();
echo $renderer->render($table);
echo $OUTPUT->footer();
示例10: enrol_cohort_search_cohorts
/**
* Gets cohorts the user is able to view.
*
* @global moodle_database $DB
* @param course_enrolment_manager $manager
* @param int $offset limit output from
* @param int $limit items to output per load
* @param string $search search string
* @return array Array(more => bool, offset => int, cohorts => array)
*/
function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '')
{
global $DB;
$context = $manager->get_context();
$cohorts = array();
$instances = $manager->get_enrolment_instances();
$enrolled = array();
foreach ($instances as $instance) {
if ($instance->enrol == 'cohort') {
$enrolled[] = $instance->customint1;
}
}
list($sqlparents, $params) = $DB->get_in_or_equal($context->get_parent_context_ids());
// Add some additional sensible conditions.
$tests = array('contextid ' . $sqlparents);
// Modify the query to perform the search if required.
if (!empty($search)) {
$conditions = array('name', 'idnumber', 'description');
$searchparam = '%' . $DB->sql_like_escape($search) . '%';
foreach ($conditions as $key => $condition) {
$conditions[$key] = $DB->sql_like($condition, "?", false);
$params[] = $searchparam;
}
$tests[] = '(' . implode(' OR ', $conditions) . ')';
}
$wherecondition = implode(' AND ', $tests);
$sql = "SELECT id, name, idnumber, contextid, description\n FROM {cohort}\n WHERE {$wherecondition}\n ORDER BY name ASC, idnumber ASC";
$rs = $DB->get_recordset_sql($sql, $params, $offset);
// Produce the output respecting parameters.
foreach ($rs as $c) {
// Track offset.
$offset++;
// Check capabilities.
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}
if ($limit === 0) {
// We have reached the required number of items and know that there are more, exit now.
$offset--;
break;
}
$cohorts[$c->id] = array('cohortid' => $c->id, 'name' => shorten_text(format_string($c->name, true, array('context' => context::instance_by_id($c->contextid))), 35), 'users' => $DB->count_records('cohort_members', array('cohortid' => $c->id)), 'enrolled' => in_array($c->id, $enrolled));
// Count items.
$limit--;
}
$rs->close();
return array('more' => !(bool) $limit, 'offset' => $offset, 'cohorts' => $cohorts);
}
示例11: switch
if ($action) {
// Check if the page is confirmed (and sesskey is correct)
$confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
$actiontaken = false;
$pagetitle = '';
$pageheading = '';
$mform = null;
$pagecontent = null;
switch ($action) {
/**
* Unenrols a user from this course (including removing all of their grades)
*/
case 'unenrol':
$ue = $DB->get_record('user_enrolments', array('id' => required_param('ue', PARAM_INT)), '*', MUST_EXIST);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if ($instance && $plugin && $plugin->allow_unenrol($instance) && has_capability("enrol/{$instance->enrol}:unenrol", $manager->get_context())) {
if ($confirm && $manager->unenrol_user($ue)) {
redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id' => $ue->userid), '*', MUST_EXIST);
$yesurl = new moodle_url($PAGE->url, array('action' => 'unenrol', 'ue' => $ue->id, 'confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenrolconfirm', 'enrol', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$pagetitle = get_string('unenrol', 'enrol');
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
break;
/**
* Removes a role from the user with this course
*/
示例12: enrol_cohort_get_cohorts
/**
* Gets all the cohorts the user is able to view.
*
* @global moodle_database $DB
* @return array
*/
function enrol_cohort_get_cohorts(course_enrolment_manager $manager)
{
global $DB;
$context = $manager->get_context();
$cohorts = array();
$instances = $manager->get_enrolment_instances();
$enrolled = array();
foreach ($instances as $instance) {
if ($instance->enrol == 'cohort') {
$enrolled[] = $instance->customint1;
}
}
list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($context));
$sql = "SELECT id, name, contextid\n FROM {cohort}\n WHERE contextid {$sqlparents}\n ORDER BY name ASC";
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $c) {
$context = get_context_instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}
$cohorts[$c->id] = array('cohortid' => $c->id, 'name' => format_string($c->name), 'users' => $DB->count_records('cohort_members', array('cohortid' => $c->id)), 'enrolled' => in_array($c->id, $enrolled));
}
$rs->close();
return $cohorts;
}