Retrieve query ids limitation for the current optimizer, if any.

@param OptimizerInterface $entity The optimizer being saved

@return array
516354
private function getQueryIdsLimitation($entity)
    {
        $searchContainerData = $entity->getData('quick_search_container');
        $applyTo  = is_array($searchContainerData) ? ((bool) $searchContainerData['apply_to'] ?? false) : false;
        $queryIds = [];

        if (($applyTo !== false) && (isset($searchContainerData['query_ids']) && !empty($searchContainerData['query_ids']))) {
            $ids = $queryIds = $searchContainerData['query_ids'];

            if (is_array(current($ids))) {
                $queryIds = [];
                foreach ($ids as $queryId) {
                    if (isset($queryId['id'])) {
                        $queryIds[] = (int) $queryId['id'];
                    }
                }
            }
        }

        return $queryIds;
    }
166444
public function entityByResult(string $entity): array
    {
        $result = array_get($this->response, "data.result", '');

        return array_get($this->response, "data.entities.$entity.$result", []);
    }
17009
public static function getStringId(ResourceEntityInterface $entity = NULL)
    {
        return is_null($entity)
            ? NULL
            : (string) $entity->getId();
    }
147312
public function getEntityId($entity)
    {
        $entityId = $this->idAccessorRegistry->getEntityId($entity);

        if (is_array($entityId)) {
            ksort($entityId);
            $entityId = json_encode($entityId);
        }

        return $entityId;
    }
1309042
protected function getCurrent(EntityInterface $entity) {
		$conditions = $this->buildConditions($entity);

		return $this->_table->find()
			->where($conditions)
			->first();
	}
1268183
public function getPersisterForEntity(EntityInterface $entity)
    {
        return $this->isNewEntity($entity) ? $this->createPersister() : $this->createUpdateQuery();
    }
161491
public function getEntityModel(EntityInterface $entity): string
    {
        $source = $entity->source();
        if (substr($source, -5) == 'Table') {
            $source = substr($source, 0, -5);
        }

        return $source;
    }
188212
public function getFieldsChoices($entity = null)
    {
        $entityChoices = $this->getEntityChoices();

        $fieldsChoices = [];

        $translator = $this->getContainer()->get('translator');

        $adminPool = $this->getContainer()->get('sonata.admin.pool');

        $em = $this->getContainer()->get('doctrine')->getManager();

        foreach ($entityChoices as $entityChoiceKey => $entityChoice) {
            if ($entity && $entityChoice !== $entity) {
                continue;
            }

            $admin = $adminPool->getAdminByClass($entityChoice);

            if (!$admin) {
                throw new \RuntimeException('Not found admin by class: ' . $entityChoice);
            }

            $translation_domain = $admin->getTranslationDomain();

            $classMetadata = $em->getClassMetadata($entityChoice);

            /** @var array $associationMappings */
            $associationMappings = $classMetadata->associationMappings;

            /** @var array $fieldsMappings */
            $fieldsMappings = $classMetadata->fieldMappings;

            foreach ($fieldsMappings as $fieldsMapping) {
                $fieldsChoices[$fieldsMapping['fieldName']] =
                    $entityChoiceKey . ' / ' . $translator->trans('form.label_' . $fieldsMapping['columnName'], [], $translation_domain);
            }

            foreach ($associationMappings as $associationMapping) {
                $mappingFieldName = $associationMapping['fieldName'];
                $mappingAdmin = $adminPool->getAdminByClass($associationMapping['targetEntity']);

                if (!$mappingAdmin) {
                    continue;
                }

                $mappingTranslationDomain = $mappingAdmin->getTranslationDomain();

                $classMetadataMapping = $em->getClassMetadata($associationMapping['targetEntity']);

                /** @var array $fieldsMappingsMapping */
                $fieldsMappingsMapping = $classMetadataMapping->fieldMappings;

                foreach ($fieldsMappingsMapping as $fieldsMappingAssoc) {
                    $fieldsChoices[$mappingFieldName . '.' . $fieldsMappingAssoc['fieldName']] =
                        $entityChoiceKey . ' / '
                        . $translator->trans('form.label_' . $this->camelCaseToUnderscore($mappingFieldName), [], $translation_domain) . ' / '
                        . $translator->trans('form.label_' . $this->camelCaseToUnderscore($fieldsMappingAssoc['fieldName']), [], $mappingTranslationDomain);
                }
            }
        }

        return $fieldsChoices;
    }
