Process the Truncate operator.

@return integer|null The truncated value or NULL if the sub-expression is NaN or if the sub-expression is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException
964783
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull() === true) {
            return null;
        }

        if ($operands->exclusivelySingle() === false) {
            $msg = "The Truncate operator only accepts operands with a single cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->exclusivelyNumeric() === false) {
            $msg = "The Truncate operator only accepts operands with an integer or float baseType.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        }

        $operand = $operands[0];

        if (is_nan($operand->getValue())) {
            return null;
        } elseif (is_infinite($operand->getValue())) {
            return new QtiFloat(INF);
        } else {
            return new QtiInteger(intval($operand->getValue()));
        }
    }
599385
protected function nextOperand()
    {
        if (isset($this->operands[$this->operandsCount])) {
            $operand = $this->operands[$this->operandsCount];
            if (!$operand->isMultiple()) {
                $this->operandsCount++;
            }
            return $operand;
        }

        return null;
    }
535676
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->exclusivelyRecord() === false) {
            $msg = "The FieldValue operator only accepts operands with a cardinality of record.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        $fieldIdentifier = $this->getExpression()->getFieldIdentifier();

        return $operands[0][$fieldIdentifier];
    }
424115
private function processLimitDefinition()
    {
        if (isset($this->definition['limit'])) {
            
            // Upper and lower limit? Or a single value?
            if (is_array($this->definition['limit'])) {
                
                switch (count($this->definition['limit'])) {
                    
                    case 1:
                        $this->limit['lower'] = (int) $this->definition['limit'][0];
                        break;
                    
                    case 2:
                    default:
                        $this->limit['lower'] = (int) $this->definition['limit'][0];
                        $this->limit['upper'] = (int) $this->definition['limit'][1];
                        break;
                }
            } else {
                $this->limit['lower'] = $this->definition['limit'];
            }
        }
    }
1294330
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull()) {
            return null;
        }

        if ($operands->exclusivelyMultipleOrOrdered() === false) {
            $msg = "The Contains Expression only accept operands with multiple or ordered cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->sameCardinality() === false) {
            $msg = "The Contains Expression only accept operands with the same cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->sameBaseType() === false) {
            $msg = "The Contains Expression only accept operands with the same baseType.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        }

        $operand1 = $operands[0];
        $operand2 = $operands[1];

        if ($operand1->getCardinality() === Cardinality::MULTIPLE) {
            foreach ($operand2 as $value) {
                if ($operand1->contains($value) === false || $operand1->occurences($value) !== $operand2->occurences($value)) {
                    return new QtiBoolean(false);
                }
            }

            return new QtiBoolean(true);
        } else {
            // $operand1->getCardinality() === Cardinality::ORDERED
            $op1Index = 0;
            $op2Index = 0;
            $lastFoundIndex = -1;
            $foundCount = 0;

            while ($op1Index < count($operand1)) {
                $op1Val = $operand1[$op1Index];
                $op2Val = $operand2[$op2Index];

                if ($op2Val === $op1Val || ($op2Val instanceof Comparable && $op2Val->equals($op1Val))) {
                    $op2Index++;

                    if ($lastFoundIndex >= 0 && ($op1Index - $lastFoundIndex) > 1) {
                        // Sequence not respected.
                        return new QtiBoolean(false);
                    } else {
                        $lastFoundIndex = $op1Index;
                        $foundCount++;
                    }
                }

                $op1Index++;
            }

            if ($foundCount > 0 && $foundCount === count($operand2)) {
                return new QtiBoolean(true);
            } else {
                return new QtiBoolean(false);
            }
        }
    }
302350
public static function process()
    {
        $out = null;

        //session handler enabled
        if (self::$status) {
            //get session into array
            $tmp = isset($_SESSION) ? $_SESSION : [];

            //remove excluded keys if were set, and if session is set
            if (!empty(self::$exclude_keys) && isset($_SESSION) && !empty($_SESSION)) {
                foreach (self::$exclude_keys as $key) {
                    if (isset($tmp[$key])) {
                        unset($tmp[$key]);
                    }
                }
            }

            $out = serialize($tmp);
        }

        return $out;
    }
144671
protected function handleSubExpression()
    {
        // Flag, checking for mismatching parentheses
        $clean = false;

        // Pop operators off the operatorStack until its empty, or
        // we find an opening parenthesis, building subexpressions
        // on the operandStack as we go.
        while ($popped = $this->operatorStack->pop()) {

            // ok, we have our matching opening parenthesis
            if ($popped instanceof SubExpressionNode) {
                $clean = true;
                break;
            }

            $node = $this->handleExpression($popped);
            $this->operandStack->push($node);

        }

        // Throw an error if the parenthesis couldn't be matched
        if (!$clean) {
            throw new ParenthesisMismatchException();
        }


        // Check to see if the parenthesis pair was in fact part
        // of a function application. If so, create the corresponding
        // FunctionNode and push it onto the operandStack.
        $previous = $this->operatorStack->peek();
        if ($previous instanceof FunctionNode) {
            $node = $this->operatorStack->pop();
            $operand = $this->operandStack->pop();
            $node->setOperand($operand);
            $this->operandStack->push($node);
        }
    }
848213
public function process(): string
    {
        while ($this->string->valid()) {
            $this->handleTxt();
            $this->handleComment();
            $this->handleMultiline();
            $this->append();
        }

        $this->removeWhitespace();

        return $this->normalisedString;
    }
316490
public function truncate() {
        $json = $this->getClient()->delete('data/' . $this->getDataSet()->id);
        return (isset($json['success']) && $json['success']);
    }
