2017-06-15 20:54:14 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\Setting;
|
|
|
|
use App\Models\Actionlog;
|
|
|
|
use Auth;
|
|
|
|
|
|
|
|
class AssetObserver
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Listen to the User created event.
|
|
|
|
*
|
|
|
|
* @param Asset $asset
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-07-08 03:38:39 -07:00
|
|
|
public function updating(Asset $asset)
|
2017-06-15 20:54:14 -07:00
|
|
|
{
|
2017-07-08 03:38:39 -07:00
|
|
|
|
2017-08-24 16:52:27 -07:00
|
|
|
|
|
|
|
if ((isset($asset->getOriginal()['assigned_to'])) && ($asset->getAttributes()['assigned_to'] == $asset->getOriginal()['assigned_to'])
|
2017-07-08 03:38:39 -07:00
|
|
|
&& ($asset->getAttributes()['last_checkout'] == $asset->getOriginal()['last_checkout'])
|
|
|
|
&& ($asset->getAttributes()['status_id'] == $asset->getOriginal()['status_id']))
|
|
|
|
{
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = Asset::class;
|
|
|
|
$logAction->item_id = $asset->id;
|
|
|
|
$logAction->created_at = date("Y-m-d H:i:s");
|
|
|
|
$logAction->user_id = Auth::id();
|
|
|
|
$logAction->logaction('update');
|
|
|
|
}
|
|
|
|
|
2017-06-15 20:54:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to the Asset created event, and increment
|
|
|
|
* the next_auto_tag_base value in the settings table when i
|
|
|
|
* a new asset is created.
|
|
|
|
*
|
|
|
|
* @param Asset $asset
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function created(Asset $asset)
|
|
|
|
{
|
2017-08-23 14:07:01 -07:00
|
|
|
if ($settings = Setting::first()) {
|
|
|
|
$settings->increment('next_auto_tag_base');
|
|
|
|
}
|
2017-06-15 20:54:14 -07:00
|
|
|
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = Asset::class;
|
|
|
|
$logAction->item_id = $asset->id;
|
|
|
|
$logAction->created_at = date("Y-m-d H:i:s");
|
2017-06-20 20:38:13 -07:00
|
|
|
$logAction->user_id = Auth::id();
|
2017-06-15 20:54:14 -07:00
|
|
|
$logAction->logaction('create');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to the Asset deleting event.
|
|
|
|
*
|
|
|
|
* @param Asset $asset
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleting(Asset $asset)
|
|
|
|
{
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = Asset::class;
|
|
|
|
$logAction->item_id = $asset->id;
|
|
|
|
$logAction->created_at = date("Y-m-d H:i:s");
|
2017-06-20 20:38:13 -07:00
|
|
|
$logAction->user_id = Auth::id();
|
2017-06-15 20:54:14 -07:00
|
|
|
$logAction->logaction('delete');
|
|
|
|
}
|
|
|
|
}
|