491575
public function fields(EntityInterface $entity)
    {
        $fields = [];
        foreach ((array)$this->getConfig('fields') as $field) {
            if (!$entity->isDirty($field)) {
                continue;
            }
            $fields[$field] = $entity->$field;
            $entity->setDirty($field, false);
        }

        return $fields;
    }
536796
public function getLevel($entity)
    {
        $primaryKey = $this->_getPrimaryKey();
        $id = $entity;
        if ($entity instanceof EntityInterface) {
            $id = $entity->get($primaryKey);
        }
        $config = $this->getConfig();
        $entity = $this->_table->find('all')
            ->select([$config['left'], $config['right']])
            ->where([$primaryKey => $id])
            ->first();

        if ($entity === null) {
            return false;
        }

        $query = $this->_table->find('all')->where([
            $config['left'] . ' <' => $entity[$config['left']],
            $config['right'] . ' >' => $entity[$config['right']],
        ]);

        return $this->_scope($query)->count();
    }
150613
private function getAddresses($entity)
    {
        if ($entity instanceof AccountInterface) {
            return $entity->getAccountAddresses();
        } elseif ($entity instanceof Contact) {
            return $entity->getContactAddresses();
        }

        return;
    }
1120881
private function getRelatedEntityIdentifier($entity)
    {
        \assert('is_object($entity)');

        if ($entity instanceof \Doctrine\Common\Persistence\Proxy) {
            $entity->__load();
        }

        $relClass = \get_class($entity);

        $ManagerForClass = $this->registry->getManagerForClass($relClass);

        if (!$ManagerForClass) {
            throw new \InvalidArgumentException(sprintf('The getManagerForClass for entity of class "%s" was empty.', $relClass));
        }

        $relId = $ManagerForClass->getMetadataFactory()
            ->getMetadataFor($relClass)->getIdentifierValues($entity);

        asort($relId);

        if (!$relId) {
            throw new \InvalidArgumentException(sprintf('The identifier for entity of class "%s" was empty.', $relClass));
        }

        return [$relClass, json_encode($relId)];
    }
640442
public function getIdentifierValues($entity)
    {
        if ($this->isIdentifierComposite) {
            $id = array();

            foreach ($this->identifier as $idField) {
                $value = $this->reflFields[$idField]->getValue($entity);

                if ($value !== null) {
                    $id[$idField] = $value;
                }
            }

            return $id;
        }

        $id = $this->identifier[0];
        $value = $this->reflFields[$id]->getValue($entity);

        if (null === $value) {
            return array();
        }

        return array($id => $value);
    }
317557
public function getEntityRulesFor($entity)
    {
        $class = is_object($entity) ? ClassUtils::getClass($entity) : $entity;

        if (null === $rules = $this->ruleMappings->get($class)) {
            throw ValidationConfigurationException::noEntityRulesMappingExists($class);
        }

        return $rules;
    }
78573
protected function _getScope(EntityInterface $entity)
    {
        $scope = [];
        $config = $this->getConfig();

        // If scope are specified and data for all scope fields is not
        // provided we cannot calculate new order
        if ($config['scope']) {
            $scope = $entity->extract($config['scope']);
            if (count($scope) !== count($config['scope'])) {
                return false;
            }

            // Modify where clauses when NULL values are used
            foreach ($scope as $field => $value) {
                if (is_null($value)) {
                    $scope[$field . ' IS'] = $value;
                    unset($scope[$field]);
                }
            }
        }

        return $scope;
    }
1292229
protected function _extractDirtyFields(EntityInterface $entity): array
    {
        $dirtyFields = [];
        $fields = array_keys($entity->toArray());
        $dirtyFields = $entity->extract($fields, true);
        unset($dirtyFields['modified']);

        return array_keys($dirtyFields);
    }
166593
protected function HLGetIdByCode($entity)
    {
        $filter = [
            'filter' => ['=NAME' => $entity],
        ];
        $hlblock = HighloadBlockTable::getRow($filter);

        return !empty($hlblock['ID']) ? $hlblock['ID'] : null;
    }