<?php
class local_badiunet_sessionlib  {
    
    function add($dto) {
         global $DB;
	$dto->timecreated=time();
        return  $DB->insert_record('local_badiunet_session', $dto);
       
    }
    public function exist($name) {
	   global $CFG,$DB;
	   $sql="SELECT COUNT(id) AS countrecord FROM {$CFG->prefix}local_badiunet_session WHERE  name='".$name."'";
           $r= $DB->get_record_sql($sql);
            return $r->countrecord;
    }
    
    public function getValue($name) {
	   global $CFG,$DB;
	   $sql="SELECT value FROM {$CFG->prefix}local_badiunet_session WHERE  name='".$name."'";
           $r= $DB->get_record_sql($sql);
           if(empty($r)){return null;}
           return $r->value;
    }
    public function get($name) {
	   global $CFG,$DB;
	   $sql="SELECT id,name,value,userid,ipallowed,timecreated FROM {$CFG->prefix}local_badiunet_session WHERE  name='".$name."'";
           $r= $DB->get_record_sql($sql);
           return $r;
    }
}
?>