1
0
mirror of https://github.com/flarum/core.git synced 2025-10-26 21:21:28 +01:00

Implement notifications

This commit is contained in:
Toby Zerner
2015-03-24 15:07:38 +10:30
parent 1d1025dcd2
commit 4a1550215c
34 changed files with 808 additions and 38 deletions

View File

@@ -0,0 +1,25 @@
<?php namespace Flarum\Core\Repositories;
use Flarum\Core\Models\Notification;
use DB;
class EloquentNotificationRepository implements NotificationRepositoryInterface
{
public function findByUser($userId, $count = null, $start = 0)
{
$primaries = Notification::select(DB::raw('MAX(id) AS id'), DB::raw('SUM(is_read = 0) AS unread_count'))
->where('user_id', $userId)
->whereIn('type', array_keys(Notification::getTypes()))
->groupBy('type', 'subject_id')
->orderBy('time', 'desc')
->skip($start)
->take($count);
return Notification::with('subject')
->select('notifications.*', 'p.unread_count')
->mergeBindings($primaries->getQuery())
->join(DB::raw('('.$primaries->toSql().') p'), 'notifications.id', '=', 'p.id')
->orderBy('time', 'desc')
->get();
}
}

View File

@@ -0,0 +1,6 @@
<?php namespace Flarum\Core\Repositories;
interface NotificationRepositoryInterface
{
public function findByUser($userId, $count = null, $start = 0);
}