Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/ts.corals.io/corals-api/Corals/core/User/Communication/Classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ts.corals.io/corals-api/Corals/core/User/Communication/Classes/CoralsNotification.php
<?php

namespace Corals\User\Communication\Classes;


use Carbon\Carbon;
use Corals\User\Communication\Models\NotificationTemplate;
use Corals\User\Models\User;

class CoralsNotification
{
    public $events = [];

    /**
     * Notification constructor.
     */
    function __construct()
    {
    }

    /**
     * @param $name
     * @param $event_name
     * @param $friendlyName
     * @param $notificationClass
     * @param string $title
     * @param array $body
     */
    public function addEvent($event_name, $friendlyName, $notificationClass, $name = '', $title = '', $body = [])
    {
        if (empty($name)) {
            $name = $event_name;
        }

        $this->events[$name] = [
            'name' => $name,
            'notificationClass' => $notificationClass,
            'friendly_name' => $friendlyName,
            'event_name' => $event_name,
            'title' => $title,
            'body' => json_encode($body)
        ];
    }

    public function getEventsList()
    {
        return $this->events;
    }

    public function getEventByEventName($event_name)
    {
        $events = collect($this->getEventsList());

        return $events->where('event_name', $event_name);
    }

    public function getEventByName($name)
    {
        return $this->getEventsList()[$name];
    }

    public function insertNewEventsToDatabase()
    {
        $eventsInDatabase = NotificationTemplate::query()->get();

        $eventsNamesInDatabase = $eventsInDatabase->pluck('name')->toArray();

        $allEventsNames = array_keys($this->getEventsList());

        $newEventsNames = array_diff($allEventsNames, $eventsNamesInDatabase);

        $newEventsNames = array_map(function ($name) {
            $event = $this->getEventByName($name);

            $eventObj = [
                'name' => $name,
                'friendly_name' => $event['friendly_name'],
                'title' => $event['title'],
                'body' => $event['body'],
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now()
            ];

            if (\Schema::hasColumn('notification_templates', 'event_name')) {
                $eventObj['event_name'] = $event['event_name'];
            }

            return $eventObj;
        }, $newEventsNames);

        if (!empty($newEventsNames)) {
            NotificationTemplate::query()->insert($newEventsNames);
        }
    }

    /*
     * @return array
     * function to return the notification parameters and there description for a given template
     */
    public function getNotificationParametersDescription(NotificationTemplate $notificationTemplate)
    {
        return $this->getEventByName($notificationTemplate->name)['notificationClass']::getNotificationMessageParametersDescriptions();
    }

    /**
     * @param User $user
     * @return mixed
     */
    public function getUserNotificationTemplates(User $user)
    {
        return NotificationTemplate::whereHas('roles', function ($query) use ($user) {
            $query->whereIn('role_id', $user->roles()->pluck('id'));
        })->where('via', 'like', '%user_preferences%')->get();
    }
}

Spamworldpro Mini