/**
  * Generate the module
  */
 protected function compile()
 {
     global $objPage;
     // Get the total number of items
     $objRecipe = \SimpleRecipesEntriesModel::findByIdOrAlias(\Input::get('recipe'));
     if ($objRecipe === null) {
         // Do not index or cache the page
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         // Send a 404 header
         header('HTTP/1.1 404 Not Found');
         $this->Template->articles = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>';
         return;
     }
     $recipeData = $objRecipe->row();
     // Kategorie
     if ((int) $recipeData['categories'] > 0) {
         $recipeData['categories'] = array();
         $catObj = $this->Database->prepare('SELECT * FROM `tl_simple_recipes_categories` WHERE `id`=? ')->limit(1)->execute($recipeData['categories']);
         if ($catObj->numRows > 0) {
             while ($catObj->next()) {
                 $recipeData['categories'][] = $catObj->name;
             }
         }
     }
     //Bilder vorbereiten
     $scaletype = 'proportional';
     $img_height = 250;
     $img_width = 250;
     $recipeData['images'] = array();
     for ($ic = 0; $ic <= 5; $ic++) {
         if (strlen($recipeData['image_' . $ic]) > 0) {
             $recipeData['images'][] = array('thumb' => \Image::get($recipeData['image_' . $ic], $img_width, $img_height, $scaletype), 'src' => $recipeData['image_' . $ic]);
         }
     }
     $this->Template->data = $recipeData;
     $this->Template->ingredients = unserialize($recipeData['ingredients']);
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     $offset = intval($this->skipFirst);
     $limit = null;
     $this->Template->recipes = array();
     // Maximum number of items
     if ($this->numberOfItems > 0) {
         $limit = $this->numberOfItems;
     }
     // Get the total number of items
     $intTotal = \SimpleRecipesEntriesModel::countRecipesByOpen();
     // Filter anwenden um die Gesamtanzahl zuermitteln
     if ($intTotal > 0) {
         $filterObj = \SimpleRecipesEntriesModel::findRecipes($intTotal, 0);
         $counter = 0;
         $idArr = array();
         while ($filterObj->next()) {
             //wenn alle Filter stimmen -> Werte setzen
             $idArr[] = $filterObj->id;
             $counter++;
         }
         if ((int) $intTotal > $counter) {
             $intTotal = $counter;
         }
     }
     if ((int) $intTotal < 1) {
         $this->Template = new \FrontendTemplate('mod_simple_recipes_entries_empty');
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyBmList'];
         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;
             $objTarget = \PageModel::findByPk($objPage->id);
             if ($objTarget !== null) {
                 $reloadUrl = ampersand($this->generateFrontendUrl($objTarget->row()));
             }
             $this->redirect($reloadUrl);
         }
         // 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, $GLOBALS['TL_CONFIG']['maxPaginationLinks'], $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     // Get the items
     if (isset($limit)) {
         $recipesObj = \SimpleRecipesEntriesModel::findRecipes($limit, $offset, $idArr);
     } else {
         $recipesObj = \SimpleRecipesEntriesModel::findRecipes(0, $offset, $idArr);
     }
     // No items found
     if ($recipesObj === null) {
         $this->Template = new \FrontendTemplate('mod_simple_recipes_entries_empty');
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptySimpleRecipesList'];
     } else {
         $this->Template->recipes = $this->parseRecipes($recipesObj);
     }
     $this->Template->totalItems = $intTotal;
 }