This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/Forum/ForumPerms.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;
}
}
}