コード例 #1
0
 /**
  * @return TransGeneratorValue
  */
 public function createValue($path, $string, $ref_domain = null)
 {
     if (null === $ref_domain) {
         $this->set($path, $string);
         if ($this->path) {
             $path = $this->path . '.' . $path;
         }
         return new TransGeneratorValue($path, $this->domain, $string);
     } else {
         $tr = $this->gen->getTransGenerator($ref_domain);
         $tr->set($path, $string);
         return new TransGeneratorValue($path, $ref_domain, $string);
     }
 }
コード例 #2
0
 public function create($class_name, $property_name, \Symforce\AdminBundle\Compiler\Annotation\Form $annot, \Symforce\AdminBundle\Compiler\MetaType\PropertyContainer $parent, \Symforce\AdminBundle\Compiler\MetaType\Admin\Entity $entity = null)
 {
     $om = $this->doctrine->getManagerForClass($class_name);
     if (!$om) {
         throw new \Exception(sprintf("%s->%s has no orm", $class_name, $property_name));
     }
     $meta = $om->getClassMetadata($class_name);
     if (!$meta) {
         throw new \Exception(sprintf("%s->%s has no orm", $class_name, $property_name));
     }
     $map = null;
     if ($meta->hasAssociation($property_name)) {
         $map = $meta->getAssociationMapping($property_name);
     }
     $orm_type = $meta->getTypeOfField($property_name);
     $form_type = $annot->type;
     if ($entity) {
         if ($entity->class_name !== $class_name) {
             throw new \Exception(sprintf("%s->%s not match admin(%s) ", $class_name, $property_name, $entity->admin_name));
         }
     } else {
         if (!$this->gen->hasAdminClass($class_name)) {
             throw new \Exception(sprintf("%s->%s not find admin", $class_name, $property_name));
         }
         $entity = $this->gen->getAdminByClass($class_name);
     }
     if ($form_type) {
         if ('workflow' === $form_type) {
             if (!$entity->workflow) {
                 throw new \Exception(sprintf("%s->%s use form type:%s without define workflow", $class_name, $property_name, $form_type));
             } else {
                 if ($entity->workflow->property !== $property_name) {
                     throw new \Exception(sprintf("%s->%s use form type:%s, but workflow property is %s", $class_name, $property_name, $form_type, $entity->workflow->property));
                 }
             }
         }
         if ('owner' === $form_type) {
             if (!$entity->owner) {
                 throw new \Exception(sprintf("%s->%s use form type:%s without define owner", $class_name, $property_name, $form_type));
             } else {
                 if ($entity->owner->owner_property !== $property_name) {
                     throw new \Exception(sprintf("%s->%s use form type:%s, but owner property is %s", $class_name, $property_name, $form_type, $entity->owner->owner_property));
                 }
             }
         }
         if ($map) {
             if ($map['targetEntity'] !== $this->types[$form_type]['map'] && '*' !== $this->types[$form_type]['map']) {
                 if ($this->types[$form_type]['map']) {
                     throw new \Exception(sprintf("%s->%s use form type:%s with orm map type:%s, form type not accept orm map", $class_name, $property_name, $form_type, $map['targetEntity']));
                 } else {
                     throw new \Exception(sprintf("%s->%s use form type:%s with orm map type:%s, only accept orm map:(%s)", $class_name, $property_name, $form_type, $map['targetEntity'], $this->types[$form_type]['map']));
                 }
             }
         } else {
             if ($orm_type && !in_array($orm_type, $this->types[$form_type]['orm'])) {
                 throw new \Exception(sprintf("%s->%s use form type:%s with orm type:%s, only accept orm:(%s)", $class_name, $property_name, $form_type, $orm_type, join(',', $this->types[$form_type]['orm'])));
             }
         }
     } else {
         if ($entity->workflow && $entity->workflow->property === $property_name) {
             $form_type = 'workflow';
         } else {
             if ($entity->owner && $entity->owner->owner_property === $property_name) {
                 $form_type = 'owner';
             }
         }
         if (!$form_type) {
             if ($map) {
                 // $map['targetEntity']
                 foreach ($this->types as $_type_name => $_type) {
                     if ($map['targetEntity'] === $_type['map']) {
                         $form_type = $_type_name;
                         break;
                     }
                 }
                 if (!$form_type) {
                     // check if it is embed type
                     $cache = $this->gen->getAnnotationCache($class_name);
                     if (isset($cache->propertie_annotations[$property_name]['properties'])) {
                         $form_type = 'embed';
                     } else {
                         $form_type = 'entity';
                     }
                 }
             } else {
                 if ('string' === $orm_type) {
                     foreach ($this->guess as $keyword => $_type) {
                         if (false !== strpos($property_name, $keyword)) {
                             $form_type = $_type;
                             break;
                         }
                     }
                 } else {
                     if (isset($this->default_type[$orm_type])) {
                         $form_type = $this->default_type[$orm_type];
                     }
                     foreach ($this->types as $_type_name => $_type) {
                         if (!$_type['map'] && in_array($orm_type, $_type['orm'])) {
                             $form_type = $_type_name;
                             break;
                         }
                     }
                 }
                 if (!$form_type) {
                     $form_type = 'text';
                 }
             }
         }
     }
     if (!isset($this->types[$form_type]['class'])) {
         throw new \Exception(sprintf("%s->%s with form(%s) no class ", $class_name, $property_name, $form_type));
     }
     $form_class = $this->types[$form_type]['class'];
     /*
             if( !($form_class instanceof \Symforce\AdminBundle\Compiler\MetaType\Form\Element) ) {
                 throw new \Exception(sprintf("`%s` is invalid ", $form_class));
             }*/
     $form_element = new $form_class($parent, $entity, $property_name, $annot);
     $form_element->compile_meta_type = $form_type;
     $form_element->compile_form_type = $this->types[$form_type]['type'];
     $form_element->compile_orm_type = $orm_type;
     if ($meta->hasField($property_name)) {
         if ($meta->isUniqueField($property_name)) {
             if (null === $annot->unique) {
                 $form_element->unique = true;
             }
         }
     }
     if ($form_element->unique) {
         $cache = $this->gen->getAnnotationCache($class_name);
         if (isset($cache->propertie_annotations[$property_name])) {
             // $cache->propertie_annotations[$property_name]['Gedmo\Mapping\Annotation\Translatable']
             if (isset($cache->propertie_annotations[$property_name]['Gedmo\\Mapping\\Annotation\\Slug'])) {
                 if (null === $annot->unique) {
                     $form_element->unique = false;
                 }
                 if (null === $annot->required) {
                     $form_element->required = false;
                 }
             }
         }
     }
     return $form_element;
 }
