2014-09-05 19:18:49 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Controllers\ViewProxies;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Helpers\EnumHelper;
|
|
|
|
use Szurubooru\Privilege;
|
|
|
|
use Szurubooru\Services\PrivilegeService;
|
2014-09-05 19:18:49 +02:00
|
|
|
|
|
|
|
class UserViewProxy extends AbstractViewProxy
|
|
|
|
{
|
2014-09-06 10:00:26 +02:00
|
|
|
private $privilegeService;
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
public function __construct(PrivilegeService $privilegeService)
|
2014-09-06 10:00:26 +02:00
|
|
|
{
|
|
|
|
$this->privilegeService = $privilegeService;
|
|
|
|
}
|
|
|
|
|
2014-09-25 23:53:47 +02:00
|
|
|
public function fromEntity($user, $config = [])
|
2014-09-05 19:18:49 +02:00
|
|
|
{
|
|
|
|
$result = new \StdClass;
|
|
|
|
if ($user)
|
|
|
|
{
|
2014-09-13 23:58:13 +02:00
|
|
|
$result->id = $user->getId();
|
|
|
|
$result->name = $user->getName();
|
|
|
|
$result->registrationTime = $user->getRegistrationTime();
|
|
|
|
$result->lastLoginTime = $user->getLastLoginTime();
|
2014-10-08 14:47:47 +02:00
|
|
|
$result->avatarStyle = EnumHelper::avatarStyleToString($user->getAvatarStyle());
|
2014-09-30 13:22:11 +02:00
|
|
|
$result->banned = $user->isBanned();
|
2014-09-06 10:00:26 +02:00
|
|
|
|
2014-09-07 14:50:16 +02:00
|
|
|
if ($this->privilegeService->isLoggedIn($user))
|
|
|
|
{
|
2014-09-13 23:58:13 +02:00
|
|
|
$result->browsingSettings = $user->getBrowsingSettings();
|
2014-09-07 14:50:16 +02:00
|
|
|
}
|
|
|
|
|
2014-10-12 11:45:09 +02:00
|
|
|
if ($this->privilegeService->hasPrivilege(Privilege::VIEW_ALL_ACCESS_RANKS) or
|
|
|
|
$this->privilegeService->isLoggedin($user))
|
|
|
|
{
|
|
|
|
$result->accessRank = EnumHelper::accessRankToString($user->getAccessRank());
|
|
|
|
}
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
if ($this->privilegeService->hasPrivilege(Privilege::VIEW_ALL_EMAIL_ADDRESSES) or
|
2014-09-06 10:00:26 +02:00
|
|
|
$this->privilegeService->isLoggedIn($user))
|
|
|
|
{
|
2014-09-13 23:58:13 +02:00
|
|
|
$result->email = $user->getEmail();
|
|
|
|
$result->emailUnconfirmed = $user->getEmailUnconfirmed();
|
2014-09-06 10:00:26 +02:00
|
|
|
}
|
2014-09-10 18:06:49 +02:00
|
|
|
|
2014-09-14 16:44:57 +02:00
|
|
|
$result->confirmed = $user->isAccountConfirmed();
|
2014-09-05 19:18:49 +02:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|