90021
public function truncateSql(): string
    {
        $connection = $this->getConnection();
        $builder = QueryBuilderFactory::getQueryBuilder($connection);
        $tableName = $builder->getQuotedName(TableNameResolver::getTableName($this->getModel()->tableName()));

        return $connection
            ->getDatabasePlatform()
            ->getTruncateTableSQL($tableName);
    }
1021516
public function convert()
    {
        if (count($this->arrayBlocks) <= 0) {
            return null;
        }
        try {
            $this->blockRepository->startTransaction();
            $result = $this->deleteBlocks();
            if (false !== $result) {
                $languages = $this->languageRepository->activeLanguages();
                foreach ($this->arrayBlocks as $block) {
                    foreach ($languages as $language) {
                        $result = $this->updateBlock($block, $language->getId(), 1);
                    }
                }

                if ($result) {
                    $this->blockRepository->commit();
                } else {
                    $this->blockRepository->rollBack();
                }
            }

            return $result;
        } catch (\Exception $e) {
            if (isset($this->blockRepository) && $this->blockRepository !== null) {
                $this->blockRepository->rollBack();
            }

            throw $e;
        }
    }
924361
public static function truncateValue($string, $limit, $endchars = '...')
    {

        if (!is_array($string) && !is_object($string)) {
            $stringLength = strlen($string);
            $endcharsLength = strlen($endchars);

            if ($stringLength > (int) $limit) {
                $cut = (int) ($limit - $endcharsLength);
                $string = substr($string, 0, $cut) . $endchars;
            }
        }
        return $string;
    }
576454
protected function process_value() {
		$this->value = trim( $this->value );

		// If you use calc() there, I suppose you know what you're doing.
		// No need to process this any further, just exit.
		if ( false !== strpos( $this->value, 'calc' ) ) {
			return;
		}

		// If the value is initial or inherit, we don't need to do anything.
		// Just exit.
		if ( 'initial' === $this->value || 'inherit' === $this->value ) {
			return;
		}

		$x_dimensions = [ 'left', 'center', 'right' ];
		$y_dimensions = [ 'top', 'center', 'bottom' ];

		// If there's a space, we have an X and a Y value.
		if ( false !== strpos( $this->value, ' ' ) ) {
			$xy = explode( ' ', $this->value );

			$x = trim( $xy[0] );
			$y = trim( $xy[1] );

			// If x is not left/center/right, we need to sanitize it.
			if ( ! in_array( $x, $x_dimensions, true ) ) {
				$x = sanitize_text_field( $x );
			}
			if ( ! in_array( $y, $y_dimensions, true ) ) {
				$y = sanitize_text_field( $y );
			}
			$this->value = $x . ' ' . $y;
			return;
		}
		$x = 'center';
		foreach ( $x_dimensions as $x_dimension ) {
			if ( false !== strpos( $this->value, $x_dimension ) ) {
				$x = $x_dimension;
			}
		}
		$y = 'center';
		foreach ( $y_dimensions as $y_dimension ) {
			if ( false !== strpos( $this->value, $y_dimension ) ) {
				$y = $y_dimension;
			}
		}
		$this->value = $x . ' ' . $y;
	}
1345189
public function process()
    {
        $value = $this->value();
        if ($value === null) {
            return false;
        }

        $isMultiValue = is_array($value);
        if ($isMultiValue &&
            empty($value)
        ) {
            return false;
        }

        if (!$this->manager()->getRepository() instanceof Table) {
            foreach ($this->fields() as $field) {
                $this->getQuery()->where([
                    $field => $value,
                ]);
            }

            return true;
        }

        $expressions = [];
        foreach ($this->fields() as $field) {
            $expressions[] = function (QueryExpression $e) use ($field, $value, $isMultiValue) {
                if ($isMultiValue) {
                    return $e->in($field, $value);
                }

                return $e->eq($field, $value);
            };
        }

        $this->getQuery()->andWhere([$this->getConfig('mode') => $expressions]);

        return true;
    }
831555
private function parseOperand (){

		$negate = false;
		$offset = $this->pos+1;
		if( $offset >= $this->input_len ){
			return;
		}
		$char = $this->input[$offset];
		if( $char === '@' || $char === '(' ){
			$negate = $this->MatchChar('-');
		}

		$o = $this->MatchFuncs(array('parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall'));

		if( $negate ){
			$o->parensInOp = true;
			$o = $this->NewObj1('Less_Tree_Negative',$o);
		}

		return $o;
	}
909351
final public function truncate() {
      $this->connection();
      $this->sql = "TRUNCATE TABLE {$this->table};";

      if($this->driver=='firebird'||$this->driver=='sqlite')
         $this->sql = "DELETE FROM {$this->table};";

      // $this->fetch(false);
      $this->fetch();

      return $this->resultset?true:false;
   }
873608
public function comparisonOperator()
    {
        switch ($this->lexer->lookahead['value']) {
            case '=':
                $this->match(Lexer::T_EQUALS);

                return '=';
            case '<':
                $this->match(Lexer::T_LOWER_THAN);
                $operator = '<';

                if ($this->lexer->isNextToken(Lexer::T_EQUALS)) {
                    $this->match(Lexer::T_EQUALS);
                    $operator .= '=';
                } else if ($this->lexer->isNextToken(Lexer::T_GREATER_THAN)) {
                    $this->match(Lexer::T_GREATER_THAN);
                    $operator .= '>';
                }

                return $operator;

            case '>':
                $this->match(Lexer::T_GREATER_THAN);
                $operator = '>';

                if ($this->lexer->isNextToken(Lexer::T_EQUALS)) {
                    $this->match(Lexer::T_EQUALS);
                    $operator .= '=';
                }

                return $operator;

            case '!':
                $this->match(Lexer::T_NEGATE);
                $this->match(Lexer::T_EQUALS);

                return '<>';

            default:
                $this->syntaxError('=, <, <=, <>, >, >=, !=');
        }

        return null;
    }