<?php
class Polls extends Controller
{

    private $pollModel;

    public function __construct()
    {
        $this->pollModel = $this->model('Poll');
    }
    public function index()
    {
        $userid = $_SESSION[SESSION_USER_KEY] ?? null;
        $polls = $this->pollModel->getAllPolls($userid);
        $pollsCat = $this->pollModel->getPollsCategories();
        // Load View
        $this->view('polls/index', [
            'polls' => $polls,
            'pollsCat' => $pollsCat,
             'activeCategoryId' => null,
        ]);
    }
    public function category($id)
    {
        $userid = $_SESSION[SESSION_USER_KEY] ?? null;
        $polls = $this->pollModel->getPollsByCategory($userid, $id);
        $pollsCat = $this->pollModel->getPollsCategories();
        // Load View
        $this->view('polls/index', [
            'polls' => $polls,
            'pollsCat' => $pollsCat,
             'activeCategoryId' => $id,
        ]);
    }
}