auditModel.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class auditModel extends Staple_Model
  3. {
  4. private $db;
  5. private $timestamp;
  6. private $action;
  7. private $userId;
  8. private $group;
  9. private $item;
  10. /**
  11. * @return mixed
  12. */
  13. public function getTimestamp()
  14. {
  15. return $this->timestamp;
  16. }
  17. /**
  18. * @return mixed
  19. */
  20. public function getAction()
  21. {
  22. return $this->action;
  23. }
  24. /**
  25. * @param mixed $action
  26. */
  27. public function setAction($action)
  28. {
  29. $this->action = $action;
  30. }
  31. /**
  32. * @return mixed
  33. */
  34. public function getUserId()
  35. {
  36. return $this->userId;
  37. }
  38. /**
  39. * @param mixed $userId
  40. */
  41. public function setUserId($userId)
  42. {
  43. $this->userId = $userId;
  44. }
  45. /**
  46. * @return mixed
  47. */
  48. public function getGroup()
  49. {
  50. return $this->group;
  51. }
  52. /**
  53. * @param mixed $group
  54. */
  55. public function setGroup($group)
  56. {
  57. $this->group = $group;
  58. }
  59. /**
  60. * @return mixed
  61. */
  62. public function getItem()
  63. {
  64. return $this->item;
  65. }
  66. /**
  67. * @param mixed $item
  68. */
  69. public function setItem($item)
  70. {
  71. $this->item = $item;
  72. }
  73. function __construct()
  74. {
  75. $this->db = Staple_DB::get();
  76. }
  77. function save()
  78. {
  79. if(isset($this->userId) && isset($this->action) && isset($this->item))
  80. {
  81. $sql = "
  82. INSERT INTO audit (action, userId, item) VALUES ('".$this->db->real_escape_string($this->getAction())."','".$this->db->real_escape_string($this->getUserId())."','".$this->db->real_escape_string($this->getItem())."');
  83. ";
  84. if($this->db->query($sql))
  85. {
  86. return true;
  87. }
  88. }
  89. }
  90. function getAll()
  91. {
  92. $sql = "
  93. SELECT * FROM audit WHERE 1 ORDER BY timestamp ASC;
  94. ";
  95. if($this->db->query($sql)->num_rows > 0)
  96. {
  97. $query = $this->db->query($sql);
  98. $data = array();
  99. $i = 0;
  100. while($result = $query->fetch_assoc())
  101. {
  102. $data[$i]['timestamp'] = $result['timestamp'];
  103. $account = new userModel();
  104. $data[$i]['account'] = $account->userInfo($result['userId']);
  105. $data[$i]['action'] = $result['action'];
  106. $data[$i]['item'] = $result['item'];
  107. $i++;
  108. }
  109. return $data;
  110. }
  111. else
  112. {
  113. return array();
  114. }
  115. }
  116. }
  117. ?>