当前位置: 首页>>代码示例>>PHP>>正文


PHP get_assignable_roles函数代码示例

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


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

示例1: require_login

    $coursecontext = $context;
}
require_login($course);
$baseurl = 'override.php?contextid=' . $context->id;
if (!empty($userid)) {
    $baseurl .= '&userid=' . $userid;
}
if ($courseid != SITEID) {
    $baseurl .= '&courseid=' . $courseid;
}
if ($cancel) {
    redirect($baseurl);
}
/// needed for tabs.php
$overridableroles = get_overridable_roles($context);
$assignableroles = get_assignable_roles($context);
/// Get some language strings
$strroletooverride = get_string('roletooverride', 'role');
$straction = get_string('overrideroles', 'role');
$strcurrentrole = get_string('currentrole', 'role');
$strparticipants = get_string('participants');
/// Make sure this user can override that role
if ($roleid) {
    if (!user_can_override($context, $roleid)) {
        error('you can not override this role in this context');
    }
}
if ($userid) {
    $user = get_record('user', 'id', $userid);
    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:override.php

示例2: get_best_assignable_role

 /**
  * Given one role, as loaded from XML, perform the best possible matching against the assignable
  * roles, using different fallback alternatives (shortname, archetype, editingteacher => teacher, defaultcourseroleid)
  * returning the id of the best matching role or 0 if no match is found
  */
 protected static function get_best_assignable_role($role, $courseid, $userid, $samesite)
 {
     global $CFG, $DB;
     // Gather various information about roles
     $coursectx = get_context_instance(CONTEXT_COURSE, $courseid);
     $allroles = $DB->get_records('role');
     $assignablerolesshortname = get_assignable_roles($coursectx, ROLENAME_SHORT, false, $userid);
     // Note: under 1.9 we had one function restore_samerole() that performed one complete
     // matching of roles (all caps) and if match was found the mapping was availabe bypassing
     // any assignable_roles() security. IMO that was wrong and we must not allow such
     // mappings anymore. So we have left that matching strategy out in 2.0
     // Empty assignable roles, mean no match possible
     if (empty($assignablerolesshortname)) {
         return 0;
     }
     // Match by shortname
     if ($match = array_search($role->shortname, $assignablerolesshortname)) {
         return $match;
     }
     // Match by archetype
     list($in_sql, $in_params) = $DB->get_in_or_equal(array_keys($assignablerolesshortname));
     $params = array_merge(array($role->archetype), $in_params);
     if ($rec = $DB->get_record_select('role', "archetype = ? AND id {$in_sql}", $params, 'id', IGNORE_MULTIPLE)) {
         return $rec->id;
     }
     // Match editingteacher to teacher (happens a lot, from 1.9)
     if ($role->shortname == 'editingteacher' && in_array('teacher', $assignablerolesshortname)) {
         return array_search('teacher', $assignablerolesshortname);
     }
     // No match, return 0
     return 0;
 }
开发者ID:numbas,项目名称:moodle,代码行数:37,代码来源:restore_dbops.class.php

示例3: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     list($instance, $plugin, $course) = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $groups = array(0 => get_string('none'));
     foreach (groups_get_all_groups($course->id) as $group) {
         $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext));
     }
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
     $mform->setType('name', PARAM_TEXT);
     $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
     $mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options);
     if ($instance->id) {
         if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) {
             $cohorts = array($instance->customint1 => format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))));
         } else {
             $cohorts = array($instance->customint1 => get_string('error'));
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->setConstant('customint1', $instance->customint1);
         $mform->hardFreeze('customint1', $instance->customint1);
     } else {
         $cohorts = array('' => get_string('choosedots'));
         $allcohorts = cohort_get_available_cohorts($coursecontext, 0, 0, 0);
         foreach ($allcohorts as $c) {
             $cohorts[$c->id] = format_string($c->name);
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     }
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // Descending default sortorder.
     $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles);
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     if ($instance->id and !isset($roles[$instance->roleid])) {
         if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
             $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
             $roles[$instance->roleid] = role_get_name($role, $coursecontext);
         } else {
             $roles[$instance->roleid] = get_string('error');
         }
     }
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups);
     $mform->addElement('hidden', 'courseid', null);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     if ($instance->id) {
         $this->add_action_buttons(true);
     } else {
         $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     }
     $this->set_data($instance);
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:60,代码来源:edit_form.php

