42 lines
890 B
PHP
42 lines
890 B
PHP
<?php
|
|
/**
|
|
* Holds the forum permission handler.
|
|
* @package Sakura
|
|
*/
|
|
|
|
namespace Sakura\Forum;
|
|
|
|
use Sakura\DB;
|
|
use Sakura\User;
|
|
use Sakura\PermissionHandler;
|
|
use Traversable;
|
|
|
|
/**
|
|
* Forum permission handler.
|
|
* @package Sakura
|
|
* @author Julian van de Groep <me@flash.moe>
|
|
*/
|
|
class ForumPerms extends PermissionHandler
|
|
{
|
|
public const TABLE = 'forum_perms';
|
|
|
|
public function __construct(Forum $forum, User $user)
|
|
{
|
|
$this->additionalRequirements['where_in']['forum_id'] = iterator_to_array($this->getForumIds($forum->id));
|
|
parent::__construct($user);
|
|
}
|
|
|
|
public function getForumIds(int $id): Traversable
|
|
{
|
|
// yield the initial id
|
|
yield $id;
|
|
|
|
while ($id > 0) {
|
|
$id = DB::table('forums')
|
|
->where('forum_id', $id)
|
|
->value('forum_category');
|
|
|
|
yield $id;
|
|
}
|
|
}
|
|
}
|