mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
Merge branch 'MDL-44985-master' of git://github.com/ankitagarwal/moodle
This commit is contained in:
commit
eb7ab07ef8
@ -26,7 +26,6 @@
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir . '/conditionlib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course_sections.id
|
||||
$sectionreturn = optional_param('sr', 0, PARAM_INT);
|
||||
|
@ -998,9 +998,6 @@ function get_array_of_activities($courseid) {
|
||||
// groupingid - grouping id
|
||||
// extra - contains extra string to include in any link
|
||||
global $CFG, $DB;
|
||||
if(!empty($CFG->enableavailability)) {
|
||||
require_once($CFG->libdir.'/conditionlib.php');
|
||||
}
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$courseid));
|
||||
|
||||
|
@ -28,7 +28,6 @@ require_once("lib.php");
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
require_once($CFG->libdir.'/conditionlib.php');
|
||||
require_once($CFG->libdir.'/plagiarismlib.php');
|
||||
require_once($CFG->dirroot . '/course/modlib.php');
|
||||
|
||||
|
@ -233,7 +233,7 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
']}';
|
||||
$coursegradeitem = grade_item::fetch_course_item($moduleinfo->course); //the activity will become available only when the user reach some grade into the course itself.
|
||||
$moduleinfo->conditiongradegroup = array(array('conditiongradeitemid' => $coursegradeitem->id, 'conditiongrademin' => 10, 'conditiongrademax' => 80));
|
||||
$moduleinfo->conditionfieldgroup = array(array('conditionfield' => 'email', 'conditionfieldoperator' => OP_CONTAINS, 'conditionfieldvalue' => '@'));
|
||||
$moduleinfo->conditionfieldgroup = array(array('conditionfield' => 'email', 'conditionfieldoperator' => \availability_profile\condition::OP_CONTAINS, 'conditionfieldvalue' => '@'));
|
||||
$moduleinfo->conditioncompletiongroup = array(array('conditionsourcecmid' => $assigncm->id, 'conditionrequiredcompletion' => COMPLETION_COMPLETE)); // "conditionsourcecmid == 0" => none
|
||||
|
||||
// Grading and Advanced grading.
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
require_once('../config.php');
|
||||
require_once('lib.php');
|
||||
require_once($CFG->libdir.'/conditionlib.php');
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
|
@ -15,12 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Used to be used for tracking conditions that apply before activities are
|
||||
* displayed to students ('conditional availability').
|
||||
*
|
||||
* Now replaced by the availability API. This library is a stub; some functions
|
||||
* still work while others throw exceptions. New code should not rely on the
|
||||
* classes, functions, or constants defined here.
|
||||
* DO NOT INCLUDE THIS FILE.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
@ -30,509 +25,5 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* CONDITION_STUDENTVIEW_HIDE - The activity is not displayed to students at all when conditions aren't met.
|
||||
*/
|
||||
define('CONDITION_STUDENTVIEW_HIDE', 0);
|
||||
/**
|
||||
* CONDITION_STUDENTVIEW_SHOW - The activity is displayed to students as a greyed-out name, with
|
||||
* informational text that explains the conditions under which it will be available.
|
||||
*/
|
||||
define('CONDITION_STUDENTVIEW_SHOW', 1);
|
||||
|
||||
/**
|
||||
* CONDITION_MISSING_NOTHING - The $item variable is expected to contain all completion-related data
|
||||
*/
|
||||
define('CONDITION_MISSING_NOTHING', 0);
|
||||
/**
|
||||
* CONDITION_MISSING_EXTRATABLE - The $item variable is expected to contain the fields from
|
||||
* the relevant table (course_modules or course_sections) but not the _availability data
|
||||
*/
|
||||
define('CONDITION_MISSING_EXTRATABLE', 1);
|
||||
/**
|
||||
* CONDITION_MISSING_EVERYTHING - The $item variable is expected to contain nothing except the ID
|
||||
*/
|
||||
define('CONDITION_MISSING_EVERYTHING', 2);
|
||||
|
||||
/**
|
||||
* OP_CONTAINS - comparison operator that determines whether a specified user field contains
|
||||
* a provided variable
|
||||
*/
|
||||
define('OP_CONTAINS', 'contains');
|
||||
/**
|
||||
* OP_DOES_NOT_CONTAIN - comparison operator that determines whether a specified user field does not
|
||||
* contain a provided variable
|
||||
*/
|
||||
define('OP_DOES_NOT_CONTAIN', 'doesnotcontain');
|
||||
/**
|
||||
* OP_IS_EQUAL_TO - comparison operator that determines whether a specified user field is equal to
|
||||
* a provided variable
|
||||
*/
|
||||
define('OP_IS_EQUAL_TO', 'isequalto');
|
||||
/**
|
||||
* OP_STARTS_WITH - comparison operator that determines whether a specified user field starts with
|
||||
* a provided variable
|
||||
*/
|
||||
define('OP_STARTS_WITH', 'startswith');
|
||||
/**
|
||||
* OP_ENDS_WITH - comparison operator that determines whether a specified user field ends with
|
||||
* a provided variable
|
||||
*/
|
||||
define('OP_ENDS_WITH', 'endswith');
|
||||
/**
|
||||
* OP_IS_EMPTY - comparison operator that determines whether a specified user field is empty
|
||||
*/
|
||||
define('OP_IS_EMPTY', 'isempty');
|
||||
/**
|
||||
* OP_IS_NOT_EMPTY - comparison operator that determines whether a specified user field is not empty
|
||||
*/
|
||||
define('OP_IS_NOT_EMPTY', 'isnotempty');
|
||||
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
/**
|
||||
* Core class to handle conditional activities.
|
||||
*
|
||||
* This class is now deprecated and partially functional. Public functions either
|
||||
* work and output deprecated messages or (in the case of the more obscure ones
|
||||
* which weren't really for public use, or those which can't be implemented in
|
||||
* the new API) throw exceptions.
|
||||
*
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
class condition_info extends condition_info_base {
|
||||
/**
|
||||
* Constructs with course-module details.
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @uses CONDITION_MISSING_NOTHING
|
||||
* @param object $cm Moodle course-module object. Required ->id, ->course
|
||||
* will save time, using a full cm_info will save more time
|
||||
* @param int $expectingmissing Used to control whether or not a developer
|
||||
* debugging message (performance warning) will be displayed if some of
|
||||
* the above data is missing and needs to be retrieved; a
|
||||
* CONDITION_MISSING_xx constant
|
||||
* @param bool $loaddata If you need a 'write-only' object, set this value
|
||||
* to false to prevent database access from constructor
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function __construct($cm, $expectingmissing = CONDITION_MISSING_NOTHING,
|
||||
$loaddata=true) {
|
||||
global $DB;
|
||||
debugging('The condition_info class is deprecated; change to \core_availability\info_module',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
// Check ID as otherwise we can't do the other queries.
|
||||
if (empty($cm->id)) {
|
||||
throw new coding_exception('Invalid parameters; item ID not included');
|
||||
}
|
||||
|
||||
// Load cm_info object.
|
||||
if (!($cm instanceof cm_info)) {
|
||||
// Get modinfo.
|
||||
if (empty($cm->course)) {
|
||||
$modinfo = get_fast_modinfo(
|
||||
$DB->get_field('course_modules', 'course', array('id' => $cm->id), MUST_EXIST));
|
||||
} else {
|
||||
$modinfo = get_fast_modinfo($cm->course);
|
||||
}
|
||||
|
||||
// Get $cm object.
|
||||
$cm = $modinfo->get_cm($cm->id);
|
||||
}
|
||||
|
||||
$this->item = $cm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the extra availability conditions (if any) into the given
|
||||
* course-module (or section) object.
|
||||
*
|
||||
* This function may be called statically (for the editing form) or
|
||||
* dynamically.
|
||||
*
|
||||
* @param object $cm Moodle course-module data object
|
||||
* @deprecated Since Moodle 2.7 (does nothing)
|
||||
*/
|
||||
public static function fill_availability_conditions($cm) {
|
||||
debugging('Calls to condition_info::fill_availability_conditions should be removed',
|
||||
DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the course-module object with full necessary data to determine availability.
|
||||
*
|
||||
* @return object Course-module object with full data
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function get_full_course_module() {
|
||||
debugging('Calls to condition_info::get_full_course_module should be removed',
|
||||
DEBUG_DEVELOPER);
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to update a table (which no longer exists) based on form data
|
||||
* (which is no longer used).
|
||||
*
|
||||
* Should only have been called from core code. Now removed (throws exception).
|
||||
*
|
||||
* @param object $cm Course-module with as much data as necessary, min id
|
||||
* @param object $fromform Data from form
|
||||
* @param bool $wipefirst If true, wipes existing conditions
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public static function update_cm_from_form($cm, $fromform, $wipefirst=true) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to be used in course/lib.php because we needed to disable the
|
||||
* completion JS if a completion value affects a conditional activity.
|
||||
*
|
||||
* Should only have been called from core code. Now removed (throws exception).
|
||||
*
|
||||
* @global stdClass $CONDITIONLIB_PRIVATE
|
||||
* @param object $course Moodle course object
|
||||
* @param object $item Moodle course-module
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public static function completion_value_used_as_condition($course, $cm) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles conditional access to sections.
|
||||
*
|
||||
* This class is now deprecated and partially functional. Public functions either
|
||||
* work and output deprecated messages or (in the case of the more obscure ones
|
||||
* which weren't really for public use, or those which can't be implemented in
|
||||
* the new API) throw exceptions.
|
||||
*
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
class condition_info_section extends condition_info_base {
|
||||
/**
|
||||
* Constructs with course-module details.
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @uses CONDITION_MISSING_NOTHING
|
||||
* @param object $section Moodle section object. Required ->id, ->course
|
||||
* will save time, using a full section_info will save more time
|
||||
* @param int $expectingmissing Used to control whether or not a developer
|
||||
* debugging message (performance warning) will be displayed if some of
|
||||
* the above data is missing and needs to be retrieved; a
|
||||
* CONDITION_MISSING_xx constant
|
||||
* @param bool $loaddata If you need a 'write-only' object, set this value
|
||||
* to false to prevent database access from constructor
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function __construct($section, $expectingmissing = CONDITION_MISSING_NOTHING,
|
||||
$loaddata=true) {
|
||||
global $DB;
|
||||
debugging('The condition_info_section class is deprecated; change to \core_availability\info_section',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
// Check ID as otherwise we can't do the other queries.
|
||||
if (empty($section->id)) {
|
||||
throw new coding_exception('Invalid parameters; item ID not included');
|
||||
}
|
||||
|
||||
// Load cm_info object.
|
||||
if (!($section instanceof section_info)) {
|
||||
// Get modinfo.
|
||||
if (empty($section->course)) {
|
||||
$modinfo = get_fast_modinfo(
|
||||
$DB->get_field('course_sections', 'course', array('id' => $section->id), MUST_EXIST));
|
||||
} else {
|
||||
$modinfo = get_fast_modinfo($section->course);
|
||||
}
|
||||
|
||||
// Get $cm object.
|
||||
foreach ($modinfo->get_section_info_all() as $possible) {
|
||||
if ($possible->id === $section->id) {
|
||||
$section = $possible;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->item = $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the extra availability conditions (if any) into the given
|
||||
* course-module (or section) object.
|
||||
*
|
||||
* This function may be called statically (for the editing form) or
|
||||
* dynamically.
|
||||
*
|
||||
* @param object $section Moodle section data object
|
||||
* @deprecated Since Moodle 2.7 (does nothing)
|
||||
*/
|
||||
public static function fill_availability_conditions($section) {
|
||||
debugging('Calls to condition_info_section::fill_availability_conditions should be removed',
|
||||
DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the section object with full necessary data to determine availability.
|
||||
*
|
||||
* @return section_info Section object with full data
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function get_full_section() {
|
||||
debugging('Calls to condition_info_section::get_full_section should be removed',
|
||||
DEBUG_DEVELOPER);
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function that used to be called by modedit.php; updated a
|
||||
* table (that no longer exists) based on the module form data.
|
||||
*
|
||||
* Should only have been called from core code. Now removed (throws exception).
|
||||
*
|
||||
* @param object $section Section object, must at minimum contain id
|
||||
* @param object $fromform Data from form
|
||||
* @param bool $wipefirst If true, wipes existing conditions
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public static function update_section_from_form($section, $fromform, $wipefirst=true) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base class to handle conditional items (course_modules or sections).
|
||||
*
|
||||
* This class is now deprecated and partially functional. Public functions either
|
||||
* work and output deprecated messages or (in the case of the more obscure ones
|
||||
* which weren't really for public use, or those which can't be implemented in
|
||||
* the new API) throw exceptions.
|
||||
*
|
||||
* @copyright 2012 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
abstract class condition_info_base {
|
||||
/** @var cm_info|section_info Item with availability data */
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* The operators that provide the relationship
|
||||
* between a field and a value.
|
||||
*
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public static function get_condition_user_field_operators() {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of user fields that can be compared.
|
||||
*
|
||||
* If you specify $formatoptions, then format_string will be called on the
|
||||
* custom field names. This is necessary for multilang support to work so
|
||||
* you should include this parameter unless you are going to format the
|
||||
* text later.
|
||||
*
|
||||
* @param array $formatoptions Passed to format_string if provided
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public static function get_condition_user_fields($formatoptions = null) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the database a condition based on completion of another module.
|
||||
*
|
||||
* Should only have been called from core and test code. Now removed
|
||||
* (throws exception).
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @param int $cmid ID of other module
|
||||
* @param int $requiredcompletion COMPLETION_xx constant
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public function add_completion_condition($cmid, $requiredcompletion) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds user fields condition
|
||||
*
|
||||
* Should only have been called from core and test code. Now removed
|
||||
* (throws exception).
|
||||
*
|
||||
* @param mixed $field numeric if it is a user profile field, character
|
||||
* if it is a column in the user table
|
||||
* @param int $operator specifies the relationship between field and value
|
||||
* @param char $value the value of the field
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public function add_user_field_condition($field, $operator, $value) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the database a condition based on the value of a grade item.
|
||||
*
|
||||
* Should only have been called from core and test code. Now removed
|
||||
* (throws exception).
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @param int $gradeitemid ID of grade item
|
||||
* @param float $min Minimum grade (>=), up to 5 decimal points, or null if none
|
||||
* @param float $max Maximum grade (<), up to 5 decimal points, or null if none
|
||||
* @param bool $updateinmemory If true, updates data in memory; otherwise,
|
||||
* memory version may be out of date (this has performance consequences,
|
||||
* so don't do it unless it really needs updating)
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public function add_grade_condition($gradeitemid, $min, $max, $updateinmemory=false) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases from the database all conditions for this activity.
|
||||
*
|
||||
* Should only have been called from core and test code. Now removed
|
||||
* (throws exception).
|
||||
*
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public function wipe_conditions() {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration point with new API; obtains the new class for this item.
|
||||
*
|
||||
* @return \core_availability\info Availability info for item
|
||||
*/
|
||||
protected function get_availability_info() {
|
||||
if ($this->item instanceof section_info) {
|
||||
return new \core_availability\info_section($this->item);
|
||||
} else {
|
||||
return new \core_availability\info_module($this->item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a string describing all availability restrictions (even if
|
||||
* they do not apply any more).
|
||||
*
|
||||
* @param course_modinfo|null $modinfo Usually leave as null for default. Specify when
|
||||
* calling recursively from inside get_fast_modinfo()
|
||||
* @return string Information string (for admin) about all restrictions on
|
||||
* this item
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function get_full_information($modinfo=null) {
|
||||
debugging('condition_info*::get_full_information() is deprecated, replace ' .
|
||||
'with new \core_availability\info_module($cm)->get_full_information()',
|
||||
DEBUG_DEVELOPER);
|
||||
return $this->get_availability_info()->get_full_information($modinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this particular item is currently available
|
||||
* according to these criteria.
|
||||
*
|
||||
* - This does not include the 'visible' setting (i.e. this might return
|
||||
* true even if visible is false); visible is handled independently.
|
||||
* - This does not take account of the viewhiddenactivities capability.
|
||||
* That should apply later.
|
||||
*
|
||||
* @uses COMPLETION_COMPLETE
|
||||
* @uses COMPLETION_COMPLETE_FAIL
|
||||
* @uses COMPLETION_COMPLETE_PASS
|
||||
* @param string $information If the item has availability restrictions,
|
||||
* a string that describes the conditions will be stored in this variable;
|
||||
* if this variable is set blank, that means don't display anything
|
||||
* @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 If set, specifies a different user ID to check availability for
|
||||
* @param course_modinfo|null $modinfo Usually leave as null for default. Specify when
|
||||
* calling recursively from inside get_fast_modinfo()
|
||||
* @return bool True if this item is available to the user, false otherwise
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function is_available(&$information, $grabthelot=false, $userid=0, $modinfo=null) {
|
||||
debugging('condition_info*::is_available() is deprecated, replace ' .
|
||||
'with new \core_availability\info_module($cm)->is_available()',
|
||||
DEBUG_DEVELOPER);
|
||||
return $this->get_availability_info()->is_available(
|
||||
$information, $grabthelot, $userid, $modinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether availability information should be shown to normal users.
|
||||
*
|
||||
* This information no longer makes sense with the new system because there
|
||||
* are multiple show options. (I doubt anyone much used this function anyhow!)
|
||||
*
|
||||
* @return bool True if information about availability should be shown to
|
||||
* normal users
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public function show_availability() {
|
||||
debugging('condition_info*::show_availability() is deprecated and there ' .
|
||||
'is no direct replacement (this is no longer a boolean value), ' .
|
||||
'please refactor code',
|
||||
DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to be called by grade code to inform the completion system when a
|
||||
* grade was changed.
|
||||
*
|
||||
* This function should not have ever been used outside the grade API, so
|
||||
* it now just throws an exception.
|
||||
*
|
||||
* @param grade_grade $grade
|
||||
* @param bool $deleted
|
||||
* @deprecated Since Moodle 2.7 (not available)
|
||||
* @throws Always throws a coding_exception
|
||||
*/
|
||||
public static function inform_grade_changed($grade, $deleted) {
|
||||
throw new coding_exception('Function no longer available');
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to be used for testing.
|
||||
*
|
||||
* @deprecated since 2.6
|
||||
*/
|
||||
public static function wipe_session_cache() {
|
||||
debugging('Calls to completion_info::wipe_session_cache should be removed', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the global cache
|
||||
*
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
public static function init_global_cache() {
|
||||
debugging('Calls to completion_info::init_globa_cache should be removed', DEBUG_DEVELOPER);
|
||||
}
|
||||
}
|
||||
throw new coding_exception('condition_info,condition_info_section,condition_info_base classes can not be used any more,
|
||||
please use respective classes from \core_availability namespace');
|
@ -3903,22 +3903,13 @@ function ajaxenabled(array $browsers = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a course module is visible within a course,
|
||||
* this is different from instance_is_visible() - faster and visibility for user
|
||||
* Determine whether a course module is visible within a course.
|
||||
*
|
||||
* @global object
|
||||
* @global object
|
||||
* @uses DEBUG_DEVELOPER
|
||||
* @uses CONTEXT_MODULE
|
||||
* @param object $cm object
|
||||
* @param int $userid empty means current user
|
||||
* @return bool Success
|
||||
* @deprecated Since Moodle 2.7
|
||||
* @deprecated Since Moodle 2.7 MDL-44070
|
||||
*/
|
||||
function coursemodule_visible_for_user($cm, $userid=0) {
|
||||
debugging('coursemodule_visible_for_user() deprecated since Moodle 2.7. ' .
|
||||
'Replace with \core_availability\info_module::is_user_visible().');
|
||||
return \core_availability\info_module::is_user_visible($cm, $userid, false);
|
||||
throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
|
||||
please use \core_availability\info_module::is_user_visible()');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1065,9 +1065,7 @@ class cm_info implements IteratorAggregate {
|
||||
'added' => false,
|
||||
'availability' => false,
|
||||
'available' => 'get_available',
|
||||
'availablefrom' => 'get_deprecated_available_date',
|
||||
'availableinfo' => 'get_available_info',
|
||||
'availableuntil' => 'get_deprecated_available_date',
|
||||
'completion' => false,
|
||||
'completionexpected' => false,
|
||||
'completiongradeitemnumber' => false,
|
||||
@ -1095,7 +1093,6 @@ class cm_info implements IteratorAggregate {
|
||||
'score' => false,
|
||||
'section' => false,
|
||||
'sectionnum' => false,
|
||||
'showavailability' => 'get_show_availability',
|
||||
'showdescription' => false,
|
||||
'uservisible' => 'get_user_visible',
|
||||
'visible' => false,
|
||||
@ -1185,9 +1182,6 @@ class cm_info implements IteratorAggregate {
|
||||
|
||||
// Do not iterate over deprecated properties.
|
||||
$props = self::$standardproperties;
|
||||
unset($props['showavailability']);
|
||||
unset($props['availablefrom']);
|
||||
unset($props['availableuntil']);
|
||||
unset($props['groupmembersonly']);
|
||||
|
||||
foreach ($props as $key => $unused) {
|
||||
@ -1798,7 +1792,6 @@ class cm_info implements IteratorAggregate {
|
||||
$this->state = self::STATE_BUILDING_DYNAMIC;
|
||||
|
||||
if (!empty($CFG->enableavailability)) {
|
||||
require_once($CFG->libdir. '/conditionlib.php');
|
||||
// Get availability information.
|
||||
$ci = new \core_availability\info_module($this);
|
||||
|
||||
@ -1847,35 +1840,6 @@ class cm_info implements IteratorAggregate {
|
||||
return $this->available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property $showavailability. Works by checking the
|
||||
* availableinfo property to see if it's empty or not.
|
||||
*
|
||||
* @return int
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
private function get_show_availability() {
|
||||
debugging('$cm->showavailability property has been deprecated. You ' .
|
||||
'can replace it by checking if $cm->availableinfo has content.',
|
||||
DEBUG_DEVELOPER);
|
||||
return ($this->get_available_info() !== '') ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for $availablefrom and $availableuntil. Just returns zero
|
||||
* as these are no longer supported.
|
||||
*
|
||||
* @return int Zero
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
private function get_deprecated_available_date() {
|
||||
debugging('$cm->availablefrom and $cm->availableuntil have been deprecated. This ' .
|
||||
'information is no longer available as the system provides more complex ' .
|
||||
'options (for example, there might be different dates for different users).',
|
||||
DEBUG_DEVELOPER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for $availablefrom and $availableuntil. Just returns zero
|
||||
* as these are no longer supported.
|
||||
@ -1906,7 +1870,6 @@ class cm_info implements IteratorAggregate {
|
||||
*
|
||||
* If the activity is unavailable, additional checks are required to determine if its hidden or greyed out
|
||||
*
|
||||
* @see is_user_access_restricted_by_conditional_access()
|
||||
* @return void
|
||||
*/
|
||||
private function update_user_visible() {
|
||||
@ -1975,33 +1938,13 @@ class cm_info implements IteratorAggregate {
|
||||
* Checks whether the module's conditional access settings mean that the
|
||||
* user cannot see the activity at all
|
||||
*
|
||||
* This is deprecated because it is confusing (name sounds like it's about
|
||||
* access restriction but it is actually about display), is not used
|
||||
* anywhere, and is not necessary. Nobody (outside conditional libraries)
|
||||
* should care what it is that restricted something.
|
||||
*
|
||||
* @return bool True if the user cannot see the module. False if the activity is either available or should be greyed out.
|
||||
* @deprecated since 2.7
|
||||
* @deprecated since 2.7 MDL-44070
|
||||
*/
|
||||
public function is_user_access_restricted_by_conditional_access() {
|
||||
global $CFG;
|
||||
debugging('cm_info::is_user_access_restricted_by_conditional_access() ' .
|
||||
'is deprecated; this function is not needed (use $cm->uservisible ' .
|
||||
throw new coding_exception('cm_info::is_user_access_restricted_by_conditional_access() ' .
|
||||
'can not be used any more; this function is not needed (use $cm->uservisible ' .
|
||||
'and $cm->availableinfo to decide whether it should be available ' .
|
||||
'or appear)', DEBUG_DEVELOPER);
|
||||
|
||||
if (empty($CFG->enableavailability)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$userid = $this->modinfo->get_user_id();
|
||||
if ($userid == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return false if user can access the activity, or if its availability
|
||||
// info is set (= should be displayed even though not accessible).
|
||||
return !$this->get_user_visible() && !$this->get_available_info();
|
||||
'or appear)');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2698,7 +2641,6 @@ class section_info implements IteratorAggregate {
|
||||
$this->_available = true;
|
||||
$this->_availableinfo = '';
|
||||
if (!empty($CFG->enableavailability)) {
|
||||
require_once($CFG->libdir. '/conditionlib.php');
|
||||
// Get availability information.
|
||||
$ci = new \core_availability\info_section($this);
|
||||
$this->_available = $ci->is_available($this->_availableinfo, true,
|
||||
@ -2772,62 +2714,6 @@ class section_info implements IteratorAggregate {
|
||||
return $this->_uservisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for property $showavailability. Works by checking the
|
||||
* availableinfo property to see if it's empty or not.
|
||||
*
|
||||
* @return int
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
private function get_showavailability() {
|
||||
debugging('$section->showavailability property has been deprecated. You ' .
|
||||
'can replace it by checking if $section->availableinfo has content.',
|
||||
DEBUG_DEVELOPER);
|
||||
return ($this->get_availableinfo() !== '') ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for $availablefrom. Just returns zero as no longer supported.
|
||||
*
|
||||
* @return int Zero
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
private function get_availablefrom() {
|
||||
debugging('$section->availablefrom has been deprecated. This ' .
|
||||
'information is no longer available as the system provides more complex ' .
|
||||
'options (for example, there might be different dates for different users).',
|
||||
DEBUG_DEVELOPER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for $availablefrom. Just returns zero as no longer supported.
|
||||
*
|
||||
* @return int Zero
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
private function get_availableuntil() {
|
||||
debugging('$section->availableuntil has been deprecated. This ' .
|
||||
'information is no longer available as the system provides more complex ' .
|
||||
'options (for example, there might be different dates for different users).',
|
||||
DEBUG_DEVELOPER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for $groupingid. Just returns zero as no longer supported.
|
||||
*
|
||||
* @return int Zero
|
||||
* @deprecated Since Moodle 2.7
|
||||
*/
|
||||
private function get_groupingid() {
|
||||
debugging('$section->groupingid has been deprecated. This ' .
|
||||
'information is no longer available as the system provides more complex ' .
|
||||
'options (for example, combining multiple groupings).',
|
||||
DEBUG_DEVELOPER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the course_sections.sequence value
|
||||
*
|
||||
|
@ -1,214 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for deprecated conditional activities classes.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/lib/conditionlib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Tests for deprecated conditional activities classes.
|
||||
*
|
||||
* @package core_availability
|
||||
* @copyright 2014 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
*/
|
||||
class core_conditionlib_testcase extends advanced_testcase {
|
||||
|
||||
protected function setUp() {
|
||||
global $CFG;
|
||||
parent::setUp();
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$CFG->enableavailability = 1;
|
||||
$CFG->enablecompletion = 1;
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
}
|
||||
|
||||
public function test_constructor() {
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course();
|
||||
$page = $generator->get_plugin_generator('mod_page')->create_instance(
|
||||
array('course' => $course));
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
// No ID.
|
||||
try {
|
||||
$test = new condition_info((object)array());
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
// Do nothing.
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
// Get actual cm_info for comparison.
|
||||
$realcm = $modinfo->get_cm($page->cmid);
|
||||
|
||||
// No other data.
|
||||
$test = new condition_info((object)array('id' => $page->cmid));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals($realcm, $test->get_full_course_module());
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Course id.
|
||||
$test = new condition_info((object)array('id' => $page->cmid, 'course' => $course->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals($realcm, $test->get_full_course_module());
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Full cm.
|
||||
$test = new condition_info($realcm);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals($realcm, $test->get_full_course_module());
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as above test but for course_sections instead of course_modules.
|
||||
*/
|
||||
public function test_section_constructor() {
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course(
|
||||
array('numsections' => 1), array('createsections' => true));
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
// No ID.
|
||||
try {
|
||||
$test = new condition_info_section(((object)array()));
|
||||
$this->fail();
|
||||
} catch (coding_exception $e) {
|
||||
// Do nothing.
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
// Get actual cm_info for comparison.
|
||||
$realsection = $modinfo->get_section_info(1);
|
||||
|
||||
// No other data.
|
||||
$test = new condition_info_section((object)array('id' => $realsection->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals($realsection, $test->get_full_section());
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Course id.
|
||||
$test = new condition_info_section((object)array('id' => $realsection->id,
|
||||
'course' => $course->id));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals($realsection, $test->get_full_section());
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Full object.
|
||||
$test = new condition_info_section($realsection);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals($realsection, $test->get_full_section());
|
||||
$this->assertDebuggingCalled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the is_available function for modules. This does not test all the
|
||||
* conditions and stuff, because it only needs to check that the system
|
||||
* connects through to the real availability API. Also tests
|
||||
* get_full_information function.
|
||||
*/
|
||||
public function test_is_available() {
|
||||
// Create course.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course();
|
||||
|
||||
// Create activity with no restrictions and one with date restriction.
|
||||
$page1 = $generator->get_plugin_generator('mod_page')->create_instance(
|
||||
array('course' => $course));
|
||||
$time = time() + 100;
|
||||
$avail = '{"op":"|","show":true,"c":[{"type":"date","d":">=","t":' . $time . '}]}';
|
||||
$page2 = $generator->get_plugin_generator('mod_page')->create_instance(
|
||||
array('course' => $course, 'availability' => $avail));
|
||||
|
||||
// No conditions.
|
||||
$ci = new condition_info((object)array('id' => $page1->cmid),
|
||||
CONDITION_MISSING_EVERYTHING);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertTrue($ci->is_available($text, false, 0));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals('', $text);
|
||||
|
||||
// Date condition.
|
||||
$ci = new condition_info((object)array('id' => $page2->cmid),
|
||||
CONDITION_MISSING_EVERYTHING);
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertFalse($ci->is_available($text));
|
||||
$this->assertDebuggingCalled();
|
||||
$expectedtime = userdate($time, get_string('strftimedate', 'langconfig'));
|
||||
$this->assertContains($expectedtime, $text);
|
||||
|
||||
// Full information display.
|
||||
$text = $ci->get_full_information();
|
||||
$this->assertDebuggingCalled();
|
||||
$expectedtime = userdate($time, get_string('strftimedate', 'langconfig'));
|
||||
$this->assertContains($expectedtime, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the is_available function for sections.
|
||||
*/
|
||||
public function test_section_is_available() {
|
||||
global $DB;
|
||||
|
||||
// Create course.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $generator->create_course(
|
||||
array('numsections' => 2), array('createsections' => true));
|
||||
|
||||
// Set one of the sections unavailable.
|
||||
$time = time() + 100;
|
||||
$avail = '{"op":"|","show":true,"c":[{"type":"date","d":">=","t":' . $time . '}]}';
|
||||
$DB->set_field('course_sections', 'availability', $avail, array(
|
||||
'course' => $course->id, 'section' => 2));
|
||||
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
|
||||
// No conditions.
|
||||
$ci = new condition_info_section($modinfo->get_section_info(1));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertTrue($ci->is_available($text, false, 0));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertEquals('', $text);
|
||||
|
||||
// Date condition.
|
||||
$ci = new condition_info_section($modinfo->get_section_info(2));
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertFalse($ci->is_available($text));
|
||||
$this->assertDebuggingCalled();
|
||||
$expectedtime = userdate($time, get_string('strftimedate', 'langconfig'));
|
||||
$this->assertContains($expectedtime, $text);
|
||||
|
||||
// Full information display.
|
||||
$text = $ci->get_full_information();
|
||||
$this->assertDebuggingCalled();
|
||||
$expectedtime = userdate($time, get_string('strftimedate', 'langconfig'));
|
||||
$this->assertContains($expectedtime, $text);
|
||||
}
|
||||
}
|
@ -26,7 +26,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/modinfolib.php');
|
||||
require_once($CFG->libdir . '/conditionlib.php');
|
||||
|
||||
/**
|
||||
* Unit tests for modinfolib.php
|
||||
@ -416,88 +415,6 @@ class core_modinfolib_testcase extends advanced_testcase {
|
||||
$this->assertNotEquals('Illegal overwriting', $modinfo->cms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is_user_access_restricted_by_conditional_access()
|
||||
*
|
||||
* The underlying conditional access system is more thoroughly tested in lib/tests/conditionlib_test.php
|
||||
*/
|
||||
public function test_is_user_access_restricted_by_conditional_access() {
|
||||
global $DB, $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Enable conditional availability before creating modules, otherwise the condition data is not written in DB.
|
||||
$CFG->enableavailability = true;
|
||||
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// 1. Create an activity that is currently unavailable and hidden entirely (for students).
|
||||
$assign1 = $this->getDataGenerator()->create_module('assign', array('course'=>$course->id),
|
||||
array('availability' => '{"op":"|","show":false,"c":[' .
|
||||
'{"type":"date","d":">=","t":' . (time() + 10000) . '}]}'));
|
||||
// 2. Create an activity that is currently available.
|
||||
$assign2 = $this->getDataGenerator()->create_module('assign', array('course'=>$course->id));
|
||||
// 3. Create an activity that is currently unavailable and set to be greyed out.
|
||||
$assign3 = $this->getDataGenerator()->create_module('assign', array('course'=>$course->id),
|
||||
array('availability' => '{"op":"|","show":true,"c":[' .
|
||||
'{"type":"date","d":">=","t":' . (time() + 10000) . '}]}'));
|
||||
|
||||
// Set up a teacher.
|
||||
$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);
|
||||
|
||||
// If conditional availability is disabled the activity will always be unrestricted.
|
||||
$CFG->enableavailability = false;
|
||||
$cm = get_fast_modinfo($course)->instances['assign'][$assign1->id];
|
||||
$this->assertTrue($cm->uservisible);
|
||||
|
||||
// Test deprecated function.
|
||||
$this->assertFalse($cm->is_user_access_restricted_by_conditional_access());
|
||||
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
|
||||
phpunit_util::reset_debugging();
|
||||
|
||||
// Turn on conditional availability and reset the get_fast_modinfo cache.
|
||||
$CFG->enableavailability = true;
|
||||
get_fast_modinfo($course, 0, true);
|
||||
|
||||
// The unavailable, hidden entirely activity should now be restricted.
|
||||
$cm = get_fast_modinfo($course)->instances['assign'][$assign1->id];
|
||||
$this->assertFalse($cm->uservisible);
|
||||
$this->assertFalse($cm->available);
|
||||
$this->assertEquals('', $cm->availableinfo);
|
||||
|
||||
// Test deprecated function.
|
||||
$this->assertTrue($cm->is_user_access_restricted_by_conditional_access());
|
||||
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
|
||||
phpunit_util::reset_debugging();
|
||||
|
||||
// If the activity is available it should not be restricted.
|
||||
$cm = get_fast_modinfo($course)->instances['assign'][$assign2->id];
|
||||
$this->assertTrue($cm->uservisible);
|
||||
$this->assertTrue($cm->available);
|
||||
|
||||
// If the activity is unavailable and set to be greyed out it should not be restricted.
|
||||
$cm = get_fast_modinfo($course)->instances['assign'][$assign3->id];
|
||||
$this->assertFalse($cm->uservisible);
|
||||
$this->assertFalse($cm->available);
|
||||
$this->assertNotEquals('', (string)$cm->availableinfo);
|
||||
|
||||
// Test deprecated function (weird case, it actually checks visibility).
|
||||
$this->assertFalse($cm->is_user_access_restricted_by_conditional_access());
|
||||
$this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
|
||||
phpunit_util::reset_debugging();
|
||||
|
||||
// If the activity is unavailable and set to be hidden entirely its restricted unless user has 'moodle/course:viewhiddenactivities'.
|
||||
// Switch to a teacher and reload the context info.
|
||||
$this->setUser($teacher);
|
||||
$this->assertTrue(has_capability('moodle/course:viewhiddenactivities', $coursecontext));
|
||||
$cm = get_fast_modinfo($course)->instances['assign'][$assign1->id];
|
||||
$this->assertTrue($cm->uservisible);
|
||||
$this->assertFalse($cm->available);
|
||||
}
|
||||
|
||||
public function test_is_user_access_restricted_by_capability() {
|
||||
global $DB;
|
||||
|
||||
@ -747,75 +664,6 @@ class core_modinfolib_testcase extends advanced_testcase {
|
||||
$this->assertNull($section->availability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Some properties have been deprecated from both the section and module
|
||||
* classes. This checks they still work (and show warnings).
|
||||
*/
|
||||
public function test_availability_deprecations() {
|
||||
global $CFG, $DB;
|
||||
$this->resetAfterTest();
|
||||
$CFG->enableavailability = true;
|
||||
|
||||
// Create a course with two modules. The modules are not available to
|
||||
// users. One of them is set to show this information, the other is not.
|
||||
// Same setup for sections.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $this->getDataGenerator()->create_course(
|
||||
array('format' => 'topics', 'numsections' => 2),
|
||||
array('createsections' => true));
|
||||
$show = '{"op":"|","show":true,"c":[{"type":"date","d":"<","t":1395857332}]}';
|
||||
$noshow = '{"op":"|","show":false,"c":[{"type":"date","d":"<","t":1395857332}]}';
|
||||
$forum1 = $generator->create_module('forum',
|
||||
array('course' => $course->id, 'availability' => $show));
|
||||
$forum2 = $generator->create_module('forum',
|
||||
array('course' => $course->id, 'availability' => $noshow));
|
||||
$DB->set_field('course_sections', 'availability',
|
||||
$show, array('course' => $course->id, 'section' => 1));
|
||||
$DB->set_field('course_sections', 'availability',
|
||||
$noshow, array('course' => $course->id, 'section' => 2));
|
||||
|
||||
// Create a user without special permissions.
|
||||
$user = $generator->create_user();
|
||||
$generator->enrol_user($user->id, $course->id);
|
||||
|
||||
// Get modinfo and cm objects.
|
||||
$modinfo = get_fast_modinfo($course, $user->id);
|
||||
$cm1 = $modinfo->get_cm($forum1->cmid);
|
||||
$cm2 = $modinfo->get_cm($forum2->cmid);
|
||||
|
||||
// Check the showavailability property.
|
||||
$this->assertEquals(1, $cm1->showavailability);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
$this->assertEquals(0, $cm2->showavailability);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
|
||||
// Check the dates (these always return 0 now).
|
||||
$this->assertEquals(0, $cm1->availablefrom);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
$this->assertEquals(0, $cm1->availableuntil);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
|
||||
// Get section objects.
|
||||
$section1 = $modinfo->get_section_info(1);
|
||||
$section2 = $modinfo->get_section_info(2);
|
||||
|
||||
// Check showavailability.
|
||||
$this->assertEquals(1, $section1->showavailability);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
$this->assertEquals(0, $section2->showavailability);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
|
||||
// Check dates (zero).
|
||||
$this->assertEquals(0, $section1->availablefrom);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
$this->assertEquals(0, $section1->availableuntil);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
|
||||
// Check groupingid (zero).
|
||||
$this->assertEquals(0, $section1->groupingid);
|
||||
$this->assertDebuggingCalled(null, DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for get_groups() method.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user