Exemplo n.º 1
0
 public function writeCallParent()
 {
     $ps = $this->getParameters();
     $_ps = array();
     if ($ps) {
         foreach ($ps as $p) {
             $_ps[] = '$' . $p->getName();
         }
     }
     $code = 'parent::' . $this->getName() . '(' . join(', ', $_ps) . ');';
     $this->_writer->writeln($code);
 }
Exemplo n.º 2
0
 public function writeCache(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $lazy_writer, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer)
 {
     $default_value = $this->getDefaultValue();
     if ($this->_lazy) {
         $lazy_writer->writeln('$this->' . $this->getName() . ' = ' . $this->_class->propertyEncode($default_value) . ' ; ');
         $default_value = null;
     }
     $writer->write("\n");
     if ($this->getDocblock()) {
         $writer->writeln($this->getDocblock());
     }
     $writer->write($this->getVisibility())->write(' $')->write($this->getName())->write(' = ')->write($this->_class->propertyEncode($default_value))->writeln(" ;");
     if ($this->_get) {
         $this->genGetter();
     }
 }
Exemplo n.º 3
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("}");
 }
Exemplo n.º 4
0
 public function compileView(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $twig_writer)
 {
     $property_name = $this->class_property;
     $show_on_start = '';
     $show_on_end = '';
     if ($this->form_element && $this->form_element->show_on) {
         $show_on_start = '{% ' . sprintf('if admin.isFieldVisiable("%s", _object ) ', $property_name) . " %}\n";
         $show_on_end = "{% endif %}\n";
     }
     $twig_writer->writeln('{% ' . sprintf('if admin.isPropertyVisiable("%s", action, _object ) ', $property_name) . ' %}')->write($show_on_start)->indent()->writeln('{% set view_property_count = view_property_count + 1 %}')->writeln('{% set _property_value = ' . $this->getTwigValue() . ' %}')->writeln('{% ' . sprintf('block _admin_%s_view', $property_name) . ' %}')->indent()->writeln('<div class="form-group">')->indent()->write('{% ' . sprintf('block _admin_%s_label', $property_name) . ' %}')->write('<div class="control-label col-xs-3">')->write('{{ ' . $this->getCompileLabelCode() . '}}')->write('</div>')->writeln('{% endblock %} ')->write('{% ' . sprintf('block _admin_%s_value', $property_name) . ' %}')->write('<div class="control-value col-xs-9">')->write($this->getCompileValueCode())->write('</div>')->writeln('{% endblock %} ')->outdent()->writeln('</div>')->outdent()->writeln('{% endblock %} ')->outdent()->write($show_on_end)->writeln('{% endif %} ')->write("\n");
 }
Exemplo n.º 5
0
 private function compileAnonymousChildren(array $_anonymous_children, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $twig_writer)
 {
     foreach ($_anonymous_children as $child_admin_name => $child_properties) {
         $child_admin = $this->admin_object->generator->getAdminByName($child_admin_name);
         $twig_writer->writeln('{# if ' . sprintf('sf_auth("%s", "list")', $child_admin->name) . ' #}')->indent()->writeln('{% ' . sprintf('import "%s" as child_macro', $child_admin->_final_template) . ' %}');
         foreach ($child_properties as $child_property) {
             $macro_name = 'admin_parent_' . $child_property;
             $twig_writer->writeln('{% ' . sprintf('if twig_macro_exists(child_macro, "%s") ', $macro_name) . ' %}')->writeln('{% set view_property_count = view_property_count + 1 %}')->writeln('<div class="form-group">')->indent()->writeln('<div class="control-label col-xs-3">')->indent()->writeln('{% ' . sprintf('if twig_macro_exists(child_macro, "%s_label") ', $macro_name) . ' %}')->indent()->writeln('{{ ' . sprintf('child_macro.%s_label(admin)', $macro_name) . '}}')->outdent()->writeln('{% else %}')->indent()->writeln($child_admin->label->getTwigCode())->outdent()->writeln('{% endif %}')->outdent()->writeln('</div>')->writeln('<div class="control-value col-xs-9">')->writeln('<td>')->indent()->writeln('{{ ' . sprintf('child_macro.%s( sf_admin_class(%s), admin, _object)', $macro_name, var_export($child_admin->class_name, 1)) . '}}')->outdent()->writeln('</td>')->writeln('</div>')->outdent()->writeln('</div>')->writeln('{% endif %}');
         }
         $twig_writer->outdent()->writeln('{# endif #}');
     }
 }
 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());
 }
