private function addRuleCondition(QueryBuilder $query, EntityDefinition $definition, Context $context): void
    {
        if ($definition->isBlacklistAware() && $context->getRuleIds()) {
            $wheres = [];

            $accessor = $this->getFieldAccessor('blacklistIds', $definition, $definition->getEntityName(), $context);

            foreach ($context->getRuleIds() as $ruleId) {
                if (!Uuid::isValid($ruleId)) {
                    throw new InvalidUuidException($ruleId);
                }
                $wheres[] = sprintf(
                    'JSON_CONTAINS(IFNULL(' . $accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))',
                    'contextRule' . $ruleId
                );
                $query->setParameter('contextRule' . $ruleId, $ruleId);
            }

            $query->andWhere(implode(' + ', $wheres) . ' = 0');
        }

        if (!$definition->isWhitelistAware()) {
            return;
        }

        $accessor = $this->getFieldAccessor('whitelistIds', $definition, $definition->getEntityName(), $context);

        $wheres = [];
        foreach ($context->getRuleIds() as $id) {
            if (!Uuid::isValid($id)) {
                throw new InvalidUuidException($id);
            }
            $wheres[] = sprintf(
                'JSON_CONTAINS(IFNULL(' . $accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))',
                'contextRule' . $id
            );
            $query->setParameter('contextRule' . $id, $id);
        }

        $conditions = [
            '(JSON_DEPTH(' . $accessor . ') is null)',
            '(JSON_DEPTH(' . $accessor . ') = 1)',
        ];

        if (!empty($wheres)) {
            $conditions[] = implode(' + ', $wheres) . ' >= 1';
        }

        $query->andWhere('(' . implode(' OR ', $conditions) . ')');
    }
private function addRuleCondition(QueryBuilder $query, EntityDefinition $definition, Context $context): void
    {
        if ($definition->isBlacklistAware() && $context->getRuleIds()) {
            $wheres = [];

            $accessor = $this->getFieldAccessor('blacklistIds', $definition, $definition->getEntityName(), $context);

            foreach ($context->getRuleIds() as $ruleId) {
                if (!Uuid::isValid($ruleId)) {
                    throw new InvalidUuidException($ruleId);
                }
                $wheres[] = sprintf(
                    'JSON_CONTAINS(IFNULL(' . $accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))',
                    'contextRule' . $ruleId
                );
                $query->setParameter('contextRule' . $ruleId, $ruleId);
            }

            $query->andWhere(implode(' + ', $wheres) . ' = 0');
        }

        if (!$definition->isWhitelistAware()) {
            return;
        }

        $accessor = $this->getFieldAccessor('whitelistIds', $definition, $definition->getEntityName(), $context);

        $wheres = [];
        foreach ($context->getRuleIds() as $id) {
            if (!Uuid::isValid($id)) {
                throw new InvalidUuidException($id);
            }
            $wheres[] = sprintf(
                'JSON_CONTAINS(IFNULL(' . $accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))',
                'contextRule' . $id
            );
            $query->setParameter('contextRule' . $id, $id);
        }

        $conditions = [
            '(JSON_DEPTH(' . $accessor . ') is null)',
            '(JSON_DEPTH(' . $accessor . ') = 1)',
        ];

        if (!empty($wheres)) {
            $conditions[] = implode(' + ', $wheres) . ' >= 1';
        }

        $query->andWhere('(' . implode(' OR ', $conditions) . ')');
    }
private function addRuleCondition ( QueryBuilder $ query , EntityDefinition $ definition , Context $ context ) : void { if ( $ definition -> isBlacklistAware ( ) && $ context -> getRuleIds ( ) ) { $ wheres = [ ] ; $ accessor = $ this -> getFieldAccessor ( 'blacklistIds' , $ definition , $ definition -> getEntityName ( ) , $ context ) ; foreach ( $ context -> getRuleIds ( ) as $ ruleId ) { if ( ! Uuid :: isValid ( $ ruleId ) ) { throw new InvalidUuidException ( $ ruleId ) ; } $ wheres [ ] = sprintf ( 'JSON_CONTAINS(IFNULL(' . $ accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))' , 'contextRule' . $ ruleId ) ; $ query -> setParameter ( 'contextRule' . $ ruleId , $ ruleId ) ; } $ query -> andWhere ( implode ( ' + ' , $ wheres ) . ' = 0' ) ; } if ( ! $ definition -> isWhitelistAware ( ) ) { return ; } $ accessor = $ this -> getFieldAccessor ( 'whitelistIds' , $ definition , $ definition -> getEntityName ( ) , $ context ) ; $ wheres = [ ] ; foreach ( $ context -> getRuleIds ( ) as $ id ) { if ( ! Uuid :: isValid ( $ id ) ) { throw new InvalidUuidException ( $ id ) ; } $ wheres [ ] = sprintf ( 'JSON_CONTAINS(IFNULL(' . $ accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))' , 'contextRule' . $ id ) ; $ query -> setParameter ( 'contextRule' . $ id , $ id ) ; } $ conditions = [ '(JSON_DEPTH(' . $ accessor . ') is null)' , '(JSON_DEPTH(' . $ accessor . ') = 1)' , ] ; if ( ! empty ( $ wheres ) ) { $ conditions [ ] = implode ( ' + ' , $ wheres ) . ' >= 1' ; } $ query -> andWhere ( '(' . implode ( ' OR ' , $ conditions ) . ')' ) ; }
Adds a blacklist and whitelist where condition to the provided query.
This function is only for internal usage for the root entity of the query.
Adds a blacklist and whitelist where condition to the provided query . This function is only for internal usage for the root entity of the query .