<?php

class PhotosMenu extends Menu
{
    public function get_vars()
    {
        $vars = parent::get_vars();

        $print = ['Nenastaveno', 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'];

        $SQL = sqlQuery('SELECT DISTINCT YEAR(date) AS y, MONTH(date) AS m 
      							FROM '.getTableName('photos').' AS p
      							ORDER BY y DESC, m DESC');
        $data = [];
        $year = null;
        foreach ($SQL as $key => $row) {
            if (!$year || $year['year'] != $row['y']) {
                unset($year);
                $year = [
                    'year' => $row['y'],
                    'title' => $row['y'],
                    'submenu' => [],
                ];
                $data[] = &$year;

                if ($year['year'] == 0) {
                    $year['title'] = $print[0];
                    $year['year'] = 'null';
                    break;
                }
            }

            $year['submenu'][] = [
                'month' => $row['m'],
                'year' => $row['y'],
                'title' => $print[$row['m']],
            ];
        }

        return array_merge($vars, [
            'data' => $data,
        ]);
    }
}