コード例 #3
0
 public function flush(\Symforce\AdminBundle\Compiler\Generator $gen)
 {
     $template_path = $gen->getParameter('kernel.root_dir') . '/Resources/views/' . $this->template_file;
     \Dev::write_file($template_path, $this->writer->getContent());
 }
コード例 #4
0
 public function buildMenuTree(\Symforce\AdminBundle\Compiler\Generator $gen, array &$menu_config)
 {
     $list = array('root' => new Menu('root'));
     $tr = $gen->getTransNodeByPath($gen->sf_domain, 'sf.menu');
     foreach ($menu_config['groups'] as $name => $attr) {
         $_menu = new Menu($name);
         if (false !== $attr['position']) {
             $_menu->setPosition($attr['position']);
         }
         if ($attr['label']) {
             $tr->set($name, $attr['label']);
         }
         $_menu->setLabel('sf.menu.' . $name);
         $_menu->setDomain($gen->sf_domain);
         if (false !== $attr['route']) {
             $_menu->setRouteName($attr['route']);
         }
         if (false !== $attr['url']) {
             $_menu->setUrl($attr['url']);
         }
         if (isset($attr['divider'])) {
             $_menu->setDivider($attr['divider']);
         }
         if (isset($attr['icon'])) {
             $_menu->setIcon($attr['icon']);
         }
         $list[$name] = $_menu;
         $parent_name = $attr['parent'];
         if (!isset($list[$parent_name])) {
             $_parent = new Menu($parent_name);
             $list[$parent_name] = $_parent;
         }
         $list[$parent_name]->addChild($_menu);
     }
     foreach ($gen->admin_generators as $object) {
         if ($object instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Entity) {
             /**
              * @var \Symforce\AdminBundle\Compiler\MetaType\Entity 
              */
             $menu = $object->menu;
             if (!$menu) {
                 continue;
             }
             if ($menu instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Menu) {
                 $name = $object->name;
                 $tr = $object->tr_node;
                 if (isset($list[$name])) {
                     $_menu = $list[$name];
                 } else {
                     $_menu = new Menu($name);
                     $list[$name] = $_menu;
                 }
                 if (null !== $menu->divider) {
                     $_menu->setDivider($menu->divider);
                 }
                 if (null !== $menu->label) {
                     $tr->set('menu', $menu->label);
                     $_menu->setLabel($name . '.menu');
                 } else {
                     $_menu->setLabel($name . '.label');
                 }
                 $_menu->setDomain($object->tr_domain);
                 if (null !== $menu->icon) {
                     $_menu->setIcon($menu->icon);
                 } else {
                     if (null !== $object->icon) {
                         $_menu->setIcon($object->icon);
                     }
                 }
                 if (null !== $menu->position) {
                     $_menu->setPosition($menu->position);
                 }
                 $_menu->admin = true;
                 $_parent_name = $menu->group;
                 if (true === $_parent_name) {
                     continue;
                     $_parent_name = $gen->getEntityByName($name)->getParent()->getName();
                 }
                 if (isset($list[$_parent_name])) {
                     $_parent = $list[$_parent_name];
                 } else {
                     $_parent = new Menu($_parent_name);
                     $list[$_parent_name] = $_parent;
                 }
                 $_parent->addChild($_menu);
             } else {
                 echo __FILE__, ':', __LINE__, "\n";
                 exit;
             }
         } else {
             echo __FILE__, ':', __LINE__, "\n";
             exit;
         }
     }
     /* check associated */
     foreach ($list as $name => $menu) {
         if (!$menu->admin) {
             continue;
         }
         if (!$menu->getParent()) {
             continue;
         }
         if (!$menu->getParent()->admin) {
             continue;
         }
         continue;
         $_entity = $this->getAdminByName($name);
         if ($_entity->getParent()->getName() != $menu->getParent()->getName()) {
             $_entity->throwError("memu group(%s) is not associated parent `%s`", $menu->getParent()->getName(), $_entity->getPureObject()->getParent()->getName());
         }
     }
     return $list['root'];
 }
