/**
  * @param TableModel $table
  */
 public function __construct(TableModel $table)
 {
     parent::__construct('Display');
     $this->tableModel = $table;
     $tableHeaders = $this->tableModel->getTableHeaders();
     // Group checkboxes by property
     $columnGroups = array();
     foreach ($tableHeaders as $tableHeader) {
         /** @var TableHeaderCellModel $tableHeader */
         $columnNameSegments = explode('.', $tableHeader->getName());
         if (!is_array($columnNameSegments) || empty($columnNameSegments)) {
             continue;
         }
         // Create all values for each property
         $label = $tableHeader->getName();
         $columnGroupName = 'base';
         if (count($columnNameSegments) > 1) {
             $columnGroupName = $columnNameSegments[0];
             $segments = $columnNameSegments;
             unset($segments[0]);
             $label = implode('.', $segments);
         }
         if (!array_key_exists($columnGroupName, $columnGroups)) {
             $columnGroups[$columnGroupName] = array();
         }
         $valueOption = array('value' => $tableHeader->getName(), 'label' => $label, 'selected' => $tableHeader->isVisible());
         $columnGroups[$columnGroupName][] = $valueOption;
     }
     // Create the actual form element per property
     foreach ($columnGroups as $property => $checkboxValues) {
         $entityColumn = new NestedSettingsFieldset($property, $checkboxValues);
         $this->add($entityColumn);
     }
     $this->add(array('name' => 'submit', 'type' => 'submit', 'label' => '<span class="glyphicon glyphicon glyphicon-refresh"></span>', 'attributes' => array('value' => 'Apply', 'class' => 'btn btn-default')));
 }
 /**
  * If the TableModel holds information about filters that where applied, we pass them into the form element
  *
  * @param Element $element
  * @param string $fieldName
  * @return Element
  */
 protected function setElementCurrentValue(Element $element, $fieldName)
 {
     $filter = $this->tableModel->getTableFilter($fieldName);
     if ($filter && !empty($filter->getSelectedValue())) {
         $element->setValue($filter->getSelectedValue());
     }
     return $element;
 }
 /**
  * Retrieve an new TableModel
  * based on your data configuration in this object
  * @return Table
  */
 public function getTable()
 {
     if (empty($this->queryBuilder->getSelectedTableColumns())) {
         $this->filtersPrepared = false;
         $this->selectColumns($this->getModuleOptions()->getDefaultColumns());
     }
     $dataTypes = array_merge($this->queryBuilder->getTableColumnTypes(), $this->moduleOptions->getRenders());
     $filterValues = $this->resolveAssociationColumns ? $this->queryBuilder->preLoadAllAssociationFields() : array();
     $tableHeaders = $this->sortColumns($this->queryBuilder->getAvailableTableColumns(), $this->moduleOptions->getDefaultColumns());
     $table = new Table();
     $table->setDataTypes($dataTypes);
     $table->addHeaders($tableHeaders, $this->queryBuilder->getSelectedTableColumns(), $this->moduleOptions->getColumnWidths());
     $table->addRows($this->queryBuilder->getResultSet());
     $table->setPrefetchedFilterValues($filterValues);
     $table->addFilters($this->searchFilterHelper->getFilters(), $this->usedFilters);
     $table->setPageNumber($this->page);
     $table->setMaxPageNumber($this->calculateMaxPages());
     $table->setOptionRoutes($this->moduleOptions->getOptionRoutes());
     return $table;
 }
 /**
  * @param TableModel $table
  */
 public function __construct(TableModel $table)
 {
     parent::__construct('Display');
     $this->tableModel = $table;
     $tableHeaders = $this->tableModel->getTableHeaders();
     // Group checkboxes by property
     $columnGroups = array();
     foreach ($tableHeaders as $tableHeader) {
         /** @var TableHeaderCellModel $tableHeader */
         $columnNameSegments = explode('.', $tableHeader->getName());
         if (!array_key_exists($columnNameSegments[0], $columnGroups)) {
             $columnGroups[$columnNameSegments[0]] = array();
         }
     }
     // Create all values for each property
     foreach ($tableHeaders as $tableHeader) {
         $columnNameSegments = explode('.', $tableHeader->getName());
         $label = $tableHeader->getName();
         if (count($columnNameSegments) > 1) {
             $segments = $columnNameSegments;
             unset($segments[0]);
             $label = implode('.', $segments);
         }
         $valueOption = array('value' => $tableHeader->getName(), 'label' => $label, 'selected' => $tableHeader->isVisible());
         $columnGroups[$columnNameSegments[0]][] = $valueOption;
     }
     // Create the actual form element per property
     foreach ($columnGroups as $property => $checkboxValues) {
         $multiCheckbox = new MultiCheckbox($this->checkboxName);
         $multiCheckbox->setOptions(array('inline' => false, 'value_options' => $checkboxValues));
         $isParentField = strpos($checkboxValues[0]['value'], ".") !== false;
         if (count($checkboxValues) >= 2 || count($checkboxValues) == 1 && $isParentField) {
             $multiCheckbox->setLabel($property);
         }
         // Dirty hack, because this->add() does not detect element or fieldset naming conflicts
         $this->iterator->insert($property, $multiCheckbox, 0);
     }
     $this->add(array('name' => 'submit', 'type' => 'submit', 'label' => '<span class="glyphicon glyphicon glyphicon-refresh"></span>', 'attributes' => array('value' => 'Apply', 'class' => 'btn knopSearch')));
 }
Exemplo n.º 5
0
 /**
  * To prevent double foreach loops, pre render the columns in a private array
  */
 public function prepareTable()
 {
     foreach ($this->tableModel->getTableFilters() as $filter) {
         $header = $filter->getHeader();
         if (!is_null($header) && $header->isVisible()) {
             $this->displayedHeaders[] = $header;
             continue;
         }
         // Its a special filter, but only add it when it has an instance
         if (!is_null($filter->getInstance())) {
             $this->additionalFilters[$filter->getName()] = $filter;
         }
     }
 }
 /**
  * If the TableModel holds information about filters that where applied, we pass them into the form element
  *
  * @param ElementInterface $element
  * @param string $fieldName
  * @param TableModel $tableModel
  * @return Element
  */
 public static function setElementCurrentValue(ElementInterface $element, $fieldName, TableModel $tableModel)
 {
     $filter = $tableModel->getTableFilter($fieldName);
     if ($filter && !empty($filter->getSelectedValue())) {
         $element->setValue($filter->getSelectedValue());
     }
     return $element;
 }