Skip to content

Commit

Permalink
MDL-24698 hopefully fixed all completion_info problems
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Nov 17, 2010
1 parent 2c0b6ab commit 516c5ec
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 32 deletions.
1 change: 1 addition & 0 deletions course/completion_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}

require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir.'/completionlib.php');

class course_completion_form extends moodleform {

Expand Down
4 changes: 2 additions & 2 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
defined('MOODLE_INTERNAL') || die;

require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir.'/completionlib.php');

class course_edit_form extends moodleform {
protected $course;
Expand Down Expand Up @@ -234,8 +235,7 @@ function definition() {
$mform->setDefault('lang', $courseconfig->lang);

//--------------------------------------------------------------------------------
require_once($CFG->libdir.'/completionlib.php');
if(completion_info::is_enabled_for_site()) {
if (completion_info::is_enabled_for_site()) {
$mform->addElement('header','', get_string('progress','completion'));
$mform->addElement('select', 'enablecompletion', get_string('completion','completion'),
array(0=>get_string('completiondisabled','completion'), 1=>get_string('completionenabled','completion')));
Expand Down
1 change: 1 addition & 0 deletions course/format/topics/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/completionlib.php');

$topic = optional_param('topic', -1, PARAM_INT);

Expand Down
1 change: 1 addition & 0 deletions course/format/weeks/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/completionlib.php');

$week = optional_param('week', -1, PARAM_INT);

Expand Down
4 changes: 2 additions & 2 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,7 @@ function average_number_of_participants() {
$sql = 'SELECT COUNT(*) FROM (
SELECT DISTINCT ue.userid, e.courseid
FROM {user_enrolments} ue, {enrol} e, {course} c
WHERE ue.enrolid = e.id
WHERE ue.enrolid = e.id
AND e.courseid <> :siteid
AND c.id = e.courseid
AND c.visible = 1) as total';
Expand Down Expand Up @@ -3731,7 +3731,7 @@ function average_number_of_courses_modules() {
$sql = 'SELECT COUNT(*) FROM (
SELECT cm.course, cm.module
FROM {course} c, {course_modules} cm
WHERE c.id = cm.course
WHERE c.id = cm.course
AND c.id <> :siteid
AND cm.visible = 1
AND c.visible = 1) as total';
Expand Down
4 changes: 1 addition & 3 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
require_once ($CFG->libdir.'/formslib.php');
if (!empty($CFG->enablecompletion) or !empty($CFG->enableavailability)) {
require_once($CFG->libdir.'/completionlib.php');
}
require_once($CFG->libdir.'/completionlib.php');

/**
* This class adds extra methods to form wrapper specific to be used for module
Expand Down
2 changes: 2 additions & 0 deletions course/report/completion/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
}

require_once($CFG->libdir.'/completionlib.php');

if (has_capability('coursereport/completion:view', $context)) {
$completion = new completion_info($course);
if ($completion->is_enabled() && $completion->has_criteria()) {
Expand Down
2 changes: 2 additions & 0 deletions course/report/progress/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page
}

require_once($CFG->libdir.'/completionlib.php');

if (has_capability('coursereport/progress:view', $context)) {
$completion = new completion_info($course);
if ($completion->is_enabled()) {
Expand Down
2 changes: 1 addition & 1 deletion course/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

require_once("../config.php");
require_once("lib.php");
require_once($CFG->libdir.'/completionlib.php');

$id = required_param('id',PARAM_INT); // course id
$user = required_param('user',PARAM_INT); // user id
Expand Down Expand Up @@ -355,7 +356,6 @@
case "coursecompletions":

// Display course completion user report
require_once $CFG->libdir.'/completionlib.php';

// Grab all courses the user is enrolled in and their completion status
$sql = "
Expand Down
1 change: 1 addition & 0 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once('../config.php');
require_once('lib.php');
require_once($CFG->dirroot.'/mod/forum/lib.php');
require_once($CFG->libdir.'/completionlib.php');

$id = optional_param('id', 0, PARAM_INT);
$name = optional_param('name', '', PARAM_RAW);
Expand Down
4 changes: 3 additions & 1 deletion lib/conditionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* to students ('conditional availability').
*
* @package core
* @subpackage completion
* @subpackage condition
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -40,6 +40,8 @@
/** The $cm variable is expected to contain nothing except the ID */
define('CONDITION_MISSING_EVERYTHING',2);

require_once($CFG->libdir.'/completionlib.php');

/**
* @global stdClass $CONDITIONLIB_PRIVATE
* @name $CONDITIONLIB_PRIVATE
Expand Down
2 changes: 2 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4151,6 +4151,7 @@ function delete_course($courseorid, $showfeedback = true) {
*/
function remove_course_contents($courseid, $showfeedback = true) {
global $CFG, $DB, $OUTPUT;
require_once($CFG->libdir.'/completionlib.php');
require_once($CFG->libdir.'/questionlib.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/group/lib.php');
Expand Down Expand Up @@ -4343,6 +4344,7 @@ function shift_course_mod_dates($modname, $fields, $timeshift, $courseid) {
function reset_course_userdata($data) {
global $CFG, $USER, $DB;
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/completionlib.php');
require_once($CFG->dirroot.'/group/lib.php');

$data->courseid = $data->id;
Expand Down
1 change: 1 addition & 0 deletions mod/chat/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/chat/lib.php');
require_once($CFG->libdir.'/completionlib.php');

$id = optional_param('id', 0, PARAM_INT);
$c = optional_param('c', 0, PARAM_INT);
Expand Down
10 changes: 7 additions & 3 deletions mod/choice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ function choice_prepare_options($choice, $user, $coursemodule, $allresponses) {
* @param object $cm
*/
function choice_user_submit_response($formanswer, $choice, $userid, $course, $cm) {
global $DB;
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

$current = $DB->get_record('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid));
$context = get_context_instance(CONTEXT_MODULE, $cm->id);

Expand Down Expand Up @@ -525,7 +527,9 @@ function prepare_choice_show_results($choice, $course, $cm, $allresponses, $forc
* @return bool
*/
function choice_delete_responses($attemptids, $choice, $cm, $course) {
global $DB;
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

if(!is_array($attemptids) || empty($attemptids)) {
return false;
}
Expand Down Expand Up @@ -841,7 +845,7 @@ function choice_get_completion_state($course, $cm, $userid, $type) {
$choice = $DB->get_record('choice', array('id'=>$cm->instance), '*',
MUST_EXIST);

// If completion option is enabled, evaluate it and return true/false
// If completion option is enabled, evaluate it and return true/false
if($choice->completionsubmit) {
return $DB->record_exists('choice_answers', array(
'choiceid'=>$choice->id, 'userid'=>$userid));
Expand Down
34 changes: 18 additions & 16 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
require_once($CFG->libdir.'/eventslib.php');
/** Include calendar/lib.php */
require_once($CFG->dirroot.'/calendar/lib.php');
/** Include completionlib.php */
require_once($CFG->libdir . '/completionlib.php');


define('FEEDBACK_ANONYMOUS_YES', 1);
define('FEEDBACK_ANONYMOUS_NO', 2);
Expand Down Expand Up @@ -438,7 +435,7 @@ function feedback_get_completion_state($course, $cm, $userid, $type) {
// Get feedback details
$feedback = $DB->get_record('feedback', array('id'=>$cm->instance), '*', MUST_EXIST);

// If completion option is enabled, evaluate it and return true/false
// If completion option is enabled, evaluate it and return true/false
if($feedback->completionsubmit) {
return $DB->record_exists('feedback_tracking', array('userid'=>$userid, 'feedback'=>$feedback->id));
} else {
Expand Down Expand Up @@ -1054,7 +1051,10 @@ function feedback_delete_template($id) {
* @param boolean $deleteold
*/
function feedback_items_from_template($feedback, $templateid, $deleteold = false) {
global $DB;
global $DB, $CFG;

require_once($CFG->libdir.'/completionlib.php');

$fs = get_file_storage();

//get all templateitems
Expand All @@ -1079,7 +1079,7 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
}
//delete tracking-data
$DB->delete_records('feedback_tracking', array('feedback'=>$feedback->id));

if($completeds = $DB->get_records('feedback_completed', array('feedback'=>$feedback->id))) {
$completion = new completion_info($course);
foreach($completeds as $completed) {
Expand Down Expand Up @@ -1368,20 +1368,21 @@ function feedback_delete_item($itemid, $renumber = true){
* @return void
*/
function feedback_delete_all_items($feedbackid){
global $DB;
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

if(!$feedback = $DB->get_record('feedback', array('id'=>$feedbackid))) {
return false;
}

if (!$cm = get_coursemodule_from_instance('feedback', $feedback->id)) {
return false;
}

if(!$course = $DB->get_record('course', array('id'=>$feedback->course))) {
return false;
}

if(!$items = $DB->get_records('feedback_item', array('feedback'=>$feedbackid))) {
return;
}
Expand All @@ -1399,9 +1400,9 @@ function feedback_delete_all_items($feedbackid){
$DB->delete_records('feedback_completed', array('id'=>$completed->id));
}
}

$DB->delete_records('feedback_completedtmp', array('feedback'=>$feedbackid));

}

/**
Expand Down Expand Up @@ -2333,20 +2334,21 @@ function feedback_delete_all_completeds($feedbackid) {
* @return boolean
*/
function feedback_delete_completed($completedid) {
global $DB;
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

if (!$completed = $DB->get_record('feedback_completed', array('id'=>$completedid))) {
return false;
}

if (!$feedback = $DB->get_record('feedback', array('id'=>$completed->feedback))) {
return false;
}

if (!$course = $DB->get_record('course', array('id'=>$feedback->course))) {
return false;
}

if (!$cm = get_coursemodule_from_instance('feedback', $feedback->id)) {
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
/** Include required files */
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/eventslib.php');
require_once($CFG->libdir . '/completionlib.php');
require_once($CFG->dirroot.'/user/selector/lib.php');

/// CONSTANTS ///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -4153,7 +4152,9 @@ function forum_add_discussion($discussion, $mform=null, &$message=null, $userid=
* @return bool
*/
function forum_delete_discussion($discussion, $fulldelete, $course, $cm, $forum) {
global $DB;
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

$result = true;

if ($posts = $DB->get_records("forum_posts", array("discussion" => $discussion->id))) {
Expand Down Expand Up @@ -4205,6 +4206,7 @@ function forum_delete_discussion($discussion, $fulldelete, $course, $cm, $forum)
*/
function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion=false) {
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

$context = get_context_instance(CONTEXT_MODULE, $cm->id);

Expand Down
1 change: 1 addition & 0 deletions mod/forum/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

require_once('../../config.php');
require_once('lib.php');
require_once($CFG->libdir.'/completionlib.php');

$reply = optional_param('reply', 0, PARAM_INT);
$forum = optional_param('forum', 0, PARAM_INT);
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

require_once('../../config.php');
require_once('lib.php');

require_once($CFG->libdir.'/completionlib.php');

$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$f = optional_param('f', 0, PARAM_INT); // Forum ID
Expand Down
1 change: 1 addition & 0 deletions mod/page/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

require('../../config.php');
require_once($CFG->dirroot.'/mod/page/locallib.php');
require_once($CFG->libdir.'/completionlib.php');

$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$p = optional_param('p', 0, PARAM_INT); // Page instance ID
Expand Down
2 changes: 2 additions & 0 deletions mod/resource/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ function resource_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
require_once("$CFG->libdir/filelib.php");
require_once("$CFG->dirroot/mod/resource/locallib.php");
require_once($CFG->libdir.'/completionlib.php');

$context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);

if (!$resource = $DB->get_record('resource', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions, tobemigrated, revision')) {
Expand Down
2 changes: 1 addition & 1 deletion mod/resource/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

require('../../config.php');
require_once($CFG->dirroot.'/mod/resource/locallib.php');
require_once($CFG->libdir.'/completionlib.php');

$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$r = optional_param('r', 0, PARAM_INT); // Resource instance ID
Expand Down Expand Up @@ -55,7 +56,6 @@
add_to_log($course->id, 'resource', 'view', 'view.php?id='.$cm->id, $resource->id, $cm->id);

// Update 'viewed' state if required by completion system
require_once($CFG->libdir . '/completionlib.php');
$completion = new completion_info($course);
$completion->set_module_viewed($cm);

Expand Down
1 change: 1 addition & 0 deletions mod/workshop/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->libdir.'/completionlib.php');

$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
$w = optional_param('w', 0, PARAM_INT); // workshop instance ID
Expand Down

0 comments on commit 516c5ec

Please sign in to comment.