Update manga model to use Zipper transformer

This commit is contained in:
Timothy Warren 2015-09-21 09:48:15 -04:00
parent 8fb6dae119
commit 92d9124bb7
2 changed files with 16 additions and 10 deletions

View File

@ -16,7 +16,7 @@
<?php endif ?>
<img src="<?= $escape->attr($item['manga']['poster_image']) ?>" />
<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']) ?>
<?= (isset($item['manga']['english_title'])) ? "<br />({$item['manga']['english_title']})" : ""; ?>
</a>

View File

@ -5,6 +5,7 @@
namespace Aviat\AnimeClient\Model;
use Aviat\AnimeClient\Model\API;
use Aviat\AnimeClient\Transformer\Hummingbird;
/**
* Model for handling requests dealing with the manga list
@ -127,21 +128,15 @@ class Manga extends API {
'Dropped' => [],
'Completed' => [],
];
$manga_data = [];
// Massage the two lists into one
foreach($raw_data['manga'] as $manga)
{
$manga_data[$manga['id']] = $manga;
}
$manga_data = $this->zipper_lists($raw_data);
// 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
$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'])
{
@ -171,6 +166,17 @@ class Manga extends API {
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
*