<?php

class pontoDAO {

    function __construct() {
        
    }

    function __destruct() {
        //$this->banco = NULL;
    }

    public function __set($campo, $valor) {
        $this->$campo = $valor;
    }

    public function __get($campo) {
        return $this->$campo;
    }

    static function salvar($data, $table, $dbk = NULL) {
        try {
            $fields = $data;

            $tmp = array();
            foreach ($fields as $k => $v) {
                if ($k != $dbk) {
                    $tmp[] = $k . ' = :' . $k;
                }
            }
            if (isset($dbk)) {
                $fields['id'] = $dbk;
                $SQL = 'UPDATE ' . $table . ' SET ' . implode(', ', $tmp) . ' WHERE (id=:id)';
            } else {
                $SQL = 'INSERT INTO ' . $table . ' SET ' . implode(', ', $tmp);
            }
            $db = new DB();
            $id = $db->InsertData($SQL, $fields);
            return $id;
        } catch (Exception $ex) {
            throw new Exception($ex->getMessage() . ': ' . __FUNCTION__);
        }
    }

    static function getPonto($id , $args = null) {
        try {
            $sql = "SELECT * FROM ponto WHERE id = ? $args";
            $db = new DB();
            return $db->executeReturn_FETCH_ASSOC($sql , array($id));
        } catch (Exception $err) {
            throw new Exception($err->getMessage() . ': ' . __FUNCTION__);
        }
    }
    
    static function getPontos() {
        try {
            $sql = "SELECT nome FROM ponto";
            $db = new DB();
            return $db->executeReturn_FETCH_ASSOC($sql , array($id));
        } catch (Exception $err) {
            throw new Exception($err->getMessage() . ': ' . __FUNCTION__);
        }
    }

   
   
}
