Checks whether the toggle is active for the given context.

@param Context $context

@return bool True, if one of conditions hold for the context.
188511
public function activeFor(Context $context)
    {
        switch ($this->status) {
            case self::ALWAYS_ACTIVE:
                return true;
            case self::INACTIVE:
                return false;
            case self::CONDITIONALLY_ACTIVE:
                return $this->executeCondition($context);
        }
        return false;
    }
885272
public function isRoleScopePresentOnce(ExecutionContextInterface $context) 
    {
        $roleScopesId = array_map(function(RoleScope $roleScope) {
                    return $roleScope->getId();
                }, 
                $this->getRoleScopes()->toArray());
        $countedIds = array_count_values($roleScopesId);
        
        foreach ($countedIds as $id => $nb) {
            if ($nb > 1) {
                $context->buildViolation("A permission is already present "
                        . "for the same role and scope")
                        ->addViolation();
            }
        }
    }
1329299
protected static function hasScope(ContextInterface $context, string $scope): bool
    {
        $result = false;

        if (static::ctxHasCurrentAccount($context) === true) {
            /** @var PassportAccountInterface $account */
            $account = self::ctxGetCurrentAccount($context);
            $result  = $account->hasScope($scope);
        }

        return $result;
    }
538503
public function isValid($conditionId, $context)
    {
        $conditions = $this->getConditions();
        $valid = true;
        foreach($conditions as $condition)
        {
            $valid = $valid && $condition->isValid($conditionId, $context);
        }
        
        return $valid;
    }
770481
public function predictions_exist(\context $context) {
        global $DB;

        // Filters out previous predictions keeping only the last time range one.
        $select = "modelid = :modelid AND contextid = :contextid";
        $params = array('modelid' => $this->model->id, 'contextid' => $context->id);
        return $DB->record_exists_select('analytics_predictions', $select, $params);
    }
115372
public static function is_context_expired(\context $context) : bool {
        $parents = $context->get_parent_contexts(true);
        foreach ($parents as $parent) {
            if ($parent instanceof \context_course) {
                // This is a context within a course. Check whether _this context_ is expired as a function of a course.
                return self::is_course_context_expired($context);
            }

            if ($parent instanceof \context_user) {
                // This is a context within a user. Check whether the _user_ has expired.
                return self::are_user_context_dependencies_expired($parent);
            }
        }

        return false;
    }
94762
private function atLeastOneConditionHolds(Context $context)
    {
        foreach ($this->conditions as $condition) {
            if ($condition->holdsFor($context)) {
                return true;
            }
        }

        return false;
    }
77239
public function appliesToContext(ContextInterface $context): bool
    {
        if (!$context instanceof TypeContext && !$context instanceof PropertyContext) {
            return false;
        }

        $type = $context->getType();
        $typeExists = array_key_exists($type->getName(), $this->typeMap);
        // The default rule will be used here:
        if (!$typeExists) {
            return $this->defaultRule->appliesToContext($context);
        }

        // It's possible to define a null rule, which means that no code will be generated.
        $rule = $this->typeMap[$type->getName()];
        if ($rule  === null) {
            return false;
        }

        return $rule->appliesToContext($context);
    }
561667
protected function _actionDispatch(AnCommandContext $context)
    {
        if ($this->action === 'confirm' && $this->token) {
            $context->data->append(array(
               '_action' => 'confirm',
               'token' => $this->token,
            ));

            return $this->execute('post', $context);
        }

        return parent::_actionDispatch($context);
    }
1289967
protected function _authorizeEdit($context)
    {
        $ret = parent::_authorizeEdit($context);

        if (
              $ret === false &&
              $this->_entity->isOwnable() &&
              $this->_entity->owner->allows($this->_viewer, 'com_articles:article:edit')
        ) {
            return true;
        }

        return $ret;
    }
1053153
protected function _actionVerify($context)
    {
        $context->response->status = AnHttpResponse::RESET_CONTENT;
        $this->getItem()->verify();
        return;
    }
184829
public function goBegin(Context $context = null)
    {
        $id = $this->bind($context);
        return $this->getDBQueryBuilder($context)->go($id, 'begin');
    }
122202
public function canEvaluate($context)
    {
        if (count($context) === 0) {
            return true;
        }

        foreach ($context as $contextNode) {
            if (!$contextNode instanceof NodeInterface) {
                return false;
            }
        }
        return true;
    }
346301
protected function checkRules($context = null)
    {
        $rules = $this->getRules();
        $result = false;

        foreach ($rules as $rule) {
            if ($rule->check($context)) {
                $result = true;
                break;
            }
        }

        return $result;
    }
287036
public function is_visible() {
        $type = repository::get_type_by_id($this->options['typeid']);
        $instanceoptions = repository::static_function($type->get_typename(), 'get_instance_option_names');

        if ($type->get_visible()) {
            //if the instance is unique so it's visible, otherwise check if the instance has a enabled context
            if (empty($instanceoptions) || $type->get_contextvisibility(context::instance_by_id($this->instance->contextid))) {
                return true;
            }
        }

        return false;
    }
662367
public function is($context, $original = '')
    {
        return (($this->context === $context) && ($this->original === $original)) ? true : false;
    }
1226927
public function evaluate(Context $context)
    {
        /** @var VariableOperand $left */
        /** @var VariableOperand $right */
        list($left, $right) = $this->getOperands();

        return $left->prepareValue($context)->stringContains($right->prepareValue($context)) === false;
    }