/**
  * @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;
 }
 /**
  * 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;
 }
 /**
  * @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());
 }
 /**
  * @Template()
  * @param FamilyInterface $family
  * @param Request $request
  * @return array
  * @throws \Exception
  */
 public function listAction(FamilyInterface $family, Request $request)
 {
     $this->family = $family;
     $dataGrid = $this->getDataGrid();
     $dataGrid->setActionParameters('create', ['familyCode' => $family->getCode()]);
     $this->bindDataGridRequest($dataGrid, $request);
     return ['datagrid' => $dataGrid, 'family' => $family];
 }
    /**
     * @param FamilyInterface $family
     *
     * @return string
     */
    protected function getFileHeader(FamilyInterface $family)
    {
        $content = <<<EOT
<?php

namespace Sidus\\EAV;

abstract class {$family->getCode()} extends 
EOT;
        if ($family->getParent()) {
            $content .= $family->getParent()->getCode();
        } else {
            $content .= '\\' . $family->getDataClass();
        }
        $content .= "\n{\n";
        return $content;
    }
 /**
  * @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));
 }
 /**
  * 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.º 9
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();
 }
Exemplo n.º 10
0
 /**
  * @param FamilyInterface $child
  * @throws UnexpectedValueException
  */
 public function addChild(FamilyInterface $child)
 {
     if ($child->getParent() && $child->getParent()->getCode() === $this->getCode()) {
         $this->children[$child->getCode()] = $child;
     } else {
         throw new UnexpectedValueException("Child must have it's parent set to the current family");
     }
 }