getMaxLength example



    /** * @param StringField $field * * @return Constraint[] */
    protected function getConstraints(Field $field): array
    {
        $constraints = [
            new Type('string'),
            new Length(['max' => $field->getMaxLength()]),
        ];

        if (!$field->is(AllowEmptyString::class)) {
            $constraints[] = new NotBlank();
        }

        if ($field->is(AllowEmptyString::class) && $field->is(Required::class)) {
            $constraints[] = new NotNull();
        }

        return $constraints;
    }
case $field instanceof PasswordField:
                $type = 'VARCHAR(1024)';

                break;

            case $field instanceof FloatField:
                $type = 'DOUBLE';

                break;

            case $field instanceof StringField:
                $type = 'VARCHAR(' . $field->getMaxLength() . ')';

                break;

            case $field instanceof BoolField:
                $type = 'TINYINT(1)';
                $default = 'DEFAULT \'0\'';

                break;

            case $field instanceof BlobField:
                $type = 'LONGBLOB';

                

        $this->variantHelper->joinVariants($query);

        $min = ':minLength' . md5(json_encode($condition, JSON_THROW_ON_ERROR));
        $max = ':maxLength' . md5(json_encode($condition, JSON_THROW_ON_ERROR));

        if ($condition->getMinLength() > 0) {
            $query->andWhere('allVariants.length >= ' . $min);
            $query->setParameter($min$condition->getMinLength());
        }

        if ($condition->getMaxLength() > 0) {
            $query->andWhere('allVariants.length <= ' . $max);
            $query->setParameter($max$condition->getMaxLength());
        }
    }
}
ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(LengthCondition $criteriaPart): RangeQuery
    {
        $range = [];
        if ($criteriaPart->getMinLength()) {
            $range['gte'] = $criteriaPart->getMinLength();
        }
        if ($criteriaPart->getMaxLength()) {
            $range['lte'] = $criteriaPart->getMaxLength();
        }

        return new RangeQuery('length', $range);
    }
}
Home | Imprint | This part of the site doesn't use cookies.