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

43 lines
890 B
PHP
Raw Normal View History

<?php
/**
* Holds the forum permission handler.
* @package Sakura
*/
namespace Sakura\Forum;
2016-11-02 18:58:51 +00:00
use Sakura\DB;
use Sakura\User;
2016-12-08 21:13:55 +00:00
use Sakura\PermissionHandler;
2016-12-04 19:12:39 +00:00
use Traversable;
/**
* Forum permission handler.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
2016-12-08 21:13:55 +00:00
class ForumPerms extends PermissionHandler
{
2016-12-08 21:13:55 +00:00
public const TABLE = 'forum_perms';
public function __construct(Forum $forum, User $user)
{
2016-12-08 21:13:55 +00:00
$this->additionalRequirements['where_in']['forum_id'] = iterator_to_array($this->getForumIds($forum->id));
parent::__construct($user);
}
2016-12-04 19:12:39 +00:00
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;
}
}
}