mirror of
https://github.com/flarum/core.git
synced 2025-10-13 07:54:25 +02:00
Get rid of Repository interfaces
This commit is contained in:
36
src/Core/Notifications/NotificationRepository.php
Normal file
36
src/Core/Notifications/NotificationRepository.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php namespace Flarum\Core\Notifications;
|
||||
|
||||
use Flarum\Core\Users\User;
|
||||
|
||||
class NotificationRepository
|
||||
{
|
||||
/**
|
||||
* Find a user's notifications.
|
||||
*
|
||||
* @param User $user
|
||||
* @param int|null $limit
|
||||
* @param int $offset
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function findByUser(User $user, $limit = null, $offset = 0)
|
||||
{
|
||||
$primaries = Notification::select(
|
||||
app('flarum.db')->raw('MAX(id) AS id'),
|
||||
app('flarum.db')->raw('SUM(is_read = 0) AS unread_count')
|
||||
)
|
||||
->where('user_id', $user->id)
|
||||
->whereIn('type', $user->getAlertableNotificationTypes())
|
||||
->where('is_deleted', false)
|
||||
->groupBy('type', 'subject_id')
|
||||
->latest('time')
|
||||
->skip($offset)
|
||||
->take($limit);
|
||||
|
||||
return Notification::with('subject')
|
||||
->select('notifications.*', 'p.unread_count')
|
||||
->mergeBindings($primaries->getQuery())
|
||||
->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', 'p.id')
|
||||
->latest('time')
|
||||
->get();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user