本文整理汇总了PHP中stdClass::get_modinfo方法的典型用法代码示例。如果您正苦于以下问题:PHP stdClass::get_modinfo方法的具体用法?PHP stdClass::get_modinfo怎么用?PHP stdClass::get_modinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stdClass
的用法示例。
在下文中一共展示了stdClass::get_modinfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_user_visible
/**
* Checks if an activity is visible to the given user.
*
* Unlike other checks in the availability system, this check includes the
* $cm->visible flag. It is equivalent to $cm->uservisible.
*
* If you have already checked (or do not care whether) the user has access
* to the course, you can set $checkcourse to false to save it checking
* course access.
*
* When checking for the current user, you should generally not call
* this function. Instead, use get_fast_modinfo to get a cm_info object,
* then simply check the $cm->uservisible flag. This function is intended
* to obtain that information for a separate course-module object that
* wasn't loaded with get_fast_modinfo, or for a different user.
*
* This function has a performance cost unless the availability system is
* disabled, and you supply a $cm object with necessary fields, and you
* don't check course access.
*
* @param int|\stdClass|\cm_info $cmorid Object or id representing activity
* @param int $userid User id (0 = current user)
* @param bool $checkcourse If true, checks whether the user has course access
* @return bool True if the activity is visible to the specified user
* @throws \moodle_exception If the cmid doesn't exist
*/
public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true)
{
global $USER, $DB, $CFG;
// Evaluate user id.
if (!$userid) {
$userid = $USER->id;
}
// If this happens to be already called with a cm_info for the right user
// then just return uservisible.
if ($cmorid instanceof \cm_info && $cmorid->get_modinfo()->userid == $userid) {
return $cmorid->uservisible;
}
// If the $cmorid isn't an object or doesn't have required fields, load it.
if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
$cm = $cmorid;
} else {
if (is_object($cmorid)) {
$cmorid = $cmorid->id;
}
$cm = $DB->get_record('course_modules', array('id' => $cmorid));
if (!$cm) {
// In some error cases, the course module may not exist.
debugging('info_module::is_user_visible called with invalid cmid ' . $cmorid, DEBUG_DEVELOPER);
return false;
}
}
// If requested, check user can access the course.
if ($checkcourse) {
$coursecontext = \context_course::instance($cm->course);
if (!is_enrolled($coursecontext, $userid, '', true) && !has_capability('moodle/course:view', $coursecontext, $userid)) {
return false;
}
}
// If availability is disabled, then all we need to do is check the visible flag.
if (!$CFG->enableavailability && $cm->visible) {
return true;
}
// When availability is enabled, access can depend on 3 things:
// 1. $cm->visible
// 2. $cm->availability
// 3. $section->availability (for activity section and possibly for
// parent sections)
// As a result we cannot take short cuts any longer and must get
// standard modinfo.
$modinfo = get_fast_modinfo($cm->course, $userid);
$cms = $modinfo->get_cms();
if (!isset($cms[$cm->id])) {
// In some cases this might get called with a cmid that is no longer
// available, for example when a module is hidden at system level.
debugging('info_module::is_user_visible called with invalid cmid ' . $cm->id, DEBUG_DEVELOPER);
return false;
}
return $cms[$cm->id]->uservisible;
}
示例2: is_user_visible
/**
* Checks if an activity is visible to the given user.
*
* Unlike other checks in the availability system, this check includes the
* $cm->visible flag and also (if enabled) the groupmembersonly feature.
* It is equivalent to $cm->uservisible.
*
* If you have already checked (or do not care whether) the user has access
* to the course, you can set $checkcourse to false to save it checking
* course access.
*
* When checking for the current user, you should generally not call
* this function. Instead, use get_fast_modinfo to get a cm_info object,
* then simply check the $cm->uservisible flag. This function is intended
* to obtain that information for a separate course-module object that
* wasn't loaded with get_fast_modinfo, or for a different user.
*
* This function has a performance cost unless the availability system is
* disabled, and you supply a $cm object with necessary fields, and you
* don't check course access.
*
* @param int|\stdClass|\cm_info $cmorid Object or id representing activity
* @param int $userid User id (0 = current user)
* @param bool $checkcourse If true, checks whether the user has course access
* @return bool True if the activity is visible to the specified user
* @throws \moodle_exception If the cmid doesn't exist
*/
public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true)
{
global $USER, $DB, $CFG;
// Evaluate user id.
if (!$userid) {
$userid = $USER->id;
}
// If this happens to be already called with a cm_info for the right user
// then just return uservisible.
if ($cmorid instanceof \cm_info && $cmorid->get_modinfo()->userid == $userid) {
return $cmorid->uservisible;
}
// If the $cmorid isn't an object or doesn't have required fields, load it.
if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
$cm = $cmorid;
} else {
if (is_object($cmorid)) {
$cmorid = $cmorid->id;
}
$cm = $DB->get_record('course_modules', array('id' => $cmorid), '*', MUST_EXIST);
}
// Check the groupmembersonly feature.
if (!groups_course_module_visible($cm, $userid)) {
return false;
}
// If requested, check user can access the course.
if ($checkcourse) {
$coursecontext = \context_course::instance($cm->course);
if (!is_enrolled($coursecontext, $userid, '', true) && !has_capability('moodle/course:view', $coursecontext, $userid)) {
return false;
}
}
// If availability is disabled, then all we need to do is check the visible flag.
if (!$CFG->enableavailability && $cm->visible) {
return true;
}
// When availability is enabled, access can depend on 3 things:
// 1. $cm->visible
// 2. $cm->availability
// 3. $section->availability (for activity section and possibly for
// parent sections)
// As a result we cannot take short cuts any longer and must get
// standard modinfo.
$modinfo = get_fast_modinfo($cm->course, $userid);
return $modinfo->get_cm($cm->id)->uservisible;
}