Пример #1
0
 protected function attached($form)
 {
     parent::attached($form);
     $this->fileEntity = Objects::hasProperty($this->parent->data, $this->name) ? Objects::getProperty($this->parent->data, $this->name) : NULL;
     if ($this->fileEntity instanceof \Doctrine\Common\Collections\Collection) {
         $this->multi = true;
     }
 }
Пример #2
0
 /**
  */
 public function save()
 {
     foreach ($this->entities as $entity) {
         $class = $this->getMeta($entity);
         /** @var \Kdyby\Doctrine\Forms\EntityContainer|\Kdyby\Doctrine\Forms\CollectionContainer $container */
         $container = $this->getComponent($entity);
         $values = $container->getValues();
         foreach ($values as $name => $value) {
             if (!$container[$name] instanceof IControl) {
                 continue;
             }
             if ($class->hasField($field = $this->getControlField($container[$name]))) {
                 if ($class->isIdentifier($field)) {
                     continue;
                 }
                 if (!$this->isTargetCollection($entity, $field)) {
                     // todo: wtf?
                     Objects::setProperty($entity, $field, $value);
                 }
             } elseif ($class->hasAssociation($field)) {
                 if (Objects::hasProperty($entity, $field)) {
                     Objects::setProperty($entity, $field, $value);
                     continue;
                 }
                 if ($this->isItemsControl($container[$name])) {
                     $value = $this->resolveItemsControlValue($value, $entity, $field);
                 }
                 if ($this->isTargetCollection($entity, $field)) {
                     $collection = $this->getCollection($entity, $field);
                     $collection->clear();
                     foreach ($value as $item) {
                         $collection->add($item);
                     }
                 } else {
                     $class->setFieldValue($entity, $field, $value);
                 }
             } elseif (Objects::hasProperty($entity, $field)) {
                 Objects::setProperty($entity, $field, $value);
                 continue;
             }
         }
     }
     foreach ($this->collections as $collection) {
         $container = $this->getComponent($collection);
         /** @var \Kdyby\Doctrine\Forms\EntityContainer $parentContainer */
         $parentContainer = $container->getParent();
         if (!$parentContainer instanceof IObjectContainer || !($parentEntity = $parentContainer->getData())) {
             continue;
         }
         foreach ($collection as $related) {
             $this->ensureBidirectionalRelation($parentEntity, $related, $container->getName());
         }
     }
 }