} else {
        if (!($event = $DB->get_record('trainingevent', array('id' => $dodownload)))) {
            die;
        }
        $location = $DB->get_record('classroom', array('id' => $event->classroomid));
        // Output everything to a file.
        header("Content-Type: application/download\n");
        header("Content-Disposition: attachment; filename=\"" . $event->name . ".csv\"");
        header("Expires: 0");
        header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
        header("Pragma: public");
        $locationinfo = "{$location->name}, {$location->address}, {$location->city},";
        $locationinfo .= " {$location->country}, {$location->postcode}";
        echo "\"{$event->name}, {$locationinfo}\"\n";
        echo "\"" . get_string('fullname') . "\",\"" . get_string('email') . "\"\n";
        if ($users = $DB->get_records_sql('SELECT userid AS id FROM {trainingevent_users}
                                           WHERE trainingeventid=' . $event->id . '
                                           AND userid IN (' . $allowedlist . ')')) {
            foreach ($users as $user) {
                $fulluserdata = $DB->get_record('user', array('id' => $user->id));
                $fulluserdata->department = company_user::get_department_name($user->id);
                $fullname = "{$fulluserdata->firstname} {$fulluserdata->lastname}";
                echo "\"{$fullname}\", \"{$fulluserdata->department}\", \"{$fulluserdata->email}\"\n";
            }
        }
    }
}
if (!empty($dodownload)) {
    exit;
}
echo $OUTPUT->footer();
Exemple #2
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;
 }