public function process()
    {
        $operands = $this->getOperands();

        // Retrieve the values of min and max.
        $min = $this->getExpression()->getMin();
        $max = $this->getExpression()->getMax();

        // @todo write a generic method to retrieve variable references.

        if (is_string($min) === true) {
            // variable reference for 'min' to handle.
            $state = $this->getState();
            $varName = Utils::sanitizeVariableRef($min);
            $varValue = $state[$varName];

            if (is_null($varValue)) {
                $msg = "The variable with name '${varName}' could not be resolved or is null.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
            } elseif (!$varValue instanceof QtiInteger) {
                $msg = "The variable with name '${varName}' is not an integer.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
            } else {
                $min = $varValue->getValue();
            }
        }

        if (is_string($max) === true) {
            // variable reference for 'max' to handle.
            $state = $this->getState();
            $varName = Utils::sanitizeVariableRef($max);
            $varValue = $state[$varName];

            if (is_null($varValue)) {
                $msg = "The variable with name '${varName}' could not be resolved or is null.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
            } elseif (!$varValue instanceof QtiInteger) {
                $msg = "The variable with name '${varName}' is not an integer.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
            } else {
                $max = $varValue->getValue();
            }
        }

        $nullCount = 0;
        $trueCount = 0;

        foreach ($operands as $operand) {
            if (is_null($operand)) {
                $nullCount++;
                continue;
            } elseif ($operand instanceof QtiBoolean) {
                if ($operand->getValue() === true) {
                    $trueCount++;
                }
            } else {
                // Not null, not a boolean, we have a problem...
                $msg = "The AnyN operator only accepts values with cardinality single and baseType boolean.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE_OR_CARDINALITY);
            }
        }

        if ($trueCount >= $min && $trueCount <= $max) {
            return new QtiBoolean(true);
        } else {
            // Should we return false or null?
            if ($trueCount + $nullCount >= $min && $trueCount + $nullCount <= $max) {
                // It could have match if nulls were true values.
                return null;
            } else {
                return new QtiBoolean(false);
            }
        }
    }
public function process()
    {
        $operands = $this->getOperands();

        // Retrieve the values of min and max.
        $min = $this->getExpression()->getMin();
        $max = $this->getExpression()->getMax();

        // @todo write a generic method to retrieve variable references.

        if (is_string($min) === true) {
            // variable reference for 'min' to handle.
            $state = $this->getState();
            $varName = Utils::sanitizeVariableRef($min);
            $varValue = $state[$varName];

            if (is_null($varValue)) {
                $msg = "The variable with name '${varName}' could not be resolved or is null.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
            } elseif (!$varValue instanceof QtiInteger) {
                $msg = "The variable with name '${varName}' is not an integer.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
            } else {
                $min = $varValue->getValue();
            }
        }

        if (is_string($max) === true) {
            // variable reference for 'max' to handle.
            $state = $this->getState();
            $varName = Utils::sanitizeVariableRef($max);
            $varValue = $state[$varName];

            if (is_null($varValue)) {
                $msg = "The variable with name '${varName}' could not be resolved or is null.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
            } elseif (!$varValue instanceof QtiInteger) {
                $msg = "The variable with name '${varName}' is not an integer.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
            } else {
                $max = $varValue->getValue();
            }
        }

        $nullCount = 0;
        $trueCount = 0;

        foreach ($operands as $operand) {
            if (is_null($operand)) {
                $nullCount++;
                continue;
            } elseif ($operand instanceof QtiBoolean) {
                if ($operand->getValue() === true) {
                    $trueCount++;
                }
            } else {
                // Not null, not a boolean, we have a problem...
                $msg = "The AnyN operator only accepts values with cardinality single and baseType boolean.";
                throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE_OR_CARDINALITY);
            }
        }

        if ($trueCount >= $min && $trueCount <= $max) {
            return new QtiBoolean(true);
        } else {
            // Should we return false or null?
            if ($trueCount + $nullCount >= $min && $trueCount + $nullCount <= $max) {
                // It could have match if nulls were true values.
                return null;
            } else {
                return new QtiBoolean(false);
            }
        }
    }
public function process ( ) { $ operands = $ this -> getOperands ( ) ; // Retrieve the values of min and max. $ min = $ this -> getExpression ( ) -> getMin ( ) ; $ max = $ this -> getExpression ( ) -> getMax ( ) ; // @todo write a generic method to retrieve variable references. if ( is_string ( $ min ) === true ) { // variable reference for 'min' to handle. $ state = $ this -> getState ( ) ; $ varName = Utils :: sanitizeVariableRef ( $ min ) ; $ varValue = $ state [ $ varName ] ; if ( is_null ( $ varValue ) ) { $ msg = "The variable with name '${varName}' could not be resolved or is null." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: NONEXISTENT_VARIABLE ) ; } elseif ( ! $ varValue instanceof QtiInteger ) { $ msg = "The variable with name '${varName}' is not an integer." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: WRONG_BASETYPE ) ; } else { $ min = $ varValue -> getValue ( ) ; } } if ( is_string ( $ max ) === true ) { // variable reference for 'max' to handle. $ state = $ this -> getState ( ) ; $ varName = Utils :: sanitizeVariableRef ( $ max ) ; $ varValue = $ state [ $ varName ] ; if ( is_null ( $ varValue ) ) { $ msg = "The variable with name '${varName}' could not be resolved or is null." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: NONEXISTENT_VARIABLE ) ; } elseif ( ! $ varValue instanceof QtiInteger ) { $ msg = "The variable with name '${varName}' is not an integer." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: WRONG_VARIABLE_BASETYPE ) ; } else { $ max = $ varValue -> getValue ( ) ; } } $ nullCount = 0 ; $ trueCount = 0 ; foreach ( $ operands as $ operand ) { if ( is_null ( $ operand ) ) { $ nullCount ++ ; continue ; } elseif ( $ operand instanceof QtiBoolean ) { if ( $ operand -> getValue ( ) === true ) { $ trueCount ++ ; } } else { // Not null, not a boolean, we have a problem... $ msg = "The AnyN operator only accepts values with cardinality single and baseType boolean." ; throw new OperatorProcessingException ( $ msg , $ this , OperatorProcessingException :: WRONG_BASETYPE_OR_CARDINALITY ) ; } } if ( $ trueCount >= $ min && $ trueCount <= $ max ) { return new QtiBoolean ( true ) ; } else { // Should we return false or null? if ( $ trueCount + $ nullCount >= $ min && $ trueCount + $ nullCount <= $ max ) { // It could have match if nulls were true values. return null ; } else { return new QtiBoolean ( false ) ; } } }
Process the AnyN processor.

@return boolean|null A boolean value of true if at least min of the sub-expressions are true and at most max of the sub-expressions are true. NULL is returned if the correct value for the operator cannot be determined.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException
Process the AnyN processor .