Inheritance: extends Illuminate\Database\Eloquent\Model
 /**
  * Get last notification of the current
  * entity of a specific category
  *
  * @param $category
  * @param $to_id
  * @param $entity
  * @return mixed
  */
 public function getLastNotificationByCategory($category, $to_id, $entity)
 {
     $query = $this->notification->wherePolymorphic($to_id, $entity);
     if (is_numeric($category)) {
         return $query->orderBy('created_at', 'desc')->where('category_id', $category)->first();
     }
     return $query->whereHas('body', function ($categoryQuery) use($category) {
         $categoryQuery->where('name', $category);
     })->orderBy('created_at', 'desc')->first();
 }
Example #2
0
 /** @test */
 function it_send_with_an_custom_sender()
 {
     $this->senders->extend('sendCustom', function ($notification, $app) {
         return new CustomDefaultSender($notification, $app->make('notifynder'));
     });
     $category_name = 'my.category';
     $this->createCategory(['name' => $category_name]);
     $singleNotification = $this->builder->category($category_name)->to(1)->from(2)->url('www.notifynder.io')->toArray();
     $this->senders->sendCustom($singleNotification);
     $this->assertCount(1, Notification::all());
 }
 /**
  * Retrive all notifications, in a stack.
  * You can also limit the number of
  * Notifications if you don't, it will get all.
  *
  * @param           $stackId
  * @param  null     $limit
  * @param  int|null $paginate
  * @param  string   $orderDate
  * @param Closure   $filterScope
  * @return mixed
  */
 public function getStack($stackId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null)
 {
     $query = $this->notification->with('body', 'from', 'to')->byStack($stackId)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate);
     if ($limit && !$paginate) {
         $query->limit($limit);
     }
     $query = $this->applyFilter($filterScope, $query);
     if (is_int(intval($paginate)) && $paginate) {
         return $query->paginate($limit);
     }
     return $query->get();
 }
Example #4
0
 /**
  * get the last notification
  *
  * @method getLastNotification
  * @test
  */
 function it_get_last_notification()
 {
     $this->createMultipleNotifications();
     $lastNotification = $this->user->getLastNotification();
     $notification = Notification::orderBy('created_at', 'desc')->first();
     $this->assertEquals($notification->id, $lastNotification->id);
 }
 /** @test */
 function it_delete_all_notification_expired_by_category_name()
 {
     $category = $this->createCategory(['name' => 'test']);
     $this->createNotification(['category_id' => $category->id, 'expire_time' => Carbon\Carbon::now()->subDays(1)]);
     $this->createNotification(['category_id' => $category->id, 'expire_time' => Carbon\Carbon::now()->subDays(1)]);
     $this->createNotification(['category_id' => $category->id, 'expire_time' => Carbon\Carbon::now()->subDays(1)]);
     $this->createNotification(['category_id' => $category->id, 'expire_time' => Carbon\Carbon::now()->addDays(1)]);
     $this->notificationRepo->deleteByCategory($category->name, true);
     $this->assertCount(1, Notification::all());
 }
 /**
  * Get last notification of the current
  * entity of a specific category
  *
  * @param         $category
  * @param         $to_id
  * @param         $entity
  * @param Closure $filterScope
  * @return mixed
  */
 public function getLastNotificationByCategory($category, $to_id, $entity, Closure $filterScope = null)
 {
     $query = $this->notification->wherePolymorphic($to_id, $entity)->byCategory($category)->orderBy('created_at', 'desc');
     $query = $this->applyFilter($filterScope, $query);
     return $query->first();
 }
Example #7
0
 /**
  * It send multiple Notifications
  *
  * @method send
  * @group failing
  * @test
  */
 function it_send_multiple_notifications()
 {
     Factory::times(10)->create(User::class);
     $this->createCategory(['name' => 'me']);
     $allUsers = User::all();
     $this->notifynder->loop($allUsers, function ($builder, $user) {
         $builder->category('me')->url('you')->from(1)->to($user->id);
     })->send();
     // should send 10 notifications
     $notifications = Notification::all();
     $this->assertCount(10, $notifications);
 }
Example #8
0
 /** @test */
 public function it_retrieve_notifications_by_stack_id()
 {
     $text = 'stack body text';
     $category = $this->createCategory(['text' => $text]);
     $this->createMultipleNotifications(['category_id' => $category->id]);
     $notifications = \Fenos\Notifynder\Models\Notification::byStack(1)->get();
     foreach ($notifications as $notification) {
         $this->assertEquals($text, $notification->text);
         $this->assertEquals(1, $notification->stack_id);
         $this->assertTrue($notification->hasStack());
     }
 }
 /** @test */
 public function it_delete_2_notification_to_be_sent_trought_the_handler()
 {
     $this->dispatcher->delegate(['activation' => 'notify@userActivated', 'confirmation' => 'notify@userMultiple']);
     $notification = \Fenos\Notifynder\Models\Notification::all();
     $this->assertCount(3, $notification);
 }