Exemplo n.º 1
0
 public function lazyInitialize()
 {
     if ($this->lazy_initialized) {
         throw new \Exception('big error');
     }
     $this->lazy_initialized = true;
     // add tranlation
     $this->tr_node = $this->property_container->tr_node->getNodeByPath($this->class_property);
     if (!$this->label) {
         $map = $this->getPropertyDoctrineAssociationMapping();
         if ($map && $this->admin_object->generator->hasAdminClass($map['targetEntity'])) {
             $admin = $this->admin_object->generator->getAdminByClass($map['targetEntity']);
             $this->label = $admin->getLabel();
         } else {
             $this->label = $this->admin_object->generator->getTransValue('property', $this->class_property . '.label');
         }
     } else {
         $this->label = $this->tr_node->createValue('label', $this->label);
     }
     if (null !== $this->show_on) {
         if (!is_array($this->show_on)) {
             $this->throwError("show_on need be array, you set %s", gettype($this->show_on));
         }
         $_or = $this->show_on;
         if (!\Dev::isSimpleArray($this->show_on)) {
             $_or = array($_or);
         }
         foreach ($_or as $_or_i => $_and) {
             foreach ($_and as $_property => $values) {
                 if (!$this->property_container->hasProperty($_property)) {
                     $this->throwError("show_on use property `%s` not form type", $_property);
                 }
                 $element = $this->property_container->getProperty($_property);
                 if (!$element instanceof Choice && !$element instanceof Workflow) {
                     $this->throwError("show_on use property `%s` is (%s) form type, exprect choice type", $_property, $element->compile_form_type);
                 }
             }
         }
         foreach ($_or as $and_i => $and) {
             foreach ($and as $when_i => $values) {
                 if (!is_array($values)) {
                     $values = explode(',', trim($values));
                 }
                 foreach ($values as $_value_i => $when_value) {
                     $values[$_value_i] = (string) trim($when_value);
                 }
                 $_or[$and_i][$when_i] = $values;
             }
         }
         $this->show_on = $_or;
     }
     if (null !== $this->parent_on) {
         $on = $this->parent_on;
         foreach ($on as $parent_property_name => $_or) {
             if (!\Dev::isSimpleArray($_or)) {
                 $_or = array($_or);
             }
             if (!$this->property_container->entity->reflection->hasProperty($parent_property_name)) {
                 $this->throwError("parent_on use property `%s` not exists", $parent_property_name);
             }
             if (!$this->property_container->entity->orm_metadata->hasAssociation($parent_property_name)) {
                 $this->throwError("parent_on use property `%s` not orm association", $parent_property_name);
             }
             $map = $this->property_container->entity->getPropertyDoctrineAssociationMapping($parent_property_name);
             if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_MANY) {
                 $this->throwError("parent_on use property `%s` with one to many orm map", $parent_property_name);
             }
             if ($map['type'] === \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY) {
                 $this->throwError("parent_on use property `%s` with many to many orm map", $parent_property_name);
             }
             $admin = $this->admin_object->generator->getAdminByClass($map['targetEntity']);
             foreach ($_or as $_or_i => $_and) {
                 foreach ($_and as $_property => $values) {
                     if (!$admin->reflection->hasProperty($_property)) {
                         $this->throwError("parent_on use property `%s` not exists", $parent_property_name, $_property);
                     }
                 }
             }
             foreach ($_or as $and_i => $and) {
                 foreach ($and as $when_i => $values) {
                     if (!is_array($values)) {
                         $values = explode(',', trim($values));
                     }
                     foreach ($values as $_value_i => $when_value) {
                         $values[$_value_i] = (string) trim($when_value);
                     }
                     $_or[$and_i][$when_i] = $values;
                 }
             }
             $on[$parent_property_name] = $_or;
         }
         $this->parent_on = $on;
     }
 }
Exemplo n.º 2
0
 public function compileForm($action, $parent_builder, $admin, $object, \Symforce\AdminBundle\Compiler\MetaType\PropertyContainer $property_container, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer, $parent_property = null)
 {
     $this_builder = $parent_builder . '_' . $this->id;
     $options = array("sf_form_type" => "sf_group", "label" => $this->label->getPhpCode());
     if ($this->show_on) {
         if (!is_array($this->show_on)) {
             $this->throwError("show_on need be array, you set %s", gettype($this->show_on));
         }
         $_or = $this->show_on;
         if (!\Dev::isSimpleArray($this->show_on)) {
             $_or = array($_or);
         }
         $options['sf_form_dynamic'] = $_or;
     }
     $writer->write($this_builder . ' = $builder->create("sf_form_group_' . $this->id . '", "sf_group", ')->write(var_export($options, 1))->writeln(');');
     foreach ($this->properties as $property_name) {
         if (!$property_container->hasProperty($property_name)) {
             continue;
         }
         $element = $property_container->properties[$property_name];
         $element->compileActionForm($action, $this_builder, $admin, $object, $parent_property);
     }
     $writer->writeln(sprintf('if( %s->count() > 0 ) { ', $this_builder))->indent()->writeln($parent_builder . '->add(' . $this_builder . ');')->outdent()->writeln("}");
 }