Add basic character pages

This commit is contained in:
Timothy Warren 2017-03-08 12:55:49 -05:00
parent d7c47f3c1f
commit 3e68fec704
6 changed files with 113 additions and 2 deletions

View File

@ -149,6 +149,23 @@ return [
// Manga Collection Routes // Manga Collection Routes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Other Routes
// ---------------------------------------------------------------------
'character' => [
'path' => '/character/{slug}',
'action' => 'index',
'params' => [],
'tokens' => [
'slug' => '[a-z0-9\-]+'
]
],
'user_info' => [
'path' => '/me',
'action' => 'me',
'controller' => 'me',
'verb' => 'get',
],
// ---------------------------------------------------------------------
// Default / Shared routes // Default / Shared routes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
'cache_purge' => [ 'cache_purge' => [

12
app/views/character.php Normal file
View File

@ -0,0 +1,12 @@
<main class="details">
<section class="flex flex-no-wrap">
<div>
<img class="cover" width="402" height="284" src="<?= $data['image']['original'] ?>" alt="" />
</div>
<div>
<h3><?= $data['name'] ?></h3>
<p><?= $data['description'] ?></p>
</div>
</section>
</main>

View File

@ -93,7 +93,7 @@ class Model {
* @param string $username * @param string $username
* @return string * @return string
*/ */
public function getUserIdByUsername(string $username = NULL) public function getUserIdByUsername(string $username = NULL): string
{ {
if (is_null($username)) if (is_null($username))
{ {
@ -119,6 +119,39 @@ class Model {
return $cacheItem->get(); return $cacheItem->get();
} }
/**
* Get information about a character
*
* @param string $slug
* @return array
*/
public function getCharacter(string $slug): array
{
$data = $this->getRequest('/characters', [
'query' => [
'filter' => [
'slug' => $slug
],
// 'include' => 'primaryMedia,castings'
]
]);
return $data;
}
public function getUserData(string $username): array
{
$userId = $this->getUserIdByUsername($username);
$data = $this->getRequest("/users/{$userId}", [
'query' => [
'include' => 'waifu,pinnedPost,blocks,linkedAccounts,profileLinks,mediaFollows,userRoles'
]
]);
// $data['included'] = JsonAPI::organizeIncludes($data['included']);
return $data;
}
/** /**
* Get the access token from the Kitsu API * Get the access token from the Kitsu API
* *

View File

@ -123,6 +123,13 @@ class Controller {
$this->baseData['message'] = $this->session->getFlash('message'); $this->baseData['message'] = $this->session->getFlash('message');
} }
public function me()
{
$username = $this->config->get(['kitsu_username']);
$model = $this->container->get('kitsu-model');
$this->outputJSON($model->getUserData($username));
}
/** /**
* Redirect to the default controller/url from an empty path * Redirect to the default controller/url from an empty path
* *

View File

@ -0,0 +1,41 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2017 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Controller as BaseController;
class Character extends BaseController {
public function index(string $slug)
{
$model = $this->container->get('kitsu-model');
$data = $model->getCharacter($slug);
if ( ! array_key_exists('data', $data))
{
return $this->notFound();
}
// $this->outputJSON($data);
$this->outputHTML('character', [
'title' => $this->config->get('whose_list') .
"'s Anime List &middot; Characters &middot; " . $data['data'][0]['attributes']['name'],
'data' => $data['data'][0]['attributes']
]);
}
}

View File

@ -38,7 +38,8 @@ class Util {
'update_form', 'update_form',
'login', 'login',
'logout', 'logout',
'details' 'details',
'character'
]; ];
/** /**