Update manga model to use Zipper transformer

This commit is contained in:
Timothy Warren 2015-09-21 09:48:15 -04:00
parent f87dd2636d
commit 082b5296b9
2 changed files with 16 additions and 10 deletions

View File

@ -16,7 +16,7 @@
<?php endif ?> <?php endif ?>
<img src="<?= $escape->attr($item['manga']['poster_image']) ?>" /> <img src="<?= $escape->attr($item['manga']['poster_image']) ?>" />
<div class="name"> <div class="name">
<a href="https://hummingbird.me/manga/<?= $item['manga_id'] ?>"> <a href="https://hummingbird.me/manga/<?= $item['manga']['id'] ?>">
<?= $escape->html($item['manga']['romaji_title']) ?> <?= $escape->html($item['manga']['romaji_title']) ?>
<?= (isset($item['manga']['english_title'])) ? "<br />({$item['manga']['english_title']})" : ""; ?> <?= (isset($item['manga']['english_title'])) ? "<br />({$item['manga']['english_title']})" : ""; ?>
</a> </a>

View File

@ -5,6 +5,7 @@
namespace Aviat\AnimeClient\Model; namespace Aviat\AnimeClient\Model;
use Aviat\AnimeClient\Model\API; use Aviat\AnimeClient\Model\API;
use Aviat\AnimeClient\Transformer\Hummingbird;
/** /**
* Model for handling requests dealing with the manga list * Model for handling requests dealing with the manga list
@ -127,21 +128,15 @@ class Manga extends API {
'Dropped' => [], 'Dropped' => [],
'Completed' => [], 'Completed' => [],
]; ];
$manga_data = [];
// Massage the two lists into one // Massage the two lists into one
foreach($raw_data['manga'] as $manga) $manga_data = $this->zipper_lists($raw_data);
{
$manga_data[$manga['id']] = $manga;
}
// Filter data by status // Filter data by status
foreach($raw_data['manga_library_entries'] as &$entry) foreach($manga_data as &$entry)
{ {
$entry['manga'] = $manga_data[$entry['manga_id']];
// Cache poster images // Cache poster images
$entry['manga']['poster_image'] = $this->get_cached_image($entry['manga']['poster_image'], $entry['manga_id'], 'manga'); $entry['manga']['poster_image'] = $this->get_cached_image($entry['manga']['poster_image'], $entry['manga']['id'], 'manga');
switch($entry['status']) switch($entry['status'])
{ {
@ -171,6 +166,17 @@ class Manga extends API {
return (array_key_exists($status, $data)) ? $data[$status] : $data; return (array_key_exists($status, $data)) ? $data[$status] : $data;
} }
/**
* Combine the two manga lists into one
* @param array $raw_data
* @return array
*/
private function zipper_lists($raw_data)
{
$zipper = new Hummingbird\MangaListsZipper($raw_data);
return $zipper->transform();
}
/** /**
* Sort the manga entries by their title * Sort the manga entries by their title
* *