'Recette', 'columns' => [ 'num_recette', 'titre_recette', 'slug', 'description_recette', 'photo', 'publication_date', 'temps_de_preparation' ] ]; } /** * Permet d'avoir une recette par un ID. * * @param int $id * @return Recette|null */ public function getByID( int $id ): ?Recette { $sqlQuery = "SELECT * FROM {$this->tableName} WHERE num_recette = {$id}"; $results = $this->selectGetAll($sqlQuery); if( $results === null || count( $results ) > 1 ) return null; return $results[0]; } /** * Permet d'avoir une recette par un slug. * * @param string $slug * @return Recette|null */ public function getBySlug( string $slug ): ?Recette { $sqlQuery = "SELECT * FROM {$this->tableName} WHERE slug = {$slug}"; $results = $this->selectGetAll($sqlQuery); if( $results === null || count( $results ) > 1 ) return null; return $results[0]; } public function add( Model $recette ): bool { return $this->addEntity( $recette ); } public function update( Model $recette ): bool { return $this->updateEntity( $recette, 'num_recette' ); } public function delete( Model $recette ): bool { return $this->deleteEntity( $recette, 'num_recette' ); } public function getAllLinkedIngredients(Model $entity): ?array { $ingredientRepo = new IngredientRepository(); $response = $ingredientRepo->getIdLinkedTo( 'recettes', 'num_recette', $entity ); return array_map( function($arr) use($ingredientRepo) { return $ingredientRepo->getByID( $arr['num_ingredient'] ); }, $response ); } public function addAnIngredient(Ingredient $ingredient, Model $entity): bool { $ingredientRepo = new IngredientRepository(); return $ingredientRepo->addLinkBetween( 'recettes', 'num_recette', $ingredient, $entity ); } public function removeAnIngredient(Ingredient $ingredient, Model $entity): bool { $ingredientRepo = new IngredientRepository(); return $ingredientRepo->removeLinkBetween( 'recettes', 'num_recette', $ingredient, $entity ); } }