. */ /** * Barcode Database Access Object. This class provides functionality to * load and save Barcode sentences. */ require_once(FILESYSTEMROOTPATH."include/classes/IDao.php"); class BarcodeDao implements IDao { /** MySQL object */ private $mysql; /** * Default constructor */ public function __construct(MySQL $mysql) { $this->mysql = $mysql; } /** * Load Barcode sentence by id * * @param id * @return */ public function load($id) { } /** * Load entry time in the plenary of a participant * * @param string participantId * @return entry time */ public function loadCurrent($participantId) { $query = "SELECT `enter` FROM attendance_current WHERE `participantId`='".$this->mysql->escape($participantId)."'"; if( $this->mysql->query($query) ) { $row = $this->mysql->fetchArray(); return $row['enter']; }else{ return false; } } /** * Load participant name * * @param string participantId * @return name of the participant */ public function loadName($participantId) { $query = "SELECT concat(`firstName`, ' ', `lastName`) as name FROM voting_delegates WHERE `participantId`='".$this->mysql->escape($participantId)."'"; if( $this->mysql->query($query) ) { $row = $this->mysql->fetchArray(); return $row['name']; }else return false; } /** * Load participant info * * @param participantId * @return array with name, uid of the participant */ public function loadInfo($participantId) { $query = "SELECT concat(`firstName`, ' ', `lastName`) as name, uid FROM voting_delegates WHERE `participantId`='".$this->mysql->escape($participantId)."'"; if( $this->mysql->query($query) ) { $row = $this->mysql->fetchArray(); return array( 'name'=>$row['name'], 'uid'=>$row['uid'] ); }else return false; } /** * Save participant's entrance in the plenary * * @param string participantId * @param datetime time */ public function enterCurrent($participantId, $time) { $query = "INSERT INTO attendance_current (`participantId`, `enter`) VALUES ('".$this->mysql->escape($participantId)."', '".$time."')"; if( $this->mysql->query($query) ) return true; else return false; } /** * Remove participant's entrance in the plenary from the database * * @param string participantId */ public function deleteCurrent($participantId) { $query = "DELETE FROM attendance_current WHERE `participantId`='".$this->mysql->escape($participantId)."'"; if( $this->mysql->query($query) ) return true; else return false; } /** * Save participant's entrance in the plenary * * @param string participantId * @param datetime time */ public function registerPresence($uid, $enter, $exit) { $query = "INSERT INTO attendance_log (`uid`, `enter`, `exit`, `agora_id`) VALUES ('".$uid."', '".$enter."', '".$exit."', '".$_SESSION['JC_MODULE']['AgoraId']."')"; if( $this->mysql->query($query) ) return true; else return false; } /** * Purge the Current Attendance * * @param string participantId * @param datetime time */ public function emptyCurrentAttendance() { $query = "TRUNCATE TABLE attendance_current"; if( $this->mysql->query($query) ) return true; else return false; } /** * Save the open sessions * * @param datetime time */ public function closeOpenSessions( $exit ) { $query = "INSERT INTO `attendance_log` (`uid`, `enter`, `exit`, `agora_id`) SELECT vd.`uid`, ac.`enter`, '".$exit."', '".$_SESSION['JC_MODULE']['AgoraId']."' FROM `attendance_current` ac INNER JOIN `voting_delegates` vd ON vd.`participantId`=ac.`participantId` WHERE ac.`enter`<='".$exit."'"; if( $this->mysql->query($query) ) return true; else return false; } /** * Load all Barcode * * @return array of sentences */ public function loadAll() { } public function setScannerPassword($pass){ $encrypt = sha1($pass); $query = "SELECT id FROM `config` WHERE `name` = 'scanners'"; if(!($this->mysql->query($query)) ) return false; $row = $this->mysql->fetchArray(); if ($row){ $query = "UPDATE `config` SET `value`='".$encrypt."' WHERE `id`=".$row["id"]; }else{ $query = "INSERT INTO `config` (`name`, `value`) VALUES ('scanners','$encrypt')"; } if( $this->mysql->query($query) ) return true; else return false; } /** * Save or update Barcode: * @param Barcode object with the data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $Barcode) { } /** * Load closing times of all open plenaries of the current Agora * * @return array of datetime */ public function safeToScan() { $aid = $_SESSION['JC_MODULE']['AgoraId']; $query = "SELECT count(1) problem FROM plenaries p INNER JOIN agorae a ON p.agoraId=a.id WHERE agoraId =".$aid." AND (p.`close`<(now()- INTERVAL 90 MINUTE)) AND p.`status`=0"; if( $this->mysql->query($query) ) { $row = $this->mysql->fetchArray(); if( $row['problem'] == 0 ) return true; } return false; } } ?>