mirror of
https://github.com/flarum/core.git
synced 2025-10-20 03:06:07 +02:00
Add group management actions to API
This commit is contained in:
50
src/Core/Groups/GroupRepository.php
Normal file
50
src/Core/Groups/GroupRepository.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php namespace Flarum\Core\Groups;
|
||||
|
||||
use Flarum\Core\Users\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class GroupRepository
|
||||
{
|
||||
/**
|
||||
* Get a new query builder for the groups table.
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return User::query();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a user by ID, optionally making sure it is visible to a certain
|
||||
* user, or throw an exception.
|
||||
*
|
||||
* @param int $id
|
||||
* @param User $actor
|
||||
* @return Group
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*/
|
||||
public function findOrFail($id, User $actor = null)
|
||||
{
|
||||
$query = Group::where('id', $id);
|
||||
|
||||
return $this->scopeVisibleTo($query, $actor)->firstOrFail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include records that are visible to a user.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param User $actor
|
||||
* @return Builder
|
||||
*/
|
||||
protected function scopeVisibleTo(Builder $query, User $actor = null)
|
||||
{
|
||||
if ($actor !== null) {
|
||||
$query->whereVisibleTo($actor);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user