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
|
|
|
|
*
|
2023-07-13 11:08:05 -04:00
|
|
|
* PHP version 8.1
|
2018-11-01 22:12:41 -04:00
|
|
|
*
|
2023-07-13 11:08:05 -04:00
|
|
|
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
|
2018-11-01 22:12:41 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-12-10 17:06:50 -05:00
|
|
|
* @version 5.2
|
2023-07-13 11:08:05 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2018-11-01 22:12:41 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-05-09 12:49:36 -04:00
|
|
|
use Aviat\Ion\Attribute\{Controller, Route};
|
2018-11-01 22:12:41 -04:00
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
2022-03-03 17:26:09 -05:00
|
|
|
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
|
2018-11-01 22:12:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for handling routes that don't fit elsewhere
|
|
|
|
*/
|
2023-03-16 13:04:55 -04:00
|
|
|
#[Controller]
|
2022-03-03 17:26:09 -05:00
|
|
|
final class User extends BaseController
|
|
|
|
{
|
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.
|
|
|
|
*
|
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
|
|
|
|
*/
|
2023-03-16 13:04:55 -04:00
|
|
|
#[Route('default_user_info', '/me')]
|
2018-11-01 22:12:41 -04:00
|
|
|
public function me(): void
|
|
|
|
{
|
|
|
|
$this->about('me');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the user profile page
|
|
|
|
*/
|
2023-03-16 13:04:55 -04:00
|
|
|
#[Route('user_info', '/user/{username}')]
|
2018-11-01 22:12:41 -04:00
|
|
|
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);
|
2023-05-18 16:27:31 -04:00
|
|
|
if ($rawData['data']['findProfileBySlug'] === NULL)
|
2023-05-18 16:25:50 -04:00
|
|
|
{
|
2023-05-19 10:54:08 -04:00
|
|
|
$this->notFound('Sorry, user not found', "The user '{$username}' does not seem to exist.");
|
2023-05-18 16:25:50 -04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
$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
|
|
|
]);
|
|
|
|
}
|
2022-03-03 17:26:09 -05:00
|
|
|
}
|