public function course_completion_gauge(&$course, $div, $width = 160, $height = 160, $type = 'progressbar')
 {
     global $USER, $PAGE;
     $str = '';
     $completion = new completion_info($course);
     if ($completion->is_enabled(null)) {
         $alltracked = count($completion->get_activities());
         $progressinfo = $completion->get_progress_all('u.id = :userid', array('userid' => $USER->id));
         $completed = 0;
         if (!empty($progressinfo)) {
             if (!empty($progressinfo[$USER->id]->progress)) {
                 foreach ($progressinfo[$USER->id]->progress as $progressrecord) {
                     if ($progressrecord->completionstate) {
                         $completed++;
                     }
                 }
             }
         }
         $ratio = $alltracked == 0 ? 0 : round($completed / $alltracked * 100);
         $jqwrenderer = $PAGE->get_renderer('local_vflibs');
         if ($div == 'div') {
             $str .= '<div class="course-completion" title="' . get_string('completion', 'local_my', 0 + $ratio) . '">';
         } else {
             $str .= '<td class="course-completion" title="' . get_string('completion', 'local_my', 0 + $ratio) . '">';
         }
         if ($type == 'gauge') {
             $properties = array('width' => $width, 'height' => $height, 'max' => 100, 'crop' => 120);
             $str .= $jqwrenderer->jqw_bargauge_simple('completion-jqw-' . $course->id, array($ratio), $properties);
         } else {
             $properties = array('width' => $width, 'height' => $height, 'animation' => 300, 'template' => 'success');
             $str .= $jqwrenderer->jqw_progress_bar('completion-jqw-' . $course->id, $ratio, $properties);
         }
         if ($div == 'div') {
             $str .= '</div>';
         } else {
             $str .= '</td>';
         }
     } else {
         if ($div == 'div') {
             $str .= '<div class="course-completion">';
         } else {
             $str .= '<td class="course-completion">';
         }
         if ($div == 'div') {
             $str .= '</div>';
         } else {
             $str .= '</td>';
         }
     }
     return $str;
 }
    $where_params['silast'] = $silast . '%';
}
// Get user match count
$total = $completion->get_num_tracked_users(implode(' AND ', $where), $where_params, $group);
// Total user count
$grandtotal = $completion->get_num_tracked_users('', array(), $group);
// If no users in this course what-so-ever
if (!$grandtotal) {
    echo $OUTPUT->container(get_string('err_nousers', 'completion'), 'errorbox errorboxcontent');
    echo $OUTPUT->footer();
    exit;
}
// Get user data
$progress = array();
if ($total) {
    $progress = $completion->get_progress_all(implode(' AND ', $where), $where_params, $group, $firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC', $csv ? 0 : COMPLETION_REPORT_PAGE, $csv ? 0 : $start);
}
// Build link for paging
$link = $CFG->wwwroot . '/course/report/completion/?course=' . $course->id;
if (strlen($sort)) {
    $link .= '&amp;sort=' . $sort;
}
$link .= '&amp;start=';
// Build the the page by Initial bar
$initials = array('first', 'last');
$alphabet = explode(',', get_string('alphabet', 'langconfig'));
$pagingbar = '';
foreach ($initials as $initial) {
    $var = 'si' . $initial;
    $pagingbar .= ' <div class="initialbar ' . $initial . 'initial">';
    $pagingbar .= get_string($initial . 'name') . ':&nbsp;';
Exemple #3
0
 /**
  * Get Activities completion status
  *
  * @param int $courseid ID of the Course
  * @param int $userid ID of the User
  * @return array of activities progress and warnings
  * @throws moodle_exception
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function get_activities_completion_status($courseid, $userid)
 {
     global $CFG, $USER;
     require_once $CFG->libdir . '/grouplib.php';
     $warnings = array();
     $arrayparams = array('courseid' => $courseid, 'userid' => $userid);
     $params = self::validate_parameters(self::get_activities_completion_status_parameters(), $arrayparams);
     $course = get_course($params['courseid']);
     $user = core_user::get_user($params['userid'], 'id', MUST_EXIST);
     $context = context_course::instance($course->id);
     self::validate_context($context);
     // Check that current user have permissions to see this user's activities.
     if ($user->id != $USER->id) {
         require_capability('report/progress:view', $context);
         if (!groups_user_groups_visible($course, $user->id)) {
             // We are not in the same group!
             throw new moodle_exception('accessdenied', 'admin');
         }
     }
     $completion = new completion_info($course);
     $activities = $completion->get_activities();
     $progresses = $completion->get_progress_all();
     $userprogress = $progresses[$user->id];
     $results = array();
     foreach ($activities as $activity) {
         // Check if current user has visibility on this activity.
         if (!$activity->uservisible) {
             continue;
         }
         // Get progress information and state.
         if (array_key_exists($activity->id, $userprogress->progress)) {
             $thisprogress = $userprogress->progress[$activity->id];
             $state = $thisprogress->completionstate;
             $timecompleted = $thisprogress->timemodified;
         } else {
             $state = COMPLETION_INCOMPLETE;
             $timecompleted = 0;
         }
         $results[] = array('cmid' => $activity->id, 'modname' => $activity->modname, 'instance' => $activity->instance, 'state' => $state, 'timecompleted' => $timecompleted, 'tracking' => $activity->completion);
     }
     $results = array('statuses' => $results, 'warnings' => $warnings);
     return $results;
 }
Exemple #4
0
require_capability('coursereport/progress:view', $context);
// Get group mode
$group = groups_get_course_group($course, true);
// Supposed to verify group
if ($group === 0 && $course->groupmode == SEPARATEGROUPS) {
    require_capability('moodle/site:accessallgroups', $context);
}
// Get data on activities and progress of all users, and give error if we've
// nothing to display (no users or no activities)
$reportsurl = $CFG->wwwroot . '/course/report.php?id=' . $course->id;
$completion = new completion_info($course);
$activities = $completion->get_activities();
if (count($activities) == 0) {
    print_error('err_noactivities', 'completion', $reportsurl);
}
$progress = $completion->get_progress_all($firstnamesort, $group, $csv ? 0 : COMPLETION_REPORT_PAGE, $csv ? 0 : $start);
if ($csv) {
    header('Content-Disposition: attachment; filename=progress.' . preg_replace('/[^a-z0-9-]/', '_', strtolower($course->shortname)) . '.csv');
    // Unicode byte-order mark for Excel
    if ($excel) {
        header('Content-Type: text/csv; charset=UTF-16LE');
        print chr(0xff) . chr(0xfe);
        $sep = "\t" . chr(0);
        $line = "\n" . chr(0);
    } else {
        header('Content-Type: text/csv; charset=UTF-8');
        $sep = ",";
        $line = "\n";
    }
} else {
    // Use SVG to draw sideways text if supported
Exemple #5
0
 public static function get_completion($userid, $courseid)
 {
     global $DB;
     // Going to build an array for the data.
     $data = array();
     // Count the three statii for the graph.
     $notstarted = 0;
     $inprogress = 0;
     $completed = 0;
     // Get completion data for course.
     // Get course object.
     if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
         error('unable to find course record');
     }
     $datum = new stdclass();
     $datum->coursename = $course->fullname;
     // Instantiate completion info thingy.
     $info = new completion_info($course);
     // Get gradebook details.
     $gbsql = "select gg.finalgrade as result from {grade_grades} gg, {grade_items} gi\n                  WHERE gi.courseid={$courseid} AND gi.itemtype='course' AND gg.userid={$userid}\n                  AND gi.id=gg.itemid";
     if (!($gradeinfo = $DB->get_record_sql($gbsql))) {
         $gradeinfo = new object();
         $gradeinfo->result = null;
     }
     // If completion is not enabled on the course
     // there's no point carrying on.
     if (!$info->is_enabled()) {
         $datum->enabled = false;
         $data[$courseid] = $datum;
         return false;
     } else {
         $datum->enabled = true;
     }
     // Get criteria for coursed.
     // This is an array of tracked activities (only tracked ones).
     $criteria = $info->get_criteria();
     // Number of tracked activities to complete.
     $trackedcount = count($criteria);
     $datum->trackedcount = $trackedcount;
     // Get data for all users in course.
     // This is an array of users in the course. It contains a 'progress'
     // array showing completed *tracked* activities.
     $progress = $info->get_progress_all();
     $u = new stdclass();
     // Iterate over users to get info.
     if (isset($progress[$userid])) {
         $user = $progress[$userid];
         // Find user's completion info for this course.
         if ($completioninfo = $DB->get_record('course_completions', array('userid' => $user->id, 'course' => $courseid))) {
             $u->timeenrolled = $completioninfo->timeenrolled;
             if (!empty($completioninfo->timestarted)) {
                 $u->timestarted = $completioninfo->timestarted;
                 if (!empty($completioninfo->timecompleted)) {
                     $u->timecompleted = $completioninfo->timecompleted;
                     $u->status = 'completed';
                     ++$completed;
                 } else {
                     $u->timecompleted = 0;
                     $u->status = 'inprogress';
                     ++$inprogress;
                 }
             } else {
                 $u->timestarted = 0;
                 $u->status = 'notstarted';
                 ++$notstarted;
             }
         } else {
             $u->timeenrolled = 0;
             $u->timecompleted = 0;
             $u->timestarted = 0;
             $u->status = 'notstarted';
             ++$notstarted;
         }
     } else {
         $u->completed_count = 0;
         $u->completed_percent = '--';
         $u->completed_progress = 'notstarted';
     }
     $u->result = round($gradeinfo->result, 0);
     $datum->completion = $u;
     $data[$courseid] = $datum;
     // Make return object.
     $returnobj = new stdclass();
     $returnobj->data = $data;
     $returnobj->criteria = $criteria;
     return $returnobj;
 }
Exemple #6
0
 public static function get_completion($companyid, $courseid = 0, $wantedusers = null, $compfrom = 0, $compto = 0)
 {
     global $DB, $CFG;
     // Get list of course ids.
     $courseids = array();
     if ($courseid == 0) {
         if (!($courses = $DB->get_records_sql("SELECT c.id AS courseid FROM {course} c\n                                                  WHERE c.id in (\n                                                    SELECT courseid FROM {companycourse}\n                                                    WHERE companyid = {$companyid} )\n                                                  OR c.id in (\n                                                    SELECT pc.courseid FROM {iomad_courses} pc\n                                                    INNER JOIN {company_shared_courses} csc\n                                                    ON pc.courseid=csc.courseid\n                                                    WHERE pc.shared=2\n                                                    AND csc.companyid = {$companyid} )\n                                                  OR c.id in (\n                                                    SELECT pc.courseid FROM {iomad_courses} pc\n                                                    WHERE pc.shared=1)"))) {
             // No courses for company, so exit.
             return false;
         }
         foreach ($courses as $course) {
             $courseids[] = $course->courseid;
         }
     } else {
         $courseids[] = $courseid;
     }
     // Going to build an array for the data.
     $data = array();
     // Count the three statii for the graph.
     $notstarted = 0;
     $inprogress = 0;
     $completed = 0;
     // Get completion data for each course.
     foreach ($courseids as $courseid) {
         // Get course object.
         if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
             error('unable to find course record');
         }
         $datum = null;
         $datum->coursename = $course->fullname;
         // Instantiate completion info thingy.
         $info = new completion_info($course);
         // If completion is not enabled on the course
         // there's no point carrying on.
         if (!$info->is_enabled()) {
             $datum->enabled = false;
             $data[$courseid] = $datum;
             continue;
         } else {
             $datum->enabled = true;
         }
         // Get criteria for coursed.
         // This is an array of tracked activities (only tracked ones).
         $criteria = $info->get_criteria();
         // Number of tracked activities to complete.
         $trackedcount = count($criteria);
         $datum->trackedcount = $trackedcount;
         // Get data for all users in course.
         // This is an array of users in the course. It contains a 'progress'
         // array showing completed *tracked* activities.
         $progress = $info->get_progress_all();
         // Iterate over users to get info.
         $users = array();
         $numusers = 0;
         $numprogress = 0;
         $numcomplete = 0;
         $numnotstarted = 0;
         foreach ($wantedusers as $wanteduser) {
             if (empty($progress[$wanteduser])) {
                 continue;
             }
             $user = $progress[$wanteduser];
             ++$numusers;
             $u = null;
             $u->fullname = fullname($user);
             // Count of progress is the number they have completed.
             $u->completed_count = count($user->progress);
             if ($trackedcount > 0) {
                 $u->completed_percent = round(100 * $u->completed_count / $trackedcount, 2);
             } else {
                 $u->completed_percent = '0';
             }
             // Find user's completion info for this course.
             if ($completioninfo = $DB->get_record('course_completions', array('userid' => $user->id, 'course' => $courseid))) {
                 if ((!empty($compfrom) || !empty($compto)) && empty($completioninfo->timecompleted)) {
                     continue;
                 } else {
                     if (!empty($compfrom) && $completioninfo->timecompleted < $compfrom) {
                         continue;
                     } else {
                         if (!empty($compto) && $completioninfo->timecompleted > $compto) {
                             continue;
                         } else {
                             $u->timeenrolled = $completioninfo->timeenrolled;
                             if (!empty($completioninfo->timestarted)) {
                                 $u->timestarted = $completioninfo->timestarted;
                                 if (!empty($completioninfo->timecompleted)) {
                                     $u->timecompleted = $completioninfo->timecompleted;
                                     $u->status = 'completed';
                                     ++$numcomplete;
                                 } else {
                                     $u->timecompleted = 0;
                                     $u->status = 'inprogress';
                                     ++$numprogress;
                                 }
                             } else {
                                 $u->timestarted = 0;
                                 $u->status = 'notstarted';
                                 ++$numnotstarted;
                             }
                         }
                     }
                 }
             } else {
                 $u->timeenrolled = 0;
                 $u->timecompleted = 0;
                 $u->timestarted = 0;
                 $u->status = 'notstarted';
                 ++$numnotstarted;
             }
             // Get the users score.
             $gbsql = "select gg.finalgrade as result from {grade_grades} gg, {grade_items} gi\n                          WHERE gi.courseid={$courseid} AND gi.itemtype='course' AND gg.userid=" . $user->id . "\n                          AND gi.id=gg.itemid";
             if (!($gradeinfo = $DB->get_record_sql($gbsql))) {
                 $gradeinfo = new object();
                 $gradeinfo->result = null;
             }
             $u->result = round($gradeinfo->result, 0);
             $userinfo = $DB->get_record('user', array('id' => $user->id));
             $u->email = $userinfo->email;
             $u->id = $user->id;
             $u->department = company_user::get_department_name($user->id);
             // Add to revised user array.
             $users[$user->id] = $u;
         }
         $datum->users = $users;
         $datum->completed = $numcomplete;
         $datum->numusers = $numusers;
         $datum->started = $numnotstarted;
         $datum->inprogress = $numprogress;
         $data[$courseid] = $datum;
     }
     // Make the data for the graph.
     $graphdata = array('notstarted' => $notstarted, 'inprogress' => $inprogress, 'completed' => $completed);
     // Make return object.
     $returnobj = null;
     $returnobj->data = $data;
     $returnobj->graphdata = $graphdata;
     return $returnobj;
 }
Exemple #7
0
 public function get_completion($companyid, $courseid = 0)
 {
     global $DB;
     // Get list of course ids.
     $courseids = array();
     if ($courseid == 0) {
         if (!($courses = $DB->get_records('companycourse', array('companyid' => $companyid)))) {
             // No courses for company, so exit.
             return false;
         }
         foreach ($courses as $course) {
             $courseids[] = $course->courseid;
         }
     } else {
         $courseids[] = $courseid;
     }
     // Going to build an array for the data.
     $data = array();
     // Count the three statii for the graph.
     $notstarted = 0;
     $inprogress = 0;
     $completed = 0;
     // Get completion data for each course.
     foreach ($courseids as $courseid) {
         // Get course object.
         if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
             error('unable to find course record');
         }
         $datum = null;
         $datum->coursename = $course->fullname;
         // Instantiate completion info thingy.
         $info = new completion_info($course);
         // If completion is not enabled on the course
         // there's no point carrying on.
         if (!$info->is_enabled()) {
             $datum->enabled = false;
             $data[$courseid] = $datum;
             continue;
         } else {
             $datum->enabled = true;
         }
         // Get criteria for coursed.
         // This is an array of tracked activities (only tracked ones).
         $criteria = $info->get_criteria();
         // Number of tracked activities to complete.
         $trackedcount = count($criteria);
         $datum->trackedcount = $trackedcount;
         // Get data for all users in course.
         // This is an array of users in the course. It contains a 'progress'
         // array showing completed *tracked* activities.
         $progress = $info->get_progress_all();
         // Iterate over users to get info.
         $users = array();
         $numusers = 0;
         $numprogress = 0;
         $numcomplete = 0;
         $numnotstarted = 0;
         foreach ($progress as $user) {
             ++$numusers;
             $u = null;
             $u->fullname = fullname($user);
             // Count of progress is the number they have completed.
             $u->completed_count = count($user->progress);
             if ($trackedcount > 0) {
                 $u->completed_percent = round(100 * $u->completed_count / $trackedcount, 2);
             } else {
                 $u->completed_percent = '0';
             }
             // Find user's last access to this course.
             if ($lastaccess = $DB->get_record('user_lastaccess', array('userid' => $user->id, 'courseid' => $courseid))) {
                 $u->lastaccess = $lastaccess->timeaccess;
             } else {
                 $u->lastaccess = 0;
             }
             // Work out status.
             if ($u->completed_percent == 0) {
                 $u->status = 'notstarted';
                 ++$notstarted;
                 ++$numnotstarted;
             } else {
                 if ($u->completed_percent < 100) {
                     $u->status = 'inprogress';
                     ++$inprogress;
                     ++$numprogress;
                 } else {
                     $u->status = 'completed';
                     ++$completed;
                     ++$numcomplete;
                 }
             }
             // Add to revised user array.
             $users[$user->id] = $u;
         }
         $datum->users = $users;
         $datum->completed = $numcomplete;
         $datum->numusers = $numusers;
         $datum->started = $numnotstarted;
         $datum->inprogress = $numprogress;
         $data[$courseid] = $datum;
     }
     // Make the data for the graph.
     $graphdata = array('notstarted' => $notstarted, 'inprogress' => $inprogress, 'completed' => $completed);
     // Make return object.
     $returnobj = null;
     $returnobj->data = $data;
     $returnobj->graphdata = $graphdata;
     return $returnobj;
 }