<?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 VystavyModel extends Repository {
    
    public function getVystavyByYear($year) {
            return $this->connection->table('vystavy')->where('rok',$year);
    }
    
    public function getTridyByVystavaId($id) {
            return $this->connection->table('vystavy_tridy')->where('id_vystavy',$id);
    }
    
    public function getPsy() {
            return $this->connection->table('tridy_psi');
    }
    
    public function getPsyByTridaId($id) {
            return $this->connection->table('tridy_psi')->where('id_tridy',$id);
    }
    
    public function getVystava($id) {
    return $this->connection->table('vystavy')
                    ->where('id = ?', $id)
                    ->fetch();
    }
    
     public function getTrida($id) {
    return $this->connection->table('vystavy_tridy')
                    ->where('id = ?', $id)
                    ->fetch();
    }
    
    public function getPes($id) {
    return $this->connection->table('tridy_psi')
                    ->where('id = ?', $id)
                    ->fetch();
    }
    
    public function updateVystava($id, $data) {
    $this->connection->table('vystavy')
        ->where('id = ?', $id)
        ->update($data);
    }
    
    public function updatePes($id, $data) {
    $this->connection->table('tridy_psi')
        ->where('id = ?', $id)
        ->update($data);
    }
    
    public function updateTrida($id, $data) {
    $this->connection->table('vystavy_tridy')
        ->where('id = ?', $id)
        ->update($data);
    }

    public function deleteVystava($id) {
        $this->connection->table('vystavy')
            ->where('id = ?', $id)
            ->delete();
    }
    
    public function deleteTrida($id) {
        $this->connection->table('vystavy_tridy')
            ->where('id = ?', $id)
            ->delete();
    }
    
     public function deletePes($id) {
        $this->connection->table('tridy_psi')
            ->where('id = ?', $id)
            ->delete();
    }
    
    public function addVystava($data) {
    $this->connection->table('vystavy')
        ->insert($data);
    }
    
     public function addTrida($data) {
    $this->connection->table('vystavy_tridy')
        ->insert($data);
    }
    
    public function addPes($data) {
    $this->connection->table('tridy_psi')
        ->insert($data);
    }
    
    
    public function getRoky() {
        
        //$this->database->table('prispevky')->select('count(id) as pocet')->fetch();
        return $this->connection->table('vystavy')
                    ->select('DISTINCT rok')
                    ->fetchAll();
    }
}

