public function onloadCallback(DataContainer $objDC) { $objCompanyArchive = CompanyArchiveModel::findByPk($objDC->id); switch ($objCompanyArchive->sort_order) { case 2: $GLOBALS['TL_DCA']['tl_company']['list']['sorting']['mode'] = 4; $GLOBALS['TL_DCA']['tl_company']['list']['sorting']['fields'] = array('sorting'); $GLOBALS['TL_DCA']['tl_company']['list']['sorting']['headerFields'] = array('title'); break; case 1: default: // Nothing to do break; } }
protected function compile() { // Read jump to page details $objPage = \PageModel::findByIdOrAlias($this->jumpTo); // Check if filter should be displayed if (!$this->company_filter_disabled) { $objTemplateFilter = new FrontendTemplate('company_list_filter'); // Filter category $intFilterCategory = Input::get('filterCategory'); $strFilterUrl = ''; if ($intFilterCategory > 0) { $strFilterUrl = '&filterCategory=' . $intFilterCategory; } // Filter search $strSearch = Input::get('search'); $strSearchUrl = 'search=%s'; $objTemplateFilter->strLink = $strSearch != '' ? Environment::get('base') . $this->addToUrl(sprintf($strSearchUrl, $strSearch) . '&filterCategory=ID', true) : Environment::get('base') . $this->addToUrl('filterCategory=ID', true); // Generate letters $arrAlphabet = range('A', 'Z'); $strHtml = '<a href="' . $this->addToUrl($strFilterUrl, TRUE) . '">Alle</a> '; for ($i = 0; $i < count($arrAlphabet); $i++) { $strHtml .= '<a href="' . $this->addToUrl(sprintf($strSearchUrl, $arrAlphabet[$i]) . $strFilterUrl, TRUE) . '">' . $arrAlphabet[$i] . '</a> '; } $objTemplateFilter->strFilterName = $strHtml; // Get Categories $this->loadLanguageFile('tl_company_category'); $objCategories = CompanyCategoryModel::findBy('pid', $this->company_archiv, array('order' => 'title ASC')); $strOptions = '<option value="0">' . $GLOBALS['TL_LANG']['tl_company_category']['category'][0] . '</option>'; if ($objCategories) { while ($objCategories->next()) { $strOptions .= '<option value="' . $objCategories->id . '"' . ($intFilterCategory != $objCategories->id ? '' : ' selected') . '>' . $objCategories->title . '</option>'; } } $objTemplateFilter->strCategoryOptions = $strOptions; $this->Template->strFilter = $objTemplateFilter->parse(); } else { $strSearch = ''; $intFilterCategory = 0; } // Get items to calculate total number of items $objCompanies = CompanyModel::findItems($this->company_archiv, $strSearch, $intFilterCategory); // Pagination $intLimit = 0; $intOffset = 0; $intTotal = 0; // Set limit to maximum number of items if ($this->numberOfItems > 0) { $intLimit = $this->numberOfItems; $intTotal = $this->numberOfItems; } elseif ($objCompanies) { $intTotal = $objCompanies->count(); } // If per page is set and maximum number of items greater than per page use Pagination if ($objCompanies && $this->perPage > 0 && ($intLimit == 0 || $this->numberOfItems > $this->perPage)) { // Set limit, page and offset $intLimit = $this->perPage; $intPage = $this->Input->get('page') ? $this->Input->get('page') : 1; $intOffset = ($intPage - 1) * $intLimit; // Add pagination menu $objPagination = new \Pagination($intTotal, $intLimit); $this->Template->strPagination = $objPagination->generate(); } // Order $objCompanyArchive = CompanyArchiveModel::findByPk($this->company_archiv); switch ($objCompanyArchive->sort_order) { case 2: $strOrder = 'sorting ASC'; break; case 1: default: $strOrder = $this->company_random ? 'RAND()' : 'company ASC'; break; } $objCompanies = CompanyModel::findItems($this->company_archiv, $strSearch, $intFilterCategory, $intOffset, $intLimit, $strOrder); if ($objCompanies) { $this->Template->strCompanies = $this->getCompanies($objCompanies, $objPage); } else { $this->Template->strCompanies = 'Mit den ausgewählten Filterkriterien sind keine Einträge vorhanden.'; } }
public function exportCSV() { $arrColumns = array('id', 'company', 'contact_person', 'street', 'postal_code', 'city', 'lat', 'lng', 'phone', 'fax', 'email', 'homepage', 'logo', 'information'); $this->loadLanguageFile('tl_company'); $arrCsv = array(); foreach ($arrColumns as $strColumn) { $arrCsv[0][] = $GLOBALS['TL_LANG']['tl_company'][$strColumn][0]; } $intPid = Input::get('id'); $objCompanyArchive = CompanyArchiveModel::findByPk($intPid); $objCompany = CompanyModel::findBy('pid', $intPid); if ($objCompany) { while ($objCompany->next()) { $arrTemp = array(); foreach ($arrColumns as $strColumn) { if ($strColumn == 'logo') { $arrTemp[] = \FilesModel::findByUuid($objCompany->{$strColumn})->name; } else { $arrTemp[] = $objCompany->{$strColumn}; } } $arrCsv[] = $arrTemp; } } ob_start(); $objFile = fopen("php://output", 'w'); fputcsv($objFile, $this->arrFields); foreach ($arrCsv as $arrRow) { fputcsv($objFile, $arrRow); } fclose($objFile); $strCsv = ob_get_clean(); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" . $objCompanyArchive->title . ".csv\""); header("Content-Length: " . strlen($strCsv)); echo $strCsv; exit; }