Start of changes for Manga list

This commit is contained in:
Timothy Warren 2017-01-03 21:06:49 -05:00
parent 9bd5d62ca7
commit 772aeae20f
8 changed files with 121 additions and 157 deletions

View File

@ -23,7 +23,7 @@ return [
'on_hold' => '/on_hold', 'on_hold' => '/on_hold',
'dropped' => '/dropped', 'dropped' => '/dropped',
'completed' => '/completed', 'completed' => '/completed',
'all' => '/all' //'all' => '/all'
] ]
], ],
'manga_list' => [ 'manga_list' => [
@ -34,7 +34,7 @@ return [
'on_hold' => '/on_hold', 'on_hold' => '/on_hold',
'dropped' => '/dropped', 'dropped' => '/dropped',
'completed' => '/completed', 'completed' => '/completed',
'all' => '/all' //'all' => '/all'
] ]
] ]
]; ];

View File

@ -1,7 +1,7 @@
<main> <main>
<?php if ($auth->is_authenticated()): ?> <?php /* if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a> <a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a>
<?php endif ?> <?php endif */ ?>
<?php if (empty($sections)): ?> <?php if (empty($sections)): ?>
<h3>There's nothing here!</h3> <h3>There's nothing here!</h3>
<?php else: ?> <?php else: ?>
@ -11,12 +11,12 @@
<section class="media-wrap"> <section class="media-wrap">
<?php foreach($items as $item): ?> <?php foreach($items as $item): ?>
<article class="media" id="manga-<?= $item['id'] ?>"> <article class="media" id="manga-<?= $item['id'] ?>">
<?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> <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']) ?>" />
<div class="name"> <div class="name">
<a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>"> <a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>">
@ -25,13 +25,13 @@
</a> </a>
</div> </div>
<div class="table"> <div class="table">
<?php if ($auth->is_authenticated()): ?> <?php /*if ($auth->is_authenticated()): ?>
<div class="row"> <div class="row">
<span class="edit"> <span class="edit">
<a class="bracketed" title="Edit information about this manga" href="<?= $urlGenerator->url("manga/edit/{$item['id']}/{$name}") ?>">Edit</a> <a class="bracketed" title="Edit information about this manga" href="<?= $urlGenerator->url("manga/edit/{$item['id']}/{$name}") ?>">Edit</a>
</span> </span>
</div> </div>
<?php endif ?> <?php endif */ ?>
<div class="row"> <div class="row">
<div class="user_rating">Rating: <?= $item['user_rating'] ?> / 10</div> <div class="user_rating">Rating: <?= $item['user_rating'] ?> / 10</div>
</div> </div>
@ -55,6 +55,6 @@
<?php endforeach ?> <?php endforeach ?>
<?php endif ?> <?php endif ?>
</main> </main>
<?php if ($auth->is_authenticated()): ?> <?php /*if ($auth->is_authenticated()): ?>
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script> <script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
<?php endif ?> <?php endif*/ ?>

View File

@ -1,7 +1,7 @@
<main> <main>
<?php if ($auth->is_authenticated()): ?> <?php /*if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a> <a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a>
<?php endif ?> <?php endif*/ ?>
<?php if (empty($sections)): ?> <?php if (empty($sections)): ?>
<h3>There's nothing here!</h3> <h3>There's nothing here!</h3>
<?php else: ?> <?php else: ?>
@ -10,9 +10,9 @@
<table> <table>
<thead> <thead>
<tr> <tr>
<?php if ($auth->is_authenticated()): ?> <?php /*if ($auth->is_authenticated()): ?>
<th>&nbsp;</th> <th>&nbsp;</th>
<?php endif ?> <?php endif*/ ?>
<th>Title</th> <th>Title</th>
<th>Rating</th> <th>Rating</th>
<th>Chapters</th> <th>Chapters</th>
@ -23,11 +23,11 @@
<tbody> <tbody>
<?php foreach($items as $item): ?> <?php foreach($items as $item): ?>
<tr id="manga-<?= $item['id'] ?>"> <tr id="manga-<?= $item['id'] ?>">
<?php if($auth->is_authenticated()): ?> <?php /*if($auth->is_authenticated()): ?>
<td> <td>
<a class="bracketed" href="<?= $urlGenerator->url("manga/edit/{$item['id']}/{$name}") ?>">Edit</a> <a class="bracketed" href="<?= $urlGenerator->url("manga/edit/{$item['id']}/{$name}") ?>">Edit</a>
</td> </td>
<?php endif ?> <?php endif*/ ?>
<td class="align_left"> <td class="align_left">
<a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>"> <a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>">
<?= $item['manga']['title'] ?> <?= $item['manga']['title'] ?>

View File

