Manga lists and detail pages

This commit is contained in:
Timothy Warren 2017-01-04 13:16:58 -05:00
parent 3030b6b908
commit f1893d9708
9 changed files with 146 additions and 137 deletions

View File

@ -14,7 +14,6 @@
<?php /*if ($auth->is_authenticated()): ?> <?php /*if ($auth->is_authenticated()): ?>
<div class="edit_buttons" hidden> <div class="edit_buttons" hidden>
<button class="plus_one_chapter">+1 Chapter</button> <button class="plus_one_chapter">+1 Chapter</button>
<button class="plus_one_volume">+1 Volume</button>
</div> </div>
<?php endif */ ?> <?php endif */ ?>
<img src="<?= $escape->attr($item['manga']['image']) ?>" /> <img src="<?= $escape->attr($item['manga']['image']) ?>" />
@ -43,8 +42,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="volume_completion"> <div class="volume_completion">
Volumes: <span class="volumes_read"><?= $item['volumes']['read'] ?></span> / Volumes: <span class="volume_count"><?= $item['volumes']['total'] ?></span>
<span class="volume_count"><?= $item['volumes']['total'] ?></span>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
<main class="details"> <main class="details">
<section class="flex flex-no-wrap"> <section class="flex flex-no-wrap">
<div> <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 />
<br /> <br />
<table> <table>
@ -26,9 +26,9 @@
</table> </table>
</div> </div>
<div> <div>
<h2><a rel="external" href="https://hummingbird.me/manga/<?= $data['id'] ?>"><?= $data['romaji_title'] ?></a></h2> <h2><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2>
<?php if( ! empty($data['english_title'])): ?> <?php if( ! empty($data['en_title'])): ?>
<h3><?= $data['english_title'] ?></h3> <h3><?= $data['en_title'] ?></h3>
<?php endif ?> <?php endif ?>
<br /> <br />

View File

@ -15,8 +15,8 @@
<?php endif*/ ?> <?php endif*/ ?>
<th>Title</th> <th>Title</th>
<th>Rating</th> <th>Rating</th>
<th>Chapters</th> <th>Completed Chapters</th>
<th>Volumes</th> <th># of Volumes</th>
<th>Type</th> <th>Type</th>
</tr> </tr>
</thead> </thead>
@ -36,7 +36,7 @@
</td> </td>
<td><?= $item['user_rating'] ?> / 10</td> <td><?= $item['user_rating'] ?> / 10</td>
<td><?= $item['chapters']['read'] ?> / <?= $item['chapters']['total'] ?></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> <td><?= $item['manga']['type'] ?></td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>

View File

@ -24,8 +24,8 @@ use Aviat\Ion\Enum as BaseEnum;
class MangaReadingStatus extends BaseEnum { class MangaReadingStatus extends BaseEnum {
const READING = 1; const READING = 1;
const PLAN_TO_READ = 2; const PLAN_TO_READ = 2;
const DROPPED = 3; const DROPPED = 5;
const ON_HOLD = 4; const ON_HOLD = 4;
const COMPLETED = 5; const COMPLETED = 3;
} }
// End of MangaReadingStatus.php // End of MangaReadingStatus.php

View File

