@param Request            $request
@param AttributeInterface $attribute

@throws \UnexpectedValueException
@throws \LogicException
@throws \Sidus\EAVModelBundle\Exception\MissingFamilyException

@return QueryBuilder
189341
protected function getQueryBuilderByAttribute(Request $request, AttributeInterface $attribute)
    {
        $term = '%'.trim($request->get('term'), '%').'%';

        if (!$attribute->getType()->isRelation() && !$attribute->getType()->isEmbedded()) {
            $family = $attribute->getFamily();
            $repository = $this->entityManager->getRepository($family->getDataClass());
            if (!$repository instanceof DataRepository) {
                throw new \UnexpectedValueException(
                    "Repository for class {$family->getDataClass()} must be a DataRepository"
                );
            }
            $eavQb = $repository->createFamilyQueryBuilder($family);
            $attributeQb = $eavQb->attribute($attribute);
            $qb = $eavQb->apply($attributeQb->like($term));
            $qb
                ->select($attributeQb->getColumn())
                ->groupBy($attributeQb->getColumn())
                ->orderBy($attributeQb->getColumn());

            return $qb;
        }

        /** @var array $familyCodes */
        $familyCodes = $attribute->getOption('allowed_families', []);
        $families = [];
        foreach ($familyCodes as $familyCode) {
            $families[] = $this->familyRegistry->getFamily($familyCode);
        }

        return $this->dataManager->getQbForFamiliesAndLabel($families, $term);
    }
133639
public function angularAction(Request $request, $attributes = array())
    {
        $attributes = $request->request->get('attributes');
        $form = $this->createFormBuilder([]);

        foreach ($attributes as $attribute) {
            $attributeEntity = new Attribute();
            $valueType = str_replace('Opifer\EavBundle\Entity', '\Opifer\EavBundle\Form\Type\ValueType', $attribute['valueType']) . 'Type';
            if (class_exists($valueType)) {
                $valueType = new $valueType($attributeEntity);
            } else {
                $valueType = new ValueType($attributeEntity);
            }

            $form->add($attribute['name'], $valueType, [
                'label' => $attribute['displayName'],
                'angular'  => [
                    'ng-model'  => 'subject.parameters[\''.$attribute["name"].'\']'
                ]
            ]);
        }
        $form = $form->getForm();

        return $this->render('OpiferContentBundle:Form:form.html.twig', ['form' => $form->createView()]);
    }
326724
public function isEmpty(AttributeInterface $attribute, array $context = null)
    {
        foreach ($this->getValuesData($attribute, $context) as $valueData) {
            if (null !== $valueData && '' !== $valueData) {
                return false;
            }
        }

        return true;
    }
974677
protected function getEAVAttributeContext(
        DataInterface $object,
        AttributeInterface $attribute,
        /* @noinspection PhpUnusedParameterInspection */
        $rawValue,
        array $context
    ) {
        $resolvedContext = parent::getEAVAttributeContext($object, $attribute, $rawValue, $context);

        if (!\is_object($rawValue)) {
            return $resolvedContext;
        }

        $resolvedContext['resource_class'] = ClassUtils::getClass($rawValue);
        unset($resolvedContext['item_operation_name'], $resolvedContext['collection_operation_name']);

        return $resolvedContext;
    }
1198204
private function initField(AttributeInterface $attribute)
    {
        $fieldName = $attribute->getAttributeCode();
        $fieldConfig = $this->attributeHelper->getMappingFieldOptions($attribute);

        if ($attribute->usesSource()) {
            $optionFieldName = $this->attributeHelper->getOptionTextFieldName($fieldName);
            $fieldType = FieldInterface::FIELD_TYPE_TEXT;
            $fieldOptions = ['name' => $optionFieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];
            $this->fields[$optionFieldName] = $this->fieldFactory->create($fieldOptions);

            // Reset parent field values : only the option text field should be used for spellcheck and autocomplete.
            $fieldConfig['is_used_in_spellcheck'] = false;
            $fieldConfig['is_searchable'] = false;
        }

        $fieldType    = $this->attributeHelper->getFieldType($attribute);
        $fieldOptions = ['name' => $fieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];

        $this->fields[$fieldName] = $this->fieldFactory->create($fieldOptions);

        return $this;
    }
183596
public function addAttributeValue(AttributeValueInterface $attributeValue)
    {
        if (!$this->attributeValues->contains($attributeValue)) {
            $attributeValue->setSubject($this);
            $this->attributeValues->add($attributeValue);
        }

        return $this;
    }
