MDL-44070 Conditional availability enhancements (6): core changes

Changes core code to use new API instead of the old one when
checking user access to activities and sections.

Includes changes to other libraries that are necessary after
adding the availability system and removing old conditional tables
etc.
This commit is contained in:
sam marshall 2014-03-26 12:01:52 +00:00
parent 6a601097a0
commit 8d1f33e122
14 changed files with 393 additions and 402 deletions

View file

@ -1522,6 +1522,11 @@ function get_all_instances_in_course($modulename, $course, $userid=NULL, $includ
* and the module's type (eg "forum") returns whether the object
* is visible or not, groupmembersonly visibility not tested
*
* NOTE: This does NOT take into account visibility to a particular user.
* To get visibility access for a specific user, use get_fast_modinfo, get a
* cm_info object from this, and check the ->uservisible property; or use
* the \core_availability\info_module::is_user_visible() static function.
*
* @global object
* @param $moduletype Name of the module eg 'forum'
@ -1548,46 +1553,6 @@ function instance_is_visible($moduletype, $module) {
return true; // visible by default!
}
/**
* Determine whether a course module is visible within a course,
* this is different from instance_is_visible() - faster and visibility for user
*
* @global object
* @global object
* @uses DEBUG_DEVELOPER
* @uses CONTEXT_MODULE
* @uses CONDITION_MISSING_EXTRATABLE
* @param object $cm object
* @param int $userid empty means current user
* @return bool Success
*/
function coursemodule_visible_for_user($cm, $userid=0) {
global $USER,$CFG;
if (empty($cm->id)) {
debugging("Incorrect course module parameter!", DEBUG_DEVELOPER);
return false;
}
if (empty($userid)) {
$userid = $USER->id;
}
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id), $userid)) {
return false;
}
if ($CFG->enableavailability) {
require_once($CFG->libdir.'/conditionlib.php');
$ci=new condition_info($cm,CONDITION_MISSING_EXTRATABLE);
if(!$ci->is_available($cm->availableinfo,false,$userid) and
!has_capability('moodle/course:viewhiddenactivities',
context_module::instance($cm->id), $userid)) {
return false;
}
}
return groups_course_module_visible($cm, $userid);
}
/// LOG FUNCTIONS /////////////////////////////////////////////////////