123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- class auditModel extends Staple_Model
- {
- private $db;
- private $timestamp;
- private $action;
- private $userId;
- private $group;
- private $item;
- /**
- * @return mixed
- */
- public function getTimestamp()
- {
- return $this->timestamp;
- }
- /**
- * @return mixed
- */
- public function getAction()
- {
- return $this->action;
- }
- /**
- * @param mixed $action
- */
- public function setAction($action)
- {
- $this->action = $action;
- }
- /**
- * @return mixed
- */
- public function getUserId()
- {
- return $this->userId;
- }
- /**
- * @param mixed $userId
- */
- public function setUserId($userId)
- {
- $this->userId = $userId;
- }
- /**
- * @return mixed
- */
- public function getGroup()
- {
- return $this->group;
- }
- /**
- * @param mixed $group
- */
- public function setGroup($group)
- {
- $this->group = $group;
- }
- /**
- * @return mixed
- */
- public function getItem()
- {
- return $this->item;
- }
- /**
- * @param mixed $item
- */
- public function setItem($item)
- {
- $this->item = $item;
- }
- function __construct()
- {
- $this->db = Staple_DB::get();
- }
- function save()
- {
- if(isset($this->userId) && isset($this->action) && isset($this->item))
- {
- $sql = "
- 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())."');
- ";
- if($this->db->query($sql))
- {
- return true;
- }
- }
- }
- function getAll()
- {
- $sql = "
- SELECT * FROM audit WHERE 1 ORDER BY timestamp ASC;
- ";
- if($this->db->query($sql)->num_rows > 0)
- {
- $query = $this->db->query($sql);
- $data = array();
- $i = 0;
- while($result = $query->fetch_assoc())
- {
- $data[$i]['timestamp'] = $result['timestamp'];
- $account = new userModel();
- $data[$i]['account'] = $account->userInfo($result['userId']);
- $data[$i]['action'] = $result['action'];
- $data[$i]['item'] = $result['item'];
- $i++;
- }
- return $data;
- }
- else
- {
- return array();
- }
- }
- }
- ?>
|