mirror of
https://github.com/moodle/moodle.git
synced 2025-07-23 07:11:28 +02:00
Includes all the conditions that were in previous Moodle versions: * Date * Grade * Completion (of another activity) * User profile field Also includes conditions that are used to reimplement groupmembersonly: * Grouping * Group For each condition, the component plus unit tests are included. PLEASE NOTE: The code to actually check each condition is reused from previous Moodle versions and has not been modified except to pass codechecker. This is intentional, to reduce the risk of the change and maximise the chance that behaviour is preserved. Some of this code might not be very good and might need updating but that can happen separately. AMOS BEGIN CPY [contains,core_condition],[op_contains,availability_profile] CPY [doesnotcontain,core_condition],[op_doesnotcontain,availability_profile] CPY [endswith,core_condition],[op_endswith,availability_profile] CPY [isempty,core_condition],[op_isempty,availability_profile] CPY [isequalto,core_condition],[op_isequalto,availability_profile] CPY [isnotempty,core_condition],[op_isnotempty,availability_profile] CPY [startswith,core_condition],[op_startswith,availability_profile] CPY [completion_fail,core_condition],[option_fail,availability_completion] CPY [completion_pass,core_condition],[option_pass,availability_completion] CPY [completion_complete,core_condition],[option_complete,availability_completion] CPY [completion_incomplete,core_condition],[option_incomplete,availability_completion] AMOS END
95 lines
3.4 KiB
PHP
95 lines
3.4 KiB
PHP
<?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/>.
|
|
|
|
/**
|
|
* Front-end class.
|
|
*
|
|
* @package availability_completion
|
|
* @copyright 2014 The Open University
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
namespace availability_completion;
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
/**
|
|
* Front-end class.
|
|
*
|
|
* @package availability_completion
|
|
* @copyright 2014 The Open University
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class frontend extends \core_availability\frontend {
|
|
/**
|
|
* @var array Cached init parameters
|
|
*/
|
|
protected $cacheparams = array();
|
|
|
|
/**
|
|
* @var string IDs of course, cm, and section for cache (if any)
|
|
*/
|
|
protected $cachekey = '';
|
|
|
|
protected function get_javascript_strings() {
|
|
return array('option_complete', 'option_fail', 'option_incomplete', 'option_pass',
|
|
'label_cm', 'label_completion');
|
|
}
|
|
|
|
protected function get_javascript_init_params($course, \cm_info $cm = null,
|
|
\section_info $section = null) {
|
|
// Use cached result if available. The cache is just because we call it
|
|
// twice (once from allow_add) so it's nice to avoid doing all the
|
|
// print_string calls twice.
|
|
$cachekey = $course->id . ',' . ($cm ? $cm->id : '') . ($section ? $section->id : '');
|
|
if ($cachekey !== $this->cachekey) {
|
|
// Get list of activities on course which have completion values,
|
|
// to fill the dropdown.
|
|
$context = \context_course::instance($course->id);
|
|
$cms = array();
|
|
$modinfo = get_fast_modinfo($course);
|
|
foreach ($modinfo->cms as $id => $othercm) {
|
|
// Add each course-module if it has completion turned on and is not
|
|
// the one currently being edited.
|
|
if ($othercm->completion && (empty($cm) || $cm->id != $id)) {
|
|
$cms[] = (object)array('id' => $id, 'name' =>
|
|
format_string($othercm->name, true, array('context' => $context)));
|
|
}
|
|
}
|
|
|
|
$this->cachekey = $cachekey;
|
|
$this->cacheinitparams = array($cms);
|
|
}
|
|
return $this->cacheinitparams;
|
|
}
|
|
|
|
protected function allow_add($course, \cm_info $cm = null,
|
|
\section_info $section = null) {
|
|
global $CFG;
|
|
|
|
// Check if completion is enabled for the course.
|
|
require_once($CFG->libdir . '/completionlib.php');
|
|
$info = new \completion_info($course);
|
|
if (!$info->is_enabled()) {
|
|
return false;
|
|
}
|
|
|
|
// Check if there's at least one other module with completion info.
|
|
$params = $this->get_javascript_init_params($course, $cm, $section);
|
|
return ((array)$params[0]) != false;
|
|
}
|
|
}
|