Пример #1
0
 /**
  * @param string
  */
 public function __construct($className, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = 'URI')
 {
     if (!is_string($className)) {
         throw new \InvalidArgumentException('Class name was not a string');
     }
     $this->className = $className;
     parent::__construct($this->getItems(), $labelPath, $preferredChoices, $groupPath, $valuePath);
 }
Пример #2
0
 /**
  * @param array|\Traversable|string $rm
  * @param TypeMapperRegistry        $typeMapperRegistry
  * @param array                     $choices
  * @param null|string               $class
  * @param QueryBuilder|null         $queryBuilder
  * @param null                      $labelPath
  * @param array                     $preferredChoices
  * @param null                      $groupPath
  * @param null                      $valuePath
  * @param PropertyAccessorInterface $propertyAccessor
  */
 public function __construct($rm, $choices, $class, $queryBuilder, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->rm = $rm;
     $this->class = $class;
     if ($queryBuilder === null) {
         $this->queryBuilder = $this->rm->getRepository($class)->getQueryBuilder();
     } else {
         if ($queryBuilder !== false) {
             $this->queryBuilder = $queryBuilder;
         }
     }
     parent::__construct($choices, $labelPath, $preferredChoices, $groupPath, $valuePath, $propertyAccessor);
 }
Пример #3
0
 /**
  * @param string         $class
  * @param string         $labelPath
  * @param array          $choices
  * @param \ModelCriteria $queryObject
  * @param string         $groupPath
  */
 public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null)
 {
     $this->class = $class;
     $queryClass = $this->class . 'Query';
     $query = new $queryClass();
     $this->identifier = $query->getTableMap()->getPrimaryKeys();
     $this->query = $queryObject ?: $query;
     $this->loaded = is_array($choices) || $choices instanceof \Traversable;
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $choices = array();
     }
     parent::__construct($choices, $labelPath, array(), $groupPath);
 }
Пример #4
0
 /**
  * Creates a new entity choice list.
  *
  * @param ObjectManager         $manager      An EntityManager instance
  * @param string                $class        The class name
  * @param string                $labelPath    The property path used for the label
  * @param EntityLoaderInterface $entityLoader An optional query builder
  * @param array                 $entities     An array of choices
  * @param string                $groupPath    A property path pointing to the property used
  *                                            to group the choices. Only allowed if
  *                                            the choices are given as flat array.
  */
 public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null)
 {
     $this->em = $manager;
     $this->entityLoader = $entityLoader;
     $this->classMetadata = $manager->getClassMetadata($class);
     $this->class = $this->classMetadata->getName();
     $this->identifier = $this->classMetadata->getIdentifierFieldNames();
     $this->loaded = is_array($entities) || $entities instanceof \Traversable;
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $entities = array();
     }
     parent::__construct($entities, $labelPath, array(), $groupPath);
 }
 /**
  * Constructor.
  *
  * @see \Symfony\Bridge\Propel1\Form\Type\ModelType How to use the preferred choices.
  *
  * @param string                   $class             The FQCN of the model class to be loaded.
  * @param string                   $labelPath         A property path pointing to the property used for the choice labels.
  * @param array                    $choices           An optional array to use, rather than fetching the models.
  * @param ModelCriteria            $queryObject       The query to use retrieving model data from database.
  * @param string                   $groupPath         A property path pointing to the property used to group the choices.
  * @param array|ModelCriteria      $preferred         The preferred items of this choice.
  *                                                    Either an array if $choices is given,
  *                                                    or a ModelCriteria to be merged with the $queryObject.
  * @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
  */
 public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null, $preferred = array(), PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->class = $class;
     $queryClass = $this->class . 'Query';
     $query = new $queryClass();
     $this->query = $queryObject ?: $query;
     $this->identifier = $this->query->getTableMap()->getPrimaryKeys();
     $this->loaded = is_array($choices) || $choices instanceof \Traversable;
     if ($preferred instanceof ModelCriteria) {
         $this->preferredQuery = $preferred->mergeWith($this->query);
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $choices = array();
         $preferred = array();
     }
     if (1 === count($this->identifier) && $this->isScalar(current($this->identifier))) {
         $this->identifierAsIndex = true;
     }
     parent::__construct($choices, $labelPath, $preferred, $groupPath, null, $propertyAccessor);
 }
