Determines if given criteria was completed.

@param AchievementCriteria         $criteria
@param AchievementCriteriaProgress $progress

@return bool
433548
protected function isCompletedCriteria(AchievementCriteria $criteria, AchievementCriteriaProgress $progress): bool
    {
        $progress->completed = $progress->value >= $criteria->maxValue();

        return $progress->completed;
    }
199424
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\DateMetadata &&
            $criterion->target === 'modified' &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ
            );
    }
822315
public function achievementStatus(Achievement $achievement)
    {
        return $this->achievements()->where('achievement_id', $achievement->getModel()->id)->first();
    }
684842
public function process_course_completion_crit_compl($data) {
        global $DB;

        $data = (object)$data;

        // This may be empty if criteria could not be restored
        $data->criteriaid = $this->get_mappingid('course_completion_criteria', $data->criteriaid);

        $data->course = $this->get_courseid();
        $data->userid = $this->get_mappingid('user', $data->userid);

        if (!empty($data->criteriaid) && !empty($data->userid)) {
            $params = array(
                'userid' => $data->userid,
                'course' => $data->course,
                'criteriaid' => $data->criteriaid,
                'timecompleted' => $data->timecompleted
            );
            if (isset($data->gradefinal)) {
                $params['gradefinal'] = $data->gradefinal;
            }
            if (isset($data->unenroled)) {
                $params['unenroled'] = $data->unenroled;
            }
            $DB->insert_record('course_completion_crit_compl', $params);
        }
    }
667243
public function countPermissionsRelatedById(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collPermissionsRelatedByIdPartial && !$this->isNew();
        if (null === $this->collPermissionsRelatedById || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collPermissionsRelatedById) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getPermissionsRelatedById());
            }

            $query = ChildPermissionQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByPermissionRelatedByParentId($this)
                ->count($con);
        }

        return count($this->collPermissionsRelatedById);
    }
140900
private function matchesCriteria(array $criteria, array $metadata)
    {
        foreach ($criteria as $key => $value) {
            if (!array_key_exists($key, $metadata) || $metadata[$key] !== $value) {
                return false;
            }
        }

        return true;
    }
911624
public CocoTask<T> progress(final Dialog progress) {
        if (progress != null) {
            this.progress = new WeakReference<Object>(progress);
        }
        return this;
    }
1246582
public function progress($progress = file_progress::INDETERMINATE, $max = file_progress::INDETERMINATE) {
        $reporter = $this->task->get_progress();

        // Start tracking progress if necessary.
        if (!$this->startedprogress) {
            $reporter->start_progress('extract_file_to_dir', ($max == file_progress::INDETERMINATE)
                    ? \core\progress\base::INDETERMINATE : $max);
            $this->startedprogress = true;
        }

        // Pass progress through to whatever handles it.
        $reporter->progress(($progress == file_progress::INDETERMINATE)
                ? \core\progress\base::INDETERMINATE : $progress);
     }
1340175
public static function course_criteria_review(\core\event\course_completed $event) {
        global $DB, $CFG;

        if (!empty($CFG->enablebadges)) {
            require_once($CFG->dirroot.'/lib/badgeslib.php');

            $userid = $event->relateduserid;
            $courseid = $event->courseid;

            // Need to take into account that course can be a part of course_completion and courseset_completion criteria.
            if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'course_' . $courseid, 'value' => $courseid))) {
                foreach ($rs as $r) {
                    $crit = $DB->get_record('badge_criteria', array('id' => $r->critid), 'badgeid, criteriatype', MUST_EXIST);
                    $badge = new badge($crit->badgeid);
                    if (!$badge->is_active() || $badge->is_issued($userid)) {
                        continue;
                    }

                    if ($badge->criteria[$crit->criteriatype]->review($userid)) {
                        $badge->criteria[$crit->criteriatype]->mark_complete($userid);

                        if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) {
                            $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid);
                            $badge->issue($userid);
                        }
                    }
                }
            }
        }
    }
839364
public function updateDropProgression(Dropzone $dropzone, Drop $drop, $progression)
    {
        $this->om->startFlushSuite();

        if (Dropzone::DROP_TYPE_TEAM === $dropzone->getDropType()) {
            foreach ($drop->getUsers() as $user) {
                $this->resourceEvalManager->createResourceEvaluation(
                    $dropzone->getResourceNode(),
                    $user,
                    null,
                    ['progression' => $progression, 'data' => $this->serializeDrop($drop)],
                    ['progression' => true]
                );
            }
        } else {
            $this->resourceEvalManager->createResourceEvaluation(
                $dropzone->getResourceNode(),
                $drop->getUser(),
                null,
                ['progression' => $progression, 'data' => $this->serializeDrop($drop)],
                ['progression' => true]
            );
        }
        $this->om->endFlushSuite();
    }
1349338
function (progressFn, m) {
  var idx = m.p.indexOf(WO);
  if (idx >= 0) {
    // set scores manually to avoid the `_verify` walkover scoring restriction
    m.m = (idx === 0) ? [0, 1] : [1, 0];
    progressFn(m);
  }
}
1315096
def progress_inc(self, step=1, new_status=None):
    
    self._value += step
    self.progress(self._value, new_status=new_status)
155527
public void setProgress(int progress) {
        if (progress > mMax || progress < 0) {
            throw new IllegalArgumentException(
                    String.format("Progress (%d) must be between %d and %d", progress, 0, mMax));
        }
        mProgress = progress;
        if (null != mListener) {
            if (mProgress == mMax) {
                mListener.onProgressCompleted();
            } else {
                mListener.onProgressChanged(mProgress, mMax);
            }
        }
        invalidate();
    }
629644
public function get_user_completion($user_id, $criteria) {
        $params = array(
            'course'        => $this->course_id,
            'userid'        => $user_id,
            'criteriaid'    => $criteria->id,
        );

        $completion = new completion_criteria_completion($params);
        return $completion;
    }
916879
public function get_completion($user_id, $criteriatype) {
        $completions = $this->get_completions($user_id, $criteriatype);

        if (empty($completions)) {
            return false;
        } elseif (count($completions) > 1) {
            print_error('multipleselfcompletioncriteria', 'completion');
        }

        return $completions[0];
    }
786450
protected function findWithCriteria(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $qb = $this->getLoadQuery();
        foreach ($criteria as $col => $val) {
            if (is_array($val)) {
                $qb->andWhere($this->getAlias() . ".$col IN(:$col)");
                $qb->setParameter(":$col", $val, Connection::PARAM_INT_ARRAY);
            } else {
                $qb->andWhere($this->getAlias() . ".$col = :$col");
                $qb->setParameter(":$col", $val);
            }
        }
        if ($orderBy) {
            $qb->orderBy($orderBy[0], $orderBy[1]);
        }
        if ($limit) {
            $qb->setMaxResults($limit);
        }
        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb;
    }
1310709
public function check_progress( $method, $x = null ) {

		$method = str_replace( 'migrate_', '', $method );

		if ( isset( $this->progress[ $method ] ) ) {
			if ( null === $x ) {
				return $this->progress[ $method ];
			} elseif ( isset( $this->progress[ $method ][ $x ] ) ) {
				return (boolean) $this->progress[ $method ][ $x ];
			}
		}

		return false;
	}