Version 5.1 - All the GraphQL #32
@ -14,6 +14,7 @@
|
||||
<th>Type</th>
|
||||
<th>Progress</th>
|
||||
<th>Rated</th>
|
||||
<th>Notes</th>
|
||||
<th>Genres</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -26,15 +27,16 @@
|
||||
</a>
|
||||
</td>
|
||||
<td class="align_left"><?= $item['anime']['alternate_title'] ?></td>
|
||||
<td class="align_left"><?= $item['anime']['status'] ?></td>
|
||||
<td><?= (int)($item['rating']['value'] * 2) ?> / 10 </td>
|
||||
<td><?= $item['anime']['show_type'] ?></td>
|
||||
<td>Episodes: <?= $item['episodes_watched'] ?> / <?= $item['anime']['episode_count'] ?></td>
|
||||
<td class="align_left"><?= $item['airing']['status'] ?></td>
|
||||
<td><?= $item['user_rating'] ?> / 10 </td>
|
||||
<td><?= $item['anime']['type'] ?></td>
|
||||
<td>Episodes: <?= $item['episodes']['watched'] ?> / <?= $item['episodes']['total'] ?></td>
|
||||
<td><?= $item['anime']['age_rating'] ?></td>
|
||||
<td><?= $item['notes'] ?></td>
|
||||
<td class="flex flex-justify-space-around align-left">
|
||||
<?php sort($item['anime']['genres']) ?>
|
||||
<?php foreach($item['anime']['genres'] as $genre): ?>
|
||||
<span><?= $genre['name'] ?></span>
|
||||
<span><?= $genre ?></span>
|
||||
<?php endforeach ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<main>
|
||||
<?php if (is_logged_in()): ?>
|
||||
<?php /* if (is_logged_in()): ?>
|
||||
[<a href="<?= $urlGenerator->full_url('collection/add', 'anime') ?>">Add Item</a>]
|
||||
<?php endif ?>
|
||||
<?php endif */ ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
<?php else: ?>
|
||||
@ -17,9 +17,9 @@
|
||||
<th>Show Type</th>
|
||||
<th>Age Rating</th>
|
||||
<th>Notes</th>
|
||||
<?php if (is_logged_in()): ?>
|
||||
<?php /*if (is_logged_in()): ?>
|
||||
<th> </th>
|
||||
<?php endif ?>
|
||||
<?php endif*/ ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -42,9 +42,9 @@
|
||||
<td><?= $item['show_type'] ?></td>
|
||||
<td><?= $item['age_rating'] ?></td>
|
||||
<td class="align_left"><?= $item['notes'] ?></td>
|
||||
<?php if (is_logged_in()): ?>
|
||||
<?php /* if (is_logged_in()): ?>
|
||||
<td>[<a href="<?= $urlGenerator->full_url("collection/edit/{$item['hummingbird_id']}", "anime") ?>">Edit</a>]</td>
|
||||
<?php endif ?>
|
||||
<?php endif */ ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<main>
|
||||
<?= $message ?>
|
||||
<aside>
|
||||
<form method="post" action="<?= $config->full_url('/login', $url_type) ?>">
|
||||
<form method="post" action="<?= $urlGenerator->full_url('/login', $url_type) ?>">
|
||||
<dl>
|
||||
<?php /*<dt><label for="username">Username: </label></dt>
|
||||
<dd><input type="text" id="username" name="username" required="required" /></dd>*/ ?>
|
||||
|
@ -14,27 +14,27 @@
|
||||
<button class="plus_one_volume">+1 Volume</button>
|
||||
</div>
|
||||
<?php endif*/ ?>
|
||||
<img src="<?= $escape->attr($item['manga']['poster_image']) ?>" />
|
||||
<img src="<?= $escape->attr($item['manga']['image']) ?>" />
|
||||
<div class="name">
|
||||
<a href="https://hummingbird.me/manga/<?= $item['manga']['id'] ?>">
|
||||
<?= $escape->html($item['manga']['romaji_title']) ?>
|
||||
<?= (isset($item['manga']['english_title'])) ? "<br />({$item['manga']['english_title']})" : ""; ?>
|
||||
<a href="<?= $item['manga']['url'] ?>">
|
||||
<?= $escape->html($item['manga']['title']) ?>
|
||||
<?= (isset($item['manga']['alternate_title'])) ? "<br />({$item['manga']['alternate_title']})" : ""; ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<div class="user_rating">Rating: <?= ($item['rating'] > 0) ? (int)($item['rating'] * 2) : '-' ?> / 10</div>
|
||||
<div class="user_rating">Rating: <?= $item['user_rating'] ?> / 10</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="chapter_completion">
|
||||
Chapters: <span class="chapters_read"><?= $item['chapters_read'] ?></span> /
|
||||
<span class="chapter_count"><?= ($item['manga']['chapter_count'] > 0) ? $item['manga']['chapter_count'] : "-" ?></span>
|
||||
Chapters: <span class="chapters_read"><?= $item['chapters']['read'] ?></span> /
|
||||
<span class="chapter_count"><?= $item['chapters']['total'] ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="volume_completion">
|
||||
Volumes: <span class="volumes_read"><?= $item['volumes_read'] ?></span> /
|
||||
<span class="volume_count"><?= ($item['manga']['volume_count'] > 0) ? $item['manga']['volume_count'] : "-" ?></span>
|
||||
Volumes: <span class="volumes_read"><?= $item['volumes']['read'] ?></span> /
|
||||
<span class="volume_count"><?= $item['volumes']['total'] ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -19,14 +19,14 @@
|
||||
<tr id="manga-<?= $item['manga']['id'] ?>">
|
||||
<td class="align_left">
|
||||
<a href="https://hummingbird.me/manga/<?= $item['manga']['id'] ?>">
|
||||
<?= $item['manga']['romaji_title'] ?>
|
||||
<?= $item['manga']['title'] ?>
|
||||
</a>
|
||||
<?= (array_key_exists('english_title', $item['manga'])) ? " · " . $item['manga']['english_title'] : "" ?>
|
||||
<?= ( ! is_null($item['manga']['alternate_title'])) ? " · " . $item['manga']['alternate_title'] : "" ?>
|
||||
</td>
|
||||
<td><?= ($item['rating'] > 0) ? (int)($item['rating'] * 2) : '-' ?> / 10</td>
|
||||
<td><?= $item['chapters_read'] ?> / <?= ($item['manga']['chapter_count'] > 0) ? $item['manga']['chapter_count'] : "-" ?></td>
|
||||
<td><?= $item['volumes_read'] ?> / <?= ($item['manga']['volume_count'] > 0) ? $item['manga']['volume_count'] : "-" ?></td>
|
||||
<td><?= $item['manga']['manga_type'] ?></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['manga']['type'] ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
|
@ -6,11 +6,21 @@
|
||||
namespace Aviat\AnimeClient\Model;
|
||||
|
||||
use Aviat\AnimeClient\Model\API;
|
||||
use Aviat\AnimeClient\Enum\Hummingbird\AnimeWatchingStatus;
|
||||
use Aviat\AnimeClient\Transformer\Hummingbird\AnimeListTransformer;
|
||||
|
||||
/**
|
||||
* Model for handling requests dealing with the anime list
|
||||
*/
|
||||
class Anime extends API {
|
||||
|
||||
// Display constants
|
||||
const WATCHING = 'Watching';
|
||||
const PLAN_TO_WATCH = 'Plan to Watch';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
|
||||
/**
|
||||
* The base url for api requests
|
||||
* @var string $base_url
|
||||
@ -42,11 +52,11 @@ class Anime extends API {
|
||||
public function get_all_lists()
|
||||
{
|
||||
$output = [
|
||||
'Watching' => [],
|
||||
'Plan to Watch' => [],
|
||||
'On Hold' => [],
|
||||
'Dropped' => [],
|
||||
'Completed' => [],
|
||||
self::WATCHING => [],
|
||||
self::PLAN_TO_WATCH => [],
|
||||
self::ON_HOLD => [],
|
||||
self::DROPPED => [],
|
||||
self::COMPLETED => [],
|
||||
];
|
||||
|
||||
$data = $this->_get_list();
|
||||
@ -55,24 +65,24 @@ class Anime extends API {
|
||||
{
|
||||
switch($datum['status'])
|
||||
{
|
||||
case "completed":
|
||||
$output['Completed'][] = $datum;
|
||||
case AnimeWatchingStatus::COMPLETED:
|
||||
$output[self::COMPLETED][] = $datum;
|
||||
break;
|
||||
|
||||
case "plan-to-watch":
|
||||
$output['Plan to Watch'][] = $datum;
|
||||
case AnimeWatchingStatus::PLAN_TO_WATCH:
|
||||
$output[self::PLAN_TO_WATCH][] = $datum;
|
||||
break;
|
||||
|
||||
case "dropped":
|
||||
$output['Dropped'][] = $datum;
|
||||
case AnimeWatchingStatus::DROPPED:
|
||||
$output[self::DROPPED][] = $datum;
|
||||
break;
|
||||
|
||||
case "on-hold":
|
||||
$output['On Hold'][] = $datum;
|
||||
case AnimeWatchingStatus::ON_HOLD:
|
||||
$output[self::ON_HOLD][] = $datum;
|
||||
break;
|
||||
|
||||
case "currently-watching":
|
||||
$output['Watching'][] = $datum;
|
||||
case AnimeWatchingStatus::WATCHING:
|
||||
$output[self::WATCHING][] = $datum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -95,14 +105,14 @@ class Anime extends API {
|
||||
public function get_list($status)
|
||||
{
|
||||
$map = [
|
||||
'currently-watching' => 'Watching',
|
||||
'plan-to-watch' => 'Plan to Watch',
|
||||
'on-hold' => 'On Hold',
|
||||
'dropped' => 'Dropped',
|
||||
'completed' => 'Completed',
|
||||
AnimeWatchingStatus::WATCHING => self::WATCHING,
|
||||
AnimeWatchingStatus::PLAN_TO_WATCH => self::PLAN_TO_WATCH,
|
||||
AnimeWatchingStatus::ON_HOLD => self::ON_HOLD,
|
||||
AnimeWatchingStatus::DROPPED => self::DROPPED,
|
||||
AnimeWatchingStatus::COMPLETED => self::COMPLETED,
|
||||
];
|
||||
|
||||
$data = $this->_get_list($status);
|
||||
$data = $this->_get_list_From_api($status);
|
||||
$this->sort_by_name($data);
|
||||
|
||||
$output = [];
|
||||
@ -158,17 +168,13 @@ class Anime extends API {
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually retreive the data from the api
|
||||
* Retrieve data from the api
|
||||
*
|
||||
* @param string $status - Status to filter by
|
||||
* @param string $status
|
||||
* @return array
|
||||
*/
|
||||
private function _get_list($status="all")
|
||||
private function _get_list_from_api($status="all")
|
||||
{
|
||||
$errorHandler = $this->container->get('error-handler');
|
||||
|
||||
$cache_file = "{$this->config->data_cache_path}/anime-{$status}.json";
|
||||
|
||||
$config = [
|
||||
'allow_redirects' => FALSE
|
||||
];
|
||||
@ -179,45 +185,45 @@ class Anime extends API {
|
||||
}
|
||||
|
||||
$response = $this->client->get("users/{$this->config->hummingbird_username}/library", $config);
|
||||
|
||||
$errorHandler->addDataTable('anime_list_response', (array)$response);
|
||||
|
||||
if ($response->getStatusCode() != 200)
|
||||
{
|
||||
if ( ! file_exists($cache_file))
|
||||
{
|
||||
throw new DomainException($response->getEffectiveUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = json_decode(file_get_contents($cache_file), TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = $response->json();
|
||||
$output_json = json_encode($output);
|
||||
|
||||
if (( ! file_exists($cache_file)) || file_get_contents($cache_file) !== $output_json)
|
||||
{
|
||||
// Attempt to create the cache folder if it doesn't exist
|
||||
if ( ! is_dir($this->config->data_cache_path))
|
||||
{
|
||||
mkdir($this->config->data_cache_path);
|
||||
}
|
||||
// Cache the call in case of downtime
|
||||
file_put_contents($cache_file, json_encode($output));
|
||||
}
|
||||
}
|
||||
$output = $this->_check_cache($status, $response);
|
||||
|
||||
foreach($output as &$row)
|
||||
{
|
||||
$row['anime']['cover_image'] = $this->get_cached_image($row['anime']['cover_image'], $row['anime']['slug'], 'anime');
|
||||
$row['anime']['image'] = $this->get_cached_image($row['anime']['image'], $row['anime']['slug'], 'anime');
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle caching of transformed api data
|
||||
*
|
||||
* @param string $status
|
||||
* @param \GuzzleHttp\Message\Response
|
||||
* @return array
|
||||
*/
|
||||
private function _check_cache($status, $response)
|
||||
{
|
||||
$cache_file = "{$this->config->data_cache_path}/anime-{$status}.json";
|
||||
$transformed_cache_file = "{$this->config->data_cache_path}/anime-{$status}-transformed.json";
|
||||
|
||||
$cached = json_decode(file_get_contents($cache_file), TRUE);
|
||||
$api = $response->json();
|
||||
|
||||
if ($api !== $cached)
|
||||
{
|
||||
file_put_contents($cache_file, json_encode($api));
|
||||
$transformer = new AnimeListTransformer();
|
||||
$transformed = $transformer->transform_collection($api);
|
||||
file_put_contents($transformed_cache_file, json_encode($transformed));
|
||||
return $transformed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return json_decode(file_get_contents($transformed_cache_file),TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the list by title
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user