<?php

class Clanok extends Model {

  function Clanok() {
  
    parent::Model();
  
  }
  
  function vyber($jazyk = "", $clanok = 0)
  {
    $query = $this->db->query("
      SELECT  c.id        as clanok_id,
              c.nazov_" . ($jazyk == "" ? "sk" : $jazyk) . " as clanok_nazov,
              c.text_" . ($jazyk == "" ? "sk" : $jazyk) . " as clanok_text
      FROM clanky c
      ".($clanok == 0 ? '' : "WHERE c.id = $clanok")."
    ");
    
    if ($clanok == 0)
      return $query->result_array();
    
    return $query->row_array();
  }
  
  function vyberVsetko()
  {
    $query = $this->db->get('clanky');
    
    return $query->result_array();
  }
  
  function uloz($id, $data)
  {
    $query = $this->db->query("UPDATE clanky SET nazov_sk = '".$data['nazov_sk']."', nazov_hu = '".$data['nazov_hu']."', nazov_en = '".$data['nazov_en']."', text_sk = '".$data['text_sk']."', text_hu = '".$data['text_hu']."', text_en = '".$data['text_en']."' WHERE id = $id");
  }
  
  function vyberPodlaIdentifikatoru($jazyk = "", $clanok)
  {
    $query = $this->db->query("
      SELECT  c.id        as clanok_id,
              c.nazov_" . ($jazyk == "" ? "sk" : $jazyk) . " as clanok_nazov,
              c.text_" . ($jazyk == "" ? "sk" : $jazyk) . " as clanok_text
      FROM clanky c
      WHERE c.identificator = '$clanok'
    ");
    
    return $query->row_array();
  }
  
  function adminUprav($data)
  {
    
  }
  
  function adminNacitaj($id)
  {
    $query = $this->db->query("SELECT * FROM clanoy WHERE id = $id");
    
    return $query->row_array();
  }

}

?>