2018-02-10 03:58:06 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* UserTransformer.php
|
|
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Transformers;
|
|
|
|
|
|
|
|
|
2018-02-13 11:24:06 -06:00
|
|
|
use FireflyIII\Models\Role;
|
2018-12-20 15:03:34 -06:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2018-02-10 03:58:06 -06:00
|
|
|
use FireflyIII\User;
|
2018-12-15 00:59:02 -06:00
|
|
|
use Log;
|
2018-02-10 03:58:06 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class UserTransformer
|
|
|
|
*/
|
2018-12-15 15:03:42 -06:00
|
|
|
class UserTransformer extends AbstractTransformer
|
2018-02-10 03:58:06 -06:00
|
|
|
{
|
2018-12-20 15:03:34 -06:00
|
|
|
/** @var UserRepositoryInterface */
|
|
|
|
private $repository;
|
2018-02-11 13:45:33 -06:00
|
|
|
/**
|
2018-02-17 03:47:06 -06:00
|
|
|
* UserTransformer constructor.
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
2018-02-11 13:45:33 -06:00
|
|
|
*/
|
2018-12-15 15:03:42 -06:00
|
|
|
public function __construct()
|
2018-02-11 13:45:33 -06:00
|
|
|
{
|
2018-12-20 15:03:34 -06:00
|
|
|
$this->repository = app(UserRepositoryInterface::class);
|
2018-12-15 00:59:02 -06:00
|
|
|
if ('testing' === config('app.env')) {
|
|
|
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
|
|
|
}
|
2018-02-11 13:45:33 -06:00
|
|
|
}
|
2018-12-15 15:03:42 -06:00
|
|
|
|
2018-02-10 03:58:06 -06:00
|
|
|
/**
|
2018-02-17 03:47:06 -06:00
|
|
|
* Transform user.
|
|
|
|
*
|
2018-02-10 03:58:06 -06:00
|
|
|
* @param User $user
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(User $user): array
|
|
|
|
{
|
|
|
|
return [
|
2018-02-11 00:46:34 -06:00
|
|
|
'id' => (int)$user->id,
|
|
|
|
'created_at' => $user->created_at->toAtomString(),
|
2018-12-12 13:30:25 -06:00
|
|
|
'updated_at' => $user->updated_at->toAtomString(),
|
2018-02-11 00:46:34 -06:00
|
|
|
'email' => $user->email,
|
2018-08-06 12:14:30 -05:00
|
|
|
'blocked' => 1 === (int)$user->blocked,
|
2018-12-03 00:18:05 -06:00
|
|
|
'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code,
|
2018-12-20 15:03:34 -06:00
|
|
|
'role' => $this->repository->getRoleByUser($user),
|
2018-02-11 00:46:34 -06:00
|
|
|
'links' => [
|
2018-02-10 03:58:06 -06:00
|
|
|
[
|
|
|
|
'rel' => 'self',
|
2018-02-11 00:46:34 -06:00
|
|
|
'uri' => '/users/' . $user->id,
|
2018-02-10 03:58:06 -06:00
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-03-05 12:35:58 -06:00
|
|
|
}
|