2018-07-27 15:23:58 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Events\AccessoryCheckedIn;
|
|
|
|
use App\Events\AccessoryCheckedOut;
|
|
|
|
use App\Events\AssetCheckedIn;
|
|
|
|
use App\Events\AssetCheckedOut;
|
|
|
|
use App\Events\ComponentCheckedIn;
|
|
|
|
use App\Events\ComponentCheckedOut;
|
|
|
|
use App\Events\ConsumableCheckedOut;
|
2018-07-27 16:15:32 -07:00
|
|
|
use App\Events\ItemAccepted;
|
|
|
|
use App\Events\ItemDeclined;
|
2018-07-27 15:23:58 -07:00
|
|
|
use App\Events\LicenseCheckedIn;
|
|
|
|
use App\Events\LicenseCheckedOut;
|
|
|
|
use App\Models\Actionlog;
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\Component;
|
|
|
|
|
|
|
|
|
|
|
|
class LogListener
|
|
|
|
{
|
|
|
|
public function onAccessoryCheckedIn(AccessoryCheckedIn $event) {
|
|
|
|
$event->accessory->logCheckin($event->checkedOutTo, $event->note);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onAccessoryCheckedOut(AccessoryCheckedOut $event) {
|
|
|
|
$event->accessory->logCheckout($event->note, $event->checkedOutTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onAssetCheckedIn(AssetCheckedIn $event) {
|
|
|
|
$event->asset->logCheckin($event->checkedOutTo, $event->note);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onAssetCheckedOut(AssetCheckedOut $event) {
|
|
|
|
$event->asset->logCheckout($event->note, $event->checkedOutTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onComponentCheckedIn(ComponentCheckedIn $event) {
|
|
|
|
$log = new Actionlog();
|
|
|
|
$log->user_id = $event->checkedInBy->id;
|
|
|
|
$log->action_type = 'checkin from';
|
|
|
|
$log->target_type = Asset::class;
|
|
|
|
$log->target_id = $event->checkedOutTo->asset_id;
|
|
|
|
$log->item_id = $event->checkedOutTo->component_id;
|
|
|
|
$log->item_type = Component::class;
|
|
|
|
$log->note = $event->note;
|
|
|
|
$log->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onComponentCheckedOut(ComponentCheckedOut $event) {
|
2018-07-27 15:41:31 -07:00
|
|
|
// Since components don't have a "note" field, submit empty note
|
|
|
|
$event->component->logCheckout(null, $event->checkedOutTo);
|
2018-07-27 15:23:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onConsumableCheckedOut(ConsumableCheckedOut $event) {
|
|
|
|
$event->consumable->logCheckout($event->note, $event->checkedOutTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onLicenseCheckedIn(LicenseCheckedIn $event) {
|
|
|
|
$event->license->logCheckin($event->checkedOutTo, $event->note);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onLicenseCheckedOut(LicenseCheckedOut $event) {
|
|
|
|
$event->license->logCheckout($event->note, $event->checkedOutTo);
|
|
|
|
}
|
|
|
|
|
2018-07-27 16:15:32 -07:00
|
|
|
public function onItemAccepted(ItemAccepted $event) {
|
|
|
|
$logaction = new Actionlog();
|
|
|
|
$logaction->item()->associate($event->item);
|
|
|
|
$logaction->target()->associate($event->acceptedBy);
|
|
|
|
$logaction->accept_signature = $event->signature;
|
|
|
|
$logaction->action_type = 'accepted';
|
|
|
|
|
|
|
|
$logaction->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onItemDeclined(ItemDeclined $event) {
|
|
|
|
$logaction = new Actionlog();
|
|
|
|
$logaction->item()->associate($event->item);
|
|
|
|
$logaction->target()->associate($event->declinedBy);
|
|
|
|
$logaction->accept_signature = $event->signature;
|
|
|
|
$logaction->action_type = 'declined';
|
|
|
|
|
|
|
|
$logaction->save();
|
|
|
|
}
|
|
|
|
|
2018-07-27 15:23:58 -07:00
|
|
|
/**
|
|
|
|
* Register the listeners for the subscriber.
|
|
|
|
*
|
|
|
|
* @param Illuminate\Events\Dispatcher $events
|
|
|
|
*/
|
|
|
|
public function subscribe($events)
|
|
|
|
{
|
|
|
|
$list = [
|
|
|
|
'AccessoryCheckedIn',
|
2018-07-27 15:41:31 -07:00
|
|
|
'AccessoryCheckedOut',
|
2018-07-27 15:23:58 -07:00
|
|
|
'AssetCheckedIn',
|
|
|
|
'AssetCheckedOut',
|
|
|
|
'ComponentCheckedIn',
|
|
|
|
'ComponentCheckedOut',
|
|
|
|
'ConsumableCheckedOut',
|
|
|
|
'LicenseCheckedIn',
|
|
|
|
'LicenseCheckedOut',
|
2018-07-27 16:15:32 -07:00
|
|
|
'ItemAccepted',
|
|
|
|
'ItemDeclined',
|
2018-07-27 15:23:58 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach($list as $event) {
|
|
|
|
$events->listen(
|
|
|
|
'App\Events\\' . $event,
|
|
|
|
'App\Listeners\LogListener@on' . $event
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|