Exemplo n.º 7
0
 public function compileFormOption(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer, array &$options)
 {
     $writer->writeln('return ' . var_export($options, 1) . ';');
 }
 public function generateRouteGenerator(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $generator, $use_object, $is_first = false)
 {
     $admin_name = $this->admin->getName();
     $route_parent = $this->admin->getRouteParent();
     if ($route_parent) {
         if ($is_first) {
             $generator->writeln(sprintf('$%s = $loader->getAdminByClass("%s");', $admin_name, $this->admin->getClassName()));
             $generator->writeln(sprintf('$_sf_admin_route_parameters = $%s->getRouteParameters();', $admin_name));
         }
         $route_parent_name = $route_parent->getName();
         $parent_property = $this->admin->getRouteParentProperty();
         $generator->writeln(sprintf('if( !isset($options["%s_id"] )) {', $route_parent_name))->indent();
         if ($use_object) {
             $generator->writeln(sprintf('$%s_object = $%s_object ? $accessor->getValue($%s_object, "%s") : null ;', $route_parent_name, $admin_name, $admin_name, $parent_property))->writeln(sprintf('if( $%s_object ) {', $route_parent_name))->indent()->writeln(sprintf('$options["%s_id"] = $accessor->getValue($%s_object, "%s") ;', $route_parent_name, $route_parent_name, $route_parent->getPropertyIdName()))->outdent()->writeln(sprintf('} else if( isset($_sf_admin_route_parameters["%s_id"] )) {', $route_parent_name))->indent()->writeln(sprintf('$options["%s_id"] = $_sf_admin_route_parameters["%s_id"] ;', $route_parent_name, $route_parent_name))->outdent()->writeln('} else {')->indent()->writeln(sprintf(' $options["%s_id"] = $loader->getAdminByClass("%s")->getRouteObjectId() ;', $route_parent_name, $route_parent->getClassName()))->outdent()->writeln('}');
         } else {
             $generator->writeln(sprintf('if( isset($_sf_admin_route_parameters["%s_id"] )) {', $route_parent_name))->indent()->writeln(sprintf(' $options["%s_id"] = $_sf_admin_route_parameters["%s_id"] ;', $route_parent_name, $route_parent_name))->outdent()->writeln('} else {')->indent()->writeln(sprintf(' $options["%s_id"] = $loader->getAdminByClass("%s")->getRouteObjectId() ;', $route_parent_name, $route_parent->getClassName()))->outdent()->writeln('} ');
         }
         $generator->outdent()->writeln('}');
         $route_parent_generator = $this->loader->getAdminRouteGenerator($route_parent_name);
         $route_parent_generator->generateRouteGenerator($generator, $use_object);
     }
 }
 public function getRoutePath(array &$requirements_entitys, array &$requirements, array &$requirement_keys, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $generator, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $dispatcher, $with_entity, $path, $break_requirement_key = null, $first_entity_call = true)
 {
     $entity_object_name = '$' . $this->admin_name;
     if ($with_entity) {
         $requirements_entitys[$this->admin_class] = $this->eneity_id_name;
         if ($this->admin->getPropertySlugName()) {
             if ($this->admin->isPropertySlugNullable()) {
                 $requirements[$this->eneity_id_name] = '\\w*';
             } else {
                 $requirements[$this->eneity_id_name] = '\\w+';
             }
         } else {
             $requirements[$this->eneity_id_name] = '\\d+';
         }
         $property_slug_name = $this->admin->getPropertyIdName();
         $property_id_name = $this->admin->getPropertySlugName();
         if (!empty($property_slug_name)) {
             $generator->writeln(sprintf('$options["%s"] = $accessor->getValue(%s, "%s");', $this->eneity_id_name, $entity_object_name, $property_slug_name));
             $generator->writeln(sprintf('if( empty($options["%s"]) ) $options["%s"] = $accessor->getValue(%s, "%s");', $this->eneity_id_name, $this->eneity_id_name, $entity_object_name, $property_id_name));
         } else {
             $generator->writeln(sprintf('$options["%s"] = $accessor->getValue(%s, "%s");', $this->eneity_id_name, $entity_object_name, $property_id_name));
         }
         if ($first_entity_call) {
             $first_entity_call = false;
             $dispatcher->writeln(sprintf('%s = $controller->getPageObject("%s", $request->get("%s") );', $entity_object_name, $this->admin_name, $this->eneity_id_name));
         } else {
             $dispatcher->writeln(sprintf('$controller->setPageObject(%s, "%s", $request->get("%s") );', $entity_object_name, $this->admin_name, $this->eneity_id_name));
         }
     }
     if (!$first_entity_call) {
         if (!isset($requirement_keys[$this->eneity_id_name])) {
             if ($break_requirement_key) {
                 if ($with_entity) {
                     $path = '/' . $this->route_path . '/' . '{' . $this->eneity_id_name . '}' . $path;
                 } else {
                     $path = '/' . $this->route_path . $path;
                 }
             }
         } else {
             if ($break_requirement_key) {
                 // throw new \Exception(sprintf("%s: `{%s}` duplicate, maybe you missing `{%s}` in path `%s`", $this->err_msg, $this->eneity_id_name, $break_requirement_key, $path ));
             }
         }
     }
     if ($this->page_parent_entity) {
         $parent_entity_object_name = '$' . $this->parent_admin->getName();
         if ($with_entity) {
             $generator->writeln(sprintf('%s = $accessor->getValue(%s, "%s");', $parent_entity_object_name, $entity_object_name, $this->property_page_name));
         }
         $parent_generator = $this->page_loader->getPageGeneratorByClass($this->page_parent_entity);
         if (!$first_entity_call) {
             $dispatcher->writeln(sprintf('%s = $accessor->getValue(%s, "%s");', $parent_entity_object_name, $entity_object_name, $this->property_page_name));
         }
         if (!$break_requirement_key && !isset($requirement_keys[$this->eneity_id_name])) {
             $break_requirement_key = $this->eneity_id_name;
         }
         $path = $parent_generator->getRoutePath($requirements_entitys, $requirements, $requirement_keys, $generator, $dispatcher, true, $path, $break_requirement_key, $first_entity_call);
     }
     return $path;
 }