示例4: definition

	function definition() {
		global $CFG;
		$mform = & $this->_form;
		$course = $this->_customdata['course'];
		$context = $this->_customdata['context'];

		// the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
		//$this->set_upload_manager(new upload_manager('attachment'));

		$mform->addElement('header', 'general', ''); //fill in the data depending on page params
		//later using set_data
		$mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile'));

		$mform->addRule('attachment', null, 'required');
		
		$choices = csv_import_reader::get_delimiter_list();
        $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
        if (array_key_exists('cfg', $choices)) {
            $mform->setDefault('delimiter_name', 'cfg');
        } else if (get_string('listsep', 'langconfig') == ';') {
            $mform->setDefault('delimiter_name', 'semicolon');
        } else {
            $mform->setDefault('delimiter_name', 'comma');
        }

        $choices = textlib::get_encodings();
        $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
        $mform->setDefault('encoding', 'UTF-8');
		
		
        $roles = get_assignable_roles($context);
		$mform->addElement('select', 'roleassign', get_string('roleassign', 'local_mass_enroll'), $roles);
		$mform->setDefault('roleassign', 5); //student

		$ids = array (
			'idnumber' => get_string('idnumber', 'local_mass_enroll'),
			'username' => get_string('username', 'local_mass_enroll'),
			'email' => get_string('email')
		);
		$mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids);
		$mform->setDefault('firstcolumn', 'idnumber');

		$mform->addElement('selectyesno', 'creategroups', get_string('creategroups', 'local_mass_enroll'));
		$mform->setDefault('creategroups', 1);

			$mform->addElement('selectyesno', 'creategroupings', get_string('creategroupings', 'local_mass_enroll'));
			$mform->setDefault('creategroupings', 1);


		$mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll'));
		$mform->setDefault('mailreport', 1);

		//-------------------------------------------------------------------------------
		// buttons

		$this->add_action_buttons(true, get_string('enroll', 'local_mass_enroll'));

		$mform->addElement('hidden', 'id', $course->id);
		$mform->setType('id', PARAM_INT);
	}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:60,代码来源:mass_enroll_form.php

示例5: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata['course'];
     $enrol = $this->_customdata['enrol'];
     $service = $this->_customdata['service'];
     $coursecontext = context_course::instance($course->id);
     $subscribers = $service->get_remote_subscribers();
     $hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
     foreach ($subscribers as $hostid => $subscriber) {
         $hosts[$hostid] = $subscriber->appname . ': ' . $subscriber->hostname . ' (' . $subscriber->hosturl . ')';
     }
     $roles = get_assignable_roles($coursecontext);
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_mnet'));
     $mform->addElement('select', 'hostid', get_string('remotesubscriber', 'enrol_mnet'), $hosts);
     $mform->addHelpButton('hostid', 'remotesubscriber', 'enrol_mnet');
     $mform->addRule('hostid', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'roleid', get_string('roleforremoteusers', 'enrol_mnet'), $roles);
     $mform->addHelpButton('roleid', 'roleforremoteusers', 'enrol_mnet');
     $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     $mform->addElement('text', 'name', get_string('instancename', 'enrol_mnet'));
     $mform->addHelpButton('name', 'instancename', 'enrol_mnet');
     $mform->setType('name', PARAM_TEXT);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons();
     $this->set_data(array('id' => $course->id));
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:30,代码来源:addinstance_form.php

示例6: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $cohorts = array('' => get_string('choosedots'));
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $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] = format_string($c->name);
     }
     $rs->close();
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // descending default sortorder
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
     $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'roleid', get_string('role'), $roles);
     $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
开发者ID:nigeli,项目名称:moodle,代码行数:34,代码来源:addinstance_form.php

