public function __toString() { $str = '<article class="category">' . PHP_EOL; $str .= '<h1>' . $this->getHierarchy() . '<span class="self">' . $this->getLabel() . '</span></h1>'; $ingredients = IngredientDAO::getByCategory($this); $str .= '<section class="content">'; $str .= '<div class="subs"><h2>Filtres</h2>'; if (empty($ingredients)) { $str .= '<p class="sad">Aucun filtre applicable.</p>'; } else { $str .= '<ul title="Sous-ingredients">'; foreach ($ingredients as $ingredient) { $str .= '<li><a href="ingredient/' . urlencode($ingredient->getId()) . '">' . $ingredient->getLabel() . '</a></li>'; } $str .= '</ul>'; } $str .= '</div>'; $str .= '<div class="recipes"><h2>Recettes</h2>'; if ($recipes = RecipeDAO::getByCategory($this)) { $str .= '<ul title="Recettes">'; foreach ($recipes as $recipe) { $str .= '<li><a href="recipe/' . $recipe->getId() . '">' . $recipe->getTitle() . '</a></li>'; } $str .= '</ul>'; } else { $str .= '<p class="sad">Aucune recette à afficher.</p>'; } $str .= '</div>'; $str .= '</section></article>'; return $str; }
<?php $presenter->data['recipes'] = RecipeDAO::getAll();
<?php if (!isset($_GET['id'])) { $request->redirect('all'); } $presenter->data['recipe'] = RecipeDAO::getById(@$_GET['id']);
public static function addById($recipeId) { if (!isset($_SESSION['cocktailsFavorites'])) { $_SESSION['cocktailsFavorites'] = array(); } if (isset($_SESSION['cocktailsFavorites'][$recipeId])) { return false; } $favorite = new Favorite(RecipeDAO::getById($recipeId)); $_SESSION['cocktailsFavorites'][$recipeId] = $favorite; if (isset($_SESSION['cocktailsUser'])) { $favorite->setUser($_SESSION['cocktailsUser']); self::create($favorite); } }