|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 // // 00005 // NOTICE OF COPYRIGHT // 00006 // // 00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 00008 // http://moodle.com // 00009 // // 00010 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // 00011 // // 00012 // This program is free software; you can redistribute it and/or modify // 00013 // it under the terms of the GNU General Public License as published by // 00014 // the Free Software Foundation; either version 2 of the License, or // 00015 // (at your option) any later version. // 00016 // // 00017 // This program is distributed in the hope that it will be useful, // 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00020 // GNU General Public License for more details: // 00021 // // 00022 // http://www.gnu.org/copyleft/gpl.html // 00023 // // 00025 00026 if (!defined('MOODLE_INTERNAL')) { 00027 die('Direct access to this script is forbidden.'); 00028 } 00029 00030 require_once($CFG->libdir.'/formslib.php'); 00031 require_once($CFG->libdir.'/completionlib.php'); 00032 00033 class course_completion_form extends moodleform { 00034 00035 function definition() { 00036 global $USER, $CFG, $DB, $js_enabled; 00037 00038 $courseconfig = get_config('moodlecourse'); 00039 $mform =& $this->_form; 00040 00041 $course = $this->_customdata['course']; 00042 $completion = new completion_info($course); 00043 00044 $params = array( 00045 'course' => $course->id 00046 ); 00047 00048 00050 //-------------------------------------------------------------------------------- 00051 00052 // Check if there is existing criteria completions 00053 if ($completion->is_course_locked()) { 00054 $mform->addElement('header', '', get_string('completionsettingslocked', 'completion')); 00055 $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion')); 00056 $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion')); 00057 } 00058 00059 // Get array of all available aggregation methods 00060 $aggregation_methods = $completion->get_aggregation_methods(); 00061 00062 // Overall criteria aggregation 00063 $mform->addElement('header', 'overallcriteria', get_string('overallcriteriaaggregation', 'completion')); 00064 $mform->addElement('select', 'overall_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods); 00065 $mform->setDefault('overall_aggregation', $completion->get_aggregation_method()); 00066 00067 // Course prerequisite completion criteria 00068 $mform->addElement('header', 'courseprerequisites', get_string('courseprerequisites', 'completion')); 00069 00070 // Get applicable courses 00071 $courses = $DB->get_records_sql( 00072 " 00073 SELECT DISTINCT 00074 c.id, 00075 c.category, 00076 c.fullname, 00077 cc.id AS selected 00078 FROM 00079 {course} c 00080 LEFT JOIN 00081 {course_completion_criteria} cc 00082 ON cc.courseinstance = c.id 00083 AND cc.course = {$course->id} 00084 INNER JOIN 00085 {course_completion_criteria} ccc 00086 ON ccc.course = c.id 00087 WHERE 00088 c.enablecompletion = ".COMPLETION_ENABLED." 00089 AND c.id <> {$course->id} 00090 " 00091 ); 00092 00093 if (!empty($courses)) { 00094 if (count($courses) > 1) { 00095 $mform->addElement('select', 'course_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods); 00096 $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE)); 00097 } 00098 00099 // Get category list 00100 $list = array(); 00101 $parents = array(); 00102 make_categories_list($list, $parents); 00103 00104 // Get course list for select box 00105 $selectbox = array(); 00106 $selected = array(); 00107 foreach ($courses as $c) { 00108 $selectbox[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $c->id))); 00109 00110 // If already selected 00111 if ($c->selected) { 00112 $selected[] = $c->id; 00113 } 00114 } 00115 00116 // Show multiselect box 00117 $mform->addElement('select', 'criteria_course', get_string('coursesavailable', 'completion'), $selectbox, array('multiple' => 'multiple', 'size' => 6)); 00118 00119 // Select current criteria 00120 $mform->setDefault('criteria_course', $selected); 00121 00122 // Explain list 00123 $mform->addElement('static', 'criteria_courses_explaination', '', get_string('coursesavailableexplaination', 'completion')); 00124 00125 } else { 00126 $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion')); 00127 } 00128 00129 // Manual self completion 00130 $mform->addElement('header', 'manualselfcompletion', get_string('manualselfcompletion', 'completion')); 00131 $criteria = new completion_criteria_self($params); 00132 $criteria->config_form_display($mform); 00133 00134 // Role completion criteria 00135 $mform->addElement('header', 'roles', get_string('manualcompletionby', 'completion')); 00136 00137 $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, get_context_instance(CONTEXT_COURSE, $course->id)); 00138 00139 if (!empty($roles)) { 00140 $mform->addElement('select', 'role_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods); 00141 $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE)); 00142 00143 foreach ($roles as $role) { 00144 $params_a = array('role' => $role->id); 00145 $criteria = new completion_criteria_role(array_merge($params, $params_a)); 00146 $criteria->config_form_display($mform, $role); 00147 } 00148 } else { 00149 $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion')); 00150 } 00151 00152 // Activity completion criteria 00153 $mform->addElement('header', 'activitiescompleted', get_string('activitiescompleted', 'completion')); 00154 00155 $activities = $completion->get_activities(); 00156 if (!empty($activities)) { 00157 if (count($activities) > 1) { 00158 $mform->addElement('select', 'activity_aggregation', get_string('aggregationmethod', 'completion'), $aggregation_methods); 00159 $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY)); 00160 } 00161 00162 foreach ($activities as $activity) { 00163 $params_a = array('moduleinstance' => $activity->id); 00164 $criteria = new completion_criteria_activity(array_merge($params, $params_a)); 00165 $criteria->config_form_display($mform, $activity); 00166 } 00167 } else { 00168 $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion')); 00169 } 00170 00171 // Completion on date 00172 $mform->addElement('header', 'date', get_string('date')); 00173 $criteria = new completion_criteria_date($params); 00174 $criteria->config_form_display($mform); 00175 00176 // Completion after enrolment duration 00177 $mform->addElement('header', 'duration', get_string('durationafterenrolment', 'completion')); 00178 $criteria = new completion_criteria_duration($params); 00179 $criteria->config_form_display($mform); 00180 00181 // Completion on course grade 00182 $mform->addElement('header', 'grade', get_string('grade')); 00183 00184 // Grade enable and passing grade 00185 $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course')); 00186 $criteria = new completion_criteria_grade($params); 00187 $criteria->config_form_display($mform, $course_grade); 00188 00189 // Completion on unenrolment 00190 $mform->addElement('header', 'unenrolment', get_string('unenrolment', 'completion')); 00191 $criteria = new completion_criteria_unenrol($params); 00192 $criteria->config_form_display($mform); 00193 00194 00195 //-------------------------------------------------------------------------------- 00196 $this->add_action_buttons(); 00197 //-------------------------------------------------------------------------------- 00198 $mform->addElement('hidden', 'id', $course->id); 00199 $mform->setType('id', PARAM_INT); 00200 00201 // If the criteria are locked, freeze values and submit button 00202 if ($completion->is_course_locked()) { 00203 $except = array('settingsunlock'); 00204 $mform->hardFreezeAllVisibleExcept($except); 00205 $mform->addElement('cancel'); 00206 } 00207 } 00208 00209 00211 function validation($data, $files) { 00212 global $DB, $CFG; 00213 00214 $errors = parent::validation($data, $files); 00215 00216 return $errors; 00217 } 00218 } 00219 ?>