3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 // Edit course completion settings
28 require_once('../config.php');
29 require_once('lib.php');
30 require_once($CFG->libdir
.'/completionlib.php');
31 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_self.php');
32 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_date.php');
33 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_unenrol.php');
34 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_activity.php');
35 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_duration.php');
36 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_grade.php');
37 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_role.php');
38 require_once($CFG->dirroot
.'/completion/criteria/completion_criteria_course.php');
39 require_once $CFG->libdir
.'/gradelib.php';
40 require_once('completion_form.php');
42 $id = required_param('id', PARAM_INT
); // course id
44 /// basic access control checks
45 if ($id) { // editing course
48 // don't allow editing of 'site course' using this from
49 print_error('cannoteditsiteform');
52 if (!$course = $DB->get_record('course', array('id'=>$id))) {
53 print_error('invalidcourseid');
55 require_login($course);
56 require_capability('moodle/course:update', context_course
::instance($course->id
));
60 print_error('needcourseid');
64 $streditcompletionsettings = get_string("editcoursecompletionsettings", 'completion');
65 $PAGE->set_course($course);
66 $PAGE->set_url('/course/completion.php', array('id' => $course->id
));
67 //$PAGE->navbar->add($streditcompletionsettings);
68 $PAGE->set_title($course->shortname
);
69 $PAGE->set_heading($course->fullname
);
70 $PAGE->set_pagelayout('standard');
72 /// first create the form
73 $form = new course_completion_form('completion.php?id='.$id, compact('course'));
75 // now override defaults if course already exists
76 if ($form->is_cancelled()){
77 redirect($CFG->wwwroot
.'/course/view.php?id='.$course->id
);
79 } else if ($data = $form->get_data()) {
81 $completion = new completion_info($course);
83 /// process criteria unlocking if requested
84 if (!empty($data->settingsunlock
)) {
86 $completion->delete_course_completion_data();
88 // Return to form (now unlocked)
89 redirect($CFG->wwwroot
."/course/completion.php?id=$course->id");
92 /// process data if submitted
93 // Delete old criteria
94 $completion->clear_criteria();
96 // Loop through each criteria type and run update_config
97 global $COMPLETION_CRITERIA_TYPES;
98 foreach ($COMPLETION_CRITERIA_TYPES as $type) {
99 $class = 'completion_criteria_'.$type;
100 $criterion = new $class();
101 $criterion->update_config($data);
104 // Handle aggregation methods
105 // Overall aggregation
107 'course' => $data->id
,
108 'criteriatype' => null
110 $aggregation = new completion_aggregation($aggdata);
111 $aggregation->setMethod($data->overall_aggregation
);
112 $aggregation->save();
114 // Activity aggregation
115 if (empty($data->activity_aggregation
)) {
116 $data->activity_aggregation
= 0;
119 $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_ACTIVITY
;
120 $aggregation = new completion_aggregation($aggdata);
121 $aggregation->setMethod($data->activity_aggregation
);
122 $aggregation->save();
124 // Course aggregation
125 if (empty($data->course_aggregation
)) {
126 $data->course_aggregation
= 0;
129 $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_COURSE
;
130 $aggregation = new completion_aggregation($aggdata);
131 $aggregation->setMethod($data->course_aggregation
);
132 $aggregation->save();
135 if (empty($data->role_aggregation
)) {
136 $data->role_aggregation
= 0;
139 $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_ROLE
;
140 $aggregation = new completion_aggregation($aggdata);
141 $aggregation->setMethod($data->role_aggregation
);
142 $aggregation->save();
144 add_to_log($course->id
, 'course', 'completion updated', 'completion.php?id='.$course->id
);
146 $url = new moodle_url('/course/view.php', array('id' => $course->id
));
154 echo $OUTPUT->header();
155 echo $OUTPUT->heading($streditcompletionsettings);
159 echo $OUTPUT->footer();