示例7: enrol_users

 /**
  * Enrolment of users.
  *
  * Function throw an exception at the first error encountered.
  * @param array $enrolments  An array of user enrolment
  * @since Moodle 2.2
  */
 public static function enrol_users($enrolments)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/enrollib.php';
     $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments' => $enrolments));
     $transaction = $DB->start_delegated_transaction();
     // Rollback all enrolment if an error occurs
     // (except if the DB doesn't support it).
     // Retrieve the manual enrolment plugin.
     $enrol = enrol_get_plugin('manual');
     if (empty($enrol)) {
         throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual');
     }
     foreach ($params['enrolments'] as $enrolment) {
         // Ensure the current user is allowed to run this function in the enrolment context.
         $context = context_course::instance($enrolment['courseid'], IGNORE_MISSING);
         self::validate_context($context);
         // Check that the user has the permission to manual enrol.
         require_capability('enrol/manual:enrol', $context);
         // Throw an exception if user is not able to assign the role.
         $roles = get_assignable_roles($context);
         if (!array_key_exists($enrolment['roleid'], $roles)) {
             $errorparams = new stdClass();
             $errorparams->roleid = $enrolment['roleid'];
             $errorparams->courseid = $enrolment['courseid'];
             $errorparams->userid = $enrolment['userid'];
             throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams);
         }
         // Check manual enrolment plugin instance is enabled/exist.
         $instance = null;
         $enrolinstances = enrol_get_instances($enrolment['courseid'], true);
         foreach ($enrolinstances as $courseenrolinstance) {
             if ($courseenrolinstance->enrol == "manual") {
                 $instance = $courseenrolinstance;
                 break;
             }
         }
         if (empty($instance)) {
             $errorparams = new stdClass();
             $errorparams->courseid = $enrolment['courseid'];
             throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams);
         }
         // Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).
         if (!$enrol->allow_enrol($instance)) {
             $errorparams = new stdClass();
             $errorparams->roleid = $enrolment['roleid'];
             $errorparams->courseid = $enrolment['courseid'];
             $errorparams->userid = $enrolment['userid'];
             throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams);
         }
         // Finally proceed the enrolment.
         $enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0;
         $enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0;
         $enrolment['status'] = isset($enrolment['suspend']) && !empty($enrolment['suspend']) ? ENROL_USER_SUSPENDED : ENROL_USER_ACTIVE;
         $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid'], $enrolment['timestart'], $enrolment['timeend'], $enrolment['status']);
     }
     $transaction->allow_commit();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:65,代码来源:externallib.php

示例8: definition

    public function definition()
    {
        global $CFG, $DB;
        $mform = $this->_form;
        $course = $this->_customdata['course'];
        $instance = $this->_customdata['instance'];
        $this->course = $course;
        $existing = array();
        if ($instance) {
            $existing = $DB->get_records('enrol_metaplus', array('enrolid' => $instance->id), '', 'courseid, id');
        }
        $courses = array();
        $select = context_helper::get_preload_record_columns_sql('ctx');
        $sql = <<<SQL
            SELECT c.id, c.fullname, c.shortname, c.visible, {$select}
            FROM {course} c
            LEFT JOIN {context} ctx
                ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)
SQL;
        $rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE));
        foreach ($rs as $c) {
            if ($c->id == SITEID || $c->id == $course->id) {
                continue;
            }
            context_helper::preload_from_record($c);
            $coursecontext = context_course::instance($c->id);
            if (!$c->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                continue;
            }
            if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
                continue;
            }
            $courses[$c->id] = $coursecontext->get_context_name(false);
        }
        $rs->close();
        $mform->addElement('header', 'general', get_string('pluginname', 'enrol_meta'));
        $mform->addElement('select', 'link', get_string('linkedcourse', 'enrol_metaplus'), $courses, array('multiple' => 'multiple', 'class' => 'chosen'));
        $mform->addRule('link', get_string('required'), 'required', null, 'server');
        // Add role sync list.
        $coursecontext = \context_course::instance($course->id);
        $roles = get_assignable_roles($coursecontext);
        $mform->addElement('select', 'roleexclusions', get_string('roleexclusions', 'enrol_metaplus'), $roles, array('multiple' => 'multiple'));
        $mform->addElement('hidden', 'id', null);
        $mform->setType('id', PARAM_INT);
        $mform->addElement('hidden', 'enrolid');
        $mform->setType('enrolid', PARAM_INT);
        $data = array('id' => $course->id);
        if ($instance) {
            $data['link'] = implode(',', array_keys($existing));
            $data['enrolid'] = $instance->id;
            $data['roleexclusions'] = $instance->customtext1;
            $this->add_action_buttons();
        } else {
            $this->add_add_buttons();
        }
        $this->set_data($data);
    }
开发者ID:unikent,项目名称:moodle-enrol_metaplus,代码行数:57,代码来源:addinstance_form.php

