2016-12-20 12:55:43 -05:00
|
|
|
<?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
|
|
|
|
*
|
2017-01-06 23:34:56 -05:00
|
|
|
* @package AnimeListClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2016-12-20 12:55:43 -05:00
|
|
|
* @copyright 2015 - 2016 Timothy J. Warren
|
2017-01-06 23:34:56 -05:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 4.0
|
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
2016-12-20 12:55:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
|
|
|
|
|
2017-01-05 22:24:45 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu;
|
2017-01-03 21:06:49 -05:00
|
|
|
use Aviat\Ion\StringWrapper;
|
2016-12-20 12:55:43 -05:00
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data transformation class for zippered Hummingbird manga
|
|
|
|
*/
|
|
|
|
class MangaListTransformer extends AbstractTransformer {
|
|
|
|
|
2017-01-03 21:06:49 -05:00
|
|
|
use StringWrapper;
|
2016-12-20 12:55:43 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remap zipped anime data to a more logical form
|
|
|
|
*
|
|
|
|
* @param array $item manga entry item
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform($item)
|
|
|
|
{
|
2017-01-05 22:24:45 -05:00
|
|
|
/*?><pre><?= print_r($item, TRUE) ?></pre><?php*/
|
2016-12-20 12:55:43 -05:00
|
|
|
$manga =& $item['manga'];
|
|
|
|
|
2017-01-04 13:16:58 -05:00
|
|
|
$rating = (is_numeric($item['attributes']['rating']))
|
|
|
|
? intval(2 * $item['attributes']['rating'])
|
2016-12-20 12:55:43 -05:00
|
|
|
: '-';
|
|
|
|
|
2017-01-03 21:06:49 -05:00
|
|
|
$total_chapters = ($manga['attributes']['chapterCount'] > 0)
|
|
|
|
? $manga['attributes']['chapterCount']
|
2017-01-04 13:16:58 -05:00
|
|
|
: '-';
|
2016-12-20 12:55:43 -05:00
|
|
|
|
2017-01-03 21:06:49 -05:00
|
|
|
$total_volumes = ($manga['attributes']['volumeCount'] > 0)
|
|
|
|
? $manga['attributes']['volumeCount']
|
2016-12-20 12:55:43 -05:00
|
|
|
: '-';
|
|
|
|
|
|
|
|
$map = [
|
|
|
|
'id' => $item['id'],
|
|
|
|
'chapters' => [
|
2017-01-04 13:16:58 -05:00
|
|
|
'read' => $item['attributes']['progress'],
|
2016-12-20 12:55:43 -05:00
|
|
|
'total' => $total_chapters
|
|
|
|
],
|
|
|
|
'volumes' => [
|
2017-01-04 13:16:58 -05:00
|
|
|
'read' => '-', //$item['attributes']['volumes_read'],
|
2016-12-20 12:55:43 -05:00
|
|
|
'total' => $total_volumes
|
|
|
|
],
|
|
|
|
'manga' => [
|
2017-01-05 22:24:45 -05:00
|
|
|
'titles' => Kitsu::filterTitles($manga['attributes']),
|
2016-12-20 12:55:43 -05:00
|
|
|
'alternate_title' => NULL,
|
2017-01-05 22:24:45 -05:00
|
|
|
'slug' => $manga['attributes']['slug'],
|
|
|
|
'url' => 'https://kitsu.io/manga/' . $manga['attributes']['slug'],
|
2017-01-04 13:16:58 -05:00
|
|
|
'type' => $manga['attributes']['mangaType'],
|
|
|
|
'image' => $manga['attributes']['posterImage']['small'],
|
|
|
|
'genres' => [], //$manga['genres'],
|
2016-12-20 12:55:43 -05:00
|
|
|
],
|
2017-01-04 13:16:58 -05:00
|
|
|
'reading_status' => $item['attributes']['status'],
|
|
|
|
'notes' => $item['attributes']['notes'],
|
|
|
|
'rereading' => (bool)$item['attributes']['reconsuming'],
|
|
|
|
'reread' => $item['attributes']['reconsumeCount'],
|
2016-12-20 12:55:43 -05:00
|
|
|
'user_rating' => $rating,
|
|
|
|
];
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Untransform data to update the api
|
|
|
|
*
|
|
|
|
* @param array $item
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function untransform($item)
|
|
|
|
{
|
|
|
|
$rereading = (array_key_exists('rereading', $item)) && (bool)$item['rereading'];
|
|
|
|
|
|
|
|
$map = [
|
|
|
|
'id' => $item['id'],
|
2017-01-09 20:36:48 -05:00
|
|
|
'data' => [
|
|
|
|
'status' => $item['status'],
|
|
|
|
'progress' => (int)$item['chapters_read'],
|
|
|
|
'reconsuming' => $rereading,
|
|
|
|
'reconsumeCount' => (int)$item['reread_count'],
|
|
|
|
'notes' => $item['notes'],
|
|
|
|
],
|
2016-12-20 12:55:43 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($item['new_rating'] !== $item['old_rating'] && $item['new_rating'] !== "")
|
|
|
|
{
|
2017-01-09 20:36:48 -05:00
|
|
|
$map['data']['rating'] = ($item['new_rating'] > 0)
|
2016-12-20 12:55:43 -05:00
|
|
|
? $item['new_rating'] / 2
|
|
|
|
: $item['old_rating'] / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of MangaListTransformer.php
|