Users.php delete soon

This commit is contained in:
flash 2016-02-05 12:20:33 +01:00
parent 7bf64954ec
commit 264fe683d5
4 changed files with 109 additions and 103 deletions

View file

@ -9,6 +9,7 @@ namespace Sakura\Controllers;
use Sakura\Config;
use Sakura\Database;
use Sakura\Rank;
use Sakura\Template;
use Sakura\User as UserContext;
use Sakura\Utils;
@ -22,7 +23,7 @@ use Sakura\Utils;
class User
{
/**
* Display the profile of a user
* Display the profile of a user.
*
* @param mixed $id The user ID.
*
@ -85,6 +86,13 @@ class User
return Template::render('main/profile');
}
/**
* Display the memberlist.
*
* @param int $rank Optional rank ID.
*
* @return bool|string The memberlist.
*/
public static function members($rank = 0)
{
global $currentUser;
@ -99,7 +107,7 @@ class User
'memberlist' => [
'ranks' => ($_MEMBERLIST_RANKS = \Sakura\Users::getAllRanks()),
'active' => ($_MEMBERLIST_ACTIVE = (array_key_exists($rank, $_MEMBERLIST_RANKS) ? $rank : 0)),
'users' => ($_MEMBERLIST_ACTIVE ? \Sakura\Users::getUsersInRank($_MEMBERLIST_ACTIVE) : \Sakura\Users::getAllUsers(false)),
'users' => ($_MEMBERLIST_ACTIVE ? Rank::construct($_MEMBERLIST_ACTIVE)->users() : \Sakura\Users::getAllUsers(false)),
'membersPerPage' => Config::get('members_per_page'),
]
]);

View file

@ -180,4 +180,33 @@ class Rank
return $this->permissions->check($flag, $perm);
}
/**
* Returns all users that are part of this rank.
*
* @param bool $justIds Makes this function only return the user ids when set to a positive value.
*
* @return array Either just the user IDs of the users or with objects.
*/
public function users($justIds = false)
{
// Fetch all users part of this rank
$userIds = array_column(Database::fetch('user_ranks', true, ['rank_id' => [$this->id, '=']]), 'user_id');
// Just return that if we were asked for just the ids
if ($justIds) {
return $userIds;
}
// Create the storage array
$users = [];
// Create User objects and store
foreach ($userIds as $id) {
$users[$id] = User::construct($id);
}
// Return the array
return $users;
}
}

View file

@ -782,37 +782,6 @@ class Users
return $users;
}
/**
* Get users from a rank.
*
* @param int $rankId The rank ID.
* @param mixed $users Array with users.
* @param mixed $excludeAbyss Unused.
*
* @return array Users.
*/
public static function getUsersInRank($rankId, $users = null, $excludeAbyss = true)
{
// Get all users (or use the supplied user list to keep server load down)
if (!$users) {
$users = self::getAllUsers();
}
// Make output array
$rank = [];
// Go over all users and check if they have the rank id
foreach ($users as $user) {
// If so store the user's row in the array
if ($user->hasRanks([$rankId], $user->id)) {
$rank[] = $user;
}
}
// Then return the array with the user rows
return $rank;
}
/**
* Get all users.
*

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20160204');
define('SAKURA_VERSION', '20160205');
define('SAKURA_VLABEL', 'Amethyst');
define('SAKURA_COLOUR', '#9966CC');
@ -26,8 +26,8 @@ set_time_limit(0);
mb_internal_encoding('utf-8');
// Stop the execution if the PHP Version is older than 5.4.0
if (version_compare(phpversion(), '5.4.0', '<')) {
die('Sakura requires at least PHP 5.4.0, please upgrade to a newer PHP version.');
if (version_compare(phpversion(), '5.5.0', '<')) {
die('Sakura requires at least PHP 5.5.0, please upgrade to a newer PHP version.');
}
// Include third-party libraries