Checks if the expiration date is valid
@param  ExecutionContext $context
@return void
775390
public function checkExpirationDate(ExecutionContext $context)
    {
        $expirationDate = $this->expirationDate;

        if (is_null($expirationDate)) {
            $context->addViolationAt("expirationDate", "La fecha de vencimiento es invalida", array(), null);
        } else {
            $ts = $expirationDate->format('U');
            if ($ts<=time()) {
                $context->addViolationAt("expirationDate", "La fecha de vencimiento es invalida", array(), null);
            }
        }

    }
150144
protected function _beforeInsert(DatabaseContext $context)
    {
        if($this->hasProperty('modified_by')) {
            $this->modified_by = (int) $this->getObject('user')->getId();
        }

        if($this->hasProperty('modified_on')) {
            $this->modified_on = gmdate('Y-m-d H:i:s');
        }
    }
659090
public function evaluate( Context $context ) {
		/**
		 * Extracts variables.
		 *
		 * @var \Ruler\Variable $left
		 * @var \Ruler\Variable $right
		 */
		list( $left, $right ) = $this->getOperands();

		$left  = $left->prepareValue( $context )->getValue();
		$right = $right->prepareValue( $context )->getValue();

		if ( 2 !== count( $right ) ) {
			return false;
		}

		// Make sure we have a valid range.
		if ( $right[0] > $right[1] ) {
			$temp     = $right[0];
			$right[0] = $right[1];
			$right[1] = $temp;
		}

		return ( $left >= $right[0] && $left <= $right[1] );
	}
474660
public function evaluate( Context $context ) {
		/* @var \Ruler\Variable $left */
		list( $left ) = $this->getOperands();

		$value = $left->prepareValue( $context )->getValue();

		if ( is_null( $value ) ) {
			return true;
		}

		if ( is_string( $value ) ) {
			return trim( $value ) === '';
		}

		if ( $value instanceof \Countable ) {
			return count( $value ) === 0;
		}

		return empty( $value );
	}
172472
public function isImageValid(ExecutionContextInterface $context)
    {
        if ($this->isImage() && is_null($this->getFile())) {
            $context->addViolationAt('file', 'This value should not be blank.');
        }
    }
1053153
protected function _actionVerify($context)
    {
        $context->response->status = AnHttpResponse::RESET_CONTENT;
        $this->getItem()->verify();
        return;
    }
44523
protected function _beforeInsert(KDatabaseContextInterface $context)
    {
        if($this->hasProperty('ordering'))
        {
            if($this->ordering <= 0) {
                $this->ordering = $this->getMaxOrdering() + 1;
            } else {
                $this->reorder($this->ordering);
            }
        }
    }
272891
private static function check_contexts(context $context, $values) {
        if ($context->contextlevel > CONTEXT_COURSECAT) {
            return self::check_contexts($context->get_parent_context(), $values);
        } else if ($context->contextlevel == CONTEXT_COURSECAT) {
            if (in_array($context->instanceid, $values)) {
                return true;
            } else {
                return self::check_contexts($context->get_parent_context(), $values);
            }
        } else {
            return false;
        }
    }
867049
public function initializeContext(Context $context)
    {
        if (!$context instanceof GuzzleAwareContext) {
            return;
        }

        $context->setGuzzleClient($this->client);
        $context->setGuzzleParameters($this->parameters);
    }
249039
protected function _beforeInsert(DatabaseContext $context)
    {
        $method = 'get'.ucfirst($this->_column);
        if($context->data->$method() instanceof ObjectConfigInterface) {
            $context->data->setProperty($this->_column, $context->data->$method()->toString());
        }
    }
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;
    }
14987
public function executeRules(Context $context)
    {
        foreach ($this->rules as $rule) {
            $rule->execute($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;
    }
547489
public function setExpiry(?\DateTimeImmutable $expiry = null): void
    {
        $date = new \DateTimeImmutable();
        $expiry = $expiry ?: $date;

        $this->setHeader('Date', $date->setTimezone(new \DateTimeZone('UTC'))->format('D, d M Y H:i:s \G\M\T'));
        $this->setHeader('Expires', $expiry->setTimezone(new \DateTimeZone('UTC'))->format('D, d M Y H:i:s \G\M\T'));

        if ($expiry <= $date) {
            $this->setHeader('Cache-Control', 'no-cache, no-store, must-revalidate, max-age=0');

            return;
        }

        $maxAge = $expiry->getTimestamp() - $date->getTimestamp();
        $this->setHeader('Cache-Control', 'public, max-age=' . $maxAge);
    }
634441
protected function delete_expired_context(expired_context $expiredctx) {
        $context = \context::instance_by_id($expiredctx->get('contextid'));

        $this->get_progress()->output("Deleting context {$context->id} - " . $context->get_context_name(true, true));

        // Update the expired_context and verify that it is still ready for deletion.
        $expiredctx = $this->update_expired_context($expiredctx);
        if (empty($expiredctx)) {
            $this->get_progress()->output("Context has changed since approval and is no longer pending approval. Skipping", 1);
            return false;
        }

        if (!$expiredctx->can_process_deletion()) {
            // This only happens if the record was updated after being first fetched.
            $this->get_progress()->output("Context has changed since approval and must be re-approved. Skipping", 1);
            $expiredctx->set('status', expired_context::STATUS_EXPIRED);
            $expiredctx->save();

            return false;
        }

        $privacymanager = $this->get_privacy_manager();
        if ($expiredctx->is_fully_expired()) {
            if ($context instanceof \context_user) {
                $this->delete_expired_user_context($expiredctx);
            } else {
                // This context is fully expired - that is that the default retention period has been reached, and there are
                // no remaining overrides.
                $privacymanager->delete_data_for_all_users_in_context($context);
            }

            // Mark the record as cleaned.
            $expiredctx->set('status', expired_context::STATUS_CLEANED);
            $expiredctx->save();

            return $context;
        }

        // We need to find all users in the context, and delete just those who have expired.
        $collection = $privacymanager->get_users_in_context($context);

        // Apply the expired and unexpired filters to remove the users in these categories.
        $userassignments = $this->get_role_users_for_expired_context($expiredctx, $context);
        $approvedcollection = new \core_privacy\local\request\userlist_collection($context);
        foreach ($collection as $pendinguserlist) {
            $userlist = filtered_userlist::create_from_userlist($pendinguserlist);
            $userlist->apply_expired_context_filters($userassignments->expired, $userassignments->unexpired);
            if (count($userlist)) {
                $approvedcollection->add_userlist($userlist);
            }
        }

        if (count($approvedcollection)) {
            // Perform the deletion with the newly approved collection.
            $privacymanager->delete_data_for_users_in_context($approvedcollection);
        }

        // Mark the record as cleaned.
        $expiredctx->set('status', expired_context::STATUS_CLEANED);
        $expiredctx->save();

        return $context;
    }
549004
public function validate($entity, $context = null) : bool
    {
        if (!$entity instanceof AuditEvent) {
            throw new \LogicException('The Entity to validate must be an instance of \Fei\Service\Audit\Entity\AuditEvent');
        }

        return parent::validate($entity, $context);
    }
976062
public function execute(ServerContextInterface $context = null)
    {
        if (null === $context) {
            $context = new ServerContext();
        }

        $this->logServerStart($context);

        $this->server->start(
            $context,
            $this->decorateRequestHandler($this->requestHandler)
        );
    }