293962
private function changesQuery(ServerRequestInterface $request): Builder
    {
        $from     = $request->getQueryParams()['from'] ?? '';
        $to       = $request->getQueryParams()['to'] ?? '';
        $type     = $request->getQueryParams()['type'] ?? '';
        $oldged   = $request->getQueryParams()['oldged'] ?? '';
        $newged   = $request->getQueryParams()['newged'] ?? '';
        $xref     = $request->getQueryParams()['xref'] ?? '';
        $username = $request->getQueryParams()['username'] ?? '';
        $ged      = $request->getQueryParams()['ged'] ?? '';
        $search   = $request->getQueryParams()['search'] ?? [];
        $search   = $search['value'] ?? '';


        $query = DB::table('change')
            ->leftJoin('user', 'user.user_id', '=', 'change.user_id')
            ->join('gedcom', 'gedcom.gedcom_id', '=', 'change.gedcom_id')
            ->select(['change.*', DB::raw("COALESCE(user_name, '<none>') AS user_name"), 'gedcom_name']);

        if ($search !== '') {
            $query->where(static function (Builder $query) use ($search): void {
                $query
                    ->whereContains('old_gedcom', $search)
                    ->whereContains('new_gedcom', $search, 'or');
            });
        }

        if ($from !== '') {
            $query->where('change_time', '>=', $from);
        }

        if ($to !== '') {
            // before end of the day
            $query->where('change_time', '<', Carbon::make($to)->addDay());
        }

        if ($type !== '') {
            $query->where('status', '=', $type);
        }

        if ($oldged !== '') {
            $query->whereContains('old_gedcom', $oldged);
        }
        if ($newged !== '') {
            $query->whereContains('new_gedcom', $oldged);
        }

        if ($xref !== '') {
            $query->where('xref', '=', $xref);
        }

        if ($username !== '') {
            $query->whereContains('user_name', $username);
        }

        if ($ged !== '') {
            $query->whereContains('gedcom_name', $ged);
        }

        return $query;
    }
1110493
public function findByRequest(Request $request)
    {
        $qb = $this->createQueryBuilder('s');

        if ($request->get('attribute')) {
            $qb->join('s.allowedInAttributes', 'a')
                ->andWhere('a.id = :attributeId')
                ->setParameter('attributeId', $request->get('attribute'));
        }

        return $qb->getQuery()->getArrayResult();
    }
1107092
public function getAttributeValue($attr, &$request = null) {
        $url = "entities/{$this->_id}/attrs/$attr/value";

        if ($this->_type) {
            $url .= "?type={$this->_type}";
        }

        return $this->_orion->get($url, $request, "text/plain","text/plain");
    }
747108
public static function _parseOneToMany($query, $relationship, $attribute = null)
    {
        $child = $relationship->getChildRepository();
        $child_query = $child->getQuery();
        $child_belongs_to_property = $child->getDescription()->getProperty($relationship->getChildkey());

        $columns = $child_belongs_to_property->getColumns();
        //if the relationship parent is not set then throw an error
        //if polymorphic with a base parent just use the id
        if (!$child_belongs_to_property->getParent()) {
            throw new AnDomainQueryException('Query Building Failed. Unkown Parent');
        } elseif ($child_belongs_to_property->isPolymorphic()) {
            $columnsKeys = array_keys($columns);
            $columnsValues = array_values($columns);
            $columns = array(array_shift($columnsKeys) => array_shift($columnsValues));
        }

        $condition = array();

        foreach ($columns as $parent_property => $child_column) {
            $result = self::parseColumn($query, $parent_property);
            $col = $result['columns'];
            $condition[(string) $col] = $child_column;
        }

        $query->link($child_query, $condition, array('as' => $relationship->getName()));

        if ($attribute) {
            return self::parseColumn($child_query, $attribute);
        }
    }
887433
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
    {
        foreach ($this->meta['fields'] as $field) {
            $field->fill($request, $model);
        }
    }
388840
protected function getAttributeMethods(FamilyInterface $family, AttributeInterface $attribute)
    {
        if ($this->isAttributeInherited($family, $attribute)) {
            return '';
        }
        $content = '';
        $dataClass = new \ReflectionClass($family->getDataClass());

        $getter = 'get'.ucfirst($attribute->getCode());
        if (!$dataClass->hasMethod($getter)) {
            $content .= $this->generateGetAnnotation($family, $attribute);
            $content .= "abstract public function {$getter}(array \$context = null);\n\n";
        }

        $setter = 'set'.ucfirst($attribute->getCode());
        if (!$dataClass->hasMethod($setter)) {
            $content .= $this->generateSetAnnotation($family, $attribute);
            $content .= 'abstract public function set'.ucfirst($attribute->getCode());
            $content .= '($value, array $context = null);'."\n\n";
        }

        if ($attribute->isCollection()) {
            // Adder and remover
            $setter = 'add'.ucfirst($attribute->getCode());
            if (!$dataClass->hasMethod($setter)) {
                $content .= $this->generateSetAnnotation($family, $attribute, true);
                $content .= 'abstract public function add'.ucfirst($attribute->getCode());
                $content .= '($value, array $context = null);'."\n\n";
            }

            $setter = 'remove'.ucfirst($attribute->getCode());
            if (!$dataClass->hasMethod($setter)) {
                $content .= $this->generateSetAnnotation($family, $attribute, true);
                $content .= 'abstract public function remove'.ucfirst($attribute->getCode());
                $content .= '($value, array $context = null);'."\n\n";
            }
        }

        return $content;
    }
