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;
|
2018-07-28 03:45:33 -07:00
|
|
|
use App\Events\CheckoutAccepted;
|
|
|
|
use App\Events\CheckoutDeclined;
|
2018-09-10 07:40:26 -07:00
|
|
|
use App\Events\CheckoutableCheckedIn;
|
|
|
|
use App\Events\CheckoutableCheckedOut;
|
2018-07-27 15:23:58 -07:00
|
|
|
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;
|
2018-07-28 03:45:33 -07:00
|
|
|
use App\Models\LicenseSeat;
|
2018-07-27 15:23:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
class LogListener
|
|
|
|
{
|
|
|
|
|
2018-09-10 07:40:26 -07:00
|
|
|
public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event) {
|
|
|
|
$event->checkoutable->logCheckin($event->checkedOutTo, $event->note);
|
2018-07-27 15:23:58 -07:00
|
|
|
}
|
|
|
|
|
2018-09-10 07:40:26 -07:00
|
|
|
public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event) {
|
|
|
|
$event->checkoutable->logCheckout($event->note, $event->checkedOutTo);
|
|
|
|
}
|
2018-07-27 15:23:58 -07:00
|
|
|
|
2018-07-28 03:45:33 -07:00
|
|
|
public function onCheckoutAccepted(CheckoutAccepted $event) {
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction = new Actionlog();
|
2018-07-28 03:45:33 -07:00
|
|
|
|
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable);
|
|
|
|
$logaction->target()->associate($event->acceptance->assignedTo);
|
|
|
|
$logaction->accept_signature = $event->acceptance->signature_filename;
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->action_type = 'accepted';
|
|
|
|
|
2018-07-28 03:45:33 -07:00
|
|
|
// TODO: log the actual license seat that was checked out
|
|
|
|
if($event->acceptance->checkoutable instanceof LicenseSeat) {
|
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable->license);
|
|
|
|
}
|
|
|
|
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->save();
|
|
|
|
}
|
|
|
|
|
2018-07-28 03:45:33 -07:00
|
|
|
public function onCheckoutDeclined(CheckoutDeclined $event) {
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction = new Actionlog();
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable);
|
|
|
|
$logaction->target()->associate($event->acceptance->assignedTo);
|
|
|
|
$logaction->accept_signature = $event->acceptance->signature_filename;
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->action_type = 'declined';
|
|
|
|
|
2018-07-28 03:45:33 -07:00
|
|
|
// TODO: log the actual license seat that was checked out
|
|
|
|
if($event->acceptance->checkoutable instanceof LicenseSeat) {
|
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable->license);
|
|
|
|
}
|
|
|
|
|
2018-07-27 16:15:32 -07:00
|
|
|
$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 = [
|
2018-09-10 07:40:26 -07:00
|
|
|
'CheckoutableCheckedIn',
|
|
|
|
'CheckoutableCheckedOut',
|
2018-07-28 03:45:33 -07:00
|
|
|
'CheckoutAccepted',
|
|
|
|
'CheckoutDeclined',
|
2018-07-27 15:23:58 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach($list as $event) {
|
|
|
|
$events->listen(
|
|
|
|
'App\Events\\' . $event,
|
|
|
|
'App\Listeners\LogListener@on' . $event
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|