示例9: extend_assignable_roles

 /**
  * Gets a list of roles that this user can assign for the course as the default for auto-enrolment.
  *
  * @param context $context the context.
  * @param integer $defaultrole the id of the role that is set as the default for auto-enrolment
  * @return array index is the role id, value is the role name
  */
 function extend_assignable_roles($context, $defaultrole)
 {
     global $DB;
     $roles = get_assignable_roles($context, ROLENAME_BOTH);
     if (!isset($roles[$defaultrole])) {
         if ($role = $DB->get_record('role', array('id' => $defaultrole))) {
             $roles[$defaultrole] = role_get_name($role, $context, ROLENAME_BOTH);
         }
     }
     return $roles;
 }
开发者ID:ninelanterns,项目名称:scaffold-enrol_auto,代码行数:18,代码来源:edit_form.php

示例10: definition

 public function definition()
 {
     $mform =& $this->_form;
     $mform->addElement('checkbox', 'enabled', null, get_string('enabled', 'local_anonymousposting'));
     $mform->setDefault('enabled', 1);
     $context = context_course::instance(SITEID, MUST_EXIST);
     $assignableroles = get_assignable_roles($context);
     $mform->addElement('select', 'defaultcourserole', get_string('defaultcourserole', 'local_anonymousposting'), $assignableroles);
     $mform->setDefault('defaultcourserole', '5');
     $mform->addElement('select', 'defaultactivityrole', get_string('defaultactivityrole', 'local_anonymousposting'), $assignableroles);
     $mform->setDefault('defaultactivityrole', '5');
     $this->add_action_buttons();
 }
开发者ID:hitteshahuja,项目名称:moodle-local_anonymousposting,代码行数:13,代码来源:index_form.php

示例11: specific_definition

 /**
  * Core function for creation of form defined in block_panopto_edit_form class
  */
 protected function specific_definition($mform)
 {
     global $COURSE, $CFG;
     // Construct the Panopto data proxy object.
     $panoptodata = new panopto_data($COURSE->id);
     if (!empty($panoptodata->servername) && !empty($panoptodata->instancename) && !empty($panoptodata->applicationkey)) {
         $mform->addElement('header', 'configheader', get_string('block_edit_header', 'block_panopto'));
         $params = new stdClass();
         $params->course_id = $COURSE->id;
         $params->return_url = $_SERVER['REQUEST_URI'];
         $querystring = http_build_query($params, '', '&');
         $provisionurl = "{$CFG->wwwroot}/blocks/panopto/provision_course.php?" . $querystring;
         $addtopanopto = get_string('add_to_panopto', 'block_panopto');
         $or = get_string('or', 'block_panopto');
         $mform->addElement('html', "<a href='{$provisionurl}'>{$addtopanopto}</a><br><br>-- {$or} --<br><br>");
         $courselist = $panoptodata->get_course_options();
         $mform->addElement('selectgroups', 'config_course', get_string('existing_course', 'block_panopto'), $courselist['courses']);
         $mform->setDefault('config_course', $courselist['selected']);
         // Set course context to get roles.
         $context = context_course::instance($COURSE->id);
         // Get current role mappings.
         $currentmappings = $panoptodata->get_course_role_mappings($COURSE->id);
         // Get roles that current user may assign in this course.
         $currentcourseroles = get_assignable_roles($context, $rolenamedisplay = ROLENAME_ALIAS, $withusercounts = false, $user = null);
         while ($role = current($currentcourseroles)) {
             $rolearray[key($currentcourseroles)] = $currentcourseroles[key($currentcourseroles)];
             next($currentcourseroles);
         }
         $mform->addElement('header', 'rolemapheader', get_string('role_map_header', 'block_panopto'));
         $mform->addElement('html', get_string('role_map_info_text', 'block_panopto'));
         $createselect = $mform->addElement('select', 'config_creator', get_string('creator', 'block_panopto'), $rolearray, null);
         $createselect->setMultiple(true);
         // Set default selected to previous setting.
         if (!empty($currentmappings['creator'])) {
             $createselect->setSelected($currentmappings['creator']);
         }
         $pubselect = $mform->addElement('select', 'config_publisher', get_string('publisher', 'block_panopto'), $rolearray, null);
         $pubselect->setMultiple(true);
         // Set default selected to previous setting.
         if (!empty($currentmappings['publisher'])) {
             $pubselect->setSelected($currentmappings['publisher']);
         }
     } else {
         $mform->addElement('static', 'error', '', get_string('block_edit_error', 'block_panopto'));
     }
 }
开发者ID:hitteshahuja,项目名称:Moodle-2.0-plugin-for-Panopto,代码行数:49,代码来源:edit_form.php

