<commit_before><?php

namespace App\Listeners;

class SendingCheckInNotificationsListener
{
 
    /**
     * Register the listeners for the subscriber.
     *
     * @param  Illuminate\Events\Dispatcher  $events
     */
    public function subscribe($events)
    {
        
    }

}<commit_msg>Listen for checkin events and send the appropriate notifications<commit_after><?php

namespace App\Listeners;

use App\Models\Recipients\AdminRecipient;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckinAssetNotification;
use App\Notifications\CheckinLicenseNotification;
use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseNotification;
use Illuminate\Support\Facades\Notification;

class SendingCheckInNotificationsListener
{
    /**
     * Notify the user about the checked in accessory
     */    
    public function onAccessoryCheckedIn($event) {
        /**
         * When the item wasn't checked out to a user, we can't send notifications
         */
        if(! $event->checkedOutTo instanceof User) {
            return;
        }

        Notification::send(
            $this->getNotifiables($event), 
            new CheckinAccessoryNotification($event->accessory, $event->checkedOutTo, $event->checkedInBy, $event->note)
        );
    }

    /**
     * Notify the user about the checked in asset
     */   
    public function onAssetCheckedIn($event) {
        /**
         * When the item wasn't checked out to a user, we can't send notifications
         */
        if(! $event->checkedOutTo instanceof User) {
            return;
        }

        Notification::send(
            $this->getNotifiables($event), 
            new CheckinAssetNotification($event->asset, $event->checkedOutTo, $event->checkedInBy, $event->note)
        );
    }   

    /**
     * Notify the user about the checked in license
     */   
    public function onLicenseCheckedIn($event) {
        /**
         * When the item wasn't checked out to a user, we can't send notifications
         */
        if(! $event->checkedOutTo instanceof User) {
            return;
        }

        Notification::send(
            $this->getNotifiables($event), 
            new CheckinLicenseNotification($event->license, $event->checkedOutTo, $event->checkedInBy, $event->note)
        );
    }   

    /**
     * Gets the entities to be notified of the passed event
     * 
     * @param  Event $event
     * @return Collection
     */
    private function getNotifiables($event) {
        $notifiables = collect();

        /**
         * Notify the user who checked out the item
         */
        $notifiables->push($event->checkedOutTo);

        /**
         * Notify Admin users if the settings is activated
         */
        if (Setting::getSettings()->admin_cc_email != '') {
            $notifiables->push(new AdminRecipient());
        }

        return $notifiables;       
    }

    /**
     * Register the listeners for the subscriber.
     *
     * @param  Illuminate\Events\Dispatcher  $events
     */
    public function subscribe($events)
    {
        $events->listen(
            'App\Events\AccessoryCheckedIn',
            'App\Listeners\SendingCheckInNotificationsListener@onAccessoryCheckedIn'
        ); 

        $events->listen(
            'App\Events\AssetCheckedIn',
            'App\Listeners\SendingCheckInNotificationsListener@onAssetCheckedIn'
        ); 

        $events->listen(
            'App\Events\LicenseCheckedIn',
            'App\Listeners\SendingCheckInNotificationsListener@onLicenseCheckedIn'
        );         
    }

}
{'fraction_non_alphanumeric': 0.10013245033112583, 'fraction_numerical': 0.0, 'mean_word_length': 2.3093777388255914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6955840', 'n_tokens_mistral': 1022, 'n_tokens_neox': 990, 'n_words': 224}