/**
  * @param FamilyInterface $family
  * @param Data $data
  * @return FamilyInterface
  * @throws LogicException
  * @throws UnexpectedValueException
  */
 protected function initDataFamily(FamilyInterface $family, Data $data)
 {
     if ($family->getCode() !== $data->getFamilyCode()) {
         throw new UnexpectedValueException("Data family '{$data->getFamilyCode()}'' not matching admin family {$family->getCode()}");
     }
     $this->family = $family;
 }
 /**
  * @param FamilyInterface $family
  * @param QueryBuilder    $queryBuilder
  * @param string          $alias
  */
 public function __construct(FamilyInterface $family, QueryBuilder $queryBuilder, $alias = 'e')
 {
     $this->family = $family;
     $this->queryBuilder = $queryBuilder;
     $this->alias = $alias;
     $queryBuilder->andWhere($alias . '.family = :familyCode')->setParameter('familyCode', $family->getCode());
 }
 /**
  * @param FormInterface   $form
  * @param FamilyInterface $family
  * @param DataInterface   $data
  * @param array           $options
  * @throws \Exception
  */
 public function buildValuesForm(FormInterface $form, FamilyInterface $family, DataInterface $data = null, array $options = [])
 {
     if ($family instanceof VariantFamily) {
         $form->add('axles', AxlesType::class, ['disabled' => $data->getId() ? true : false]);
         $axles = $form->get('axles');
         foreach ($family->getAxles() as $attribute) {
             $this->addAttribute($axles, $attribute, $family, $data, ['required' => true, 'constraints' => [new NotBlank()]]);
         }
     }
     parent::buildValuesForm($form, $family, $data, $options);
 }
 /**
  * Return singleton for a given family
  *
  * @param FamilyInterface $family
  *
  * @throws \LogicException
  * @throws \Doctrine\ORM\NonUniqueResultException
  *
  * @return DataInterface
  */
 public function getInstance(FamilyInterface $family)
 {
     if (!$family->isSingleton()) {
         throw new \LogicException("Family {$family->getCode()} is not a singleton");
     }
     $qb = $this->createQueryBuilder('d')->andWhere('d.family = :familyCode')->addSelect('values')->join('d.values', 'values')->setParameters(['familyCode' => $family->getCode()]);
     $instance = $qb->getQuery()->getOneOrNullResult();
     if (!$instance) {
         $dataClass = $family->getDataClass();
         $instance = new $dataClass($family);
     }
     return $instance;
 }
 /**
  * {@inheritdoc}
  */
 public function buildValuesForm(FormInterface $form, FamilyInterface $family, DataInterface $data = null, array $options = [])
 {
     foreach ($family->getAttributes() as $attribute) {
         if ($attribute->getGroup()) {
             $groupName = $attribute->getGroup();
             if (!$form->has($groupName)) {
                 $form->add($groupName, 'form', ['inherit_data' => true]);
             }
             $this->addAttribute($form->get($groupName), $attribute, $family, $data, $options);
         } else {
             $this->addAttribute($form, $attribute, $family, $data, $options);
         }
     }
 }
 /**
  * @param QueryBuilder $qb
  * @param SortConfig   $sortConfig
  */
 protected function applySort(QueryBuilder $qb, SortConfig $sortConfig)
 {
     $column = $sortConfig->getColumn();
     if (!$column || !$this->family->hasAttribute($column)) {
         parent::applySort($qb, $sortConfig);
         return;
     }
     $attribute = $this->family->getAttribute($column);
     $uid = uniqid('join');
     $fullColumnReference = $uid . '.' . $attribute->getType()->getDatabaseType();
     $qb->leftJoin($this->alias . '.values', $uid, Join::WITH, "({$uid}.data = {$this->alias}.id AND ({$uid}.attributeCode = '{$attribute->getCode()}' OR {$uid}.id IS NULL))");
     $direction = $sortConfig->getDirection() ? 'DESC' : 'ASC';
     // null or false both default to ASC
     $qb->addOrderBy($fullColumnReference, $direction);
 }
 /**
  * @param FamilyInterface $family
  */
 public function addFamily(FamilyInterface $family)
 {
     $this->isInitialized = false;
     $this->families[$family->getCode()] = $family;
 }
 /**
  * Use label from formOptions or use translation or automatically create human readable one
  *
  * @param FamilyInterface    $family
  * @param AttributeInterface $attribute
  *
  * @return string
  * @throws \InvalidArgumentException
  */
 protected function getFieldLabel(FamilyInterface $family, AttributeInterface $attribute)
 {
     $tId = "eav.{$family->getCode()}.attribute.{$attribute->getCode()}.label";
     return $this->tryTranslate($tId, [], ucfirst($attribute));
 }
 /**
  * @Template()
  * @param FamilyInterface $family
  * @param Request $request
  * @return Response
  * @throws \Exception
  */
 public function createAction(FamilyInterface $family, Request $request)
 {
     /** @var Data $data */
     $data = $family->createData();
     return $this->editAction($family, $data, $request);
 }
 /**
  * Use label from formOptions or use translation or automatically create human readable one
  *
  * @param FamilyInterface $family
  * @param string          $groupName
  * @return string
  * @throws \InvalidArgumentException
  */
 protected function getGroupIcon(FamilyInterface $family, $groupName)
 {
     $transKeys = ["eav.family.{$family->getCode()}.group.{$groupName}.icon", "eav.group.{$groupName}.icon"];
     return $this->tryTranslate($transKeys, []);
 }
Exemplo n.º 11
0
 /**
  * Initialize the data with an optional (but recommended family code)
  *
  * @param FamilyInterface $family
  *
  * @throws LogicException
  */
 public function __construct(FamilyInterface $family)
 {
     if (!$family->isInstantiable()) {
         throw new LogicException("Family {$family->getCode()} is not instantiable");
     }
     $this->family = $family;
     $this->createdAt = new DateTime();
     $this->updatedAt = new DateTime();
     $this->values = new ArrayCollection();
     $this->children = new ArrayCollection();
 }
 /**
  * @param FamilyInterface    $family
  * @param AttributeInterface $attribute
  * @return bool
  */
 protected function isAttributeInherited(FamilyInterface $family, AttributeInterface $attribute)
 {
     if (!$family->getParent()) {
         return false;
     }
     if ($family->getParent()->hasAttribute($attribute->getCode())) {
         return true;
     }
     return $this->isAttributeInherited($family->getParent(), $attribute);
 }
Exemplo n.º 13
0
 /**
  * @param FamilyInterface $parent
  */
 protected function copyFromFamily(FamilyInterface $parent)
 {
     foreach ($parent->getAttributes() as $attribute) {
         $this->addAttribute($attribute);
     }
     $this->attributeAsLabel = $parent->getAttributeAsLabel();
     $this->attributeAsIdentifier = $parent->getAttributeAsIdentifier();
     $this->valueClass = $parent->getValueClass();
     $this->dataClass = $parent->getDataClass();
 }