hcportal-dev/Aiko/Libs/LogAccess.php

85 lines
2.9 KiB
PHP

<?php
namespace Aiko;
use \Aiko\Model;
use \Aiko\Http;
use PDOException;
use PDO;
class LogAccess extends Model {
function __construct($registry) {
parent::__construct($registry);
}
function saveLog($serviceName) {
try {
$sql = 'insert into app_log(`service_name`,`username`) values(:service_name,:username)';
$stmt = $this->registry->db->prepare($sql);
$stmt->bindValue(':service_name',$serviceName, PDO::PARAM_STR);
$stmt->bindValue(':username',\Helper::getSessionVar('username'), PDO::PARAM_STR);
$stmt->execute();
return true;
} catch (PDOException $e) {
$this->registry->log->error('Action : Insert data LogAcccess/saveLog :'.$e->getMessage().', user: '.\Helper::getSessionVar('username'));
return false;
} catch (\ErrorException $e) {
$this->registry->log->error('Action : Insert data LogAcccess/saveLog :'.$e->getMessage().', user: '.\Helper::getSessionVar('username'));
return false;
}
}
public function viewLogByServiceName($serviceName)
{
try {
$sql = 'select `service_name`,`username`,`timestamp` from app_log where `service_name`=:service_name';
$stmt = $this->registry->db->prepare($sql);
$stmt->bindValue(':service_name',$serviceName, PDO::PARAM_STR);
$stmt->execute();
$rs=$stmt->fetchAll(PDO::FETCH_ASSOC);
return $rs;
} catch (PDOException $e) {
$this->registry->log->error('LogAcccess/viewLogByServiceName :'.$e->getMessage().', user: '.\Helper::getSessionVar('username'));
return false;
} catch (\ErrorException $e) {
$this->registry->log->error('LogAcccess/viewLogByServiceName :'.$e->getMessage().', user: '.\Helper::getSessionVar('username'));
return false;
}
}
public function viewLogByUsername($username)
{
try {
$sql = 'select `service_name`,`username`,`timestamp` from app_log where `username`=:username';
$stmt = $this->registry->db->prepare($sql);
$stmt->bindValue(':username',$username, PDO::PARAM_STR);
$stmt->execute();
$rs=$stmt->fetchAll(PDO::FETCH_ASSOC);
return $rs;
} catch (PDOException $e) {
$this->registry->log->error('LogAcccess/viewLogByServiceUsername :'.$e->getMessage().', user: '.\Helper::getSessionVar('username'));
return false;
} catch (ErrorException $e) {
$this->registry->log->error('LogAcccess/viewLogByServiceUsername :'.$e->getMessage().', user: '.\Helper::getSessionVar('username'));
return false;
}
}
}