/** * Index view of content by type * * @param int $type * @return Response */ public function typeAction($type) { $contentType = $this->get('opifer.content.content_type_manager')->getRepository()->find($type); if (!$contentType) { throw $this->createNotFoundException(sprintf('Content Type with ID %d could not be found.', $type)); } $queryBuilder = $this->get('opifer.content.content_manager')->getRepository()->createValuedQueryBuilder('c'); $source = new Entity($this->getParameter('opifer_content.content_class')); $source->initQueryBuilder($queryBuilder); $tableAlias = $source->getTableAlias(); $source->manipulateQuery(function ($query) use($tableAlias, $contentType) { $query->andWhere($tableAlias . '.contentType = :contentType')->setParameter('contentType', $contentType); }); $editAction = new RowAction('button.edit', 'opifer_content_contenteditor_design'); $editAction->setRouteParameters(['id', 'type' => 'content']); //$deleteAction = new RowAction('button.delete', 'opifer_content_content_delete'); //$deleteAction->setRouteParameters(['id']); /* @var $grid \APY\DataGridBundle\Grid\Grid */ $grid = $this->get('grid'); $grid->setId('content')->setSource($source)->addRowAction($editAction); //->addRowAction($deleteAction) foreach ($contentType->getSchema()->getAttributes() as $attribute) { $name = $attribute->getName(); $column = new TextColumn(['id' => $name, 'field' => 'attributes.' . $attribute->getName() . '.value', 'title' => $attribute->getDisplayName()]); $column->manipulateRenderCell(function ($value, $row, $router) use($name) { $value = $row->getEntity()->getAttributes()[$name]; return $value; }); $grid->addColumn($column); } return $grid->getGridResponse($this->getParameter('opifer_content.content_type_view'), ['content_type' => $contentType, 'grid' => $grid]); }
public function listAction() { $source = new Entity('OpiferCmsBundle:Post'); $formColumn = new TextColumn(['id' => 'posts', 'title' => 'Form', 'source' => false, 'filterable' => false, 'sortable' => false, 'safe' => false]); $formColumn->manipulateRenderCell(function ($value, $row, $router) { return '<a href="' . $this->generateUrl('opifer_form_form_edit', ['id' => $row->getEntity()->getForm()->getId()]) . '">' . $row->getEntity()->getForm()->getName() . '</a>'; }); $viewAction = new RowAction('view', 'opifer_form_post_view'); $viewAction->setRouteParameters(['id']); $deleteAction = new RowAction('delete', 'opifer_form_post_delete'); $deleteAction->setRouteParameters(['id']); $grid = $this->get('grid'); $grid->setId('posts')->setSource($source)->addColumn($formColumn, 2)->addRowAction($viewAction)->addRowAction($deleteAction); return $grid->getGridResponse('OpiferCmsBundle:Backend/Post:list.html.twig'); }
/** * @return Response */ public function indexAction() { $source = new Entity($this->get('opifer.form.form_manager')->getClass()); $postsColumn = new TextColumn(['id' => 'posts', 'title' => 'Posts', 'source' => false, 'filterable' => false, 'sortable' => false, 'safe' => false]); $postsColumn->manipulateRenderCell(function ($value, $row, $router) { return '<a href="' . $this->generateUrl('opifer_form_post_index', ['formId' => $row->getEntity()->getId()]) . '">' . count($row->getEntity()->getPosts()) . ' posts</a>'; }); $editAction = new RowAction('button.edit', 'opifer_form_form_edit'); $editAction->setRouteParameters(['id']); $deleteAction = new RowAction('button.delete', 'opifer_form_form_delete'); $deleteAction->setRouteParameters(['id']); /* @var $grid \APY\DataGridBundle\Grid\Grid */ $grid = $this->get('grid'); $grid->setId('forms')->setSource($source)->addColumn($postsColumn)->addRowAction($editAction)->addRowAction($deleteAction); return $grid->getGridResponse('OpiferCmsBundle:Backend/Form:index.html.twig'); }
/** * @return Response */ public function indexAction() { $source = new Entity('OpiferCmsBundle:Template'); $editAction = new RowAction('edit', 'opifer_cms_template_edit'); $editAction->setRouteParameters(['id']); $deleteAction = new RowAction('delete', 'opifer_cms_template_delete'); $deleteAction->setRouteParameters(['id']); $attributesColumn = new TextColumn(['id' => 'attributes', 'Attributes', 'source' => false, 'filterable' => false, 'sortable' => false, 'safe' => false]); $attributesColumn->manipulateRenderCell(function ($value, $row, $router) { $html = ''; foreach ($row->getEntity()->getAttributes() as $attribute) { $html .= '<span class="label label-primary" style="display:inline-block">' . $attribute->getDisplayName() . '</span>'; } return $html; }); $grid = $this->get('grid'); $grid->setId('templates')->setSource($source)->addColumn($attributesColumn)->addRowAction($editAction)->addRowAction($deleteAction); return $grid->getGridResponse('OpiferCmsBundle:Backend/Template:index.html.twig'); }
/** * {@inheritdoc} */ public function __initialize(array $params) { /* @var \Twig_Template[] $template */ static $template = array(); $params['safe'] = false; parent::__initialize($params); $function = $this->getParam('label_function'); if (!isset($template[$function])) { $template[$function] = $this->twig->createTemplate(sprintf('{{ %s(status) }}', $function)); } $this->callback = function ($value) use($template, $function) { return $template[$function]->render(array('status' => $value)); }; }
/** * {@inheritdoc} */ public function __initialize(array $params) { /* @var \Twig_Template $template */ static $template; $params['safe'] = false; parent::__initialize($params); $function = $this->getParam('label_function'); if (!isset($template)) { $template = $this->twig->createTemplate(sprintf('<a href="{{ route }}">{{ client_name }}</a>', $function)); } $this->callback = function ($clientName, Row $row, RouterInterface $router) use($template) { $clientId = $row->getField('client.id'); if (!empty($clientId)) { $route = $router->generate('_clients_view', array('id' => $clientId)); return $template->render(array('route' => $route, 'client_name' => $clientName)); } return $clientName; }; }
public function getFilters($source) { $parentFilters = parent::getFilters($source); $filters = array(); foreach ($parentFilters as $filter) { switch ($filter->getOperator()) { case self::OPERATOR_ISNULL: $filters[] = new Filter(self::OPERATOR_ISNULL); $filters[] = new Filter(self::OPERATOR_EQ, ''); $this->setDataJunction(self::DATA_DISJUNCTION); break; case self::OPERATOR_ISNOTNULL: $filters[] = new Filter(self::OPERATOR_ISNOTNULL); $filters[] = new Filter(self::OPERATOR_NEQ, ''); break; default: $filters[] = $filter; } } return $filters; }
public function getFilters($source) { $filters = parent::getFilters($source); return $filters; }