/** * On retire un piste des favoris de l'utilisateur * * @return void */ public function removeSongFromFavorites($song_id) { if ($song = $this->song->find($song_id)) { $statement = QueryBuilder::delete("favorites")->where("user_id = :user_id")->where("song_id = :song_id")->make(); $user_id = $this->id; return $this->execute($statement, compact('user_id', 'song_id')); } return false; }
/** * Récuparation d'une entité via sa clé primaire * * @return Model */ public function find($id) { $statement = QueryBuilder::select("*")->from($this->table)->where("{$this->primaryKey} = :id")->make(); return $this->fetchOne($statement, compact('id')); }
/** * Récupération des pistes favorites d'un utilisateur * * @return array */ public function getFavoritesByUserId($user_id) { $statement = QueryBuilder::select("{$this->table}.*")->from($this->table)->join("favorites", "favorites.song_id = {$this->table}.{$this->primaryKey}")->where("favorites.user_id = :user_id")->make(); return $this->fetchAll($statement, compact('user_id')); }