aboutsummaryrefslogtreecommitdiff
path: root/h-source/Application/Models/HardwareModel.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-02-11 00:55:42 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-02-11 00:55:42 +0000
commit51138d1c41d9be15d64d42bd25a46758d360ae4e (patch)
treecb7ad9c2d70f47e1769ad81d6a7aa8507d144df5 /h-source/Application/Models/HardwareModel.php
parent1df7d5d81c9c60029dfd6291e95f67b466673edc (diff)
improved actions history
Diffstat (limited to 'h-source/Application/Models/HardwareModel.php')
-rw-r--r--h-source/Application/Models/HardwareModel.php40
1 files changed, 39 insertions, 1 deletions
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