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/_sakura/components/Rank.php
flashwave 4afd50d766 Implemented the new Rank class.
Signed-off-by: Flashwave <me@flash.moe>
2015-10-14 21:35:16 +02:00

98 lines
1.7 KiB
PHP
Executable file

<?php
/*
* Rank Class
*/
namespace Sakura;
class Rank
{
// Rank data
public $data = [];
// Initialise the rank object
public function __construct($rid)
{
// Get the rank database row
$this->data = Database::fetch(
'ranks',
false,
[
'rank_id' => [$rid, '=', true],
]
);
// Check if the rank actually exists
if (empty($this->data)) {
// If not assign as the fallback rank
$this->data = Users::$emptyRank;
}
}
// Get the rank id
public function id()
{
return $this->data['rank_id'];
}
// Get the rank hierarchy
public function hierarchy()
{
return $this->data['rank_hierarchy'];
}
// Get the rank name
public function name($multi = false)
{
return $this->data['rank_name'] . ($multi ? $this->data['rank_multiple'] : null);
}
// Get the rank title
public function title()
{
return $this->data['rank_title'];
}
// Get the rank description
public function description()
{
return $this->data['rank_description'];
}
// Get the rank colour
public function colour()
{
return $this->data['rank_colour'];
}
// Check if the rank is hidden
public function hidden()
{
return $this->data['rank_hidden'] || $this->checkPermission('SITE', 'DEACTIVATED') || $this->checkPermission('SITE', 'RESTRICTED');
}
// Check if the rank has the proper permissions
public function checkPermission($layer, $action)
{
return Permissions::check($layer, $action, [$this->id()], 2);
}
}