protected function compile()
 {
     $db = \Database::getInstance();
     $intID = Input::get('companyID');
     $objCompany = CompanyModel::findByPk($intID);
     if ($objCompany) {
         global $objPage;
         $objPage->pageTitle = $objCompany->company;
         $objTemplate = new FrontendTemplate('company_detail');
         $objFile = FilesModel::findByPk($objCompany->logo);
         $arrSize = deserialize($this->imgSize);
         // Get Categories
         $strCategory = '';
         $arrCategories = deserialize($objCompany->category);
         if (count($arrCategories) > 0) {
             $arrCategory = array();
             $objCompanyCategories = $db->prepare("SELECT * FROM tl_company_category WHERE id IN(" . implode(',', $arrCategories) . ")")->execute();
             while ($objCompanyCategories->next()) {
                 $arrCategory[] = $objCompanyCategories->title;
             }
             $strCategory = implode(', ', $arrCategory);
         }
         $objTemplate->company = $objCompany->company;
         $objTemplate->contact_person = $objCompany->contact_person;
         $objTemplate->category = $strCategory;
         $objTemplate->street = $objCompany->street;
         $objTemplate->postal_code = $objCompany->postal_code;
         $objTemplate->city = $objCompany->city;
         $objTemplate->phone = $objCompany->phone;
         $objTemplate->fax = $objCompany->fax;
         $objTemplate->email = $objCompany->email;
         $objTemplate->homepage = $objCompany->homepage;
         $objTemplate->lat = $objCompany->lat;
         $objTemplate->lng = $objCompany->lng;
         $objTemplate->logo = \Image::get($objFile->path, $arrSize[0], $arrSize[1], $arrSize[2]);
         $objTemplate->imageWidth = $arrSize[0];
         $objTemplate->imageHeight = $arrSize[1];
         $objTemplate->information = $objCompany->information;
         $this->Template->strHtml = $objTemplate->parse();
     }
 }
 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;
 }