Merge pull request #86 from ThomasRubini/home_random_recipes
This commit is contained in:
		
						commit
						438738dde4
					
				| @ -5,26 +5,8 @@ final class DefaultController | ||||
| 
 | ||||
|     public function defaultAction(Array $A_urlParams = null, Array $A_postParams = null) | ||||
|     { | ||||
|         $array_recipes = array( | ||||
|             array( | ||||
|                 "RECIPE_LINK" => "/recipe/view/1", | ||||
|                 "NAME" => "Pâte à crêpe", | ||||
|                 "IMG_LINK" => "/static/img/recipes/1.jpg", | ||||
|                 "NOTE" => "4.5" | ||||
|             ), | ||||
|             array( | ||||
|                 "RECIPE_LINK" => "/recipe/view/1", | ||||
|                 "NAME" => "Pâte à crêpe", | ||||
|                 "IMG_LINK" => "/static/img/recipes/1.jpg", | ||||
|                 "NOTE" => "4.5" | ||||
|             ), | ||||
|             array( | ||||
|                 "RECIPE_LINK" => "/recipe/view/1", | ||||
|                 "NAME" => "Pâte à crêpe", | ||||
|                 "IMG_LINK" => "/static/img/recipes/1.jpg", | ||||
|                 "NOTE" => "4.5" | ||||
|             ), | ||||
|         ); | ||||
|         View::show("home/view", $array_recipes); | ||||
|         $A_recipes = RecipeModel::getRandomRecipes(3); | ||||
| 
 | ||||
|         View::show("home/view", array("RECIPES" => $A_recipes)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -191,4 +191,23 @@ final class RecipeModel | ||||
| 
 | ||||
|         return $A_recipes; | ||||
|     } | ||||
| 
 | ||||
|     public static function getRandomRecipes($I_n) | ||||
|     { | ||||
|         $O_model = Model::get(); | ||||
|         $stmt = $O_model->prepare(" | ||||
|         SELECT * FROM RECIPE | ||||
|         ORDER BY RAND() | ||||
|         LIMIT :n | ||||
|         ");
 | ||||
|         $stmt->bindParam("n", $I_n, PDO::PARAM_INT); | ||||
|         $stmt->execute(); | ||||
|    | ||||
|         $A_recipes = array(); | ||||
|         foreach($stmt->fetchAll() as $row){ | ||||
|             array_push($A_recipes, self::createFromRow($row, $row["ID"])); | ||||
|         } | ||||
| 
 | ||||
|         return $A_recipes; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,7 +1,10 @@ | ||||
| <a href="<?= $A_view["RECIPE_LINK"]?>"> | ||||
|     <img src="<?= $A_view["IMG_LINK"] ?>" alt="<?= $A_view["NAME"]?>"> | ||||
| <?php | ||||
| $O_recipe = $A_view["RECIPE"]; | ||||
| ?>
 | ||||
| <a href="<?= $O_recipe->getLink() ?>"> | ||||
|     <img src="<?= $O_recipe->getImageLink() ?>" alt="<?= $O_recipe->S_NAME ?>"> | ||||
|     <section> | ||||
|         <h2> <?= $A_view["NAME"]?> </h2>
 | ||||
|         <p> <?= $A_view["NOTE"]?> </p>
 | ||||
|         <h2> <?= $O_recipe->S_NAME ?> </h2>
 | ||||
|         <p> <?= $O_recipe->I_NOTE ?> </p>
 | ||||
|     </section> | ||||
| </a> | ||||
|  | ||||
| @ -7,8 +7,8 @@ | ||||
|         <section> | ||||
|             <h1> Nos idées recettes: </h1> | ||||
|             <?php | ||||
|                 foreach ($A_view as $recipe){ | ||||
|                     View::show("common/recipe", $recipe); | ||||
|                 foreach ($A_view["RECIPES"] as $O_recipe){ | ||||
|                     View::show("common/recipe", array("RECIPE" => $O_recipe)); | ||||
|                 } | ||||
|             ?>
 | ||||
|         </section> | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user