Remove data transformation from media detail pages, and into the proper transformers
timw4mail/HummingBirdAnimeClient/develop This commit looks good Details

This commit is contained in:
Timothy Warren 2018-11-08 12:15:30 -05:00
parent 27977a0c8a
commit 9ad74ed887
11 changed files with 94 additions and 74 deletions

View File

@ -39,6 +39,9 @@
</td> </td>
</tr> </tr>
</table> </table>
<br />
</aside> </aside>
<article class="text"> <article class="text">
<h2 class="toph"><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2> <h2 class="toph"><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2>
@ -141,7 +144,6 @@
<?php endif ?> <?php endif ?>
<?php if (count($data['staff']) > 0): ?> <?php if (count($data['staff']) > 0): ?>
<?php //dump($data['staff']); ?>
<section> <section>
<h2>Staff</h2> <h2>Staff</h2>

View File

@ -25,6 +25,8 @@
</td> </td>
</tr> </tr>
</table> </table>
<br />
</aside> </aside>
<article class="text"> <article class="text">
<h2 class="toph"><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2> <h2 class="toph"><a rel="external" href="<?= $data['url'] ?>"><?= $data['title'] ?></a></h2>
@ -37,11 +39,12 @@
</article> </article>
</section> </section>
<?php if (count($characters) > 0): ?> <?php if (count($data['characters']) > 0): ?>
<h2>Characters</h2> <h2>Characters</h2>
<div class="tabs"> <div class="tabs">
<?php $i = 0 ?> <?php $i = 0 ?>
<?php foreach ($characters as $role => $list): ?> <?php foreach ($data['characters'] as $role => $list): ?>
<input <input
type="radio" name="character-role-tabs" type="radio" name="character-role-tabs"
id="character-tabs<?= $i ?>" <?= $i === 0 ? 'checked' : '' ?> /> id="character-tabs<?= $i ?>" <?= $i === 0 ? 'checked' : '' ?> />
@ -66,12 +69,12 @@
</div> </div>
<?php endif ?> <?php endif ?>
<?php if (count($staff) > 0): ?> <?php if (count($data['staff']) > 0): ?>
<h2>Staff</h2> <h2>Staff</h2>
<div class="vertical-tabs"> <div class="vertical-tabs">
<?php $i = 0 ?> <?php $i = 0 ?>
<?php foreach ($staff as $role => $people): ?> <?php foreach ($data['staff'] as $role => $people): ?>
<div class="tab"> <div class="tab">
<input <input
type="radio" name="staff-roles" id="staff-role<?= $i ?>" <?= $i === 0 ? 'checked' : '' ?> /> type="radio" name="staff-roles" id="staff-role<?= $i ?>" <?= $i === 0 ? 'checked' : '' ?> />

File diff suppressed because one or more lines are too long

View File

