Version 5.1 - All the GraphQL #32
@ -23,7 +23,7 @@ return [
|
||||
'on_hold' => '/on_hold',
|
||||
'dropped' => '/dropped',
|
||||
'completed' => '/completed',
|
||||
'all' => '/all'
|
||||
//'all' => '/all'
|
||||
]
|
||||
],
|
||||
'manga_list' => [
|
||||
@ -34,7 +34,7 @@ return [
|
||||
'on_hold' => '/on_hold',
|
||||
'dropped' => '/dropped',
|
||||
'completed' => '/completed',
|
||||
'all' => '/all'
|
||||
//'all' => '/all'
|
||||
]
|
||||
]
|
||||
];
|
@ -1,7 +1,7 @@
|
||||
<main>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /* if ($auth->is_authenticated()): ?>
|
||||
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php endif */ ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
<?php else: ?>
|
||||
@ -11,12 +11,12 @@
|
||||
<section class="media-wrap">
|
||||
<?php foreach($items as $item): ?>
|
||||
<article class="media" id="manga-<?= $item['id'] ?>">
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /*if ($auth->is_authenticated()): ?>
|
||||
<div class="edit_buttons" hidden>
|
||||
<button class="plus_one_chapter">+1 Chapter</button>
|
||||
<button class="plus_one_volume">+1 Volume</button>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php endif */ ?>
|
||||
<img src="<?= $escape->attr($item['manga']['image']) ?>" />
|
||||
<div class="name">
|
||||
<a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>">
|
||||
@ -25,13 +25,13 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="table">
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /*if ($auth->is_authenticated()): ?>
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed" title="Edit information about this manga" href="<?= $urlGenerator->url("manga/edit/{$item['id']}/{$name}") ?>">Edit</a>
|
||||
</span>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php endif */ ?>
|
||||
<div class="row">
|
||||
<div class="user_rating">Rating: <?= $item['user_rating'] ?> / 10</div>
|
||||
</div>
|
||||
@ -55,6 +55,6 @@
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /*if ($auth->is_authenticated()): ?>
|
||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
||||
<?php endif ?>
|
||||
<?php endif*/ ?>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<main>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /*if ($auth->is_authenticated()): ?>
|
||||
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php endif*/ ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
<?php else: ?>
|
||||
@ -10,9 +10,9 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<?php if ($auth->is_authenticated()): ?>
|
||||
<?php /*if ($auth->is_authenticated()): ?>
|
||||
<th> </th>
|
||||
<?php endif ?>
|
||||
<?php endif*/ ?>
|
||||
<th>Title</th>
|
||||
<th>Rating</th>
|
||||
<th>Chapters</th>
|
||||
@ -23,11 +23,11 @@
|
||||
<tbody>
|
||||
<?php foreach($items as $item): ?>
|
||||
<tr id="manga-<?= $item['id'] ?>">
|
||||
<?php if($auth->is_authenticated()): ?>
|
||||
<?php /*if($auth->is_authenticated()): ?>
|
||||
<td>
|
||||
<a class="bracketed" href="<?= $urlGenerator->url("manga/edit/{$item['id']}/{$name}") ?>">Edit</a>
|
||||
</td>
|
||||
<?php endif ?>
|
||||
<?php endif*/ ?>
|
||||
<td class="align_left">
|
||||
<a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>">
|
||||
<?= $item['manga']['title'] ?>
|
||||
|
@ -22,10 +22,10 @@ use Aviat\Ion\Enum as BaseEnum;
|
||||
* Possible values for current reading status of manga
|
||||
*/
|
||||
class MangaReadingStatus extends BaseEnum {
|
||||
const READING = 'Currently Reading';
|
||||
const PLAN_TO_READ = 'Plan to Read';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
const READING = 1;
|
||||
const PLAN_TO_READ = 2;
|
||||
const DROPPED = 3;
|
||||
const ON_HOLD = 4;
|
||||
const COMPLETED = 5;
|
||||
}
|
||||
// End of MangaReadingStatus.php
|
||||
|
@ -17,7 +17,9 @@
|
||||
namespace Aviat\AnimeClient\API\Kitsu;
|
||||
|
||||
use Aviat\AnimeClient\AnimeClient;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\{AnimeTransformer, AnimeListTransformer};
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\{
|
||||
AnimeTransformer, AnimeListTransformer, MangaListTransformer
|
||||
};
|
||||
use Aviat\Ion\Json;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
|
||||
@ -45,6 +47,11 @@ class KitsuModel {
|
||||
*/
|
||||
protected $animeTransformer;
|
||||
|
||||
/**
|
||||
* @var MangaListTransformer
|
||||
*/
|
||||
protected $mangaListTransformer;
|
||||
|
||||
/**
|
||||
* KitsuModel constructor.
|
||||
*/
|
||||
@ -55,6 +62,7 @@ class KitsuModel {
|
||||
|
||||
$this->animeTransformer = new AnimeTransformer();
|
||||
$this->animeListTransformer = new AnimeListTransformer();
|
||||
$this->mangaListTransformer = new MangaListTransformer();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,6 +138,36 @@ class KitsuModel {
|
||||
return $transformed;
|
||||
}
|
||||
|
||||
public function getMangaList($status): array
|
||||
{
|
||||
$options = [
|
||||
'query' => [
|
||||
'filter' => [
|
||||
'user_id' => 2644,
|
||||
'media_type' => 'Manga',
|
||||
'status' => $status,
|
||||
],
|
||||
'include' => 'media',
|
||||
'page' => [
|
||||
'offset' => 0,
|
||||
'limit' => 200
|
||||
],
|
||||
'sort' => '-updated_at'
|
||||
]
|
||||
];
|
||||
|
||||
$data = $this->getRequest('library-entries', $options);
|
||||
|
||||
foreach($data['data'] as $i => &$item)
|
||||
{
|
||||
$item['manga'] = $data['included'][$i];
|
||||
}
|
||||
|
||||
$transformed = $this->mangaListTransformer->transformCollection($data['data']);
|
||||
|
||||
return $transformed;
|
||||
}
|
||||
|
||||
private function getGenres(string $type, string $id): array
|
||||
{
|
||||
$data = $this->getRequest("{$type}/{$id}/genres");
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
|
||||
|
||||
use Aviat\Ion\StringWrapper;
|
||||
use Aviat\Ion\Transformer\AbstractTransformer;
|
||||
|
||||
/**
|
||||
@ -23,7 +24,7 @@ use Aviat\Ion\Transformer\AbstractTransformer;
|
||||
*/
|
||||
class MangaListTransformer extends AbstractTransformer {
|
||||
|
||||
use \Aviat\Ion\StringWrapper;
|
||||
use StringWrapper;
|
||||
|
||||
/**
|
||||
* Remap zipped anime data to a more logical form
|
||||
@ -33,18 +34,20 @@ class MangaListTransformer extends AbstractTransformer {
|
||||
*/
|
||||
public function transform($item)
|
||||
{
|
||||
?><pre><?= print_r($item, TRUE) ?></pre><?php
|
||||
die();
|
||||
$manga =& $item['manga'];
|
||||
|
||||
$rating = (is_numeric($item['rating']))
|
||||
? intval(2 * $item['rating'])
|
||||
: '-';
|
||||
|
||||
$total_chapters = ($manga['chapter_count'] > 0)
|
||||
? $manga['chapter_count']
|
||||
: '-';
|
||||
$total_chapters = ($manga['attributes']['chapterCount'] > 0)
|
||||
? $manga['attributes']['chapterCount']
|
||||
: '-';
|
||||
|
||||
$total_volumes = ($manga['volume_count'] > 0)
|
||||
? $manga['volume_count']
|
||||
$total_volumes = ($manga['attributes']['volumeCount'] > 0)
|
||||
? $manga['attributes']['volumeCount']
|
||||
: '-';
|
||||
|
||||
$map = [
|
||||
|
39
src/API/Kitsu/Transformer/MangaTransformer.php
Normal file
39
src/API/Kitsu/Transformer/MangaTransformer.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Anime List Client
|
||||
*
|
||||
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package AnimeListClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @copyright 2015 - 2016 Timothy J. Warren
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 4.0
|
||||
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
|
||||
|
||||
use Aviat\Ion\Transformer\AbstractTransformer;
|
||||
|
||||
/**
|
||||
* Transformer for anime description page
|
||||
*/
|
||||
class MangaTransformer extends AbstractTransformer {
|
||||
|
||||
/**
|
||||
* Convert raw api response to a more
|
||||
* logical and workable structure
|
||||
*
|
||||
* @param array $item API library item
|
||||
* @return array
|
||||
*/
|
||||
public function transform($item)
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ namespace Aviat\AnimeClient\Model;
|
||||
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\MangaReadingStatus;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Json;
|
||||
use GuzzleHttp\Cookie\SetCookie;
|
||||
use RuntimeException;
|
||||
@ -45,11 +46,12 @@ class Manga extends API {
|
||||
MangaReadingStatus::COMPLETED => self::COMPLETED
|
||||
];
|
||||
|
||||
/**
|
||||
* The base url for api requests
|
||||
* @var string
|
||||
*/
|
||||
protected $base_url = "https://hummingbird.me/";
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
$this->kitsuModel = $container->get('kitsu-model');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an authenticated manga API call
|
||||
@ -91,85 +93,6 @@ class Manga extends API {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a manga to the list
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
$object = [
|
||||
'manga_library_entry' => [
|
||||
'status' => $data['status'],
|
||||
'manga_id' => $data['id']
|
||||
]
|
||||
];
|
||||
|
||||
return $this->_manga_api_call('post', 'manga_library_entries', $object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the selected manga
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$id = $data['id'];
|
||||
|
||||
return $this->_manga_api_call(
|
||||
'put',
|
||||
"manga_library_entries/{$id}",
|
||||
['manga_library_entry' => $data]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a manga entry
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function delete($data)
|
||||
{
|
||||
$id = $data['id'];
|
||||
|
||||
return $this->_manga_api_call('delete', "manga_library_entries/{$id}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for manga by name
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function search($name)
|
||||
{
|
||||
$logger = $this->container->getLogger('default');
|
||||
|
||||
$config = [
|
||||
'query' => [
|
||||
'scope' => 'manga',
|
||||
'depth' => 'full',
|
||||
'query' => $name
|
||||
]
|
||||
];
|
||||
|
||||
$response = $this->get('search.json', $config);
|
||||
|
||||
if ((int) $response->getStatusCode() !== 200)
|
||||
{
|
||||
$logger->warning('Non 200 response for search api call');
|
||||
$logger->warning($response->getBody());
|
||||
|
||||
throw new RuntimeException($response->getEffectiveUrl());
|
||||
}
|
||||
|
||||
return Json::decode($response->getBody(), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a category out of the full list
|
||||
@ -179,51 +102,12 @@ class Manga extends API {
|
||||
*/
|
||||
public function get_list($status)
|
||||
{
|
||||
$data = $this->cache->get($this, '_get_list_from_api');
|
||||
return ($status !== 'All') ? $data[$status] : $data;
|
||||
$data = $this->kitsuModel->getMangaList($status);
|
||||
return $this->map_by_status($data)[$status];
|
||||
/*$data = $this->cache->get($this, '_get_list_from_api');
|
||||
return ($status !== 'All') ? $data[$status] : $data;*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the list from the hummingbird api
|
||||
*
|
||||
* @param string $status
|
||||
* @return array
|
||||
*/
|
||||
public function _get_list_from_api(string $status = "All"): array
|
||||
{
|
||||
$config = [
|
||||
'query' => [
|
||||
'user_id' => $this->config->get('hummingbird_username')
|
||||
],
|
||||
'allow_redirects' => FALSE
|
||||
];
|
||||
|
||||
$response = $this->get('manga_library_entries', $config);
|
||||
$data = $this->transform($response);
|
||||
$final = $this->map_by_status($data);
|
||||
return ($status !== 'All') ? $final[$status] : $final;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the response to be more consistent
|
||||
*
|
||||
* @param \GuzzleHttp\Message\Response $response
|
||||
* @codeCoverageIgnore
|
||||
* @return array
|
||||
*/
|
||||
private function transform($response)
|
||||
{
|
||||
// Bail out early if there isn't any manga data
|
||||
$api_data = Json::decode($response->getBody(), TRUE);
|
||||
if ( ! array_key_exists('manga', $api_data))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$zipperedData = $this->zipperLists($api_data);
|
||||
$transformer = new Transformer\MangaListTransformer();
|
||||
return $transformer->transformCollection($zipperedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the details of a manga
|
||||
@ -257,11 +141,11 @@ class Manga extends API {
|
||||
|
||||
foreach ($data as &$entry)
|
||||
{
|
||||
$entry['manga']['image'] = $util->get_cached_image(
|
||||
/*$entry['manga']['image'] = $util->get_cached_image(
|
||||
$entry['manga']['image'],
|
||||
$entry['manga']['slug'],
|
||||
'manga'
|
||||
);
|
||||
);*/
|
||||
$key = $this->const_map[$entry['reading_status']];
|
||||
$output[$key][] = $entry;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user