<?php

namespace Models;

use Bases\Model;

class Tag extends Model{
    protected $table = "tags";

    /**
     * Récupérer tous les tags
     * @return object|false
     */
    public function toutTags(){
        $sql = "SELECT * FROM $this->table";

        $requete = $this->pdo()->prepare($sql);

        $requete->execute();

        return $requete->fetchAll();
    }

    /**
     * Retourne tout les tag d'un plat selon le id d'un plat
     *
     * @param int $id
     * @return object|false
     */
    public function tagSelonPlat($plat_id){
        $sql = "SELECT 
                    $this->table.*,
                    menu_tag.tag_id AS tag_id 
                FROM 
                    $this->table
                JOIN 
                    menu_tag
                ON
                    $this->table.id = menu_tag.tag_id
                WHERE
                    menu_tag.menu_id = :plat_id";
        
        $requete = $this->pdo()->prepare($sql);

        $requete->execute([
            ":plat_id" => $plat_id
        ]);

        return $requete->fetchAll();
    }
}