/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } $this->Template->persons = array(); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyStaff']; $intTotal = \StaffEmployeeModel::countPublishedByPids($this->staff_categories); if ($intTotal < 1) { return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } // Get the items if (isset($limit)) { $objEmployees = \StaffEmployeeModel::findPublishedByPids($this->staff_categories, null, $limit, $offset); } else { $objEmployees = \StaffEmployeeModel::findPublishedByPids($this->staff_categories, null, 0, $offset); } // Add the Employees if ($objEmployees !== null) { $this->Template->employees = $this->parseEmployees($objEmployees); } }