@ -22,10 +22,10 @@ use Aviat\Ion\Enum as BaseEnum;
* Possible values for current reading status of manga * Possible values for current reading status of manga
*/ */
class MangaReadingStatus extends BaseEnum { class MangaReadingStatus extends BaseEnum {
const READING = 'Currently Reading'; const READING = 1;
const PLAN_TO_READ = 'Plan to Read'; const PLAN_TO_READ = 2;
const DROPPED = 'Dropped'; const DROPPED = 3;
const ON_HOLD = 'On Hold'; const ON_HOLD = 4;
const COMPLETED = 'Completed'; const COMPLETED = 5;
} }
// End of MangaReadingStatus.php // End of MangaReadingStatus.php

View File

@ -17,7 +17,9 @@
namespace Aviat\AnimeClient\API\Kitsu; namespace Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\AnimeClient; 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 Aviat\Ion\Json;
use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ClientException;
@ -45,6 +47,11 @@ class KitsuModel {
*/ */
protected $animeTransformer; protected $animeTransformer;
/**
* @var MangaListTransformer
*/
protected $mangaListTransformer;
/** /**
* KitsuModel constructor. * KitsuModel constructor.
*/ */
@ -55,6 +62,7 @@ class KitsuModel {
$this->animeTransformer = new AnimeTransformer(); $this->animeTransformer = new AnimeTransformer();
$this->animeListTransformer = new AnimeListTransformer(); $this->animeListTransformer = new AnimeListTransformer();
$this->mangaListTransformer = new MangaListTransformer();
} }
/** /**
@ -130,6 +138,36 @@ class KitsuModel {
return $transformed; 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 private function getGenres(string $type, string $id): array
{ {
$data = $this->getRequest("{$type}/{$id}/genres"); $data = $this->getRequest("{$type}/{$id}/genres");

View File

@ -16,6 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer; namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\Ion\StringWrapper;
use Aviat\Ion\Transformer\AbstractTransformer; use Aviat\Ion\Transformer\AbstractTransformer;
/** /**
@ -23,7 +24,7 @@ use Aviat\Ion\Transformer\AbstractTransformer;
*/ */
class MangaListTransformer extends AbstractTransformer { class MangaListTransformer extends AbstractTransformer {
use \Aviat\Ion\StringWrapper; use StringWrapper;
/** /**
* Remap zipped anime data to a more logical form * Remap zipped anime data to a more logical form
@ -33,18 +34,20 @@ 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['rating']))
? intval(2 * $item['rating']) ? intval(2 * $item['rating'])
: '-'; : '-';
$total_chapters = ($manga['chapter_count'] > 0) $total_chapters = ($manga['attributes']['chapterCount'] > 0)
? $manga['chapter_count'] ? $manga['attributes']['chapterCount']
: '-'; : '-';
$total_volumes = ($manga['volume_count'] > 0) $total_volumes = ($manga['attributes']['volumeCount'] > 0)
? $manga['volume_count'] ? $manga['attributes']['volumeCount']
: '-'; : '-';
$map = [ $map = [

View 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 [
];
}
}

View File

@ -18,6 +18,7 @@ namespace Aviat\AnimeClient\Model;
use Aviat\AnimeClient\API\Kitsu\Enum\MangaReadingStatus; use Aviat\AnimeClient\API\Kitsu\Enum\MangaReadingStatus;
use Aviat\AnimeClient\API\Kitsu\Transformer; use Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Json; use Aviat\Ion\Json;
use GuzzleHttp\Cookie\SetCookie; use GuzzleHttp\Cookie\SetCookie;
use RuntimeException; use RuntimeException;
@ -45,11 +46,12 @@ class Manga extends API {
MangaReadingStatus::COMPLETED => self::COMPLETED MangaReadingStatus::COMPLETED => self::COMPLETED
]; ];
/** public function __construct(ContainerInterface $container)
* The base url for api requests {
* @var string parent::__construct($container);
*/
protected $base_url = "https://hummingbird.me/"; $this->kitsuModel = $container->get('kitsu-model');
}
/** /**
* Make an authenticated manga API call * 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 * Get a category out of the full list
@ -179,51 +102,12 @@ class Manga extends API {
*/ */
public function get_list($status) public function get_list($status)
{ {
$data = $this->cache->get($this, '_get_list_from_api'); $data = $this->kitsuModel->getMangaList($status);
return ($status !== 'All') ? $data[$status] : $data; 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 * Get the details of a manga
@ -257,11 +141,11 @@ class Manga extends API {
foreach ($data as &$entry) foreach ($data as &$entry)
{ {
$entry['manga']['image'] = $util->get_cached_image( /*$entry['manga']['image'] = $util->get_cached_image(
$entry['manga']['image'], $entry['manga']['image'],
$entry['manga']['slug'], $entry['manga']['slug'],
'manga' 'manga'
); );*/
$key = $this->const_map[$entry['reading_status']]; $key = $this->const_map[$entry['reading_status']];
$output[$key][] = $entry; $output[$key][] = $entry;
} }