2018-11-01 22:12:41 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime List Client
|
|
|
|
*
|
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
|
|
|
*
|
2020-04-10 15:39:39 -04:00
|
|
|
* PHP version 7.4
|
2018-11-01 22:12:41 -04:00
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2020-01-08 15:39:49 -05:00
|
|
|
* @copyright 2015 - 2020 Timothy J. Warren
|
2018-11-01 22:12:41 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-04-10 15:39:39 -04:00
|
|
|
* @version 5
|
2018-11-01 22:12:41 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Controller;
|
|
|
|
|
2019-12-09 14:34:23 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Model;
|
2018-11-08 11:36:42 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Transformer\UserTransformer;
|
2018-11-01 22:12:41 -04:00
|
|
|
use Aviat\AnimeClient\Controller as BaseController;
|
2018-11-08 11:36:42 -05:00
|
|
|
|
2018-11-01 22:12:41 -04:00
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
2019-12-09 14:34:23 -05:00
|
|
|
use Aviat\Ion\Di\Exception\ContainerException;
|
|
|
|
use Aviat\Ion\Di\Exception\NotFoundException;
|
2018-11-01 22:12:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for handling routes that don't fit elsewhere
|
|
|
|
*/
|
|
|
|
final class User extends BaseController {
|
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
/**
|
2019-12-09 14:34:23 -05:00
|
|
|
* @var Model
|
2018-11-08 11:36:42 -05:00
|
|
|
*/
|
2020-04-10 20:01:46 -04:00
|
|
|
private Model $kitsuModel;
|
2018-11-01 22:12:41 -04:00
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
/**
|
|
|
|
* User constructor.
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
2018-11-08 11:36:42 -05:00
|
|
|
*/
|
2018-11-01 22:12:41 -04:00
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
|
|
|
|
$this->kitsuModel = $container->get('kitsu-model');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the user profile page for the configured user
|
|
|
|
*/
|
|
|
|
public function me(): void
|
|
|
|
{
|
|
|
|
$this->about('me');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the user profile page
|
|
|
|
*
|
|
|
|
* @param string $username
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function about(string $username): void
|
|
|
|
{
|
|
|
|
$isMainUser = $username === 'me';
|
|
|
|
|
|
|
|
$username = $isMainUser
|
|
|
|
? $this->config->get(['kitsu_username'])
|
|
|
|
: $username;
|
|
|
|
|
|
|
|
$whom = $isMainUser
|
|
|
|
? $this->config->get('whose_list')
|
|
|
|
: $username;
|
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
$rawData = $this->kitsuModel->getUserData($username);
|
|
|
|
$data = (new UserTransformer())->transform($rawData)->toArray();
|
|
|
|
|
2018-11-01 22:12:41 -04:00
|
|
|
$this->outputHTML('user/details', [
|
|
|
|
'title' => 'About ' . $whom,
|
2018-11-08 11:36:42 -05:00
|
|
|
'data' => $data,
|
2018-11-01 22:12:41 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|