/** * Fetch all records (optional filtered, sorted and limited). * * @param InterfaceGeneralDataConfig $objConfig The configuration to be applied. * * @return InterfaceGeneralCollection */ public function fetchAll(InterfaceGeneralDataConfig $objConfig) { $strBackupLanguage = ''; if ($this->strCurrentLanguage != '') { $strBackupLanguage = $GLOBALS['TL_LANGUAGE']; $GLOBALS['TL_LANGUAGE'] = $this->strCurrentLanguage; } $varResult = null; $arrSorting = $objConfig->getSorting(); $strSortBy = ''; $strSortDir = ''; if ($arrSorting) { list($strSortBy, $strSortDir) = each($arrSorting); } if (!$strSortDir) { $strSortDir = DCGE::MODEL_SORTING_ASC; } $objFilter = $this->prepareFilter($objConfig->getFilter()); if ($objConfig->getIdOnly()) { $varResult = $this->objMetaModel->getIdsFromFilter($objFilter, $strSortBy ? $strSortBy : '', $objConfig->getStart(), $objConfig->getAmount(), $strSortBy ? $strSortDir : ''); } else { $objItems = $this->objMetaModel->findByFilter($objFilter, $strSortBy ? $strSortBy : '', $objConfig->getStart(), $objConfig->getAmount(), $strSortBy ? $strSortDir : ''); $objResultCollection = $this->getEmptyCollection(); foreach ($objItems as $objItem) { $objResultCollection->push(new GeneralModelMetaModel($objItem)); } $varResult = $objResultCollection; } if ($strBackupLanguage != '') { $GLOBALS['TL_LANGUAGE'] = $strBackupLanguage; } return $varResult; }
/** * Prepare the rendering */ public function prepare() { if ($this->objItems) { return $this; } // create an empty filter object if not done before if (!$this->objFilter) { $this->objFilter = $this->objMetaModel->getEmptyFilter(); } if ($this->objFilterSettings) { $this->objFilterSettings->addRules($this->objFilter, $this->arrParam); } $this->modifyFilter(); $intTotal = $this->objMetaModel->getCount($this->objFilter); $this->calculatePagination($intTotal); $this->objItems = $this->objMetaModel->findByFilter($this->objFilter, $this->strSortBy, $this->intOffset, $this->intLimit, $this->strSortDirection, $this->getAttributeNames()); return $this; }