示例12: definition

 /**
  * Form definition
  */
 public function definition()
 {
     global $DB;
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $context = $this->_customdata['context'];
     $config = get_config('local_mass_enroll');
     $mform->addElement('header', 'general', '');
     // Fill in the data depending on page params.
     // Later using set_data.
     $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile'));
     $mform->addRule('attachment', null, 'required');
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $choices = \core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $roles = get_assignable_roles($context);
     $mform->addElement('select', 'roleassign', get_string('roleassign', 'local_mass_enroll'), $roles);
     $studentrole = $DB->get_record('role', array('archetype' => 'student'));
     $mform->setDefault('roleassign', $studentrole->id);
     $ids = array('idnumber' => get_string('idnumber', 'local_mass_enroll'), 'username' => get_string('username', 'local_mass_enroll'), 'email' => get_string('email'));
     $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids);
     $mform->setDefault('firstcolumn', 'idnumber');
     $mform->addElement('selectyesno', 'creategroups', get_string('creategroups', 'local_mass_enroll'));
     $mform->setDefault('creategroups', 1);
     $mform->addElement('selectyesno', 'creategroupings', get_string('creategroupings', 'local_mass_enroll'));
     $mform->setDefault('creategroupings', 1);
     $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll'));
     $mform->setDefault('mailreport', (int) $config->mailreportdefault);
     // Buttons.
     $this->add_action_buttons(true, get_string('enroll', 'local_mass_enroll'));
     $mform->addElement('hidden', 'id', $course->id);
     $mform->setType('id', PARAM_INT);
 }
开发者ID:rogiervandongen,项目名称:moodle-local_mass_enroll,代码行数:47,代码来源:mass_enroll_form.php

示例13: definition

 /**
  * Form definition.
  */
 protected function definition()
 {
     global $DB;
     $mform = $this->_form;
     // Add student select box.
     $mform->addElement('select', 'users', 'Users', $DB->get_records_menu('user', array(), '', 'id,username'), array('class' => 'chosen', 'multiple' => 'multiple'));
     $mform->addRule('users', null, 'required', null, 'client');
     // Add student select box.
     $courses = $DB->get_records_menu('course', array(), '', 'id,CONCAT(shortname, \': \', fullname)');
     $mform->addElement('select', 'courses', 'Courses', $courses, array('class' => 'chosen', 'multiple' => 'multiple'));
     $mform->addRule('courses', null, 'required', null, 'client');
     unset($courses);
     // Add role select box.
     $course = get_site();
     $roles = get_assignable_roles(\context_course::instance($course->id));
     $mform->addElement('select', 'roleid', 'Role', $roles);
     $mform->addRule('roleid', null, 'required', null, 'client');
     $this->add_action_buttons(true, 'Enrol');
 }
开发者ID:unikent,项目名称:moodle-tool_kent,代码行数:22,代码来源:mass_enrol.php

示例14: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
     $enrol = enrol_get_plugin('jwc');
     $roles = get_assignable_roles($coursecontext);
     $roles = array_reverse($roles, true);
     // descending default sortorder
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_jwc'));
     $mform->addElement('html', '与教务管理系统的学生选课同步。只有使用HITID登录的教师和学生才能享用此功能');
     $mform->addElement('text', 'coursenumber', get_string('coursenumber', 'enrol_jwc'));
     $mform->setType('coursenumber', PARAM_ALPHANUM);
     $mform->addHelpButton('coursenumber', 'coursenumber', 'enrol_jwc');
     $mform->addRule('coursenumber', get_string('required'), 'required', null, 'client');
     $mform->addElement('hidden', 'roleid', $enrol->get_config('roleid'));
     $mform->setType('roleid', PARAM_INT);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
开发者ID:hit-moodle,项目名称:moodle-enrol_jwc,代码行数:23,代码来源:addinstance_form.php

