PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/includes/classes/general/Log.class.php

https://bitbucket.org/aescariom/dipler-framework
PHP | 100 lines | 52 code | 12 blank | 36 comment | 9 complexity | da03f5037fd1954ef9d42cc642d7f55c MD5 | raw file
  1. <?php
  2. //Access control
  3. if(!defined('IN_APP_PROJECT')) exit('Access Forbidden');
  4. require_once(RELATIVE_ABSTRACT_CLASS_PATH . 'Persistent.class.php');
  5. /**
  6. * Description of Log
  7. *
  8. * @author alejandro
  9. */
  10. class Log extends Persistent {
  11. protected $userId;
  12. protected $ip;
  13. protected $time;
  14. protected $value;
  15. protected $content;
  16. /**
  17. * default constructor
  18. */
  19. public function Log(){
  20. $this->ip = $_SERVER['REMOTE_ADDR'];
  21. $this->time = new DateTime();
  22. }
  23. /**
  24. *
  25. * @param type $value
  26. */
  27. public function setValue($value){
  28. $this->value = $value;
  29. }
  30. /**
  31. *
  32. * @param type $usr
  33. */
  34. public function setUser($usr){
  35. $this->userId = $usr;
  36. }
  37. /**
  38. *
  39. * @param type $str
  40. */
  41. public function setContent($str){
  42. $this->content = $str;
  43. }
  44. /**
  45. * stores a $msg into the log database
  46. * @param type $msg
  47. * @param type $usr
  48. */
  49. public static function this($msg, $obj = null, $usr = null){
  50. $log = new Log();
  51. $log->setValue($msg);
  52. if($usr == null){
  53. if(isset($_SESSION) && isset($_SESSION['userId'])){
  54. $usr = (int)$_SESSION['userId'];
  55. }
  56. }
  57. $log->setUser($usr);
  58. if($obj != null){
  59. $log->setContent(var_export($obj, true));
  60. }
  61. $log->persist();
  62. }
  63. /**
  64. * persists the object
  65. */
  66. public function persist(){
  67. $this->wipe();
  68. $this->insert(__CLASS__);
  69. }
  70. /**
  71. * prints the log table
  72. */
  73. public static function printTableList(){
  74. Log::printGridView(__CLASS__);
  75. }
  76. /**
  77. * cleans the object, this method should be called ALLWAYS before persising
  78. * the object (insert & update)
  79. */
  80. public function wipe(){
  81. parent::wipe();
  82. if($this->userId <= 0) $this->userId = null;
  83. if(is_object($this->time)){
  84. $this->time = $this->time->format(DATETIME_MYSQL);
  85. }
  86. }
  87. }
  88. ?>