|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 require_once('../../config.php'); 00028 require_once($CFG->libdir.'/completionlib.php'); 00029 00030 00031 // TODO: Make this page Moodle 2.0 compliant 00032 00033 00037 $id = required_param('course', PARAM_INT); 00038 // User id 00039 $userid = optional_param('user', 0, PARAM_INT); 00040 00041 // Load course 00042 $course = $DB->get_record('course', array('id' => $id)); 00043 00044 // Load user 00045 if ($userid) { 00046 $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); 00047 } else { 00048 $user = $USER; 00049 } 00050 00051 00052 // Check permissions 00053 require_login($course); 00054 00055 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); 00056 $personalcontext = get_context_instance(CONTEXT_USER, $user->id); 00057 00058 $can_view = false; 00059 00060 // Can view own report 00061 if ($USER->id == $user->id) { 00062 $can_view = true; 00063 } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) { 00064 $can_view = true; 00065 } else if (has_capability('report/completion:view', $coursecontext)) { 00066 $can_view = true; 00067 } else if (has_capability('report/completion:view', $personalcontext)) { 00068 $can_view = true; 00069 } 00070 00071 if (!$can_view) { 00072 print_error('cannotviewreport'); 00073 } 00074 00075 00076 // Load completion data 00077 $info = new completion_info($course); 00078 00079 $returnurl = "{$CFG->wwwroot}/course/view.php?id={$id}"; 00080 00081 // Don't display if completion isn't enabled! 00082 if (!$info->is_enabled()) { 00083 print_error('completionnotenabled', 'completion', $returnurl); 00084 } 00085 00086 // Load criteria to display 00087 $completions = $info->get_completions($user->id); 00088 00089 // Check if this course has any criteria 00090 if (empty($completions)) { 00091 print_error('nocriteriaset', 'completion', $returnurl); 00092 } 00093 00094 // Check this user is enroled 00095 if (!$info->is_tracked_user($user->id)) { 00096 if ($USER->id == $user->id) { 00097 print_error('notenroled', 'completion', $returnurl); 00098 } else { 00099 print_error('usernotenroled', 'completion', $returnurl); 00100 } 00101 } 00102 00103 00107 00108 // Print header 00109 $page = get_string('completionprogressdetails', 'block_completionstatus'); 00110 $title = format_string($course->fullname) . ': ' . $page; 00111 00112 $PAGE->navbar->add($page); 00113 $PAGE->set_pagelayout('standard'); 00114 $PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id)); 00115 $PAGE->set_title(get_string('course') . ': ' . $course->fullname); 00116 $PAGE->set_heading($title); 00117 echo $OUTPUT->header(); 00118 00119 00120 // Display completion status 00121 echo '<table class="generalbox boxaligncenter"><tbody>'; 00122 00123 // If not display logged in user, show user name 00124 if ($USER->id != $user->id) { 00125 echo '<tr><td colspan="2"><b>'.get_string('showinguser', 'completion').'</b>: '; 00126 echo '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a>'; 00127 echo '</td></tr>'; 00128 } 00129 00130 echo '<tr><td colspan="2"><b>'.get_string('status').':</b> '; 00131 00132 // Is course complete? 00133 $coursecomplete = $info->is_course_complete($user->id); 00134 00135 // Has this user completed any criteria? 00136 $criteriacomplete = $info->count_course_user_data($user->id); 00137 00138 if ($coursecomplete) { 00139 echo get_string('complete'); 00140 } else if (!$criteriacomplete) { 00141 echo '<i>'.get_string('notyetstarted', 'completion').'</i>'; 00142 } else { 00143 echo '<i>'.get_string('inprogress','completion').'</i>'; 00144 } 00145 00146 echo '</td></tr>'; 00147 echo '<tr><td colspan="2"><b>'.get_string('required').':</b> '; 00148 00149 // Get overall aggregation method 00150 $overall = $info->get_aggregation_method(); 00151 00152 if ($overall == COMPLETION_AGGREGATION_ALL) { 00153 echo get_string('criteriarequiredall', 'completion'); 00154 } else { 00155 echo get_string('criteriarequiredany', 'completion'); 00156 } 00157 00158 echo '</td></tr></tbody></table>'; 00159 00160 // Generate markup for criteria statuses 00161 echo '<table class="generalbox boxaligncenter" cellpadding="3"><tbody>'; 00162 echo '<tr class="ccheader">'; 00163 echo '<th class="c0 header" scope="col">'.get_string('criteriagroup', 'block_completionstatus').'</th>'; 00164 echo '<th class="c1 header" scope="col">'.get_string('criteria', 'completion').'</th>'; 00165 echo '<th class="c2 header" scope="col">'.get_string('requirement', 'block_completionstatus').'</th>'; 00166 echo '<th class="c3 header" scope="col">'.get_string('status').'</th>'; 00167 echo '<th class="c4 header" scope="col">'.get_string('complete').'</th>'; 00168 echo '<th class="c5 header" scope="col">'.get_string('completiondate', 'report_completion').'</th>'; 00169 echo '</tr>'; 00170 00171 // Save row data 00172 $rows = array(); 00173 00174 global $COMPLETION_CRITERIA_TYPES; 00175 00176 // Loop through course criteria 00177 foreach ($completions as $completion) { 00178 $criteria = $completion->get_criteria(); 00179 $complete = $completion->is_complete(); 00180 00181 $row = array(); 00182 $row['type'] = $criteria->criteriatype; 00183 $row['title'] = $criteria->get_title(); 00184 $row['status'] = $completion->get_status(); 00185 $row['timecompleted'] = $completion->timecompleted; 00186 $row['details'] = $criteria->get_details($completion); 00187 $rows[] = $row; 00188 } 00189 00190 // Print table 00191 $last_type = ''; 00192 $agg_type = false; 00193 00194 foreach ($rows as $row) { 00195 00196 // Criteria group 00197 echo '<td class="c0">'; 00198 if ($last_type !== $row['details']['type']) { 00199 $last_type = $row['details']['type']; 00200 echo $last_type; 00201 00202 // Reset agg type 00203 $agg_type = true; 00204 } else { 00205 // Display aggregation type 00206 if ($agg_type) { 00207 $agg = $info->get_aggregation_method($row['type']); 00208 00209 echo '(<i>'; 00210 00211 if ($agg == COMPLETION_AGGREGATION_ALL) { 00212 echo strtolower(get_string('all', 'completion')); 00213 } else { 00214 echo strtolower(get_string('any', 'completion')); 00215 } 00216 00217 echo '</i> '.strtolower(get_string('required')).')'; 00218 $agg_type = false; 00219 } 00220 } 00221 echo '</td>'; 00222 00223 // Criteria title 00224 echo '<td class="c1">'; 00225 echo $row['details']['criteria']; 00226 echo '</td>'; 00227 00228 // Requirement 00229 echo '<td class="c2">'; 00230 echo $row['details']['requirement']; 00231 echo '</td>'; 00232 00233 // Status 00234 echo '<td class="c3">'; 00235 echo $row['details']['status']; 00236 echo '</td>'; 00237 00238 // Is complete 00239 echo '<td class="c4">'; 00240 echo ($row['status'] === get_string('yes')) ? get_string('yes') : get_string('no'); 00241 echo '</td>'; 00242 00243 // Completion data 00244 echo '<td class="c5">'; 00245 if ($row['timecompleted']) { 00246 echo userdate($row['timecompleted'], '%e %B %G'); 00247 } else { 00248 echo '-'; 00249 } 00250 echo '</td>'; 00251 echo '</tr>'; 00252 } 00253 00254 echo '</tbody></table>'; 00255 00256 echo $OUTPUT->footer();