Exemplo n.º 10
0
 protected function compileMenuChildren(\Symforce\AdminBundle\Entity\Menu $menu, \Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer, $_deep)
 {
     if (!$menu->menu_group->multi_level) {
         return;
     }
     $deep = $_deep + 1;
     if ($deep > $menu->menu_group->menu_child_deep) {
         return;
     }
     $tag = $menu->menu_group->group_tag;
     $has_children = false;
     foreach ($menu->children as $child) {
         if ($child->disabled) {
             continue;
         }
         if (!$has_children) {
             $writer->writeln(sprintf('<%s class="sf_menu_items sf_menu_items_deep%d">', $tag, $_deep));
             $has_children = true;
         }
         $this->compileMenu($child, $writer, $deep);
     }
     if ($has_children) {
         $writer->writeln(sprintf('</%s>', $tag));
     }
 }
Exemplo n.º 11
0
 public function compileListAction(\Symforce\AdminBundle\Compiler\Generator\PhpWriter $writer)
 {
     $writer->writeln('<div class="btn-group btn-group-sm">');
     foreach ($this->children as $name => $node) {
         if (false !== $node->list) {
             if (!$node->list) {
                 continue;
             }
             if ($node->role) {
                 $writer->writeln('{% if is_granted("' . $node->role . '") %}');
             }
             $counter = '{% set sf_workflow_counter = admin.getRouteWorkflowCount("' . $name . '") %}';
             $counter .= '(<span {% if sf_workflow_counter > 0 %}class="' . $this->admin_object->name . '_workflow_count_' . $name . '{% endif %}">{{ sf_workflow_counter }}</span>)';
             if ($node->isInternal()) {
                 $label = '{{ "' . $node->label->getPath() . '"| trans({"%admin%": admin.label}, "' . $node->label->getDomain() . '") }} ' . $counter;
             } else {
                 $label = '{{ "' . $node->label->getPath() . '"| trans({}, "' . $node->label->getDomain() . '") }} ' . $counter;
             }
             $writer->writeln('<a href="{{ admin.path("list", null, {"admin_route_workflow":"' . $name . '"}) }}" class="btn {% if admin.routeworkflow == "' . $name . '" %}btn-primary{% else %}btn-default{% endif %}">' . $label . '</a>');
             if ($node->role) {
                 $writer->writeln('{% endif %}');
             }
         }
     }
     $writer->writeln('</div>');
 }