@ -39,23 +39,26 @@
table .align-right, table .align-right,
table.align-center { table.align-center {
border: 0; border: 0;
display: block; /* display: block; */
margin: 0 auto; margin-left: auto;
margin-right: auto;
text-align: left; text-align: left;
width: 100%; width: 100%;
} }
table tbody {
width: 100%;
}
table td { table td {
display: inline-block; display: inline-block;
} }
table tbody,
table.media-details {
width: 100%;
}
table.media-details td { table.media-details td {
display: block; display: block;
text-align: left !important; text-align: left !important;
width: 100%;
} }
table thead { table thead {

View File

@ -22,7 +22,7 @@ use Aviat\AnimeClient\Types\Character;
use Aviat\Ion\Transformer\AbstractTransformer; use Aviat\Ion\Transformer\AbstractTransformer;
/** /**
* Data transformation class for zippered Hummingbird manga * Data transformation class for character pages
*/ */
final class CharacterTransformer extends AbstractTransformer { final class CharacterTransformer extends AbstractTransformer {

View File

@ -51,13 +51,77 @@ final class MangaTransformer extends AbstractTransformer {
$rawTitles = array_values($item['titles']); $rawTitles = array_values($item['titles']);
$titles = array_unique(array_diff($rawTitles, [$title])); $titles = array_unique(array_diff($rawTitles, [$title]));
$characters = [];
$staff = [];
if (array_key_exists('mediaCharacters', $item['included']))
{
$mediaCharacters = $item['included']['mediaCharacters'];
foreach ($mediaCharacters as $rel)
{
// dd($rel);
// $charId = $rel['relationships']['character']['data']['id'];
$role = $rel['attributes']['role'];
foreach ($rel['relationships']['character']['characters'] as $charId => $char)
{
if (array_key_exists($charId, $item['included']['characters']))
{
$characters[$role][$charId] = $char['attributes'];
}
}
}
}
if (array_key_exists('mediaStaff', $item['included']))
{
foreach ($item['included']['mediaStaff'] as $id => $staffing)
{
$role = $staffing['attributes']['role'];
foreach ($staffing['relationships']['person']['people'] as $personId => $personDetails)
{
if ( ! array_key_exists($role, $staff))
{
$staff[$role] = [];
}
$staff[$role][$personId] = [
'id' => $personId,
'name' => $personDetails['attributes']['name'] ?? '??',
'image' => $personDetails['attributes']['image'],
];
}
}
}
if ( ! empty($characters['main']))
{
uasort($characters['main'], function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
if ( ! empty($characters['supporting']))
{
uasort($characters['supporting'], function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
ksort($characters);
ksort($staff);
return new MangaPage([ return new MangaPage([
'characters' => $characters,
'chapter_count' => $this->count($item['chapterCount']), 'chapter_count' => $this->count($item['chapterCount']),
'cover_image' => $item['posterImage']['small'], 'cover_image' => $item['posterImage']['small'],
'genres' => $genres, 'genres' => $genres,
'id' => $item['id'], 'id' => $item['id'],
'included' => $item['included'], 'included' => $item['included'],
'manga_type' => $item['mangaType'], 'manga_type' => $item['mangaType'],
'staff' => $staff,
'synopsis' => $item['synopsis'], 'synopsis' => $item['synopsis'],
'title' => $title, 'title' => $title,
'titles' => $titles, 'titles' => $titles,

View File

@ -21,7 +21,7 @@ use Aviat\AnimeClient\Types\Person;
use Aviat\Ion\Transformer\AbstractTransformer; use Aviat\Ion\Transformer\AbstractTransformer;
/** /**
* Data transformation class for zippered Hummingbird manga * Data transformation class for people pages
*/ */
final class PersonTransformer extends AbstractTransformer { final class PersonTransformer extends AbstractTransformer {

View File

@ -294,65 +294,6 @@ final class Manga extends Controller {
return; return;
} }
if (array_key_exists('mediaCharacters', $data['included']))
{
$mediaCharacters = $data['included']['mediaCharacters'];
foreach ($mediaCharacters as $rel)
{
// dd($rel);
// $charId = $rel['relationships']['character']['data']['id'];
$role = $rel['attributes']['role'];
foreach($rel['relationships']['character']['characters'] as $charId => $char)
{
if (array_key_exists($charId, $data['included']['characters']))
{
$characters[$role][$charId] = $char['attributes'];
}
}
}
}
if (array_key_exists('mediaStaff', $data['included']))
{
foreach ($data['included']['mediaStaff'] as $id => $staffing)
{
$role = $staffing['attributes']['role'];
foreach($staffing['relationships']['person']['people'] as $personId => $personDetails)
{
if ( ! array_key_exists($role, $staff))
{
$staff[$role] = [];
}
$staff[$role][$personId] = [
'id' => $personId,
'name' => $personDetails['attributes']['name'] ?? '??',
'image' => $personDetails['attributes']['image'],
];
}
}
}
if ( ! empty($characters['main']))
{
uasort($characters['main'], function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
if ( ! empty($characters['supporting']))
{
uasort($characters['supporting'], function ($a, $b) {
return $a['name'] <=> $b['name'];
});
}
ksort($characters);
ksort($staff);
$this->outputHTML('manga/details', [ $this->outputHTML('manga/details', [
'title' => $this->formatTitle( 'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List", $this->config->get('whose_list') . "'s Manga List",

View File

@ -20,12 +20,14 @@ namespace Aviat\AnimeClient\Types;
* Type representing an Anime object for display * Type representing an Anime object for display
*/ */
final class MangaPage extends AbstractType { final class MangaPage extends AbstractType {
public $characters;
public $chapter_count; public $chapter_count;
public $cover_image; public $cover_image;
public $genres; public $genres;
public $id; public $id;
public $included; public $included;
public $manga_type; public $manga_type;
public $staff;
public $synopsis; public $synopsis;
public $title; public $title;
public $titles; public $titles;

View File

@ -18,7 +18,6 @@ namespace Aviat\AnimeClient\Tests\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeTransformer; use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeTransformer;
use Aviat\AnimeClient\Tests\AnimeClientTestCase; use Aviat\AnimeClient\Tests\AnimeClientTestCase;
use Aviat\Ion\Friend;
use Aviat\Ion\Json; use Aviat\Ion\Json;
class AnimeTransformerTest extends AnimeClientTestCase { class AnimeTransformerTest extends AnimeClientTestCase {

View File

@ -1,4 +1,7 @@
<?php return Aviat\AnimeClient\Types\MangaPage::__set_state(array( <?php return Aviat\AnimeClient\Types\MangaPage::__set_state(array(
'characters' =>
array (
),
'chapter_count' => '-', 'chapter_count' => '-',
'cover_image' => 'https://media.kitsu.io/manga/poster_images/20286/small.jpg?1434293999', 'cover_image' => 'https://media.kitsu.io/manga/poster_images/20286/small.jpg?1434293999',
'genres' => 'genres' =>
@ -68,6 +71,9 @@
), ),
), ),
'manga_type' => 'manga', 'manga_type' => 'manga',
'staff' =>
array (
),
'synopsis' => 'Usa, a high-school student aspiring to begin a bachelor lifestyle, moves into a new apartment only to discover that he not only shares a room with a perverted roommate that has an obsession for underaged girls, but also that another girl, Ritsu, a love-at-first-sight, is living in the same building as well! 'synopsis' => 'Usa, a high-school student aspiring to begin a bachelor lifestyle, moves into a new apartment only to discover that he not only shares a room with a perverted roommate that has an obsession for underaged girls, but also that another girl, Ritsu, a love-at-first-sight, is living in the same building as well!
(Source: Kirei Cake)', (Source: Kirei Cake)',
'title' => 'Bokura wa Minna Kawaisou', 'title' => 'Bokura wa Minna Kawaisou',