Manga lists and detail pages
This commit is contained in:
parent
772aeae20f
commit
609ba57078
@ -14,7 +14,6 @@
|
||||
<?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 */ ?>
|
||||
<img src="<?= $escape->attr($item['manga']['image']) ?>" />
|
||||
@ -43,8 +42,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="volume_completion">
|
||||
Volumes: <span class="volumes_read"><?= $item['volumes']['read'] ?></span> /
|
||||
<span class="volume_count"><?= $item['volumes']['total'] ?></span>
|
||||
Volumes: <span class="volume_count"><?= $item['volumes']['total'] ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<main class="details">
|
||||
<section class="flex flex-no-wrap">
|
||||
<div>
|
||||
<img class="cover" src="<?= $data['poster_image'] ?>" alt="<?= $data['title'] ?> cover image" />
|
||||
<img class="cover" src="<?= $data['cover_image'] ?>" alt="<?= $data['title'] ?> cover image" />
|
||||
<br />
|
||||
<br />
|
||||
<table>
|
||||
@ -26,9 +26,9 @@
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<h2><a rel="external" href="https://hummingbird.me/manga/<?= $data['id'] ?>"><?= $data['romaji_title'] ?></a></h2>
|
||||
<?php if( ! empty($data['english_title'])): ?>
|
||||
<h3><?= $data['english_title'] ?></h3>
|
||||
<h2><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2>
|
||||
<?php if( ! empty($data['en_title'])): ?>
|
||||
<h3><?= $data['en_title'] ?></h3>
|
||||
<?php endif ?>
|
||||
|
||||
<br />
|
||||
|
@ -15,8 +15,8 @@
|
||||
<?php endif*/ ?>
|
||||
<th>Title</th>
|
||||
<th>Rating</th>
|
||||
<th>Chapters</th>
|
||||
<th>Volumes</th>
|
||||
<th>Completed Chapters</th>
|
||||
<th># of Volumes</th>
|
||||
<th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -36,7 +36,7 @@
|
||||
</td>
|
||||
<td><?= $item['user_rating'] ?> / 10</td>
|
||||
<td><?= $item['chapters']['read'] ?> / <?= $item['chapters']['total'] ?></td>
|
||||
<td><?= $item['volumes']['read'] ?> / <?= $item['volumes']['total'] ?></td>
|
||||
<td><?= $item['volumes']['total'] ?></td>
|
||||
<td><?= $item['manga']['type'] ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
|
@ -24,8 +24,8 @@ use Aviat\Ion\Enum as BaseEnum;
|
||||
class MangaReadingStatus extends BaseEnum {
|
||||
const READING = 1;
|
||||
const PLAN_TO_READ = 2;
|
||||
const DROPPED = 3;
|
||||
const DROPPED = 5;
|
||||
const ON_HOLD = 4;
|
||||
const COMPLETED = 5;
|
||||
const COMPLETED = 3;
|
||||
}
|
||||
// End of MangaReadingStatus.php
|
@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\API\Kitsu;
|
||||
|
||||
use Aviat\AnimeClient\AnimeClient;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\{
|
||||
AnimeTransformer, AnimeListTransformer, MangaListTransformer
|
||||
AnimeTransformer, AnimeListTransformer, MangaTransformer, MangaListTransformer
|
||||
};
|
||||
use Aviat\Ion\Json;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
@ -47,9 +47,9 @@ class KitsuModel {
|
||||
*/
|
||||
protected $animeTransformer;
|
||||
|
||||
/**
|
||||
* @var MangaListTransformer
|
||||
*/
|
||||
/**
|
||||
* @var MangaListTransformer
|
||||
*/
|
||||
protected $mangaListTransformer;
|
||||
|
||||
/**
|
||||
@ -62,6 +62,7 @@ class KitsuModel {
|
||||
|
||||
$this->animeTransformer = new AnimeTransformer();
|
||||
$this->animeListTransformer = new AnimeListTransformer();
|
||||
$this->mangaTransformer = new MangaTransformer();
|
||||
$this->mangaListTransformer = new MangaListTransformer();
|
||||
}
|
||||
|
||||
@ -98,16 +99,17 @@ class KitsuModel {
|
||||
return $this->animeTransformer->transform($baseData);
|
||||
}
|
||||
|
||||
public function getManga(string $mangaId): array
|
||||
{
|
||||
$baseData = $this->getRawMediaData('manga', $mangaId);
|
||||
return $this->mangaTransformer->transform($baseData);
|
||||
}
|
||||
|
||||
public function getRawAnimeData($animeId): array
|
||||
{
|
||||
return $this->getRawMediaData('anime', $animeId);
|
||||
}
|
||||
|
||||
public function getAnimeMedia($entryId): array
|
||||
{
|
||||
return $this->getRequest("library-entries/{$entryId}/media");
|
||||
}
|
||||
|
||||
public function getAnimeList($status): array
|
||||
{
|
||||
$options = [
|
||||
@ -139,34 +141,34 @@ class KitsuModel {
|
||||
}
|
||||
|
||||
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'
|
||||
]
|
||||
];
|
||||
{
|
||||
$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);
|
||||
$data = $this->getRequest('library-entries', $options);
|
||||
|
||||
foreach($data['data'] as $i => &$item)
|
||||
{
|
||||
$item['manga'] = $data['included'][$i];
|
||||
}
|
||||
foreach($data['data'] as $i => &$item)
|
||||
{
|
||||
$item['manga'] = $data['included'][$i];
|
||||
}
|
||||
|
||||
$transformed = $this->mangaListTransformer->transformCollection($data['data']);
|
||||
$transformed = $this->mangaListTransformer->transformCollection($data['data']);
|
||||
|
||||
return $transformed;
|
||||
}
|
||||
return $transformed;
|
||||
}
|
||||
|
||||
private function getGenres(string $type, string $id): array
|
||||
{
|
||||
|
@ -6,12 +6,12 @@
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package AnimeListClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @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
|
||||
* @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;
|
||||
@ -34,17 +34,15 @@ 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'])
|
||||
$rating = (is_numeric($item['attributes']['rating']))
|
||||
? intval(2 * $item['attributes']['rating'])
|
||||
: '-';
|
||||
|
||||
$total_chapters = ($manga['attributes']['chapterCount'] > 0)
|
||||
? $manga['attributes']['chapterCount']
|
||||
: '-';
|
||||
: '-';
|
||||
|
||||
$total_volumes = ($manga['attributes']['volumeCount'] > 0)
|
||||
? $manga['attributes']['volumeCount']
|
||||
@ -53,40 +51,29 @@ die();
|
||||
$map = [
|
||||
'id' => $item['id'],
|
||||
'chapters' => [
|
||||
'read' => $item['chapters_read'],
|
||||
'read' => $item['attributes']['progress'],
|
||||
'total' => $total_chapters
|
||||
],
|
||||
'volumes' => [
|
||||
'read' => $item['volumes_read'],
|
||||
'read' => '-', //$item['attributes']['volumes_read'],
|
||||
'total' => $total_volumes
|
||||
],
|
||||
'manga' => [
|
||||
'title' => $manga['romaji_title'],
|
||||
'title' => $manga['attributes']['canonicalTitle'],
|
||||
'alternate_title' => NULL,
|
||||
'slug' => $manga['id'],
|
||||
'url' => 'https://hummingbird.me/manga/' . $manga['id'],
|
||||
'type' => $manga['manga_type'],
|
||||
'image' => $manga['poster_image_thumb'],
|
||||
'genres' => $manga['genres'],
|
||||
'url' => 'https://kitsu.io/manga/' . $manga['id'],
|
||||
'type' => $manga['attributes']['mangaType'],
|
||||
'image' => $manga['attributes']['posterImage']['small'],
|
||||
'genres' => [], //$manga['genres'],
|
||||
],
|
||||
'reading_status' => $item['status'],
|
||||
'notes' => $item['notes'],
|
||||
'rereading' => (bool)$item['rereading'],
|
||||
'reread' => $item['reread_count'],
|
||||
'reading_status' => $item['attributes']['status'],
|
||||
'notes' => $item['attributes']['notes'],
|
||||
'rereading' => (bool)$item['attributes']['reconsuming'],
|
||||
'reread' => $item['attributes']['reconsumeCount'],
|
||||
'user_rating' => $rating,
|
||||
];
|
||||
|
||||
if (array_key_exists('english_title', $manga))
|
||||
{
|
||||
$diff = levenshtein($manga['romaji_title'], $manga['english_title']);
|
||||
|
||||
// If the titles are REALLY similar, don't bother showing both
|
||||
if ($diff >= 5)
|
||||
{
|
||||
$map['manga']['alternate_title'] = $manga['english_title'];
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package AnimeListClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @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
|
||||
* @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;
|
||||
@ -23,17 +23,33 @@ use Aviat\Ion\Transformer\AbstractTransformer;
|
||||
*/
|
||||
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 [
|
||||
/**
|
||||
* Convert raw api response to a more
|
||||
* logical and workable structure
|
||||
*
|
||||
* @param array $item API library item
|
||||
* @return array
|
||||
*/
|
||||
public function transform($item)
|
||||
{
|
||||
return [
|
||||
'title' => $item['canonicalTitle'],
|
||||
'en_title' => $item['titles']['en'],
|
||||
'jp_title' => $item['titles']['en_jp'],
|
||||
'cover_image' => $item['posterImage']['small'],
|
||||
'manga_type' => $item['mangaType'],
|
||||
'chapter_count' => $this->count($item['chapterCount']),
|
||||
'volume_count' => $this->count($item['volumeCount']),
|
||||
'synopsis' => $item['synopsis'],
|
||||
'url' => "https://kitsu.io/manga/{$item['slug']}",
|
||||
'genres' => $item['genres'],
|
||||
];
|
||||
}
|
||||
|
||||
];
|
||||
}
|
||||
private function count(int $value = null)
|
||||
{
|
||||
return ((int)$value === 0)
|
||||
? '-'
|
||||
: $value;
|
||||
}
|
||||
}
|
@ -264,8 +264,8 @@ class Manga extends Controller {
|
||||
$data = $this->model->get_manga($manga_id);
|
||||
|
||||
$this->outputHTML('manga/details', [
|
||||
'title' => 'Manga · ' . $data['manga']['romaji_title'],
|
||||
'data' => $data['manga'],
|
||||
'title' => 'Manga · ' . $data['title'],
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
*
|
||||
* PHP version 7
|
||||
*
|
||||
* @package AnimeListClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @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
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 4.0
|
||||
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\Model;
|
||||
@ -46,12 +46,20 @@ class Manga extends API {
|
||||
MangaReadingStatus::COMPLETED => self::COMPLETED
|
||||
];
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
protected $status_map = [
|
||||
'current' => self::READING,
|
||||
'planned' => self::PLAN_TO_READ,
|
||||
'completed' => self::COMPLETED,
|
||||
'on_hold' => self::ON_HOLD,
|
||||
'dropped' => self::DROPPED
|
||||
];
|
||||
|
||||
$this->kitsuModel = $container->get('kitsu-model');
|
||||
}
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
$this->kitsuModel = $container->get('kitsu-model');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an authenticated manga API call
|
||||
@ -102,10 +110,9 @@ class Manga extends API {
|
||||
*/
|
||||
public function get_list($status)
|
||||
{
|
||||
$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;*/
|
||||
$APIstatus = array_flip($this->const_map)[$status];
|
||||
$data = $this->kitsuModel->getMangaList($APIstatus);
|
||||
return $this->map_by_status($data)[$status];
|
||||
}
|
||||
|
||||
|
||||
@ -117,8 +124,7 @@ class Manga extends API {
|
||||
*/
|
||||
public function get_manga($manga_id)
|
||||
{
|
||||
$raw = $this->_manga_api_call('get', "manga/{$manga_id}.json");
|
||||
return Json::decode($raw['body'], TRUE);
|
||||
return $this->kitsuModel->getManga($manga_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,7 +152,7 @@ class Manga extends API {
|
||||
$entry['manga']['slug'],
|
||||
'manga'
|
||||
);*/
|
||||
$key = $this->const_map[$entry['reading_status']];
|
||||
$key = $this->status_map[$entry['reading_status']];
|
||||
$output[$key][] = $entry;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user