<?php

class Kategoria extends Model {

  function Kategoria() {
    
    parent::Model();
    
  }
  
  function dataFiltru($jazyk = "") {
    $sql = "
      SELECT  id        as filter_id,
              nazov_" . ($jazyk == "" ? "sk" : $jazyk) . " as filter_nazov,
              skryta as filter_skryta
      FROM kategorie
      ORDER BY filter_nazov";
    
    $query = $this->db->query($sql);
    
    return $query->result_array();
  }
  
  function vyberId($id)
  {
    $this->db->where("id = $id");
    $query = $this->db->get('kategorie');
    
    return $query->row_array();
  }
  
  function skryOznacene($data) {
    $where = "";
    
    $pa = array();
    
    foreach($data as $k => $v)
    {
      $pa[] = "id = " . $v;
    }
    
    $where = implode(" OR ", $pa);
  
    $this->db->query("UPDATE kategorie SET skryta = 1 WHERE " . $where);
  }
  
  function zobrazOznacene($data) {
    $where = "";
    
    $pa = array();
    
    foreach($data as $k => $v)
    {
      $pa[] = "id = " . $v;
    }
    
    $where = implode(" OR ", $pa);
  
    $this->db->query("UPDATE kategorie SET skryta = 0 WHERE " . $where);
  }
  
  function uprav($id, $data)
  {
    $query = $this->db->query("UPDATE kategorie SET nazov_sk = '".$data['nazov_sk']."', nazov_hu = '".$data['nazov_hu']."', nazov_en = '".$data['nazov_en']."', skryta = ".$data['skryta']." WHERE id = $id");
  }
  
  function vloz($data)
  {
    $query = $this->db->query("INSERT INTO kategorie SET nazov_sk = '".$data['nazov_sk']."', nazov_hu = '".$data['nazov_hu']."', nazov_en = '".$data['nazov_en']."', skryta = ".$data['skryta']."");
  }
}

?>