$group = groups_get_course_group($course, true); // Supposed to verify group if ($group === 0 && $course->groupmode == SEPARATEGROUPS) { require_capability('moodle/site:accessallgroups', $context); } /** * Load data */ // Get criteria for course $completion = new completion_info($course); if (!$completion->has_criteria()) { print_error('err_nocriteria', 'completion', $CFG->wwwroot . '/course/report.php?id=' . $course->id); } // Get criteria and put in correct order $criteria = array(); foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE) as $criterion) { $criteria[] = $criterion; } foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY) as $criterion) { $criteria[] = $criterion; } foreach ($completion->get_criteria() as $criterion) { if (!in_array($criterion->criteriatype, array(COMPLETION_CRITERIA_TYPE_COURSE, COMPLETION_CRITERIA_TYPE_ACTIVITY))) { $criteria[] = $criterion; } } // Can logged in user mark users as complete? // (if the logged in user has a role defined in the role criteria) $allow_marking = false; $allow_marking_criteria = null; if (!$csv) {
/** * Retrieves the completion status of the course for an specific user (100 if this is completed and 0 if not), returns NULL if completion tracking is not enabled for the course and criteria for completing the course has not been set * @author elever * * @param int $lo_id : id of the course * @param int $native_user_id : moodle identifier of the user * @return int $completion_status| NULL */ function block_intuitel_get_completion_status_course($lo_id, $native_user_id) { $course = get_course($lo_id); $completion = new \completion_info($course); global $DB; if ($completion->is_enabled() > 0) { $criteria = $completion->get_criteria(); if (!empty($criteria)) { //if criteria has been stablished for completing the course (in another case there is no course completion tracking) //when a user completes a course this is registered in table course_completions $timecompleted = $DB->get_field('course_completions', 'timecompleted', array('userid' => $native_user_id, 'course' => $lo_id)); if ($timecompleted == false) { $completion_status = 0; } else { $completion_status = 100; } // a record exists then the course has been completed } else { $completion_status = null; } } else { $completion_status = null; // completion is not enabled for the course } return $completion_status; }
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; }
/** * Defines the form fields. */ public function definition() { global $USER, $CFG, $DB; $courseconfig = get_config('moodlecourse'); $mform = $this->_form; $course = $this->_customdata['course']; $completion = new completion_info($course); $params = array('course' => $course->id); // Check if there are existing criteria completions. if ($completion->is_course_locked()) { $mform->addElement('header', 'completionsettingslocked', get_string('completionsettingslocked', 'completion')); $mform->addElement('static', '', '', get_string('err_settingslocked', 'completion')); $mform->addElement('submit', 'settingsunlock', get_string('unlockcompletiondelete', 'completion')); } // Get array of all available aggregation methods. $aggregation_methods = $completion->get_aggregation_methods(); // Overall criteria aggregation. $mform->addElement('header', 'overallcriteria', get_string('general', 'core_form')); // Map aggregation methods to context-sensitive human readable dropdown menu. $overallaggregationmenu = array(); foreach ($aggregation_methods as $methodcode => $methodname) { if ($methodcode === COMPLETION_AGGREGATION_ALL) { $overallaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('overallaggregation_all', 'core_completion'); } else { if ($methodcode === COMPLETION_AGGREGATION_ANY) { $overallaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('overallaggregation_any', 'core_completion'); } else { $overallaggregationmenu[$methodcode] = $methodname; } } } $mform->addElement('select', 'overall_aggregation', get_string('overallaggregation', 'core_completion'), $overallaggregationmenu); $mform->setDefault('overall_aggregation', $completion->get_aggregation_method()); // Activity completion criteria $label = get_string('coursecompletioncondition', 'core_completion', get_string('activitiescompleted', 'core_completion')); $mform->addElement('header', 'activitiescompleted', $label); // Get the list of currently specified conditions and expand the section if some are found. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY); if (!empty($current)) { $mform->setExpanded('activitiescompleted'); } $activities = $completion->get_activities(); if (!empty($activities)) { if (!$completion->is_course_locked()) { $this->add_checkbox_controller(1, null, null, 0); } foreach ($activities as $activity) { $params_a = array('moduleinstance' => $activity->id); $criteria = new completion_criteria_activity(array_merge($params, $params_a)); $criteria->config_form_display($mform, $activity); } $mform->addElement('static', 'criteria_role_note', '', get_string('activitiescompletednote', 'core_completion')); if (count($activities) > 1) { // Map aggregation methods to context-sensitive human readable dropdown menu. $activityaggregationmenu = array(); foreach ($aggregation_methods as $methodcode => $methodname) { if ($methodcode === COMPLETION_AGGREGATION_ALL) { $activityaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('activityaggregation_all', 'core_completion'); } else { if ($methodcode === COMPLETION_AGGREGATION_ANY) { $activityaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('activityaggregation_any', 'core_completion'); } else { $activityaggregationmenu[$methodcode] = $methodname; } } } $mform->addElement('select', 'activity_aggregation', get_string('activityaggregation', 'core_completion'), $activityaggregationmenu); $mform->setDefault('activity_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ACTIVITY)); } } else { $mform->addElement('static', 'noactivities', '', get_string('err_noactivities', 'completion')); } // Course prerequisite completion criteria. $label = get_string('coursecompletioncondition', 'core_completion', get_string('dependenciescompleted', 'core_completion')); $mform->addElement('header', 'courseprerequisites', $label); // Get the list of currently specified conditions and expand the section if some are found. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE); if (!empty($current)) { $mform->setExpanded('courseprerequisites'); } // Get applicable courses (prerequisites). $courses = $DB->get_records_sql("\n SELECT DISTINCT c.id, c.category, c.fullname, cc.id AS selected\n FROM {course} c\n LEFT JOIN {course_completion_criteria} cc ON cc.courseinstance = c.id AND cc.course = {$course->id}\n INNER JOIN {course_completion_criteria} ccc ON ccc.course = c.id\n WHERE c.enablecompletion = " . COMPLETION_ENABLED . "\n AND c.id <> {$course->id}"); if (!empty($courses)) { // Get category list. require_once $CFG->libdir . '/coursecatlib.php'; $list = coursecat::make_categories_list(); // Get course list for select box. $selectbox = array(); $selected = array(); foreach ($courses as $c) { $selectbox[$c->id] = $list[$c->category] . ' / ' . format_string($c->fullname, true, array('context' => context_course::instance($c->id))); // If already selected ... if ($c->selected) { $selected[] = $c->id; } } // Show multiselect box. $mform->addElement('select', 'criteria_course', get_string('coursesavailable', 'completion'), $selectbox, array('multiple' => 'multiple', 'size' => 6)); // Select current criteria. $mform->setDefault('criteria_course', $selected); // Explain list. $mform->addElement('static', 'criteria_courses_explaination', '', get_string('coursesavailableexplaination', 'completion')); if (count($courses) > 1) { // Map aggregation methods to context-sensitive human readable dropdown menu. $courseaggregationmenu = array(); foreach ($aggregation_methods as $methodcode => $methodname) { if ($methodcode === COMPLETION_AGGREGATION_ALL) { $courseaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('courseaggregation_all', 'core_completion'); } else { if ($methodcode === COMPLETION_AGGREGATION_ANY) { $courseaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('courseaggregation_any', 'core_completion'); } else { $courseaggregationmenu[$methodcode] = $methodname; } } } $mform->addElement('select', 'course_aggregation', get_string('courseaggregation', 'core_completion'), $courseaggregationmenu); $mform->setDefault('course_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_COURSE)); } } else { $mform->addElement('static', 'nocourses', '', get_string('err_nocourses', 'completion')); } // Completion on date $label = get_string('coursecompletioncondition', 'core_completion', get_string('completionondate', 'core_completion')); $mform->addElement('header', 'date', $label); // Expand the condition section if it is currently enabled. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DATE); if (!empty($current)) { $mform->setExpanded('date'); } $criteria = new completion_criteria_date($params); $criteria->config_form_display($mform); // Completion after enrolment duration $label = get_string('coursecompletioncondition', 'core_completion', get_string('enrolmentduration', 'core_completion')); $mform->addElement('header', 'duration', $label); // Expand the condition section if it is currently enabled. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_DURATION); if (!empty($current)) { $mform->setExpanded('duration'); } $criteria = new completion_criteria_duration($params); $criteria->config_form_display($mform); // Completion on unenrolment $label = get_string('coursecompletioncondition', 'core_completion', get_string('unenrolment', 'core_completion')); $mform->addElement('header', 'unenrolment', $label); // Expand the condition section if it is currently enabled. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_UNENROL); if (!empty($current)) { $mform->setExpanded('unenrolment'); } $criteria = new completion_criteria_unenrol($params); $criteria->config_form_display($mform); // Completion on course grade $label = get_string('coursecompletioncondition', 'core_completion', get_string('coursegrade', 'core_completion')); $mform->addElement('header', 'grade', $label); // Expand the condition section if it is currently enabled. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_GRADE); if (!empty($current)) { $mform->setExpanded('grade'); } $course_grade = $DB->get_field('grade_items', 'gradepass', array('courseid' => $course->id, 'itemtype' => 'course')); if (!$course_grade) { $course_grade = '0.00000'; } $criteria = new completion_criteria_grade($params); $criteria->config_form_display($mform, $course_grade); // Manual self completion $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualselfcompletion', 'core_completion')); $mform->addElement('header', 'manualselfcompletion', $label); // Expand the condition section if it is currently enabled. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_SELF); if (!empty($current)) { $mform->setExpanded('manualselfcompletion'); } $criteria = new completion_criteria_self($params); $criteria->config_form_display($mform); $mform->addElement('static', 'criteria_self_note', '', get_string('manualselfcompletionnote', 'core_completion')); // Role completion criteria $label = get_string('coursecompletioncondition', 'core_completion', get_string('manualcompletionby', 'core_completion')); $mform->addElement('header', 'roles', $label); // Expand the condition section if it is currently enabled. $current = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE); if (!empty($current)) { $mform->setExpanded('roles'); } $roles = get_roles_with_capability('moodle/course:markcomplete', CAP_ALLOW, context_course::instance($course->id, IGNORE_MISSING)); if (!empty($roles)) { foreach ($roles as $role) { $params_a = array('role' => $role->id); $criteria = new completion_criteria_role(array_merge($params, $params_a)); $criteria->config_form_display($mform, $role); } $mform->addElement('static', 'criteria_role_note', '', get_string('manualcompletionbynote', 'core_completion')); // Map aggregation methods to context-sensitive human readable dropdown menu. $roleaggregationmenu = array(); foreach ($aggregation_methods as $methodcode => $methodname) { if ($methodcode === COMPLETION_AGGREGATION_ALL) { $roleaggregationmenu[COMPLETION_AGGREGATION_ALL] = get_string('roleaggregation_all', 'core_completion'); } else { if ($methodcode === COMPLETION_AGGREGATION_ANY) { $roleaggregationmenu[COMPLETION_AGGREGATION_ANY] = get_string('roleaggregation_any', 'core_completion'); } else { $roleaggregationmenu[$methodcode] = $methodname; } } } $mform->addElement('select', 'role_aggregation', get_string('roleaggregation', 'core_completion'), $roleaggregationmenu); $mform->setDefault('role_aggregation', $completion->get_aggregation_method(COMPLETION_CRITERIA_TYPE_ROLE)); } else { $mform->addElement('static', 'noroles', '', get_string('err_noroles', 'completion')); } // Add common action buttons. $this->add_action_buttons(); // Add hidden fields. $mform->addElement('hidden', 'id', $course->id); $mform->setType('id', PARAM_INT); // If the criteria are locked, freeze values and submit button. if ($completion->is_course_locked()) { $except = array('settingsunlock'); $mform->hardFreezeAllVisibleExcept($except); $mform->addElement('cancel'); } }
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; }
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; }