/**
  * @return string
  */
 public function render()
 {
     foreach ($this->header as $field => $value) {
         header($field . ' ' . $value, false);
     }
     return $this->view->render($this->variables);
 }
 /**
  * @param FieldDescriptionInterface $fieldDescription
  * @param \Twig_TemplateInterface   $template
  * @param array                     $parameters
  *
  * @return string
  */
 public function output(FieldDescriptionInterface $fieldDescription, \Twig_TemplateInterface $template, array $parameters = array())
 {
     $content = $template->render($parameters);
     if ($this->environment->isDebug()) {
         return sprintf("\n<!-- START  \n  fieldName: %s\n  template: %s\n  compiled template: %s\n -->\n%s\n<!-- END - fieldName: %s -->", $fieldDescription->getFieldName(), $fieldDescription->getTemplate(), $template->getTemplateName(), $content, $fieldDescription->getFieldName());
     }
     return $content;
 }
Example #3
0
 public function render()
 {
     $output = $this->template->render($this->variables);
     Event::trigger('OnTemplateRender', $output);
     return $output;
 }
Example #4
0
 /**
  * Process the filters and return the result
  *
  * @return array
  */
 public function getData()
 {
     $defaultLimit = $this->getPaginationLimit();
     $page = $this->request->query->get('page', 1);
     $limit = $this->request->query->get('limit', $defaultLimit);
     $sortIndex = $this->request->query->get('sort');
     $sortOrder = $this->request->query->get('sort_order');
     $filters = $this->request->query->get('filters', array());
     $page = intval(abs($page));
     $page = $page <= 0 ? 1 : $page;
     $limit = intval(abs($limit));
     $limit = $limit <= 0 ? $defaultLimit : $limit;
     /** @todo Remove the unnecessary iterations */
     // Check and change cascade array in get
     foreach ($filters as $key => $filter) {
         if (strpos($filter['name'], '[]') !== false) {
             unset($filters[$key]);
             $name = str_replace('[]', '', $filter['name']);
             if (!isset($filters[$name])) {
                 $filters[$name] = array('name' => $name, 'value' => array($filter['value']));
             } else {
                 $filters[$name]['value'][] = $filter['value'];
             }
         }
     }
     foreach ($filters as $filter) {
         /** @var \PedroTeixeira\Bundle\GridBundle\Grid\Column $column */
         foreach ($this->columns as $column) {
             if ($filter['name'] == $column->getIndex() && $filter['value'] != '') {
                 $column->getFilter()->execute($this->getQueryBuilder(), $filter['value']);
             }
         }
     }
     if ($sortIndex) {
         if (count(explode('.', $sortIndex)) == 1) {
             $sortIndex = $sortIndex . '.id';
         }
         $this->getQueryBuilder()->orderBy($sortIndex, $sortOrder);
     }
     // Don't process grid for export
     if (!$this->isExport()) {
         $totalCount = count(new Paginator($this->getQueryBuilder()->getQuery()));
         $totalPages = ceil($totalCount / $limit);
         $totalPages = $totalPages <= 0 ? 1 : $totalPages;
         $page = $page > $totalPages ? $totalPages : $page;
         $queryOffset = $page * $limit - $limit;
         $this->getQueryBuilder()->setFirstResult($queryOffset)->setMaxResults($limit);
         $response = array('page' => $page, 'page_count' => $totalPages, 'page_limit' => $limit, 'row_count' => $totalCount, 'rows' => array());
     } else {
         $response = array('rows' => array());
     }
     foreach ($this->getQueryBuilder()->getQuery()->getResult() as $key => $row) {
         $rowValue = array();
         /** @var Column $column */
         foreach ($this->columns as $column) {
             if ($column->getExportOnly() && !$this->isExport()) {
                 continue;
             }
             $rowColumn = ' ';
             // Array
             if (array_key_exists($column->getField(), $row)) {
                 $rowColumn = $row[$column->getField()];
                 // Array scalar
             } elseif (array_key_exists(0, $row) && array_key_exists($column->getField(), $row[0])) {
                 $rowColumn = $row[0][$column->getField()];
                 // Object
             } elseif (method_exists($row, 'get' . ucfirst($column->getField()))) {
                 $method = 'get' . ucfirst($column->getField());
                 $rowColumn = $row->{$method}();
                 // Object scalar
             } elseif (array_key_exists(0, $row) && method_exists($row[0], 'get' . ucfirst($column->getField()))) {
                 $method = 'get' . ucfirst($column->getField());
                 $rowColumn = $row[0]->{$method}();
                 // Array
             } elseif ($column->getTwig()) {
                 $rowColumn = $this->templating->render($column->getTwig(), array('row' => $row));
             }
             $rowValue[$column->getField()] = $column->getRender()->setValue($rowColumn)->setStringOnly($this->isExport())->setRow($row)->render();
         }
         $response['rows'][$key] = $rowValue;
     }
     return $response;
 }
Example #5
0
 /**
  * Render the template.
  *
  * @return string
  */
 public function render()
 {
     return $this->template->render($this->data);
 }