From 51138d1c41d9be15d64d42bd25a46758d360ae4e Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Fri, 11 Feb 2011 00:55:42 +0000 Subject: improved actions history --- h-source/Application/Models/HardwareModel.php | 40 ++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'h-source/Application/Models/HardwareModel.php') diff --git a/h-source/Application/Models/HardwareModel.php b/h-source/Application/Models/HardwareModel.php index d4c9a47..150abc8 100644 --- a/h-source/Application/Models/HardwareModel.php +++ b/h-source/Application/Models/HardwareModel.php @@ -92,6 +92,9 @@ class HardwareModel extends Model_Map { $this->lastId = $clean['id']; $this->db->update('hardware','type',array($this->type),'id_hard='.$clean['id']); + //update the history table + $this->updateHistory('insert'); + $this->associate($clean['id']); } @@ -122,6 +125,10 @@ class HardwareModel extends Model_Map { if ($this->queryResult) { $this->lastId = $clean['id']; + + //update the history table + $this->updateHistory('update'); + if (!$this->checkAssociation($clean['id'],(int)$this->id_user)) { $this->associate($clean['id']); @@ -165,6 +172,10 @@ class HardwareModel extends Model_Map { if (parent::update($clean['id_hard'])) { $this->lastId = $clean['id_hard']; + + //update the history table + $this->updateHistory('update'); + if (!$this->checkAssociation($clean['id_hard'],(int)$this->id_user)) { $this->associate($clean['id_hard']); @@ -196,6 +207,33 @@ class HardwareModel extends Model_Map { return $name; } - + //save in the history all the action carried out by users + protected function updateHistory($action) + { + $translations = array( + 'insert' => 'inserted', + 'update' => 'updated', + ); + + $allowedActions = array('insert','update'); + + if (in_array($action,$allowedActions)) + { + $users = new UsersModel(); + + $clean['user'] = sanitizeAll($users->getUser($this->id_user)); + + $history = new HistoryModel(); + $history->values = array( + 'created_by' => $this->id_user, + 'type' => 'wiki', + 'action' => $action, + 'id' => $this->lastId, + 'message' => 'The device having id='.$this->lastId.' has been '.$translations[$action].' by the user ' . $clean['user'] . ' (id_user='.$this->id_user.') ', + 'gr' => 'registered', + ); + $history->insert(); + } + } } \ No newline at end of file -- cgit v1.2.3