Skip to content

Commit

Permalink
MDL-16235 yet more ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 27, 2008
1 parent 0d5d12b commit d7d8753
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/completionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ public static function is_enabled_for_site() {
* for a course-module.
*/
public function is_enabled($cm=null) {
// First check global completion
global $CFG;

// First check global completion
if ($CFG->enablecompletion == COMPLETION_DISABLED) {
return COMPLETION_DISABLED;
}
Expand Down Expand Up @@ -160,6 +161,7 @@ public function is_enabled($cm=null) {
*/
public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0) {
global $USER, $SESSION;

// Do nothing if completion is not enabled for that activity
if (!$this->is_enabled($cm)) {
return;
Expand All @@ -186,6 +188,7 @@ public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0)
default:
$this->internal_systemerror("Unexpected manual completion state for {$cm->id}: $possibleresult");
}

} else {
// Automatic tracking; get new state
$newstate = $this->internal_get_state($cm, $userid, $current);
Expand All @@ -210,8 +213,9 @@ public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0)
* @return unknown
*/
function internal_get_state($cm, $userid, $current) {
// Get user ID
global $USER, $DB;

// Get user ID
if (!$userid) {
$userid = $USER->id;
}
Expand Down Expand Up @@ -250,6 +254,7 @@ function internal_get_state($cm, $userid, $current) {
if ($newstate == COMPLETION_INCOMPLETE) {
return COMPLETION_INCOMPLETE;
}

} else {
$this->internal_systemerror("Cannot find grade item for '{$cm->modname}'
cm '{$cm->id}' matching number '{$cm->completiongradeitemnumber}'");
Expand Down Expand Up @@ -355,11 +360,12 @@ public function delete_all_state($cm) {
* @param object $cm Activity
*/
public function reset_all_state($cm) {
global $DB;

if ($cm->completion == COMPLETION_TRACKING_MANUAL) {
$this->delete_all_state($cm);
return;
}
global $DB;
// Get current list of users with completion state
$rs = $DB->get_recordset('course_modules_completion', array('coursemoduleid'=>$cm->id), '', 'userid');
$keepusers = array();
Expand Down Expand Up @@ -400,8 +406,9 @@ public function reset_all_state($cm) {
* found on the specified course
*/
public function get_data($cm, $wholecourse=false, $userid=0, $modinfo=null) {
// Get user ID
global $USER, $CFG, $SESSION, $DB;

// Get user ID
if (!$userid) {
$userid = $USER->id;
}
Expand Down Expand Up @@ -475,6 +482,7 @@ public function get_data($cm, $wholecourse=false, $userid=0, $modinfo=null) {
$this->internal_systemerror("Unexpected error: course-module {$cm->id} could not be found on course {$this->course->id}");
}
return $SESSION->completioncache[$this->course->id][$cm->id];

} else {
// Get single record
$data = $DB->get_record('course_modules_completion', array('coursemoduleid'=>$cm->id, 'userid'=>$userid));
Expand Down Expand Up @@ -513,13 +521,15 @@ public function get_data($cm, $wholecourse=false, $userid=0, $modinfo=null) {
*/
function internal_set_data($cm, $data) {
global $USER, $SESSION, $DB;

if ($data->id) {
// Has real (nonzero) id meaning that a database row exists
$DB->update_record('course_modules_completion', $data);
} else {
// Didn't exist before, needs creating
$data->id = $DB->insert_record('course_modules_completion', $data);
}

if ($data->userid == $USER->id) {
$SESSION->completioncache[$cm->course][$cm->id] = $data;
}
Expand Down Expand Up @@ -570,6 +580,7 @@ public function get_activities($modinfo=null) {
*/
function internal_get_tracked_users($sortfirstname, $groupid=0) {
global $CFG, $DB;

if (!empty($CFG->progresstrackedroles)) {
$roles = explode(', ', $CFG->progresstrackedroles);
} else {
Expand Down Expand Up @@ -648,6 +659,7 @@ public function inform_grade_changed($cm, &$item, &$grade, $deleted) {
if (!$this->is_enabled($cm) ||
is_null($cm->completiongradeitemnumber) ||
$item->itemnumber != $cm->completiongradeitemnumber) {

return;
}

Expand Down Expand Up @@ -711,6 +723,7 @@ function internal_get_grade_state(&$item, &$grade) {
*/
function internal_systemerror($error) {
global $CFG;

debugging($error, DEBUG_ALL);
print_error('err_system', 'completion', $CFG->wwwroot.'/course/view.php?id='.$this->course->id);
}
Expand Down

0 comments on commit d7d8753

Please sign in to comment.