示例15: test_get_assignable_roles

 /**
  * Test returning of assignable roles in context.
  */
 public function test_get_assignable_roles()
 {
     global $DB;
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
     $teacher = $this->getDataGenerator()->create_user();
     role_assign($teacherrole->id, $teacher->id, $coursecontext);
     $teacherename = (object) array('roleid' => $teacherrole->id, 'name' => 'Učitel', 'contextid' => $coursecontext->id);
     $DB->insert_record('role_names', $teacherename);
     $studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
     $student = $this->getDataGenerator()->create_user();
     role_assign($studentrole->id, $student->id, $coursecontext);
     $contexts = $DB->get_records('context');
     $users = $DB->get_records('user');
     $allroles = $DB->get_records('role');
     // Evaluate all results for all users in all contexts.
     foreach ($users as $user) {
         $this->setUser($user);
         foreach ($contexts as $contextid => $unused) {
             $context = context_helper::instance_by_id($contextid);
             $roles = get_assignable_roles($context, ROLENAME_SHORT);
             foreach ($allroles as $roleid => $role) {
                 if (isset($roles[$roleid])) {
                     if (is_siteadmin()) {
                         $this->assertTrue($DB->record_exists('role_context_levels', array('contextlevel' => $context->contextlevel, 'roleid' => $roleid)));
                     } else {
                         $this->assertTrue(user_can_assign($context, $roleid), "u:{$user->id} r:{$roleid}");
                     }
                     $this->assertEquals($role->shortname, $roles[$roleid]);
                 } else {
                     $allowed = $DB->record_exists('role_context_levels', array('contextlevel' => $context->contextlevel, 'roleid' => $roleid));
                     if (is_siteadmin()) {
                         $this->assertFalse($allowed);
                     } else {
                         $this->assertFalse($allowed and user_can_assign($context, $roleid), "u:{$user->id}, r:{$allroles[$roleid]->name}, c:{$context->contextlevel}");
                     }
                 }
             }
         }
     }
     // Not-logged-in user.
     $this->setUser(0);
     foreach ($contexts as $contextid => $unused) {
         $context = context_helper::instance_by_id($contextid);
         $roles = get_assignable_roles($context, ROLENAME_SHORT);
         $this->assertSame(array(), $roles);
     }
     // Test current user.
     $this->setUser(0);
     $admin = $DB->get_record('user', array('username' => 'admin'), '*', MUST_EXIST);
     $roles1 = get_assignable_roles($coursecontext, ROLENAME_SHORT, false, $admin);
     $roles2 = get_assignable_roles($coursecontext, ROLENAME_SHORT, false, $admin->id);
     $this->setAdminUser();
     $roles3 = get_assignable_roles($coursecontext, ROLENAME_SHORT);
     $this->assertSame($roles1, $roles3);
     $this->assertSame($roles2, $roles3);
     // Test parameter defaults.
     $this->setAdminUser();
     $roles1 = get_assignable_roles($coursecontext);
     $roles2 = get_assignable_roles($coursecontext, ROLENAME_ALIAS, false, $admin);
     $this->assertEquals($roles2, $roles1);
     // Verify returned names - let's allow all roles everywhere to simplify this a bit.
     $alllevels = context_helper::get_all_levels();
     $alllevels = array_keys($alllevels);
     foreach ($allroles as $roleid => $role) {
         set_role_contextlevels($roleid, $alllevels);
     }
     $alltypes = array(ROLENAME_ALIAS, ROLENAME_ALIAS_RAW, ROLENAME_BOTH, ROLENAME_ORIGINAL, ROLENAME_ORIGINALANDSHORT, ROLENAME_SHORT);
     foreach ($alltypes as $type) {
         $rolenames = role_fix_names($allroles, $coursecontext, $type);
         $roles = get_assignable_roles($coursecontext, $type, false, $admin);
         foreach ($roles as $roleid => $rolename) {
             $this->assertSame($rolenames[$roleid]->localname, $rolename);
         }
     }
     // Verify counts.
     $alltypes = array(ROLENAME_ALIAS, ROLENAME_ALIAS_RAW, ROLENAME_BOTH, ROLENAME_ORIGINAL, ROLENAME_ORIGINALANDSHORT, ROLENAME_SHORT);
     foreach ($alltypes as $type) {
         $roles = get_assignable_roles($coursecontext, $type, false, $admin);
         list($rolenames, $rolecounts, $nameswithcounts) = get_assignable_roles($coursecontext, $type, true, $admin);
         $this->assertEquals($roles, $rolenames);
         foreach ($rolenames as $roleid => $name) {
             if ($roleid == $teacherrole->id or $roleid == $studentrole->id) {
                 $this->assertEquals(1, $rolecounts[$roleid]);
             } else {
                 $this->assertEquals(0, $rolecounts[$roleid]);
             }
             $this->assertSame("{$name} ({$rolecounts[$roleid]})", $nameswithcounts[$roleid]);
         }
     }
 }
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:96,代码来源:accesslib_test.php


注:本文中的get_assignable_roles函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。