<?php
if (!defined('ABSPATH')) exit();
if (!class_exists('DbIndeedAbstract')) require_once ULP_PATH . 'classes/Abstracts/DbIndeedAbstract.class.php';
if (class_exists('Db_Ulp_Dashboard_Notifications')) return;
/*
type VARCHAR(40) NOT NULL,
value INT(11) DEFAULT 0
*/
class Db_Ulp_Dashboard_Notifications extends DbIndeedAbstract{
    /**
     * @var string
     */
    protected $table = '';
    /**
     * @param none
     * @return none
     */
    public function __construct(){
        global $wpdb;
        $this->table = $wpdb->prefix . 'ulp_dashboard_notifications';
    }
    public function save($type='', $value=''){
        $type = esc_sql($type);
        $value = esc_sql($value);
        if ($this->get($type)===null || $this->get($type)===FALSE){
            return parent::insert("'$type', $value");
        }
        return parent::update(" value=$value ", " type='$type' ");
    }
    public function delete($type=''){
        $type = esc_sql($type);
        return parent::delete(" type='$type' ");
    }
    public function get($type=''){
        $type = esc_sql($type);
        $num = parent::getVar('value', " type='$type' ");
        if ($num===FALSE || $num===null){
            $num = 0;
        }
        return $num;
    }
}
