MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/mpl.imenso.co/app/Repositories/EventInviteRepository.php
<?php

namespace App\Repositories;

use App\Models\EventNonInterest;
use App\Models\User;
use Illuminate\Support\Collection;

class EventInviteRepository extends Repository
{
    public $user;

    public static function forUser(User $user)
    {
        $repo = new self;
        $repo->user = $user;

        return $repo;
    }

    public function get()
    {
        $events = new Collection;
        $non_interested = new Collection;

        $artists = $this->user
            ->getConnections('artist', 'SeenLive')
            ->merge($this->user->getConnections('artist', 'SeeLive'))
            ->unique();

        foreach ($artists as $artist) {
            foreach ($artist->futureEvents(true) as $event) {
                $events->push($event);
            }
        }

        $events = $events->unique();
        $events = $events->sortBy('event_at');

        $event_non_interests = [];

        if (EventNonInterest::where('user_id', $this->user->id)->count()) {
            $event_non_interests = EventNonInterest::where('user_id', $this->user->id)->pluck('event_id')->toArray();
        }

        $events = $events->filter(function ($value, $key) use ($event_non_interests) {
            return ! in_array($value->id, $event_non_interests);
        });

        $this->items = $events;

        return $this->items;
    }

    public function prepareForExternalUse()
    {
        $flattened = new Collection;

        foreach ($this->items as $item) {
            $data['thumbnail'] = url($item->getThumbnailSrc());
            $data['id'] = $item->id;
            $data['name'] = $item->name;
            $data['venue_name'] = $item->venue->getName();
            $data['event_at'] = $item->event_at->format('jS F Y');
            $data['permalink'] = route('event-detail', ['id' => $item->id]);
            $data['interested'] = $this->user->isInterestedInEvent($item->id);

            $flattened->push($data);
        }

        return $flattened;
    }
}