663527
public function buildSearchRequest(RequestInterface $request)
    {
        $searchRequest = [
            'size' => $request->getSize(),
        ];

        if ($searchRequest['size'] > 0) {
            $searchRequest['sort'] = $this->getSortOrders($request);
            $searchRequest['from'] = $request->getFrom();
        }

        $query = $this->getRootQuery($request);
        if ($query) {
            $searchRequest['query'] = $query;
        }

        $filter = $this->getRootFilter($request);
        if ($filter) {
            $searchRequest['post_filter'] = $filter;
        }

        $aggregations = $this->getAggregations($request);
        if (!empty($aggregations)) {
            $searchRequest['aggregations'] = $aggregations;
        }

        return $searchRequest;
    }
125400
protected function createDefaultValues(AttributeInterface $attribute, array $context = null)
    {
        $default = $attribute->getDefault();
        if (!$attribute->isCollection()) {
            $default = (array) $default;
        }

        return $this->setInternalValuesData($attribute, $default, $context);
    }
1256361
public function cgetAction(Request $request, $id)
    {
        try {
            if ($request->get('flat') == 'true') {
                $list = $this->getListRepresentation($request, $id);
            } else {
                $list = new CollectionRepresentation(
                    $this->getManager()->findAllByAttributeIdAndLocale($this->getLocale($request), $id),
                    self::$entityKey
                );
            }
            $view = $this->view($list, 200);
        } catch (AttributeNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 404);
        }

        return $this->handleView($view);
    }
244471
protected function createComplexValue(AttributeInterface $attribute, array $options = array())
    {
        $values = array();
        $value_holder = $attribute->createValueHolder();
        $value_type = $value_holder->getValueType();

        if (class_exists($value_type)
            && preg_grep('#ComplexValueInterface$#', class_implements($value_type))
        ) {
            foreach ($value_type::getPropertyMap() as $property_name => $property_type) {
                switch ($property_type) {
                    case ComplexValue::VALUE_TYPE_TEXT:
                        if ($this->shouldGuessByName($options)) {
                            $values[$property_name] = TextGuesser::guess($property_name, $this->faker);
                        }
                        if (empty($values[$property_name])) {
                            $values[$property_name] = $this->faker->words(3, true);
                        }
                        break;
                    case ComplexValue::VALUE_TYPE_URL:
                        $values[$property_name] = $this->faker->url;
                        break;
                    case ComplexValue::VALUE_TYPE_BOOLEAN:
                        $values[$property_name] = $this->faker->boolean();
                        break;
                    case ComplexValue::VALUE_TYPE_INTEGER:
                        $values[$property_name] = $this->faker->numberBetween(0, 10);
                        break;
                    case ComplexValue::VALUE_TYPE_FLOAT:
                        $values[$property_name] = $this->faker->randomFloat(5);
                        break;
                    case ComplexValue::VALUE_TYPE_ARRAY:
                        $numberOfEntries = $this->faker->numberBetween(0, 3);
                        for ($i = 0; $i < $numberOfEntries; $i++) {
                            $values[$property_name][$this->faker->word] = $this->faker->word;
                        }
                        break;
                    default:
                        throw new BadValueException(sprintf(
                            'Unexpected ComplexValue property type "%s" on %s',
                            $property_type,
                            $value_type
                        ));
                }
            }
        }

        return new $value_type($values);
    }
246940
protected function getEAVAttributeContext(
        DataInterface $object,
        AttributeInterface $attribute,
        /** @noinspection PhpUnusedParameterInspection */
        $rawValue,
        array $context
    ) {
        $options = $attribute->getOption(static::SERIALIZER_OPTIONS, []);

        $byReference = $attribute->getType()->isRelation();
        if (array_key_exists(ByReferenceHandler::BY_REFERENCE_KEY, $options)) {
            $byReference = $options[ByReferenceHandler::BY_REFERENCE_KEY];
        }

        $byShortReference = false;
        if (array_key_exists(ByReferenceHandler::BY_SHORT_REFERENCE_KEY, $options)) {
            $byShortReference = $options[ByReferenceHandler::BY_SHORT_REFERENCE_KEY];
        }

        $maxDepth = $context[MaxDepthHandler::MAX_DEPTH_KEY];
        if (array_key_exists(MaxDepthHandler::MAX_DEPTH_KEY, $options)) {
            $maxDepth = $options[MaxDepthHandler::MAX_DEPTH_KEY];
        }

        return array_merge(
            $context,
            [
                MaxDepthHandler::MAX_DEPTH_KEY => $maxDepth,
                ByReferenceHandler::BY_REFERENCE_KEY => $byReference,
                ByReferenceHandler::BY_SHORT_REFERENCE_KEY => $byShortReference,
                'parent' => $object,
                'attribute' => $attribute->getCode(),
                'eav_attribute' => $attribute,
            ]
        );
    }