<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class NovinkyModel extends Repository {
    
    public function getNovinky() {
            return $this->connection->table('novinky')
            ->order('datum DESC');
    }
    
    public function getNovinka($id) {
    return $this->connection->table('novinky')
                    ->where('id = ?', $id)
                    ->fetch();
    }
    
    public function updateNovinka($id, $data) {
    $this->connection->table('novinky')
        ->where('id = ?', $id)
        ->update($data);
    }

    public function deleteNovinka($id) {
        $this->connection->table('novinky')
            ->where('id = ?', $id)
            ->delete();
    }
    
    public function addNovinka($data) {
    $this->connection->table('novinky')
        ->insert($data);
    }
    
    public function getNovinkyByYear($year) {
        return $this->connection->table('novinky')
                    ->where('YEAR(datum) = ?', $year);
    }
    
    public function getRoky() {
        
        //$this->database->table('prispevky')->select('count(id) as pocet')->fetch();
        return $this->connection->table('novinky')
                    ->select('DISTINCT DATE_FORMAT(datum,"%Y") AS year')
                    ->fetchAll();
    }
}

