本文整理汇总了PHP中condition_info::get_condition_user_fields方法的典型用法代码示例。如果您正苦于以下问题:PHP condition_info::get_condition_user_fields方法的具体用法?PHP condition_info::get_condition_user_fields怎么用?PHP condition_info::get_condition_user_fields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类condition_info
的用法示例。
在下文中一共展示了condition_info::get_condition_user_fields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: standard_coursemodule_elements
//.........这里部分代码省略.........
$items = $items ? $items : array();
foreach ($items as $id => $item) {
// Do not include grades for current item
if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
continue;
}
$gradeoptions[$id] = $item->get_name();
}
asort($gradeoptions);
$gradeoptions = array(0 => $strnone) + $gradeoptions;
$grouparray = array();
$grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
$grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
$grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
$grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
$grouparray[] =& $mform->createElement('static', '', '', '%');
$group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
// Get version with condition info and store it so we don't ask
// twice
if (!empty($this->_cm)) {
$ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
$this->_cm = $ci->get_full_course_module();
$count = count($this->_cm->conditionsgrade) + 1;
$fieldcount = count($this->_cm->conditionsfield) + 1;
} else {
$count = 1;
$fieldcount = 1;
}
$this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
$mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
// Conditions based on user fields
$operators = condition_info::get_condition_user_field_operators();
$useroptions = condition_info::get_condition_user_fields();
asort($useroptions);
$useroptions = array(0 => $strnone) + $useroptions;
$grouparray = array();
$grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions);
$grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators);
$grouparray[] =& $mform->createElement('text', 'conditionfieldvalue');
$mform->setType('conditionfieldvalue', PARAM_RAW);
$group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray);
$this->repeat_elements(array($group), $fieldcount, array(), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true);
$mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition');
// Conditions based on completion
$completion = new completion_info($COURSE);
if ($completion->is_enabled()) {
$completionoptions = array();
$modinfo = get_fast_modinfo($COURSE);
foreach ($modinfo->cms as $id => $cm) {
// Add each course-module if it:
// (a) has completion turned on
// (b) is not the same as current course-module
if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) {
$completionoptions[$id] = $cm->name;
}
}
asort($completionoptions);
$completionoptions = array(0 => $strnone) + $completionoptions;
$completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition'));
$grouparray = array();
$grouparray[] =& $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions);
$grouparray[] =& $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues);
$group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray);
$count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion) + 1;
$this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true);
示例2: test_condition_user_fields
/**
* Tests user fields to ensure that the list of provided fields includes only
* fields which the equivalent function can be used to obtain the value of.
*/
public function test_condition_user_fields() {
global $CFG, $DB, $USER;
// Set up basic data.
$courseid = $this->make_course();
$cmid = $this->make_course_module($courseid);
$ci = new condition_info_testwrapper(
(object)array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
// Add a custom user profile field. Unfortunately there is no back-end
// API for adding profile fields without having an actual form and doing
// redirects and stuff! These are the default text field parameters.
require_once($CFG->dirroot . '/user/profile/lib.php');
$field = (object)array(
'shortname' => 'myfield', 'name' => 'My field', 'required' => 0,
'locked' => 0, 'forceunique' => 0, 'signup' => 0,
'visible' => PROFILE_VISIBLE_ALL,
'datatype' => 'text', 'description' => 'A field of mine',
'descriptionformat' => FORMAT_HTML, 'defaultdata' => '',
'defaultdataformat' => FORMAT_HTML, 'param1' => 30, 'param2' => 2048,
'param3' => 0, 'param4' => '', 'param5' => '');
$customfieldid = $DB->insert_record('user_info_field', $field);
// Get list of condition user fields.
$fields = condition_info::get_condition_user_fields();
// Check custom field is included.
$this->assertEquals('My field', $fields[$customfieldid]);
// For all other fields, check it actually works to get data from them.
foreach ($fields as $fieldid => $name) {
// Not checking the result, just that it's possible to get it
// without error.
$ci->inspect_get_cached_user_profile_field($USER->id, $fieldid);
}
// Change to not logged in user.
$this->setUser(null);
foreach ($fields as $fieldid => $name) {
// Should get false always when not logged in.
$this->assertEquals(false, $ci->inspect_get_cached_user_profile_field($USER->id, $fieldid));
}
}
示例3: definition_after_data
public function definition_after_data()
{
global $CFG, $DB;
$mform = $this->_form;
$course = $this->_customdata['course'];
$context = context_course::instance($course->id);
if (!empty($CFG->enableavailability)) {
$mform->addElement('header', 'availabilityconditions', get_string('availabilityconditions', 'condition'));
$mform->setExpanded('availabilityconditions', false);
// String used by conditions more than once
$strcondnone = get_string('none', 'condition');
// Grouping conditions - only if grouping is enabled at site level
if (!empty($CFG->enablegroupmembersonly)) {
$options = array();
if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id))) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name, true, array('context' => $context));
}
}
collatorlib::asort($options);
$options = array(0 => get_string('none')) + $options;
$mform->addElement('select', 'groupingid', get_string('groupingsection', 'group'), $options);
$mform->addHelpButton('groupingid', 'groupingsection', 'group');
}
// Available from/to defaults to midnight because then the display
// will be nicer where it tells users when they can access it (it
// shows only the date and not time).
$date = usergetdate(time());
$midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
// Date and time conditions.
$mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
$mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
// Conditions based on grades
$gradeoptions = array();
$items = grade_item::fetch_all(array('courseid' => $course->id));
$items = $items ? $items : array();
foreach ($items as $id => $item) {
$gradeoptions[$id] = $item->get_name();
}
asort($gradeoptions);
$gradeoptions = array(0 => $strcondnone) + $gradeoptions;
$grouparray = array();
$grouparray[] = $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
$grouparray[] = $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
$grouparray[] = $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
$grouparray[] = $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
$grouparray[] = $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
$grouparray[] = $mform->createElement('static', '', '', '%');
$group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
// Get full version (including condition info) of section object
$ci = new condition_info_section($this->_customdata['cs']);
$fullcs = $ci->get_full_section();
$count = count($fullcs->conditionsgrade) + 1;
// Grade conditions
$this->repeat_elements(array($group), $count, array('conditiongradegroup[conditiongrademin]' => array('type' => PARAM_RAW), 'conditiongradegroup[conditiongrademax]' => array('type' => PARAM_RAW)), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
$mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
// Conditions based on user fields
$operators = condition_info::get_condition_user_field_operators();
$useroptions = condition_info::get_condition_user_fields(array('context' => $context));
asort($useroptions);
$useroptions = array(0 => $strcondnone) + $useroptions;
$grouparray = array();
$grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions);
$grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators);
$grouparray[] =& $mform->createElement('text', 'conditionfieldvalue');
$group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray);
$fieldcount = count($fullcs->conditionsfield) + 1;
$this->repeat_elements(array($group), $fieldcount, array('conditionfieldgroup[conditionfieldvalue]' => array('type' => PARAM_RAW)), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true);
$mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition');
// Conditions based on completion
$completion = new completion_info($course);
if ($completion->is_enabled()) {
$completionoptions = array();
$modinfo = get_fast_modinfo($course);
foreach ($modinfo->cms as $id => $cm) {
// Add each course-module if it:
// (a) has completion turned on
// (b) does not belong to current course-section
if ($cm->completion && $fullcs->id != $cm->section) {
$completionoptions[$id] = $cm->name;
}
}
asort($completionoptions);
$completionoptions = array(0 => $strcondnone) + $completionoptions;
$completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition'));
$grouparray = array();
$grouparray[] = $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions);
$grouparray[] = $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues);
$group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray);
$count = count($fullcs->conditionscompletion) + 1;
$this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true);
$mform->addHelpButton('conditioncompletiongroup[0]', 'completionconditionsection', 'condition');
}
// Availability conditions - set up form values
if (!empty($CFG->enableavailability)) {
$num = 0;
foreach ($fullcs->conditionsgrade as $gradeitemid => $minmax) {
$groupelements = $mform->getElement('conditiongradegroup[' . $num . ']')->getElements();
$groupelements[0]->setValue($gradeitemid);
$groupelements[2]->setValue(is_null($minmax->min) ? '' : format_float($minmax->min, 5, true, true));
//.........这里部分代码省略.........
示例4: taskchain_navigation_accesscontrol_form
//.........这里部分代码省略.........
$items[$id] = $cm->name;
}
}
if (count($items)) {
asort($items);
$conditioncmidmenu = $basemenuitems + $items;
}
}
$conditionfieldnamemenu = array('' => get_string('none', 'moodle'));
$conditionfieldoperatormenu = array();
$filepath = $CFG->dirroot . '/availability/condition/profile/classes/frontend.php';
if (file_exists($filepath)) {
// Moodle >= 2.7
$contents = file_get_contents($filepath);
$search = "/'([a-zA-Z0-9]+)' => get_user_field_name\\('\\1'\\)/";
if (preg_match_all($search, $contents, $items)) {
foreach ($items[1] as $item) {
$conditionfieldnamemenu[$item] = get_user_field_name($item);
}
}
$search = "/(?<=')op_([a-zA-Z0-9]+)(?=')/";
if (preg_match_all($search, $contents, $items)) {
foreach ($items[1] as $i => $item) {
$conditionfieldoperatormenu[$item] = get_string($items[0][$i], 'availability_profile');
}
}
require_once $CFG->dirroot . '/user/profile/lib.php';
if ($items = profile_get_custom_fields(true)) {
foreach ($items as $item) {
$conditionfieldnamemenu[$item->shortname] = $item->name;
}
}
} else {
if (method_exists('condition_info', 'get_condition_user_fields')) {
// Moodle >= 2.4
if ($items = condition_info::get_condition_user_fields(array('context' => $course->context))) {
$conditionfieldnamemenu += $items;
}
$conditionfieldoperatormenu = condition_info::get_condition_user_field_operators();
} else {
// Moodle <= 2.3 doesn't have conditional user fields
$conditionfieldnamemenu = array();
}
}
if ($dbman->field_exists('course_modules', 'availability')) {
// Moodle >= 2.7
if ($items = groups_get_all_groups($course->id)) {
foreach ($items as $item) {
$name = $item->name;
$name = block_taskchain_navigation::filter_text($name);
$name = block_taskchain_navigation::trim_text($name);
$conditiongroupidmenu[$item->id] = $name;
}
}
if ($items = groups_get_all_groupings($course->id)) {
foreach ($items as $item) {
$name = $item->name;
$name = block_taskchain_navigation::filter_text($name);
$name = block_taskchain_navigation::trim_text($name);
$conditiongroupingidmenu[$item->id] = $name;
}
}
}
$str = new stdClass();
if ($strman->string_exists('accessrestrictions', 'availability')) {
// Moodle >= 2.7