/**
  * {@inheritdoc}
  */
 public function display(Definition $definition)
 {
     if (!$this->isNull()) {
         return $this->datetime->format($definition->getFormat());
     }
     return parent::display($definition);
 }
Ejemplo n.º 2
0
 /**
  * Creates and returns a Schema from the given configuration array.
  *
  * @param array $configuration
  * @return Schema[]
  */
 protected function createSchemas(array $configuration)
 {
     $processor = new Processor();
     $processedConfiguration = $processor->processConfiguration(new SchemaConfiguration(), $configuration);
     $schemas = [];
     foreach ($processedConfiguration as $schemaName => $schemaConfig) {
         $schema = new Schema($schemaName, $schemaConfig['title']);
         foreach ($schemaConfig['groups'] as $groupName => $groupConfig) {
             $group = new Group($groupName, $groupConfig['title']);
             foreach ($groupConfig['characteristics'] as $characteristicName => $characteristicConfig) {
                 $fullName = implode(':', [$schemaName, $groupName, $characteristicName]);
                 $this->validateDefinitionConfig($fullName, $characteristicConfig);
                 $definition = new Definition();
                 $definition->setName($characteristicName)->setFullName($fullName)->setType($characteristicConfig['type'])->setTitle($characteristicConfig['title'])->setShared($characteristicConfig['shared'])->setVirtual($characteristicConfig['virtual'])->setPropertyPaths($characteristicConfig['property_paths'])->setFormat($characteristicConfig['format'])->setDisplayGroups($characteristicConfig['display_groups']);
                 $group->addDefinition($definition);
             }
             $schema->addGroup($group);
         }
         $schemas[] = $schema;
     }
     return $schemas;
 }
 public function findByDefinition(Definition $definition)
 {
     $query = $this->createQueryBuilder('c')->where('c.identifier = :identifier')->setParameter('identifier', $definition->getIdentifier())->orderBy('c.value', 'ASC')->getQuery();
     return $query->getResult();
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function createCharacteristicFromDefinition(Definition $definition, $value = null)
 {
     $characteristic = null;
     // TODO characteristic classes map
     switch ($definition->getType()) {
         case 'text':
             $characteristic = new TextCharacteristic();
             break;
         case 'html':
             $characteristic = new HtmlCharacteristic();
             break;
         case 'number':
             $characteristic = new NumberCharacteristic();
             break;
         case 'boolean':
             $characteristic = new BooleanCharacteristic();
             break;
         case 'datetime':
             $characteristic = new DatetimeCharacteristic();
             break;
         case 'choice':
             $characteristic = new ChoiceCharacteristic();
             if (null !== $value && !$value instanceof ChoiceCharacteristicValue) {
                 $tmp = $value;
                 $value = new ChoiceCharacteristicValue();
                 $value->setIdentifier($definition->getIdentifier())->setValue($tmp);
             }
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid type "%s".', $definition->getType()));
     }
     $characteristic->setIdentifier($definition->getIdentifier())->setValue($value);
     return $characteristic;
 }
 /**
  * {@inheritDoc}
  */
 public function display(Definition $definition)
 {
     if ($this->isNull()) {
         return 'NC';
     }
     return sprintf($definition->getFormat(), (string) $this->getValue());
 }
 /**
  * Fills the data with the proper characteristic type.
  *
  * @param \Doctrine\Common\Collections\Collection $data
  * @param \Ekyna\Component\Characteristics\Schema\Definition $definition
  * @throws \InvalidArgumentException
  */
 private function appendProperData(Collection $data, Definition $definition)
 {
     $identifier = $definition->getIdentifier();
     if ($data->offsetExists($identifier)) {
         return;
     }
     $characteristic = $this->manager->createCharacteristicFromDefinition($definition);
     $data->set($identifier, $characteristic);
 }