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()): ?>
<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>

View File

@ -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 />

View File

@ -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 ?>

View File

@ -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

View File

@ -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;
@ -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 = [

View File

@ -34,12 +34,10 @@ 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)
@ -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;
}

View File

@ -33,7 +33,23 @@ class MangaTransformer extends AbstractTransformer {
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;
}
}

View File

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

View File

@ -46,6 +46,14 @@ class Manga extends API {
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)
{
parent::__construct($container);
@ -102,10 +110,9 @@ class Manga extends API {
*/
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];
/*$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)
{
$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;
}