/** @test */ public function it_gets_alerts_by_type() { $type = Augstudios\Alerts\AlertType::Info; $this->store->shouldReceive('priorOfType')->with($type)->andReturn(Illuminate\Support\Collection::make()); $result = $this->alerts->ofType($type); $this->assertInstanceOf('Illuminate\\Support\\Collection', $result); }
function faker() { $single = count($this->locales) < 2; if (!$this->fakers) { if (!$this->locales) { $this->locales = [env('locale')]; } if ($single) { $this->fakers = Faker\Factory::create(array_values($this->locales)[0]); } else { foreach ($this->locales as $locale) { $this->fakers[] = Faker\Factory::create($locale); } $this->fakers = Illuminate\Support\Collection::make($this->fakers); } } return $single ? $this->fakers : $this->fakers->random(); }
/** * Sort the array using the given Closure. * * @param array $array * @param \Closure $callback * @return array */ function array_sort($array, Closure $callback) { return Illuminate\Support\Collection::make($array)->sortBy($callback)->all(); }
public function findNotifications() { $notifications = []; $commentRepository = App::make('CommentRepository'); // ------------------------------------- Comment::withTrashed()->withSpot()->get()->each(function ($item) use(&$notifications, &$commentRepository) { $spot = $item->spot()->withTrashed()->first(); if ($spot == NULL) { // remove this comment its dead $commentRepository->destroy($item->id); return; } if ($spot->user !== null) { $from_user_id = $item->user_id; $to_user_id = $spot->user_id; if ($from_user_id !== $to_user_id) { $notification_event = array('event' => Notification::NOTIFICATION_USER_COMMENTED, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'parent' => $item, 'timestamp' => $this->timestamp($item->created_at), 'is_read' => false); array_push($notifications, $notification_event); } } }); // ------------------------------------- Visit::withTrashed()->get()->each(function ($item) use(&$notifications) { $spot = $item->spot()->withTrashed()->first(); if ($spot == NULL) { // remove this comment its dead dd($spot); return; } if ($spot->user !== null) { $from_user_id = $item->user_id; $to_user_id = $spot->user_id; if ($from_user_id !== $to_user_id) { $notification_event = array('event' => Notification::NOTIFICATION_USER_VISITED, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'parent' => $item, 'timestamp' => $this->timestamp($item->created_at), 'is_read' => false); array_push($notifications, $notification_event); } } }); // ------------------------------------- Illuminate\Support\Collection::make(DB::table('userables')->get())->each(function ($item) use(&$notifications) { $type = $item->userable_type; $parent = $type::withTrashed()->whereId($item->userable_id)->first(); $notification_event = array('event' => Notification::NOTIFICATION_USER_ITINERARY_SHARED, 'to_user_id' => $item->user_id, 'from_user_id' => $parent->user->id, 'parent' => $parent, 'timestamp' => $this->timestamp(new Carbon($item->created_at)), 'is_read' => false); array_push($notifications, $notification_event); }); // ------------------------------------- User::all()->each(function ($user) use(&$notifications) { // welcome message $notification_event = array('event' => Notification::NOTIFICATION_USER_WELCOME, 'to_user_id' => $user->id, 'from_user_id' => null, 'parent' => $user, 'timestamp' => $this->timestamp($user->created_at), 'is_read' => false); array_push($notifications, $notification_event); // when someone added your spot to favs foreach ($user->favorites->getLocations() as $location) { if ($location->hasSpot() && $location->spot->user_id !== $user->id) { // send to the owner of the spot $to_user_id = $location->spot->user_id; // who is doing this...? $from_user_id = $user->id; // welcome message $notification_event = array('event' => Notification::NOTIFICATION_USER_FAVORITED, 'to_user_id' => $to_user_id, 'from_user_id' => $from_user_id, 'parent' => $location->spot, 'timestamp' => $this->timestamp($location->pivot->created_at), 'is_read' => false); array_push($notifications, $notification_event); } } }); foreach ($notifications as $notice) { Notification::fireNotification($notice); } return $notifications; }