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-09-10 07:40:26 -07:00
|
|
|
use App\Events\CheckoutableCheckedIn;
|
|
|
|
use App\Events\CheckoutableCheckedOut;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Events\CheckoutAccepted;
|
|
|
|
use App\Events\CheckoutDeclined;
|
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;
|
2018-07-28 03:45:33 -07:00
|
|
|
use App\Models\LicenseSeat;
|
2018-07-27 15:23:58 -07:00
|
|
|
|
|
|
|
class LogListener
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event)
|
|
|
|
{
|
2019-03-13 21:36:32 -07:00
|
|
|
$event->checkoutable->logCheckin($event->checkedOutTo, $event->note, $event->action_date);
|
2018-07-27 15:23:58 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event)
|
|
|
|
{
|
2019-03-13 21:36:32 -07:00
|
|
|
$event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout);
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2018-07-27 15:23:58 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function onCheckoutAccepted(CheckoutAccepted $event)
|
|
|
|
{
|
2018-07-28 03:45:33 -07:00
|
|
|
|
2022-03-14 19:38:36 -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;
|
2022-03-14 19:38:36 -07:00
|
|
|
$logaction->stored_eula_file = $event->acceptance->stored_eula_file;
|
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
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable->license);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-07-27 16:15:32 -07:00
|
|
|
$logaction->save();
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2018-07-27 16:15:32 -07:00
|
|
|
|
2021-06-10 13:15:52 -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
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
2018-07-28 03:45:33 -07:00
|
|
|
$logaction->item()->associate($event->acceptance->checkoutable->license);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$logaction->save();
|
|
|
|
}
|
2018-07-27 16:15:32 -07:00
|
|
|
|
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',
|
2021-06-10 13:15:52 -07:00
|
|
|
'CheckoutDeclined',
|
2018-07-27 15:23:58 -07:00
|
|
|
];
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
foreach ($list as $event) {
|
2018-07-27 15:23:58 -07:00
|
|
|
$events->listen(
|
2021-06-10 13:15:52 -07:00
|
|
|
'App\Events\\'.$event,
|
|
|
|
'App\Listeners\LogListener@on'.$event
|
2018-07-27 15:23:58 -07:00
|
|
|
);
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|
2018-07-27 15:23:58 -07:00
|
|
|
}
|
2019-03-13 20:12:03 -07:00
|
|
|
}
|