/**
  * Renders a record browser
  *
  * @param string $action Controller action
  * @param \Frohland\Ezqueries\Domain\Model\RecordManagement $recordManagement
  * @return string $code
  */
 public function render($action, $recordManagement)
 {
     $i = 0;
     $code = '';
     $recordPosition = 0;
     $records = $recordManagement->getRecords();
     if ($records) {
         $primaryKeys = $records[0]->getPrimaryKeys();
         $primaryKeysArray = $recordManagement->getPrimaryKeys();
         $countPrimaryKeys = count($primaryKeys);
         $countRightKeys = 0;
         $orderBy = $recordManagement->getConditions()->getOrderBy();
         $order = $recordManagement->getConditions()->getOrder();
         $search = $recordManagement->getConditions()->getSearch();
         $filters = $recordManagement->getConditions()->getFilters();
         $urlUtility = $this->objectManager->create('Frohland\\Ezqueries\\Utility\\URLUtility', $this->controllerContext->getUriBuilder());
         $code .= '<div class="tx_ezqueries_options_recordbrowser">';
         foreach ($primaryKeysArray as $keys) {
             $countRightKeys = 0;
             foreach ($primaryKeys as $column => $value) {
                 if ($keys[$column] == $value) {
                     $countRightKeys++;
                 }
             }
             if ($countRightKeys == $countPrimaryKeys) {
                 $recordPosition = $i;
                 break;
             } else {
                 $i++;
             }
         }
         if ($recordPosition != 0) {
             $arguments = array("primaryKeys" => $primaryKeysArray[$recordPosition - 1], "orderBy" => $orderBy, "order" => $order, "search" => $search, "filters" => $filters);
             $url = $urlUtility->createURL($action, $arguments);
             $code .= '<div class="tx_ezqueries_options_recordbrowser_previous"><a class="tx_ezqueries_link tx_ezqueries_link_button tx_ezqueries_link_' . $action . '" href="' . $url . '">' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('recordbrowser_previous', 'ezqueries') . '</a></div>';
         }
         if ($recordPosition < count($primaryKeysArray) - 1) {
             $arguments = array("primaryKeys" => $primaryKeysArray[$recordPosition + 1], "orderBy" => $orderBy, "order" => $order, "search" => $search, "filters" => $filters);
             $url = $urlUtility->createURL($action, $arguments);
             $code .= '<div class="tx_ezqueries_options_recordbrowser_next"><a class="tx_ezqueries_link tx_ezqueries_link_button tx_ezqueries_link_' . $action . '" href="' . $url . '">' . \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('recordbrowser_next', 'ezqueries') . '</a></div>';
         }
         $code .= '</div>';
     }
     return $code;
 }
Exemplo n.º 2
0
 /**
  * Initialize the Template utility object
  *
  * @param string $templateType Type of the template (e.g. list, edit, detail)
  * @param \Frohland\Ezqueries\Domain\Model\RecordManagement $recordManagement
  * @param UriBuilder $uriBuilder UriBuilder
  */
 public function initTemplateUtility($templateType, $recordManagement, $uriBuilder)
 {
     $this->recordManagement = $recordManagement;
     $this->recordManagementRepository = $recordManagement->getRecordManagementRepository();
     $this->arguments = $recordManagement->getArguments();
     $this->templateType = $templateType;
     $this->record = $recordManagement->getRecords(0);
     $this->recordNumber = 0;
     if ($this->record) {
         $this->primaryKeys = $this->record->getPrimaryKeys();
     }
     $this->primaryKeysArray = $recordManagement->getPrimaryKeys();
     $this->columnTypes = $recordManagement->getTable()->getColumnTypes();
     $this->orderBy = $recordManagement->getConditions()->getOrderBy();
     $this->order = $recordManagement->getConditions()->getOrder();
     $this->search = $recordManagement->getConditions()->getSearch();
     $this->filters = $recordManagement->getConditions()->getFilters();
     $this->selectedColumns = $recordManagement->getTable()->getSelectedColumns();
     $this->uriBuilder = $uriBuilder;
     $i = 0;
     $this->recordPosition = 0;
     $countPrimaryKeys = count($this->primaryKeys);
     $countRightKeys = 0;
     if ($this->primaryKeysArray !== NULL) {
         foreach ($this->primaryKeysArray as $keys) {
             $countRightKeys = 0;
             foreach ($this->primaryKeys as $column => $value) {
                 if ($keys[$column] == $value) {
                     $countRightKeys++;
                 }
             }
             if ($countRightKeys == $countPrimaryKeys) {
                 $this->recordPosition = $i;
                 break;
             } else {
                 $i++;
             }
         }
     }
 }