@ -18,7 +18,7 @@ namespace Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\AnimeClient; use Aviat\AnimeClient\AnimeClient;
use Aviat\AnimeClient\API\Kitsu\Transformer\{ use Aviat\AnimeClient\API\Kitsu\Transformer\{
AnimeTransformer, AnimeListTransformer, MangaListTransformer AnimeTransformer, AnimeListTransformer, MangaTransformer, MangaListTransformer
}; };
use Aviat\Ion\Json; use Aviat\Ion\Json;
use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ClientException;
@ -62,6 +62,7 @@ class KitsuModel {
$this->animeTransformer = new AnimeTransformer(); $this->animeTransformer = new AnimeTransformer();
$this->animeListTransformer = new AnimeListTransformer(); $this->animeListTransformer = new AnimeListTransformer();
$this->mangaTransformer = new MangaTransformer();
$this->mangaListTransformer = new MangaListTransformer(); $this->mangaListTransformer = new MangaListTransformer();
} }
@ -98,16 +99,17 @@ class KitsuModel {
return $this->animeTransformer->transform($baseData); 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 public function getRawAnimeData($animeId): array
{ {
return $this->getRawMediaData('anime', $animeId); return $this->getRawMediaData('anime', $animeId);
} }
public function getAnimeMedia($entryId): array
{
return $this->getRequest("library-entries/{$entryId}/media");
}
public function getAnimeList($status): array public function getAnimeList($status): array
{ {
$options = [ $options = [

View File

@ -34,12 +34,10 @@ class MangaListTransformer extends AbstractTransformer {
*/ */
public function transform($item) public function transform($item)
{ {
?><pre><?= print_r($item, TRUE) ?></pre><?php
die();
$manga =& $item['manga']; $manga =& $item['manga'];
$rating = (is_numeric($item['rating'])) $rating = (is_numeric($item['attributes']['rating']))
? intval(2 * $item['rating']) ? intval(2 * $item['attributes']['rating'])
: '-'; : '-';
$total_chapters = ($manga['attributes']['chapterCount'] > 0) $total_chapters = ($manga['attributes']['chapterCount'] > 0)
@ -53,40 +51,29 @@ die();
$map = [ $map = [
'id' => $item['id'], 'id' => $item['id'],
'chapters' => [ 'chapters' => [
'read' => $item['chapters_read'], 'read' => $item['attributes']['progress'],
'total' => $total_chapters 'total' => $total_chapters
], ],
'volumes' => [ 'volumes' => [
'read' => $item['volumes_read'], 'read' => '-', //$item['attributes']['volumes_read'],
'total' => $total_volumes 'total' => $total_volumes
], ],
'manga' => [ 'manga' => [
'title' => $manga['romaji_title'], 'title' => $manga['attributes']['canonicalTitle'],
'alternate_title' => NULL, 'alternate_title' => NULL,
'slug' => $manga['id'], 'slug' => $manga['id'],
'url' => 'https://hummingbird.me/manga/' . $manga['id'], 'url' => 'https://kitsu.io/manga/' . $manga['id'],
'type' => $manga['manga_type'], 'type' => $manga['attributes']['mangaType'],
'image' => $manga['poster_image_thumb'], 'image' => $manga['attributes']['posterImage']['small'],
'genres' => $manga['genres'], 'genres' => [], //$manga['genres'],
], ],
'reading_status' => $item['status'], 'reading_status' => $item['attributes']['status'],
'notes' => $item['notes'], 'notes' => $item['attributes']['notes'],
'rereading' => (bool)$item['rereading'], 'rereading' => (bool)$item['attributes']['reconsuming'],
'reread' => $item['reread_count'], 'reread' => $item['attributes']['reconsumeCount'],
'user_rating' => $rating, '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; return $map;
} }

View File

@ -33,7 +33,23 @@ class MangaTransformer extends AbstractTransformer {
public function transform($item) public function transform($item)
{ {
return [ 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;
}
} }

View File

@ -264,8 +264,8 @@ class Manga extends Controller {
$data = $this->model->get_manga($manga_id); $data = $this->model->get_manga($manga_id);
$this->outputHTML('manga/details', [ $this->outputHTML('manga/details', [
'title' => 'Manga &middot; ' . $data['manga']['romaji_title'], 'title' => 'Manga &middot; ' . $data['title'],
'data' => $data['manga'], 'data' => $data,
]); ]);
} }
} }

View File

@ -46,6 +46,14 @@ class Manga extends API {
MangaReadingStatus::COMPLETED => self::COMPLETED MangaReadingStatus::COMPLETED => self::COMPLETED
]; ];
protected $status_map = [
'current' => self::READING,
'planned' => self::PLAN_TO_READ,
'completed' => self::COMPLETED,
'on_hold' => self::ON_HOLD,
'dropped' => self::DROPPED
];
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
parent::__construct($container); parent::__construct($container);
@ -102,10 +110,9 @@ class Manga extends API {
*/ */
public function get_list($status) public function get_list($status)
{ {
$data = $this->kitsuModel->getMangaList($status); $APIstatus = array_flip($this->const_map)[$status];
$data = $this->kitsuModel->getMangaList($APIstatus);
return $this->map_by_status($data)[$status]; return $this->map_by_status($data)[$status];
/*$data = $this->cache->get($this, '_get_list_from_api');
return ($status !== 'All') ? $data[$status] : $data;*/
} }
@ -117,8 +124,7 @@ class Manga extends API {
*/ */
public function get_manga($manga_id) public function get_manga($manga_id)
{ {
$raw = $this->_manga_api_call('get', "manga/{$manga_id}.json"); return $this->kitsuModel->getManga($manga_id);
return Json::decode($raw['body'], TRUE);
} }
/** /**
@ -146,7 +152,7 @@ class Manga extends API {
$entry['manga']['slug'], $entry['manga']['slug'],
'manga' 'manga'
);*/ );*/
$key = $this->const_map[$entry['reading_status']]; $key = $this->status_map[$entry['reading_status']];
$output[$key][] = $entry; $output[$key][] = $entry;
} }