コード例 #5
0
ファイル: Entity.php プロジェクト: symforce/symforce-admin
 /**
  * @return \Symforce\AdminBundle\Compiler\Generator\PhpClass
  */
 public function getCompileClass()
 {
     if (null === $this->_compile_class) {
         $this->_compile_class = $this->generator->getAdminPhpGenerator($this);
     }
     return $this->_compile_class;
 }
コード例 #6
0
 public function buildDashboardGroups(\Symforce\AdminBundle\Compiler\Generator $gen, array &$dashboard_config)
 {
     $default_group_name = $dashboard_config['default_group'];
     $groups = array();
     $tr = $gen->getTransNodeByPath($gen->sf_domain, 'sf.dashboard');
     foreach ($dashboard_config['groups'] as $name => $attr) {
         if (isset($groups[$name])) {
             $_item = $groups[$name];
         } else {
             $_item = new CacheObject\DashboardGroup($name);
             $groups[$name] = $_item;
         }
         if (false !== $attr['position']) {
             $_item->setPosition($attr['position']);
         }
         if ($attr['label']) {
             $tr->set($name, $attr['label']);
         }
         $_item->setLabel('sf.dashboard.' . $name);
         if (isset($attr['icon'])) {
             $_item->setIcon($attr['icon']);
         }
         if (isset($attr['right_side'])) {
             $_item->setRightSide($attr['right_side']);
         }
     }
     foreach ($gen->admin_generators as $object) {
         if ($object instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Entity) {
             $item = $object->dashboard;
             if (!$item) {
                 continue;
             }
             if ($item instanceof \Symforce\AdminBundle\Compiler\MetaType\Admin\Dashboard) {
                 $tr = $object->tr_node;
                 $group_name = $item->group;
                 if (!$group_name) {
                     continue;
                 }
                 if (true === $group_name) {
                     $group_name = $default_group_name;
                 }
                 if (!isset($groups[$group_name])) {
                     $group = new CacheObject\DashboardGroup($group_name);
                     $groups[$group_name] = $group;
                 } else {
                     $group = $groups[$group_name];
                 }
                 $_item = new CacheObject\DashboardItem($object->name);
                 $_item->setDomain($object->tr_domain);
                 if (null !== $item->label) {
                     $_item->setLabel($object->name . '.dashboard');
                     $tr->set('dashboard', $item->label);
                 } else {
                     $_item->setLabel($object->name . '.label');
                 }
                 if (null !== $item->icon) {
                     $_item->setIcon($item->icon);
                 } else {
                     if (null !== $object->icon) {
                         $_item->setIcon($object->icon);
                     }
                 }
                 if (null !== $item->position) {
                     $_item->setPosition($item->position);
                 }
                 $_item->setEntity(true);
                 $group->addChild($_item);
                 // add actions
                 foreach ($object->action_collection->children as $action) {
                     $pos = $action->dashboard;
                     if (!$pos) {
                         continue;
                     }
                     $_action = new CacheObject\DashboardAction($action->name);
                     $_action->setLabel($action->label->getPath());
                     $_action->setDomain($action->label->getDomain());
                     $_item->addAction($_action);
                 }
             } else {
                 echo __FILE__, ':', __LINE__, "\n";
                 exit;
             }
         } else {
             echo __FILE__, ':', __LINE__, "\n";
             exit;
         }
     }
     foreach ($groups as $group_name => $group) {
         $_group = $group->children;
         $pos = array();
         foreach ($_group as $item) {
             if (null !== $item->postion) {
                 $pos[$item->postion] = true;
             }
         }
         $_pos = 1;
         foreach ($_group as $item) {
             if (null === $item->postion) {
                 while (isset($pos[$_pos])) {
                     $_pos++;
                 }
                 $item->postion = $_pos;
             }
         }
         usort($_group, array($this, 'sort_item'));
         $group->children = array();
         foreach ($_group as $item) {
             $group->children[$item->name] = $item;
         }
     }
     return $groups;
 }