Пример #6
0
 /**
  * Creates a new entity choice list.
  *
  * @param ObjectManager             $manager           An EntityManager instance
  * @param string                    $class             The class name
  * @param string                    $labelPath         The property path used for the label
  * @param EntityLoaderInterface     $entityLoader      An optional query builder
  * @param array                     $entities          An array of choices
  * @param array                     $preferredEntities An array of preferred choices
  * @param string                    $groupPath         A property path pointing to the property used
  *                                                     to group the choices. Only allowed if
  *                                                     the choices are given as flat array.
  * @param PropertyAccessorInterface $propertyAccessor  The reflection graph for reading property paths.
  */
 public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, array $preferredEntities = array(), $groupPath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->em = $manager;
     $this->entityLoader = $entityLoader;
     $this->classMetadata = $manager->getClassMetadata($class);
     $this->class = $this->classMetadata->getName();
     $this->loaded = is_array($entities) || $entities instanceof \Traversable;
     $this->preferredEntities = $preferredEntities;
     $identifier = $this->classMetadata->getIdentifierFieldNames();
     if (1 === count($identifier)) {
         $this->idField = $identifier[0];
         $this->idAsValue = true;
         if (in_array($this->classMetadata->getTypeOfField($this->idField), array('integer', 'smallint', 'bigint'))) {
             $this->idAsIndex = true;
         }
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $entities = array();
     }
     parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
 }
 /**
  * Constructor.
  *
  * @see ModelType How to use the preferred choices.
  *
  * @param string                    $class            The FQCN of the model class to be loaded.
  * @param string                    $labelPath        A property path pointing to the property used for the choice labels.
  * @param array                     $choices          An optional array to use, rather than fetching the models.
  * @param \ModelCriteria            $queryObject      The query to use retrieving model data from database.
  * @param string                    $groupPath        A property path pointing to the property used to group the choices.
  * @param array|\ModelCriteria      $preferred        The preferred items of this choice.
  *                                                    Either an array if $choices is given,
  *                                                    or a \ModelCriteria to be merged with the $queryObject.
  * @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
  * @param string                    $useAsIdentifier  a custom unique column (eg slug) to use instead of primary key.
  *
  * @throws MissingOptionsException In case the class parameter is empty.
  * @throws InvalidOptionsException In case the query class is not found.
  */
 public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null, $preferred = array(), PropertyAccessorInterface $propertyAccessor = null, $useAsIdentifier = null)
 {
     $this->class = $class;
     $queryClass = $this->class . 'Query';
     if (!class_exists($queryClass)) {
         if (empty($this->class)) {
             throw new MissingOptionsException('The "class" parameter is empty, you should provide the model class');
         }
         throw new InvalidOptionsException(sprintf('The query class "%s" is not found, you should provide the FQCN of the model class', $queryClass));
     }
     $query = new $queryClass();
     $this->query = $queryObject ?: $query;
     if ($useAsIdentifier) {
         $this->identifier = array($this->query->getTableMap()->getColumn($useAsIdentifier));
     } else {
         $this->identifier = $this->query->getTableMap()->getPrimaryKeys();
     }
     $this->loaded = is_array($choices) || $choices instanceof \Traversable;
     if ($preferred instanceof \ModelCriteria) {
         $this->preferredQuery = $preferred->mergeWith($this->query);
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $choices = array();
         $preferred = array();
     }
     if (1 === count($this->identifier) && $this->isScalar(current($this->identifier))) {
         $this->identifierAsIndex = true;
     }
     parent::__construct($choices, $labelPath, $preferred, $groupPath, null, $propertyAccessor);
 }
Пример #8
0
 /**
  * @param VariableInterface $variable
  */
 public function __construct(VariableInterface $variable)
 {
     parent::__construct($variable->getVariants(), 'name', [], null, 'id');
 }
Пример #9
0
 /**
  * Creates a new entity choice list.
  *
  * @param ObjectManager             $manager           An EntityManager instance
  * @param string                    $class             The class name
  * @param string                    $labelPath         The property path used for the label
  * @param EntityLoaderInterface     $entityLoader      An optional query builder
  * @param array|\Traversable|null   $entities          An array of choices or null to lazy load
  * @param array                     $preferredEntities An array of preferred choices
  * @param string                    $groupPath         A property path pointing to the property used
  *                                                     to group the choices. Only allowed if
  *                                                     the choices are given as flat array.
  * @param PropertyAccessorInterface $propertyAccessor  The reflection graph for reading property paths.
  */
 public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, array $preferredEntities = array(), $groupPath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->em = $manager;
     $this->entityLoader = $entityLoader;
     $this->classMetadata = $manager->getClassMetadata($class);
     $this->class = $this->classMetadata->getName();
     $this->loaded = is_array($entities) || $entities instanceof \Traversable;
     $this->preferredEntities = $preferredEntities;
     list($this->idAsIndex, $this->idAsValue, $this->idField) = $this->getIdentifierInfoForClass($this->classMetadata);
     if (null !== $this->idField && $this->classMetadata->hasAssociation($this->idField)) {
         $this->idClassMetadata = $this->em->getClassMetadata($this->classMetadata->getAssociationTargetClass($this->idField));
         list($this->idAsIndex, $this->idAsValue) = $this->getIdentifierInfoForClass($this->idClassMetadata);
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $entities = array();
     }
     parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
 }
Пример #10
0
 /**
  * Constructor.
  *
  * @param VariableInterface $variable
  */
 public function __construct(VariableInterface $variable)
 {
     parent::__construct($variable->getVariants(), 'presentation', array(), null, 'id');
 }
 /**
  * LdapObjectChoiceList constructor.
  * @param array|\Traversable $choices
  * @param null $labelPath
  * @param array $preferredChoices
  * @param null $groupPath
  * @param null $valuePath
  * @param PropertyAccessorInterface|null $propertyAccessor
  */
 public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->id = $valuePath;
     $this->ldapObjects = $choices;
     parent::__construct($choices, $labelPath, $preferredChoices, $groupPath, $valuePath);
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->_propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
     $this->_identifier = null !== $valuePath ? new PropertyPath($valuePath) : null;
     parent::__construct($choices, $labelPath, $preferredChoices, $groupPath, $valuePath, $propertyAccessor);
 }