Example #1
0
 /**
  * @param $propertyName
  * @param bool|true $fillValues
  * @return BuilderDefinition|null
  * @throws InvalidStateException
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 private function getPropertyRule($propertyName, $fillValues = TRUE)
 {
     $rule = new BuilderDefinition($propertyName);
     if ($this->entityMetadata->hasField($propertyName)) {
         // Column
         if ($this->getEntityPrimaryKeyName($this->entity) === $propertyName) {
             $rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_HIDDEN);
             $rule->setRequired(FALSE);
         } else {
             $fieldMapping = $this->entityMetadata->getFieldMapping($propertyName);
             $type = BuilderDefinition::COMPONENT_TYPE_TEXT;
             $rule->setRequired(!$fieldMapping['nullable']);
             /** @var Column $annotation */
             if ($fieldMapping['type'] === 'boolean') {
                 $type = BuilderDefinition::COMPONENT_TYPE_CHECKBOX;
             }
             // is numeric?
             if ($fieldMapping['type'] === 'integer' || $fieldMapping['type'] === 'float' || $fieldMapping['type'] === 'bigint' || $fieldMapping['type'] === 'decimal' || $fieldMapping['type'] === 'smallint') {
                 $rule->addValidationRule(Form::NUMERIC, 'This is required in numeric format', TRUE);
             }
             $rule->setComponentType($type);
         }
     } else {
         if ($this->entityMetadata->hasAssociation($propertyName)) {
             $associationMapping = $this->entityMetadata->getAssociationMapping($propertyName);
             switch ($associationMapping['type']) {
                 case ClassMetadata::MANY_TO_ONE:
                     $rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_SELECT);
                     if ($fillValues) {
                         $rule->setValues($this->getPossibleValues($associationMapping['targetEntity']));
                     }
                     $rule->setTargetEntity($associationMapping['targetEntity']);
                     $rule->setRequired(TRUE);
                     break;
                 case ClassMetadata::MANY_TO_MANY:
                     $rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_MULTI_SELECT);
                     if ($fillValues) {
                         $rule->setValues($this->getPossibleValues($associationMapping['targetEntity']));
                     }
                     $rule->setRequired(TRUE);
                     $rule->setTargetEntity($associationMapping['targetEntity']);
                     break;
             }
         }
     }
     return $rule->getComponentType() === NULL ? NULL : $rule;
 }
 private function getUniqueAndRequiredAssociations(ClassMetadata $meta, $entity)
 {
     $associations = array();
     foreach ($meta->getAssociationNames() as $associationName) {
         $mapping = $meta->getAssociationMapping($associationName);
         if (!empty($mapping['id']) && $meta->usesIdGenerator()) {
             // autogenerated id
             continue;
         }
         if (!($mapping['type'] & ClassMetadata::TO_ONE)) {
             // is not to one relation
             continue;
         }
         if (empty($mapping['isOwningSide'])) {
             // is not owning side
             continue;
         }
         foreach ($mapping['joinColumns'] as $joinColumn) {
             if (!empty($joinColumn['nullable']) && empty($joinColumn['unique'])) {
                 // is nullable and is not unique
                 continue;
             }
             $targetColumn = $joinColumn['referencedColumnName'];
             $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
             $newVal = $meta->getFieldValue($entity, $associationName);
             if ($newVal !== NULL) {
                 $newValId = $this->uow->getEntityIdentifier($newVal);
             }
             switch (TRUE) {
                 case $newVal === NULL:
                     $value = NULL;
                     break;
                 case $targetClass->containsForeignIdentifier:
                     $value = $newValId[$targetClass->getFieldForColumn($targetColumn)];
                     break;
                 default:
                     $value = $newValId[$targetClass->fieldNames[$targetColumn]];
                     break;
             }
             $sourceColumn = $joinColumn['name'];
             $quotedColumn = $this->quotes->getJoinColumnName($joinColumn, $meta, $this->platform);
             $associations[$sourceColumn]['value'] = $value;
             $associations[$sourceColumn]['quotedColumn'] = $quotedColumn;
             $associations[$sourceColumn]['type'] = $targetClass->getTypeOfColumn($targetColumn);
         }
     }
     return $associations;
 }
 private function getDiscriminatorColumn(ClassMetadata $meta)
 {
     if (!$meta->isInheritanceTypeSingleTable()) {
         return [];
     }
     $column = $meta->discriminatorColumn;
     return [$column['fieldName'] => ['value' => $meta->discriminatorValue, 'quotedColumn' => $this->platform->quoteIdentifier($column['name']), 'type' => Type::getType($column['type'])]];
 }