aboutsummaryrefslogtreecommitdiff
path: root/h-source/Application/Models
diff options
context:
space:
mode:
Diffstat (limited to 'h-source/Application/Models')
-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