first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+279
View File
@@ -0,0 +1,279 @@
<?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/>.
/**
* Course completion criteria
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/completion/data_object.php');
require_once($CFG->dirroot.'/completion/completion_criteria_completion.php');
/**
* Self completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_SELF', 1);
/**
* Date completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_DATE', 2);
/**
* Unenrol completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_UNENROL', 3);
/**
* Activity completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_ACTIVITY', 4);
/**
* Duration completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_DURATION', 5);
/**
* Grade completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_GRADE', 6);
/**
* Role completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_ROLE', 7);
/**
* Course completion criteria type
* Criteria type constant, primarily for storing criteria type in the database.
*/
define('COMPLETION_CRITERIA_TYPE_COURSE', 8);
/**
* Criteria type constant to class name mapping.
*
* This global variable would be improved if it was implemented as a cache.
*/
global $COMPLETION_CRITERIA_TYPES;
$COMPLETION_CRITERIA_TYPES = array(
COMPLETION_CRITERIA_TYPE_SELF => 'self',
COMPLETION_CRITERIA_TYPE_DATE => 'date',
COMPLETION_CRITERIA_TYPE_UNENROL => 'unenrol',
COMPLETION_CRITERIA_TYPE_ACTIVITY => 'activity',
COMPLETION_CRITERIA_TYPE_DURATION => 'duration',
COMPLETION_CRITERIA_TYPE_GRADE => 'grade',
COMPLETION_CRITERIA_TYPE_ROLE => 'role',
COMPLETION_CRITERIA_TYPE_COURSE => 'course',
);
/**
* Completion criteria abstract definition
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class completion_criteria extends data_object {
/* @var string Database table name that stores completion criteria information */
public $table = 'course_completion_criteria';
/**
* Array of required table fields, must start with 'id'.
* Defaults to id, course, criteriatype, module, moduleinstane, courseinstance,
* enrolperiod, timeend, gradepass, role
* @var array
*/
public $required_fields = array('id', 'course', 'criteriatype', 'module', 'moduleinstance', 'courseinstance', 'enrolperiod', 'timeend', 'gradepass', 'role');
/* @var int Course id */
public $course;
/**
* Criteria type
* One of the COMPLETION_CRITERIA_TYPE_* constants
* @var int
*/
public $criteriatype;
/* @var string Module type this criteria relates to (for activity criteria) */
public $module;
/* @var int Course module instance id this criteria relates to (for activity criteria) */
public $moduleinstance;
/**
* Period after enrolment completion will be triggered (for period criteria)
* The value here is the number of days as an int.
* @var int
*/
public $enrolperiod;
/**
* Date of course completion (for date criteria)
* This is a timestamp value
* @var int
*/
public $date;
/* @var float Passing grade required to complete course (for grade completion) */
public $gradepass;
/* @var int Role ID that has the ability to mark a user as complete (for role completion) */
public $role;
/** @var string course instance. */
public $courseinstance;
/** @var mixed time end. */
public $timeend;
/**
* Finds and returns all data_object instances based on params.
*
* @param array $params associative arrays varname=>value
* @return array array of data_object insatnces or false if none found.
*/
public static function fetch_all($params) {}
/**
* Factory method for creating correct class object
*
* @param array $params associative arrays varname=>value
* @return completion_criteria
*/
public static function factory($params) {
global $CFG, $COMPLETION_CRITERIA_TYPES;
if (!isset($params['criteriatype']) || !isset($COMPLETION_CRITERIA_TYPES[$params['criteriatype']])) {
throw new \moodle_exception('invalidcriteriatype', 'completion');
}
$class = 'completion_criteria_'.$COMPLETION_CRITERIA_TYPES[$params['criteriatype']];
require_once($CFG->dirroot.'/completion/criteria/'.$class.'.php');
return new $class($params, false);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodleform $mform Moodle forms object
* @param mixed $data optional Any additional data that can be used to set default values in the form
* @return void
*/
abstract public function config_form_display(&$mform, $data = null);
/**
* Update the criteria information stored in the database
*
* @param array $data Form data
* @return void
*/
abstract public function update_config(&$data);
/**
* Review this criteria and decide if the user has completed
*
* @param object $completion The user's completion record
* @param boolean $mark Optionally set false to not save changes to database
* @return boolean
*/
abstract public function review($completion, $mark = true);
/**
* Return criteria title for display in reports
*
* @return string
*/
abstract public function get_title();
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
abstract public function get_title_detailed();
/**
* Return criteria type title for display in reports
*
* @return string
*/
abstract public function get_type_title();
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array
*/
abstract public function get_details($completion);
/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
global $COMPLETION_CRITERIA_TYPES;
$criteriatype = $COMPLETION_CRITERIA_TYPES[$this->criteriatype];
return new pix_icon('i/'.$criteriatype, $alt, 'moodle', $attributes);
}
/**
* Return criteria status text for display in reports
*
* @param completion_completion $completion The user's completion record
* @return string
*/
public function get_status($completion) {
return $completion->is_complete() ? get_string('yes') : get_string('no');
}
/**
* Return true if the criteria's current status is different to what is sorted
* in the database, e.g. pending an update
*
* @param completion_completion $completion The user's criteria completion record
* @return bool
*/
public function is_pending($completion) {
$review = $this->review($completion, false);
return $review !== $completion->is_complete();
}
}
@@ -0,0 +1,266 @@
<?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/>.
/**
* This file contains the activity completion criteria type class and any
* supporting functions it may require.
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - completion on activity completion
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_activity extends completion_criteria {
/* @var int Criteria [COMPLETION_CRITERIA_TYPE_ACTIVITY] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_ACTIVITY;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return completion_criteria_activity data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_ACTIVITY;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodleform $mform Moodle forms object
* @param stdClass $data details of various modules
*/
public function config_form_display(&$mform, $data = null) {
$modnames = get_module_types_names();
$mform->addElement('advcheckbox',
'criteria_activity['.$data->id.']',
$modnames[self::get_mod_name($data->module)] . ' - ' . format_string($data->name),
null,
array('group' => 1));
if ($this->id) {
$mform->setDefault('criteria_activity['.$data->id.']', 1);
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
global $DB;
if (!empty($data->criteria_activity) && is_array($data->criteria_activity)) {
$this->course = $data->id;
// Data comes from advcheckbox, so contains keys for all activities.
// A value of 0 is 'not checked' whereas 1 is 'checked'.
foreach ($data->criteria_activity as $activity => $val) {
// Only update those which are checked.
if (!empty($val)) {
$module = $DB->get_record('course_modules', array('id' => $activity));
$this->module = self::get_mod_name($module->module);
$this->moduleinstance = $activity;
$this->id = null;
$this->insert();
}
}
}
}
/**
* Get module instance module type
*
* @param int $type Module type id
* @return string
*/
public static function get_mod_name($type) {
static $types;
if (!is_array($types)) {
global $DB;
$types = $DB->get_records('modules');
}
return $types[$type]->name;
}
/**
* Gets the module instance from the database and returns it.
* If no module instance exists this function returns false.
*
* @return stdClass|bool
*/
public function get_mod_instance() {
global $DB;
return $DB->get_record_sql(
"
SELECT
m.*
FROM
{{$this->module}} m
INNER JOIN
{course_modules} cm
ON cm.id = {$this->moduleinstance}
AND m.id = cm.instance
"
);
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @return bool
*/
public function review($completion, $mark = true) {
global $DB;
$course = $DB->get_record('course', array('id' => $completion->course));
$cm = $DB->get_record('course_modules', array('id' => $this->moduleinstance));
$info = new completion_info($course);
$data = $info->get_data($cm, false, $completion->userid);
// If the activity is complete.
if (in_array($data->completionstate, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS])) {
if ($mark) {
$completion->mark_complete();
}
return true;
}
return false;
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('activitiescompleted', 'completion');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
global $DB;
$module = $DB->get_record('course_modules', array('id' => $this->moduleinstance));
$activity = $DB->get_record($this->module, array('id' => $module->instance));
return shorten_text(format_string($activity->name, true,
array('context' => context_module::instance($module->id))));
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('activities', 'completion');
}
/**
* Find users who have completed this criteria and mark them accordingly
*/
public function cron() {
\core_completion\api::mark_course_completions_activity_criteria();
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
// Get completion info
$modinfo = get_fast_modinfo($completion->course);
$cm = $modinfo->get_cm($this->moduleinstance);
$details = array();
$details['type'] = $this->get_title();
if ($cm->has_view()) {
$details['criteria'] = html_writer::link($cm->url, $cm->get_formatted_name());
} else {
$details['criteria'] = $cm->get_formatted_name();
}
// Build requirements
$details['requirement'] = array();
if ($cm->completion == COMPLETION_TRACKING_MANUAL) {
$details['requirement'][] = get_string('markingyourselfcomplete', 'completion');
} elseif ($cm->completion == COMPLETION_TRACKING_AUTOMATIC) {
if ($cm->completionview) {
$modulename = core_text::strtolower(get_string('modulename', $this->module));
$details['requirement'][] = get_string('viewingactivity', 'completion', $modulename);
}
if (!is_null($cm->completiongradeitemnumber)) {
$details['requirement'][] = get_string('achievinggrade', 'completion');
}
if ($cm->completionpassgrade) {
$details['requirement'][] = get_string('achievingpassinggrade', 'completion');
}
}
$details['requirement'] = implode(', ', $details['requirement']);
$details['status'] = '';
return $details;
}
/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('monologo', $alt, "mod_{$this->module}", $attributes);
}
}
@@ -0,0 +1,231 @@
<?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/>.
/**
* This file contains the course criteria type.
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - completion on course completion
*
* This course completion criteria depends on another course with
* completion enabled to be marked as complete for this user
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_course extends completion_criteria {
/* @var int Criteria type constant */
public $criteriatype = COMPLETION_CRITERIA_TYPE_COURSE;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return data_object instance of data_object or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_COURSE;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodle_form $mform Moodle forms object
* @param stdClass $data data used to define default value of the form
*/
public function config_form_display(&$mform, $data = null) {
global $CFG;
$link = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$data->id}\">".s($data->fullname).'</a>';
$mform->addElement('checkbox', 'criteria_course['.$data->id.']', $link);
if ($this->id) {
$mform->setDefault('criteria_course['.$data->id.']', 1);
}
}
/**
* Update the criteria information stored in the database
*
* @param array $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_course) && is_array($data->criteria_course)) {
$this->course = $data->id;
foreach ($data->criteria_course as $course) {
$this->courseinstance = $course;
$this->id = NULL;
$this->insert();
}
}
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @return bool
*/
public function review($completion, $mark = true) {
global $DB;
$course = $DB->get_record('course', array('id' => $this->courseinstance));
$info = new completion_info($course);
// If the course is complete
if ($info->is_course_complete($completion->userid)) {
if ($mark) {
$completion->mark_complete();
}
return true;
}
return false;
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('dependenciescompleted', 'completion');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
global $DB;
$prereq = $DB->get_record('course', array('id' => $this->courseinstance));
$coursecontext = context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
return shorten_text(urldecode($fullname));
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('dependencies', 'completion');
}
/**
* Find user's who have completed this criteria
*/
public function cron() {
global $DB;
// Get all users who meet this criteria
$sql = "
SELECT DISTINCT
c.id AS course,
cr.id AS criteriaid,
ra.userid AS userid,
cc.timecompleted AS timecompleted
FROM
{course_completion_criteria} cr
INNER JOIN
{course} c
ON cr.course = c.id
INNER JOIN
{context} con
ON con.instanceid = c.id
INNER JOIN
{role_assignments} ra
ON ra.contextid = con.id
INNER JOIN
{course_completions} cc
ON cc.course = cr.courseinstance
AND cc.userid = ra.userid
LEFT JOIN
{course_completion_crit_compl} ccc
ON ccc.criteriaid = cr.id
AND ccc.userid = ra.userid
WHERE
cr.criteriatype = ".COMPLETION_CRITERIA_TYPE_COURSE."
AND con.contextlevel = ".CONTEXT_COURSE."
AND c.enablecompletion = 1
AND ccc.id IS NULL
AND cc.timecompleted IS NOT NULL
";
// Loop through completions, and mark as complete
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array) $record, DATA_OBJECT_FETCH_BY_KEY);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
global $CFG, $DB;
// Get completion info
$course = new stdClass();
$course->id = $completion->course;
$info = new completion_info($course);
$prereq = $DB->get_record('course', array('id' => $this->courseinstance));
$coursecontext = context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
$prereq_info = new completion_info($prereq);
$details = array();
$details['type'] = $this->get_title();
$details['criteria'] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$this->courseinstance.'">'.s($fullname).'</a>';
$details['requirement'] = get_string('coursecompleted', 'completion');
$details['status'] = '<a href="'.$CFG->wwwroot.'/blocks/completionstatus/details.php?course='.$this->courseinstance.'">'.get_string('seedetails', 'completion').'</a>';
return $details;
}
}
@@ -0,0 +1,233 @@
<?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/>.
/**
* This file contains the date criteria type
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - completion on specified date
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_date extends completion_criteria {
/* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_DATE] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_DATE;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return data_object data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_DATE;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param MoodleQuickForm $mform Moodle forms object
* @param stdClass $data not used
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_date', get_string('enable'));
$mform->addElement('date_selector', 'criteria_date_value', get_string('completionondatevalue', 'core_completion'));
$mform->disabledIf('criteria_date_value', 'criteria_date');
// If instance of criteria exists
if ($this->id) {
$mform->setDefault('criteria_date', 1);
$mform->setDefault('criteria_date_value', $this->timeend);
} else {
$mform->setDefault('criteria_date_value', time() + 3600 * 24);
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_date)) {
$this->course = $data->id;
$this->timeend = $data->criteria_date_value;
$this->insert();
}
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @return bool
*/
public function review($completion, $mark = true) {
// If current time is past timeend
if ($this->timeend && $this->timeend < time()) {
if ($mark) {
$completion->mark_complete();
}
return true;
}
return false;
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('date');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
return userdate($this->timeend, get_string('strftimedatemonthabbr', 'core_langconfig'));
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('date');
}
/**
* Return criteria status text for display in reports
*
* @param completion_completion $completion The user's completion record
* @return string
*/
public function get_status($completion) {
return $completion->is_complete() ? get_string('yes') : userdate(
$this->timeend,
get_string('strftimedatemonthabbr', 'core_langconfig')
);
}
/**
* Find user's who have completed this criteria
*/
public function cron() {
global $DB;
// Get all users who match meet this criteria
$sql = '
SELECT DISTINCT
c.id AS course,
cr.timeend AS timeend,
cr.id AS criteriaid,
ra.userid AS userid
FROM
{course_completion_criteria} cr
INNER JOIN
{course} c
ON cr.course = c.id
INNER JOIN
{context} con
ON con.instanceid = c.id
INNER JOIN
{role_assignments} ra
ON ra.contextid = con.id
LEFT JOIN
{course_completion_crit_compl} cc
ON cc.criteriaid = cr.id
AND cc.userid = ra.userid
WHERE
cr.criteriatype = '.COMPLETION_CRITERIA_TYPE_DATE.'
AND con.contextlevel = '.CONTEXT_COURSE.'
AND c.enablecompletion = 1
AND cc.id IS NULL
AND cr.timeend < ?
';
// Loop through completions, and mark as complete
$rs = $DB->get_recordset_sql($sql, array(time()));
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array) $record, DATA_OBJECT_FETCH_BY_KEY);
$completion->mark_complete($record->timeend);
}
$rs->close();
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
$details = array();
$details['type'] = get_string('datepassed', 'completion');
$details['criteria'] = get_string('remainingenroleduntildate', 'completion');
$details['requirement'] = userdate($this->timeend, get_string('strftimedatemonthabbr', 'core_langconfig'));
$details['status'] = '';
return $details;
}
/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/calendar', $alt, 'moodle', $attributes);
}
/**
* Shift the date when resetting course.
*
* @param int $courseid the course id
* @param int $timeshift number of seconds to shift date
* @return boolean was the operation successful?
*/
public static function update_date($courseid, $timeshift) {
if ($criteria = self::fetch(array('course' => $courseid))) {
$criteria->timeend = $criteria->timeend + $timeshift;
$criteria->update();
}
}
}
@@ -0,0 +1,285 @@
<?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/>.
/**
* Course completion critieria - completion after specific duration from course enrolment
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - completion after specific duration from course enrolment
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_duration extends completion_criteria {
/* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_DURATION] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_DURATION;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return data_object data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_DURATION;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodleform $mform Moodle forms object
* @param stdClass $data not used
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_duration', get_string('enable'));
// Populate the duration length drop down.
$thresholdmenu = array(
// We have strings for 1 - 6 days in the core.
86400 => get_string('secondstotime86400', 'core'),
172800 => get_string('secondstotime172800', 'core'),
259200 => get_string('secondstotime259200', 'core'),
345600 => get_string('secondstotime345600', 'core'),
432000 => get_string('secondstotime432000', 'core'),
518400 => get_string('secondstotime518400', 'core'),
518400 => get_string('secondstotime518400', 'core'),
);
// Append strings for 7 - 30 days (step by 1 day).
for ($i = 7; $i <= 30; $i++) {
$seconds = $i * DAYSECS;
$thresholdmenu[$seconds] = get_string('numdays', 'core', $i);
}
// Append strings for 40 - 180 days (step by 10 days).
for ($i = 40; $i <= 180; $i = $i + 10) {
$seconds = $i * DAYSECS;
$thresholdmenu[$seconds] = get_string('numdays', 'core', $i);
}
// Append string for 1 year.
$thresholdmenu[365 * DAYSECS] = get_string('numdays', 'core', 365);
$mform->addElement('select', 'criteria_duration_days', get_string('enrolmentdurationlength', 'core_completion'), $thresholdmenu);
$mform->disabledIf('criteria_duration_days', 'criteria_duration');
if ($this->id) {
$mform->setDefault('criteria_duration', 1);
$mform->setDefault('criteria_duration_days', $this->enrolperiod);
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_duration)) {
$this->course = $data->id;
$this->enrolperiod = $data->criteria_duration_days;
$this->insert();
}
}
/**
* Get the time this user was enroled
*
* @param completion_completion $completion
* @return int
*/
private function get_timeenrolled($completion) {
global $DB;
return $DB->get_field_sql('
SELECT eu.timestart
FROM {user_enrolments} eu
JOIN {enrol} e ON eu.enrolid = e.id
WHERE e.courseid = ?
AND eu.userid = ?', array($this->course, $completion->userid));
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @return bool
*/
public function review($completion, $mark = true) {
$timeenrolled = $this->get_timeenrolled($completion);
// If duration since enrollment has passed
if (!$this->enrolperiod || !$timeenrolled) {
return false;
}
if (time() > ($timeenrolled + $this->enrolperiod)) {
if ($mark) {
$completion->mark_complete();
}
return true;
}
return false;
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('enrolmentduration', 'completion');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
return get_string('xdays', 'completion', ceil($this->enrolperiod / (60 * 60 * 24)));
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('days', 'completion');
}
/**
* Return criteria status text for display in reports
*
* @param completion_completion $completion The user's completion record
* @return string
*/
public function get_status($completion) {
$timeenrolled = $this->get_timeenrolled($completion);
$timeleft = $timeenrolled + $this->enrolperiod - time();
$enrolperiod = ceil($this->enrolperiod / (60 * 60 * 24));
$daysleft = ceil($timeleft / (60 * 60 * 24));
return get_string('daysoftotal', 'completion', array(
'days' => $daysleft > 0 ? $daysleft : 0, 'total' => $enrolperiod));
}
/**
* Find user's who have completed this criteria
*/
public function cron() {
global $DB;
/*
* Get all users who match meet this criteria
*
* We can safely ignore duplicate enrolments for
* a user in a course here as we only care if
* one of the enrolments has passed the set
* duration.
*/
$sql = '
SELECT
c.id AS course,
cr.id AS criteriaid,
u.id AS userid,
ue.timestart AS otimestart,
(ue.timestart + cr.enrolperiod) AS ctimestart,
ue.timecreated AS otimeenrolled,
(ue.timecreated + cr.enrolperiod) AS ctimeenrolled
FROM
{user} u
INNER JOIN
{user_enrolments} ue
ON ue.userid = u.id
INNER JOIN
{enrol} e
ON e.id = ue.enrolid
INNER JOIN
{course} c
ON c.id = e.courseid
INNER JOIN
{course_completion_criteria} cr
ON c.id = cr.course
LEFT JOIN
{course_completion_crit_compl} cc
ON cc.criteriaid = cr.id
AND cc.userid = u.id
WHERE
cr.criteriatype = '.COMPLETION_CRITERIA_TYPE_DURATION.'
AND c.enablecompletion = 1
AND cc.id IS NULL
AND
(
(ue.timestart > 0 AND (ue.timestart + cr.enrolperiod) < ?)
OR (ue.timestart = 0 AND ue.timecreated > 0 AND (ue.timecreated + cr.enrolperiod) < ?)
)
';
// Loop through completions, and mark as complete
$now = time();
$rs = $DB->get_recordset_sql($sql, array($now, $now));
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array) $record, DATA_OBJECT_FETCH_BY_KEY);
// Use time start if not 0, otherwise use timeenrolled
if ($record->otimestart) {
$completion->mark_complete($record->ctimestart);
} else {
$completion->mark_complete($record->ctimeenrolled);
}
}
$rs->close();
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
$details = array();
$details['type'] = get_string('periodpostenrolment', 'completion');
$details['criteria'] = get_string('remainingenroledfortime', 'completion');
$details['requirement'] = get_string('xdays', 'completion', ceil($this->enrolperiod / (60*60*24)));
// Get status
$timeenrolled = $this->get_timeenrolled($completion);
$timepassed = time() - $timeenrolled;
$details['status'] = get_string('xdays', 'completion', floor($timepassed / (60*60*24)));
return $details;
}
}
@@ -0,0 +1,275 @@
<?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/>.
/**
* Course completion critieria - completion on achieving course grade
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/querylib.php';
/**
* Course completion critieria - completion on achieving course grade
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_grade extends completion_criteria {
/* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_GRADE] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_GRADE;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative array varname => value of various
* parameters used to fetch data_object
* @return data_object data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_GRADE;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodle_form $mform Moodle forms object
* @param stdClass $data containing default values to be set in the form
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
$mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
$mform->disabledIf('criteria_grade_value', 'criteria_grade');
$mform->setType('criteria_grade_value', PARAM_RAW); // Uses unformat_float.
// Grades are stored in Moodle with 5 decimal points, make sure we do not accidentally round them
// when setting the form value.
$mform->setDefault('criteria_grade_value', format_float($data, 5));
if ($this->id) {
$mform->setDefault('criteria_grade', 1);
$mform->setDefault('criteria_grade_value', format_float($this->gradepass, 5));
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_grade)) {
$formatedgrade = unformat_float($data->criteria_grade_value);
// TODO validation
if (!empty($formatedgrade) && is_numeric($formatedgrade)) {
$this->course = $data->id;
$this->gradepass = $formatedgrade;
$this->insert();
}
}
}
/**
* Get user's course grade in this course
*
* @param completion_completion $completion an instance of completion_completion class
* @return float
*/
private function get_grade($completion) {
$grade = grade_get_course_grade($completion->userid, $this->course);
return $grade->grade;
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @return bool
*/
public function review($completion, $mark = true) {
// Get user's course grade
$grade = $this->get_grade($completion);
// If user's current course grade is higher than the required pass grade
if ($this->gradepass && $this->gradepass <= $grade) {
if ($mark) {
$completion->gradefinal = $grade;
$completion->mark_complete();
}
return true;
}
return false;
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('coursegrade', 'completion');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);
$graderequired = format_float($this->gradepass, $decimalpoints);
return get_string('gradexrequired', 'completion', $graderequired);
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('gradenoun');
}
/**
* Return criteria status text for display in reports
*
* @param completion_completion $completion The user's completion record
* @return string
*/
public function get_status($completion) {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);
$grade = $this->get_grade($completion);
$graderequired = $this->get_title_detailed();
if ($grade) {
$grade = format_float($grade, $decimalpoints);
} else {
$grade = get_string('nograde');
}
return $grade.' ('.$graderequired.')';
}
/**
* Find user's who have completed this criteria
*/
public function cron() {
global $DB;
// Get all users who meet this criteria
$sql = '
SELECT DISTINCT
c.id AS course,
cr.id AS criteriaid,
ra.userid AS userid,
gg.finalgrade AS gradefinal,
gg.timemodified AS timecompleted
FROM
{course_completion_criteria} cr
INNER JOIN
{course} c
ON cr.course = c.id
INNER JOIN
{context} con
ON con.instanceid = c.id
INNER JOIN
{role_assignments} ra
ON ra.contextid = con.id
INNER JOIN
{grade_items} gi
ON gi.courseid = c.id
AND gi.itemtype = \'course\'
INNER JOIN
{grade_grades} gg
ON gg.itemid = gi.id
AND gg.userid = ra.userid
LEFT JOIN
{course_completion_crit_compl} cc
ON cc.criteriaid = cr.id
AND cc.userid = ra.userid
WHERE
cr.criteriatype = '.COMPLETION_CRITERIA_TYPE_GRADE.'
AND con.contextlevel = '.CONTEXT_COURSE.'
AND c.enablecompletion = 1
AND cc.id IS NULL
AND gg.finalgrade >= cr.gradepass
';
// Loop through completions, and mark as complete
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array) $record, DATA_OBJECT_FETCH_BY_KEY);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
$decimalpoints = grade_get_setting($this->course, 'decimalpoints', $CFG->grade_decimalpoints);
$details = array();
$details['type'] = get_string('coursegrade', 'completion');
$details['criteria'] = get_string('graderequired', 'completion');
$details['requirement'] = format_float($this->gradepass, $decimalpoints);
$details['status'] = '';
$grade = format_float($this->get_grade($completion), $decimalpoints);
if ($grade) {
$details['status'] = $grade;
}
return $details;
}
/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/grades', $alt, 'moodle', $attributes);
}
}
@@ -0,0 +1,166 @@
<?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/>.
/**
* Course completion critieria - marked by role
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - marked by role
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_role extends completion_criteria {
/* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_ROLE] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_ROLE;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return data_object data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_ROLE;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param MoodleQuickForm $mform Moodle forms object
* @param stdClass $data used to set default values of the form
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_role['.$data->id.']', $this->get_title($data));
if ($this->id) {
$mform->setDefault('criteria_role['.$data->id.']', 1);
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_role) && is_array($data->criteria_role)) {
$this->course = $data->id;
foreach (array_keys($data->criteria_role) as $role) {
$this->role = $role;
$this->id = NULL;
$this->insert();
}
}
}
/**
* Mark this criteria as complete
*
* @param completion_completion $completion The user's completion record
*/
public function complete($completion) {
$this->review($completion, true, true);
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @param bool $is_complete Set to false if the criteria has been completed just now.
* @return bool
*/
public function review($completion, $mark = true, $is_complete = false) {
// If we are marking this as complete
if ($is_complete && $mark) {
$completion->completedself = 1;
$completion->mark_complete();
return true;
}
return $completion->is_complete();
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
global $DB;
$role = $DB->get_record('role', array('id' => $this->role));
if (!$role) {
return '['.get_string('roleidnotfound', 'completion', $this->role).']';
}
return role_get_name($role, context_course::instance($this->course));
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
return $this->get_title();
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('approval', 'completion');
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
$details = array();
$details['type'] = get_string('manualcompletionby', 'completion');
$details['criteria'] = $this->get_title();
$details['requirement'] = get_string('markedcompleteby', 'completion', $details['criteria']);
$details['status'] = '';
return $details;
}
}
@@ -0,0 +1,163 @@
<?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/>.
/**
* Course completion critieria - student self marked
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - student self marked
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_self extends completion_criteria {
/* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_SELF] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_SELF;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return data_object data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_SELF;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodleform $mform Moodle forms object
* @param stdClass $data Form data
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_self', get_string('enable'));
if ($this->id ) {
$mform->setDefault('criteria_self', 1);
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_self)) {
$this->course = $data->id;
$this->insert();
}
}
/**
* Mark this criteria as complete
*
* @param completion_completion $completion The user's completion record
*/
public function complete($completion) {
$this->review($completion, true, true);
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @param bool $is_complete set true to mark activity complete.
* @return bool
*/
public function review($completion, $mark = true, $is_complete = false) {
// If we are marking this as complete
if ($is_complete && $mark) {
$completion->completedself = 1;
$completion->mark_complete();
return true;
}
return $completion->is_complete();
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('selfcompletion', 'completion');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
return $this->get_title();
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('self', 'completion');
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
$details = array();
$details['type'] = $this->get_title();
$details['criteria'] = $this->get_title();
$details['requirement'] = get_string('markingyourselfcomplete', 'completion');
$details['status'] = '';
return $details;
}
/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/completion_self', $alt, 'moodle', $attributes);
}
}
@@ -0,0 +1,145 @@
<?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/>.
/**
* Course completion critieria - completion on unenrolment
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Course completion critieria - completion on unenrolment
*
* @package core_completion
* @category completion
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_criteria_unenrol extends completion_criteria {
/* @var int Criteria type constant [COMPLETION_CRITERIA_TYPE_UNENROL] */
public $criteriatype = COMPLETION_CRITERIA_TYPE_UNENROL;
/**
* Finds and returns a data_object instance based on params.
*
* @param array $params associative arrays varname=>value
* @return data_object data_object instance or false if none found.
*/
public static function fetch($params) {
$params['criteriatype'] = COMPLETION_CRITERIA_TYPE_UNENROL;
return self::fetch_helper('course_completion_criteria', __CLASS__, $params);
}
/**
* Add appropriate form elements to the critieria form
*
* @param moodleform $mform Moodle forms object
* @param stdClass $data Form data
*/
public function config_form_display(&$mform, $data = null) {
$mform->addElement('checkbox', 'criteria_unenrol', get_string('enable'));
if ($this->id) {
$mform->setDefault('criteria_unenrol', 1);
}
}
/**
* Update the criteria information stored in the database
*
* @param stdClass $data Form data
*/
public function update_config(&$data) {
if (!empty($data->criteria_unenrol)) {
$this->course = $data->id;
$this->insert();
}
}
/**
* Review this criteria and decide if the user has completed
*
* @param completion_completion $completion The user's completion record
* @param bool $mark Optionally set false to not save changes to database
* @return bool
*/
public function review($completion, $mark = true) {
// Check enrolment
return false;
}
/**
* Return criteria title for display in reports
*
* @return string
*/
public function get_title() {
return get_string('unenrol', 'enrol');
}
/**
* Return a more detailed criteria title for display in reports
*
* @return string
*/
public function get_title_detailed() {
return $this->get_title();
}
/**
* Return criteria type title for display in reports
*
* @return string
*/
public function get_type_title() {
return get_string('unenrol', 'enrol');
}
/**
* Return criteria progress details for display in reports
*
* @param completion_completion $completion The user's completion record
* @return array An array with the following keys:
* type, criteria, requirement, status
*/
public function get_details($completion) {
$details = array();
$details['type'] = get_string('unenrolment', 'completion');
$details['criteria'] = get_string('unenrolment', 'completion');
$details['requirement'] = get_string('unenrolingfromcourse', 'completion');
$details['status'] = '';
return $details;
}
/**
* Return pix_icon for display in reports.
*
* @param string $alt The alt text to use for the icon
* @param array $attributes html attributes
* @return pix_icon
*/
public function get_icon($alt, array $attributes = null) {
return new pix_icon('i/user', $alt, 'moodle', $attributes);
}
}