/**
  * @return string
  */
 public function renderListingAssets()
 {
     static $isRendered = false;
     if (!$isRendered) {
         $isRendered = true;
         return $this->renderer->renderListingAssets();
     }
     return '<!-- Listing assets already rendered -->';
 }
 /**
  * @param ListingTypeInterface $type
  * @param array $options
  * @return Listing
  */
 public function createListing(ListingTypeInterface $type, array $options = array())
 {
     $router = $this->renderer->getRouter();
     $dataSourceResolver = function (Options $options) use($router) {
         if (isset($options['route'])) {
             $data_source = $router->generate($options['route'], isset($options['route_parameters']) ? $options['route_parameters'] : array());
         } else {
             $data_source = $options['request']->getRequestUri();
         }
         return $data_source;
     };
     $pageLengthMenuOptionsNormalizer = function (Options $options, $value) {
         $lengthMenu = array();
         foreach ($value as $length) {
             $lengthMenu[0][] = $length > 0 ? (int) $length : -1;
             $lengthMenu[1][] = $length > 0 ? (int) $length : '-';
         }
         /*
         // Ensure that "page_length" option is in "page_length_menu" array:
         if (!isset($lengthMenu[0][0]) || !in_array((int)$options['page_length'], $lengthMenu[0])) {
             $lengthMenu[0][] = $options['page_length'] > 0 ? (int)$options['page_length'] : -1;
             $lengthMenu[1][] = $options['page_length'] > 0 ? (int)$options['page_length'] : '-';
         }
         */
         return $lengthMenu;
     };
     $columnBuilder = $this->createColumnBuilder($type, $options);
     $filterBuilder = $this->createFilterBuilder($type, $options);
     // Load default options to resolver:
     $optionsResolver = new OptionsResolver();
     $optionsResolver->setRequired(array('request'));
     $optionsResolver->setDefined(array('template', 'class', 'query_builder', 'process_result_callback', 'process_row_callback', 'order_by', 'order_direction', 'order_column'));
     $optionsResolver->setDefaults(array('data_source' => $dataSourceResolver, 'page_length' => 10, 'page_length_menu' => array(10, 25, 50, 100, -1), 'auto_width' => true, 'row_attr' => array('id' => $this->defaultIdProperty ?: null, 'class' => null), 'order_column' => array(), 'save_state' => false, 'defer_load' => false));
     $optionsResolver->setNormalizers(array('page_length_menu' => $pageLengthMenuOptionsNormalizer));
     // Modify default options by ListingType:
     $type->setDefaultOptions($optionsResolver);
     $listing = new Listing($type->getName(), $columnBuilder->getColumns(), $filterBuilder->getFilters(), $this->registry, $this->eventDispatcher, $this->renderer, $optionsResolver->resolve($options));
     return $listing;
 }
Example #3
0
 /**
  * @param $data
  * @return array
  * @throws \Exception
  */
 protected function processInitialData($data)
 {
     if (!is_array($data) && !$data instanceof \Traversable) {
         throw new \Exception('Unable to process data, query result is not traversable.');
     }
     // Load renderer template:
     $this->renderer->load(isset($this->options['template']) ? $this->options['template'] : null);
     $table = array();
     foreach ($data as $row) {
         $tr = array('values' => array(), 'params' => $this->getRowSpecialParams($row));
         /** @var ListingColumnTypeInterface $column */
         foreach ($this->columns as $column) {
             $tr['values'][] = $this->renderer->renderCell($column, $row);
         }
         $table[] = $tr;
     }
     return $table;
 }