本文整理汇总了PHP中core_availability\info类的典型用法代码示例。如果您正苦于以下问题:PHP info类的具体用法?PHP info怎么用?PHP info使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了info类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_description
public function get_description($full, $not, \core_availability\info $info)
{
// Get name for module.
$modinfo = $info->get_modinfo();
if (!isset($this->expectedpublicprivate)) {
$modname = get_string('missing', 'availability_publicprivate');
}
// // Work out which lang string to use.
// if ($not) {
// // Convert NOT strings to use the equivalent where possible.
// switch ($this->expectedpublicprivate) {
// case COMPLETION_INCOMPLETE:
// $str = 'requires_' . self::get_lang_string_keyword(COMPLETION_COMPLETE);
// break;
// case COMPLETION_COMPLETE:
// $str = 'requires_' . self::get_lang_string_keyword(COMPLETION_INCOMPLETE);
// break;
// default:
// // The other two cases do not have direct opposites.
// $str = 'requires_not_' . self::get_lang_string_keyword($this->expectedpublicprivate);
// break;
// }
// } else {
// $str = 'requires_' . self::get_lang_string_keyword($this->expectedpublicprivate);
// }
if ($this->expectedpublicprivate === PUBLICPRIVATE_PRIVATE) {
$str = 'requires_private';
} else {
$str = 'requires_public';
}
return get_string($str, 'availability_publicprivate');
}
示例2: is_available
/**
* Determines whether a particular item is currently available
* according to this availability condition.
*
* @param bool $not Set true if we are inverting the condition.
* @param info $info Item we're checking.
* @param bool $grabthelot Performance hint: if true, caches information
* required for all course-modules, to make the front page and similar
* pages work more quickly (works only for current user).
* @param int $userid User ID to check availability for.
* @return bool True if available.
*/
public function is_available($not, \core_availability\info $info, $grabthelot, $userid)
{
$available = false;
if ($this->requiredlvl > 0) {
$currentlvl = $this->get_user_level($info->get_course()->id, $userid);
if ($currentlvl >= $this->requiredlvl) {
$available = true;
} else {
$available = false;
}
if ($not) {
$available = !$available;
}
}
return $available;
}
示例3: get_description
public function get_description($full, $not, \core_availability\info $info)
{
$course = $info->get_course();
// String depends on type of requirement. We are coy about
// the actual numbers, in case grades aren't released to
// students.
if (is_null($this->min) && is_null($this->max)) {
$string = 'any';
} else {
if (is_null($this->max)) {
$string = 'min';
} else {
if (is_null($this->min)) {
$string = 'max';
} else {
$string = 'range';
}
}
}
if ($not) {
// The specific strings don't make as much sense with 'not'.
if ($string === 'any') {
$string = 'notany';
} else {
$string = 'notgeneral';
}
}
$name = self::get_cached_grade_name($course->id, $this->gradeitemid);
return get_string('requires_' . $string, 'availability_grade', $name);
}
示例4: update_after_restore
public function update_after_restore($restoreid, $courseid, \base_logger $logger, $name)
{
// Update the date, if restoring with changed date.
$dateoffset = \core_availability\info::get_restore_date_offset($restoreid);
if ($dateoffset) {
$this->time += $dateoffset;
return true;
}
return false;
}
示例5: test_usage
/**
* Tests the is_available and get_description functions.
*/
public function test_usage()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/mod/assign/locallib.php';
$this->resetAfterTest();
// Create course with completion turned on.
$CFG->enablecompletion = true;
$CFG->enableavailability = true;
$generator = $this->getDataGenerator();
$course = $generator->create_course(array('enablecompletion' => 1));
$user = $generator->create_user();
$generator->enrol_user($user->id, $course->id);
$this->setUser($user);
// Create a Page with manual completion for basic checks.
$page = $generator->get_plugin_generator('mod_page')->create_instance(array('course' => $course->id, 'name' => 'Page!', 'completion' => COMPLETION_TRACKING_MANUAL));
// Create an assignment - we need to have something that can be graded
// so as to test the PASS/FAIL states. Set it up to be completed based
// on its grade item.
$assignrow = $this->getDataGenerator()->create_module('assign', array('course' => $course->id, 'name' => 'Assign!', 'completion' => COMPLETION_TRACKING_AUTOMATIC));
$DB->set_field('course_modules', 'completiongradeitemnumber', 0, array('id' => $assignrow->cmid));
$assign = new assign(context_module::instance($assignrow->cmid), false, false);
// Get basic details.
$modinfo = get_fast_modinfo($course);
$pagecm = $modinfo->get_cm($page->cmid);
$assigncm = $assign->get_course_module();
$info = new \core_availability\mock_info($course, $user->id);
// COMPLETE state (false), positive and NOT.
$cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_COMPLETE));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is marked complete~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
// INCOMPLETE state (true).
$cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_INCOMPLETE));
$this->assertTrue($cond->is_available(false, $info, true, $user->id));
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, true, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is marked complete~', $information);
// Mark page complete.
$completion = new completion_info($course);
$completion->update_state($pagecm, COMPLETION_COMPLETE);
// COMPLETE state (true).
$cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_COMPLETE));
$this->assertTrue($cond->is_available(false, $info, true, $user->id));
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$information = $cond->get_description(false, true, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is incomplete~', $information);
// INCOMPLETE state (false).
$cond = new condition((object) array('cm' => (int) $pagecm->id, 'e' => COMPLETION_INCOMPLETE));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Page!.*is incomplete~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
// We are going to need the grade item so that we can get pass/fails.
$gradeitem = $assign->get_grade_item();
grade_object::set_properties($gradeitem, array('gradepass' => 50.0));
$gradeitem->update();
// With no grade, it should return true for INCOMPLETE and false for
// the other three.
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_INCOMPLETE));
$this->assertTrue($cond->is_available(false, $info, true, $user->id));
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
// Check $information for COMPLETE_PASS and _FAIL as we haven't yet.
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_PASS));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and passed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_FAIL));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and failed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
// Change the grade to be complete and failed.
self::set_grade($assignrow, $user->id, 40);
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_INCOMPLETE));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE));
$this->assertTrue($cond->is_available(false, $info, true, $user->id));
$this->assertFalse($cond->is_available(true, $info, true, $user->id));
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_PASS));
$this->assertFalse($cond->is_available(false, $info, true, $user->id));
$information = $cond->get_description(false, false, $info);
$information = \core_availability\info::format_info($information, $course);
$this->assertRegExp('~Assign!.*is complete and passed~', $information);
$this->assertTrue($cond->is_available(true, $info, true, $user->id));
$cond = new condition((object) array('cm' => (int) $assigncm->id, 'e' => COMPLETION_COMPLETE_FAIL));
//.........这里部分代码省略.........
示例6: get_description
/**
* Obtains a string describing this restriction (whether or not
* it actually applies).
*
* @param bool $full Set true if this is the 'full information' view
* @param bool $not Set true if we are inverting the condition
* @param info $info Item we're checking
* @return string Information string (for admin) about all restrictions on
* this item
*/
public function get_description($full, $not, \core_availability\info $info)
{
global $USER;
$logmanager = get_log_manager();
if (!($readers = $logmanager->get_readers('core\\log\\sql_reader'))) {
// Should be using 2.8, use old class.
$readers = $logmanager->get_readers('core\\log\\sql_select_reader');
}
$reader = array_pop($readers);
$context = $info->get_context();
$viewscount = $reader->get_events_select_count('contextid = :context AND userid = :userid AND crud = :crud', array('context' => $context->id, 'userid' => $USER->id, 'crud' => 'r'));
$a = new \stdclass();
$a->viewslimit = $this->viewslimit;
$a->viewscount = $viewscount;
if ($not) {
return get_string('eithernotdescription', 'availability_maxviews', $a);
} else {
return get_string('eitherdescription', 'availability_maxviews', $a);
}
}
示例7: process_availability_field
/**
* Process the legacy availability fields table record. This table does not
* exist in Moodle 2.7+ but we still support restore.
*
* @param stdClass $data Record data
*/
protected function process_availability_field($data)
{
global $DB;
$data = (object) $data;
// Mark it is as passed by default
$passed = true;
$customfieldid = null;
// If a customfield has been used in order to pass we must be able to match an existing
// customfield by name (data->customfield) and type (data->customfieldtype)
if (!empty($data->customfield) xor !empty($data->customfieldtype)) {
// xor is sort of uncommon. If either customfield is null or customfieldtype is null BUT not both.
// If one is null but the other isn't something clearly went wrong and we'll skip this condition.
$passed = false;
} else {
if (!empty($data->customfield)) {
$params = array('shortname' => $data->customfield, 'datatype' => $data->customfieldtype);
$customfieldid = $DB->get_field('user_info_field', 'id', $params);
$passed = $customfieldid !== false;
}
}
if ($passed) {
// Create the object to insert into the database
$availfield = new stdClass();
$availfield->coursemoduleid = $this->task->get_moduleid();
// Lets add the availability cmid
$availfield->userfield = $data->userfield;
$availfield->customfieldid = $customfieldid;
$availfield->operator = $data->operator;
$availfield->value = $data->value;
// Get showavailability option.
$showrec = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'module_showavailability', $availfield->coursemoduleid);
if (!$showrec) {
// Should not happen.
throw new coding_exception('No matching showavailability record');
}
$show = $showrec->info->showavailability;
// The $availfieldobject is now in the format used in the old
// system. Interpret this and convert to new system.
$currentvalue = $DB->get_field('course_modules', 'availability', array('id' => $availfield->coursemoduleid), MUST_EXIST);
$newvalue = \core_availability\info::add_legacy_availability_field_condition($currentvalue, $availfield, $show);
$DB->set_field('course_modules', 'availability', $newvalue, array('id' => $availfield->coursemoduleid));
}
}
示例8: get_description
public function get_description($full, $not, \core_availability\info $info)
{
// Get name for module.
$modinfo = $info->get_modinfo();
if (!array_key_exists($this->cmid, $modinfo->cms)) {
$modname = get_string('missing', 'availability_completion');
} else {
$modname = '<AVAILABILITY_CMNAME_' . $modinfo->cms[$this->cmid]->id . '/>';
}
// Work out which lang string to use.
if ($not) {
// Convert NOT strings to use the equivalent where possible.
switch ($this->expectedcompletion) {
case COMPLETION_INCOMPLETE:
$str = 'requires_' . self::get_lang_string_keyword(COMPLETION_COMPLETE);
break;
case COMPLETION_COMPLETE:
$str = 'requires_' . self::get_lang_string_keyword(COMPLETION_INCOMPLETE);
break;
default:
// The other two cases do not have direct opposites.
$str = 'requires_not_' . self::get_lang_string_keyword($this->expectedcompletion);
break;
}
} else {
$str = 'requires_' . self::get_lang_string_keyword($this->expectedcompletion);
}
return get_string($str, 'availability_completion', $modname);
}
示例9: course_section_cm_availability
/**
* Renders HTML to show course module availability information (for someone who isn't allowed
* to see the activity itself, or for staff)
*
* @param cm_info $mod
* @param array $displayoptions
* @return string
*/
public function course_section_cm_availability(cm_info $mod, $displayoptions = array())
{
global $CFG;
if (!$mod->uservisible) {
// this is a student who is not allowed to see the module but might be allowed
// to see availability info (i.e. "Available from ...")
if (!empty($mod->availableinfo)) {
$formattedinfo = \core_availability\info::format_info($mod->availableinfo, $mod->get_course());
$output = html_writer::tag('div', $formattedinfo, array('class' => 'availabilityinfo'));
}
return $output;
}
// this is a teacher who is allowed to see module but still should see the
// information that module is not available to all/some students
$modcontext = context_module::instance($mod->id);
$canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
if ($canviewhidden && !empty($CFG->enableavailability)) {
// Don't add availability information if user is not editing and activity is hidden.
if ($mod->visible || $this->page->user_is_editing()) {
$hidinfoclass = '';
if (!$mod->visible) {
$hidinfoclass = 'hide';
}
$ci = new \core_availability\info_module($mod);
$fullinfo = $ci->get_full_information();
if ($fullinfo) {
$formattedinfo = \core_availability\info::format_info($fullinfo, $mod->get_course());
return html_writer::div($formattedinfo, 'availabilityinfo ' . $hidinfoclass);
}
}
}
return '';
}
示例10: filter_user_list
public function filter_user_list(array $users, $not, \core_availability\info $info, \core_availability\capability_checker $checker)
{
global $CFG, $DB;
require_once $CFG->libdir . '/grouplib.php';
$course = $info->get_course();
// List users for this course who match the condition.
if ($this->groupid) {
$groupusers = groups_get_members($this->groupid, 'u.id', 'u.id ASC');
} else {
$groupusers = $DB->get_records_sql("\n SELECT DISTINCT gm.userid\n FROM {groups} g\n JOIN {groups_members} gm ON gm.groupid = g.id\n WHERE g.courseid = ?", array($course->id));
}
// List users who have access all groups.
$aagusers = $checker->get_users_by_capability('moodle/site:accessallgroups');
// Filter the user list.
$result = array();
foreach ($users as $id => $user) {
// Always include users with access all groups.
if (array_key_exists($id, $aagusers)) {
$result[$id] = $user;
continue;
}
// Other users are included or not based on group membership.
$allow = array_key_exists($id, $groupusers);
if ($not) {
$allow = !$allow;
}
if ($allow) {
$result[$id] = $user;
}
}
return $result;
}
示例11: get_description
public function get_description($full, $not, \core_availability\info $info)
{
global $DB;
$context = \context_course::instance($info->get_course()->id);
$role = $DB->get_record('role', array('id' => $this->roleid));
if (!$role) {
$missing = get_string('missing', 'availability_role');
return get_string($not ? 'requires_notrole' : 'requires_role', 'availability_role', $missing);
} else {
$name = role_get_name($role, $context);
return get_string($not ? 'requires_notrole' : 'requires_role', 'availability_role', $name);
}
}
示例12: course_section_cm_availability
/**
* Renders HTML to show course module availability information
*
* @param cm_info $mod
* @param array $displayoptions
* @return string
*/
public function course_section_cm_availability(cm_info $mod, $displayoptions = array())
{
// If we have available info, always spit it out.
if (!empty($mod->availableinfo)) {
$availinfo = $mod->availableinfo;
} else {
$ci = new \core_availability\info_module($mod);
$availinfo = $ci->get_full_information();
}
if ($availinfo) {
$formattedinfo = \core_availability\info::format_info($availinfo, $mod->get_course());
return html_writer::div($formattedinfo, 'availabilityinfo');
}
return '';
}
示例13: get_description
public function get_description($full, $not, \core_availability\info $info)
{
$course = $info->get_course();
// Display the fieldname into current lang.
if ($this->customfield) {
// Is a custom profile field (will use multilang).
$customfields = self::get_custom_profile_fields();
if (array_key_exists($this->customfield, $customfields)) {
$translatedfieldname = $customfields[$this->customfield]->name;
} else {
$translatedfieldname = get_string('missing', 'availability_profile', $this->customfield);
}
} else {
$translatedfieldname = get_user_field_name($this->standardfield);
}
$context = \context_course::instance($course->id);
$a = new \stdClass();
$a->field = format_string($translatedfieldname, true, array('context' => $context));
$a->value = s($this->value);
if ($not) {
// When doing NOT strings, we replace the operator with its inverse.
// Some of them don't have inverses, so for those we use a new
// identifier which is only used for this lang string.
switch ($this->operator) {
case self::OP_CONTAINS:
$opname = self::OP_DOES_NOT_CONTAIN;
break;
case self::OP_DOES_NOT_CONTAIN:
$opname = self::OP_CONTAINS;
break;
case self::OP_ENDS_WITH:
$opname = 'notendswith';
break;
case self::OP_IS_EMPTY:
$opname = self::OP_IS_NOT_EMPTY;
break;
case self::OP_IS_EQUAL_TO:
$opname = 'notisequalto';
break;
case self::OP_IS_NOT_EMPTY:
$opname = self::OP_IS_EMPTY;
break;
case self::OP_STARTS_WITH:
$opname = 'notstartswith';
break;
default:
throw new \coding_exception('Unexpected operator: ' . $this->operator);
}
} else {
$opname = $this->operator;
}
return get_string('requires_' . $opname, 'availability_profile', $a);
}
示例14: process_module
protected function process_module($data)
{
global $CFG, $DB;
$data = (object) $data;
$oldid = $data->id;
$this->task->set_old_moduleversion($data->version);
// Get the current course module data.
$newitemid = $this->task->get_moduleid();
$params = array('id' => $newitemid);
$cmdata = $DB->get_record('course_modules', $params, '*', MUST_EXIST);
// Group mode and Grouping.
$cmdata->groupmode = $data->groupmode;
$cmdata->groupingid = $this->get_mappingid('grouping', $data->groupingid);
// Idnumber uniqueness.
if (!grade_verify_idnumber($data->idnumber, $this->get_courseid())) {
$data->idnumber = '';
}
$cmdata->idnumber = $data->idnumber;
// Completion.
if (!empty($CFG->enablecompletion)) {
$cmdata->completion = $data->completion;
$cmdata->completiongradeitemnumber = $data->completiongradeitemnumber;
$cmdata->completionview = $data->completionview;
$cmdata->completionexpected = $this->apply_date_offset($data->completionexpected);
}
// Availability.
if (empty($CFG->enableavailability)) {
$data->availability = null;
}
if (empty($data->availability)) {
// If there are legacy availablility data fields (and no new format data),
// convert the old fields.
$data->availability = \core_availability\info::convert_legacy_fields($data, false);
} else {
if (!empty($data->groupmembersonly)) {
// There is current availability data, but it still has groupmembersonly
// as well (2.7 backups), convert just that part.
require_once $CFG->dirroot . '/lib/db/upgradelib.php';
$data->availability = upgrade_group_members_only($data->groupingid, $data->availability);
}
}
$cmdata->availability = $data->availability;
// Backups that did not include showdescription, set it to default 0
// (this is not totally necessary as it has a db default, but just to
// be explicit).
if (!isset($data->showdescription)) {
$data->showdescription = 0;
}
$cmdata->showdescription = $data->showdescription;
// Course_module record ready, update it.
$DB->update_record('course_modules', $cmdata);
// Save mapping.
$this->set_mapping('course_module', $oldid, $newitemid);
// Set the new course_module id in the task.
$this->task->set_moduleid($newitemid);
// We can now create the context safely.
$ctxid = context_module::instance($newitemid)->id;
// Set the new context id in the task.
$this->task->set_contextid($ctxid);
// If there is the legacy showavailability data, store this for later use.
// (This data is not present when restoring 'new' backups.)
if (isset($cmdata->showavailability)) {
// Cache the showavailability flag using the backup_ids data field.
restore_dbops::set_backup_ids_record($this->get_restoreid(), 'module_showavailability', $newitemid, 0, null, (object) array('showavailability' => $cmdata->showavailability));
}
}
示例15: section_availability_message
/**
* If section is not visible, display the message about that ('Not available
* until...', that sort of thing). Otherwise, returns blank.
*
* For users with the ability to view hidden sections, it shows the
* information even though you can view the section and also may include
* slightly fuller information (so that teachers can tell when sections
* are going to be unavailable etc). This logic is the same as for
* activities.
*
* @param stdClass $section The course_section entry from DB
* @param bool $canviewhidden True if user can view hidden sections
* @return string HTML to output
*/
protected function section_availability_message($section, $canviewhidden)
{
global $CFG;
$o = '';
if (!$section->uservisible) {
// Note: We only get to this function if availableinfo is non-empty,
// so there is definitely something to print.
$formattedinfo = \core_availability\info::format_info($section->availableinfo, $section->course);
$o .= html_writer::div($formattedinfo, 'availabilityinfo');
} else {
if ($canviewhidden && !empty($CFG->enableavailability) && $section->visible) {
$ci = new \core_availability\info_section($section);
$fullinfo = $ci->get_full_information();
if ($fullinfo) {
$formattedinfo = \core_availability\info::format_info($fullinfo, $section->course);
$o .= html_writer::div($formattedinfo, 'availabilityinfo');
}
}
}
return $o;
}