<?php

class Nastavenie extends Model {

  var $data = array();

  function Nastavenie()
  {
  
    parent::Model();
    
    $query = $this->db->get("nastavenia");
    
    foreach ($query->result_array() as $k => $v)
    {
      $varname = $v["nazov"]; $varvalue = $v["hodnota"];
      $this->data[$varname] = $varvalue;
    }
    
  }
  
  // Ak je nazov prazdny vyberie cele pole
  function vyber($nazov = "")
  {
    if ($nazov == "")
    {
      return $this->data;
    }
    else
    {
      if (isset($this->data[$nazov]))
        return $this->data[$nazov];
      
      return FALSE;
    }
  }
  
  function zapis($pole)
  {
    $this->db->query("DELETE FROM nastavenia");
    $sql = "INSERT INTO nastavenia (nazov, hodnota) VALUES ";
    for ($i=0;$i<count($pole);$i++)
    {
      $sql .= ($i > 0 ? "," : "")."('" . $pole[$i]['nazov'] . "', '" . $pole[$i]['hodnota'] . "')";
    }
    $this->db->query($sql);
  }
}

?>