예제 #1
0
 /**
  * Get course completion criteria
  *
  * @param int $criteriatype Specific criteria type to return (optional)
  */
 public function get_criteria($criteriatype = null)
 {
     // Fill cache if empty
     if (!is_array($this->criteria)) {
         global $DB;
         $params = array('course' => $this->course->id);
         // Load criteria from database
         $records = (array) $DB->get_records('course_completion_criteria', $params);
         // Build array of criteria objects
         $this->criteria = array();
         foreach ($records as $record) {
             $this->criteria[$record->id] = completion_criteria::factory((array) $record);
         }
     }
     // If after all criteria
     if ($criteriatype === null) {
         return $this->criteria;
     }
     // If we are only after a specific criteria type
     $criteria = array();
     foreach ($this->criteria as $criterion) {
         if ($criterion->criteriatype != $criteriatype) {
             continue;
         }
         $criteria[$criterion->id] = $criterion;
     }
     return $criteria;
 }
예제 #2
0
 // Check user is logged in
 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
 $context = context_course::instance($course->id);
 require_login($course);
 $completion = new completion_info($course);
 $trackeduser = $user ? $user : $USER->id;
 if (!$completion->is_enabled()) {
     throw new moodle_exception('completionnotenabled', 'completion');
 } else {
     if (!$completion->is_tracked_user($trackeduser)) {
         throw new moodle_exception('nottracked', 'completion');
     }
 }
 if ($user && $rolec) {
     require_sesskey();
     completion_criteria::factory(array('id' => $rolec, 'criteriatype' => COMPLETION_CRITERIA_TYPE_ROLE));
     //TODO: this is dumb, because it does not fetch the data?!?!
     $criteria = completion_criteria_role::fetch(array('id' => $rolec));
     if ($criteria and user_has_role_assignment($USER->id, $criteria->role, $context->id)) {
         $criteria_completions = $completion->get_completions($user, COMPLETION_CRITERIA_TYPE_ROLE);
         foreach ($criteria_completions as $criteria_completion) {
             if ($criteria_completion->criteriaid == $rolec) {
                 $criteria->complete($criteria_completion);
                 break;
             }
         }
     }
     // Return to previous page
     $referer = clean_param($_SERVER['HTTP_REFERER'], PARAM_LOCALURL);
     if (!empty($referer)) {
         redirect($referer);
 /**
  * Return the associated criteria with this completion
  * If nothing attached, load from the db
  *
  * @return completion_criteria
  */
 public function get_criteria()
 {
     if (!$this->_criteria) {
         global $DB;
         $params = array('id' => $this->criteriaid);
         $record = $DB->get_record('course_completion_criteria', $params);
         $this->attach_criteria(completion_criteria::factory($record));
     }
     return $this->_criteria;
 }
예제 #4
0
    $completion = new completion_info($course);
    if (!$completion->is_enabled()) {
        throw new moodle_exception('completionnotenabled', 'completion');
    } elseif (!$completion->is_tracked_user($USER->id)) {
        throw new moodle_exception('nottracked', 'completion');
    }

    // Check if we are marking a user complete via the completion report
    $user = optional_param('user', 0, PARAM_INT);
    $rolec = optional_param('rolec', 0, PARAM_INT);

    if ($user && $rolec) {
        require_sesskey();

        completion_criteria::factory(array('id'=>$rolec, 'criteriatype'=>COMPLETION_CRITERIA_TYPE_ROLE)); //TODO: this is dumb, because it does not fetch the data?!?!
        $criteria = completion_criteria_role::fetch(array('id'=>$rolec));

        if ($criteria and user_has_role_assignment($USER->id, $criteria->role, $context->id)) {
            $criteria_completions = $completion->get_completions($user, COMPLETION_CRITERIA_TYPE_ROLE);

            foreach ($criteria_completions as $criteria_completion) {
                if ($criteria_completion->criteriaid == $rolec) {
                    $criteria->complete($criteria_completion);
                    break;
                }
            }
        }

        // Return to previous page
        if (!empty($_SERVER['HTTP_REFERER'])) {