/src/includes/classes/general/Log.class.php
PHP | 100 lines | 52 code | 12 blank | 36 comment | 9 complexity | da03f5037fd1954ef9d42cc642d7f55c MD5 | raw file
- <?php
- //Access control
- if(!defined('IN_APP_PROJECT')) exit('Access Forbidden');
- require_once(RELATIVE_ABSTRACT_CLASS_PATH . 'Persistent.class.php');
- /**
- * Description of Log
- *
- * @author alejandro
- */
- class Log extends Persistent {
- protected $userId;
- protected $ip;
- protected $time;
- protected $value;
- protected $content;
- /**
- * default constructor
- */
- public function Log(){
- $this->ip = $_SERVER['REMOTE_ADDR'];
- $this->time = new DateTime();
- }
- /**
- *
- * @param type $value
- */
- public function setValue($value){
- $this->value = $value;
- }
- /**
- *
- * @param type $usr
- */
- public function setUser($usr){
- $this->userId = $usr;
- }
- /**
- *
- * @param type $str
- */
- public function setContent($str){
- $this->content = $str;
- }
- /**
- * stores a $msg into the log database
- * @param type $msg
- * @param type $usr
- */
- public static function this($msg, $obj = null, $usr = null){
- $log = new Log();
- $log->setValue($msg);
- if($usr == null){
- if(isset($_SESSION) && isset($_SESSION['userId'])){
- $usr = (int)$_SESSION['userId'];
- }
- }
- $log->setUser($usr);
- if($obj != null){
- $log->setContent(var_export($obj, true));
- }
- $log->persist();
- }
- /**
- * persists the object
- */
- public function persist(){
- $this->wipe();
- $this->insert(__CLASS__);
- }
- /**
- * prints the log table
- */
- public static function printTableList(){
- Log::printGridView(__CLASS__);
- }
- /**
- * cleans the object, this method should be called ALLWAYS before persising
- * the object (insert & update)
- */
- public function wipe(){
- parent::wipe();
- if($this->userId <= 0) $this->userId = null;
- if(is_object($this->time)){
- $this->time = $this->time->format(DATETIME_MYSQL);
- }
- }
- }
- ?>