<?php

namespace Models;

use Bases\Model;

class Tag extends Model
{

    protected $table = "tags";

    /**
     * Retourne tous les tags
     *
     * @return array|false
     */
    public function tousTags()
    {
        $sql = "SELECT $this->table.*
                FROM $this->table ";

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

        $requete->execute();

        return $requete->fetchAll();
    }

    /**
     * Retourne tous les tags
     *
     * @return array|false
     */
    public function tagParPlat($id)
    {
        $sql = "SELECT plats_tags.tag_id,
                       plats.id
                FROM plats_tags
                JOIN plats on plats_tags.plat_id = plats.id
                WHERE plats.id = :id";

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

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

        return $requete->fetchAll();
    }
}
