/** * @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); }
public function testInitArrayUsesToString() { $this->obj1 = new ObjectChoiceListTest_EntityWithToString('A'); $this->obj2 = new ObjectChoiceListTest_EntityWithToString('B'); $this->obj3 = new ObjectChoiceListTest_EntityWithToString('C'); $this->obj4 = new ObjectChoiceListTest_EntityWithToString('D'); $this->list = new ObjectChoiceList(array($this->obj1, $this->obj2, $this->obj3, $this->obj4)); $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices()); $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues()); $this->assertEquals(array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', 'B'), 2 => new ChoiceView($this->obj3, '2', 'C'), 3 => new ChoiceView($this->obj4, '3', 'D')), $this->list->getRemainingViews()); }
/** * Loads the list with model objects. */ private function load() { $models = (array) $this->query->find(); try { // The second parameter $labels is ignored by ObjectChoiceList // The third parameter $preferredChoices is currently not supported parent::initialize($models, array(), array()); } catch (StringCastException $e) { throw new StringCastException(str_replace('argument $labelPath', 'option "property"', $e->getMessage()), null, $e); } $this->loaded = true; }
/** * Loads the list with entities. */ private function load() { if ($this->entityLoader) { $entities = $this->entityLoader->getEntities(); } else { $entities = $this->em->getRepository($this->class)->findAll(); } try { // The second parameter $labels is ignored by ObjectChoiceList // The third parameter $preferredChoices is currently not supported parent::initialize($entities, array(), array()); } catch (StringCastException $e) { throw new StringCastException(str_replace('argument $labelPath', 'option "property"', $e->getMessage()), null, $e); } $this->loaded = true; }
/** * Loads the complete choice list entries, once. * * If data has been loaded the choice list is initialized with the retrieved data. */ private function load() { if ($this->loaded) { return; } $models = (array) $this->query->find(); $preferred = array(); if ($this->preferredQuery instanceof ModelCriteria) { $preferred = (array) $this->preferredQuery->find(); } try { // The second parameter $labels is ignored by ObjectChoiceList parent::initialize($models, array(), $preferred); $this->loaded = true; } catch (StringCastException $e) { throw new StringCastException(str_replace('argument $labelPath', 'option "property"', $e->getMessage()), null, $e); } }
/** * @param VariableInterface $variable */ public function __construct(VariableInterface $variable) { parent::__construct($variable->getVariants(), 'name', [], null, 'id'); }
/** * Constructor. * * @param VariableInterface $variable */ public function __construct(VariableInterface $variable) { parent::__construct($variable->getVariants(), 'presentation', array(), null, 'id'); }
/** * Loads the list with entities from repository. * * @throws Exception * @throws \EasyRdf\Http\Exception */ private function load() { try { if ($this->queryBuilder) { $resources = (new NemrodQueryBuilderLoader($this->queryBuilder, $this->rm, $this->class))->getResources(Query::HYDRATE_COLLECTION, ['rdf:type' => $this->class]); // The second parameter $labels is ignored by ObjectChoiceList if ($resources) { parent::initialize($resources, array(), $this->preferredResources); } } } catch (StringCastException $e) { throw new StringCastException(str_replace('argument $labelPath', 'option "property"', $e->getMessage()), null, $e); } $this->loaded = true; }
/** * 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); }
/** * {@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); }