2017-01-12 15:41:20 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2017-01-12 15:41:20 -05:00
|
|
|
*
|
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
|
|
|
*
|
|
|
|
* PHP version 7
|
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2017-01-12 15:41:20 -05:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-15 14:43:15 -05:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2017-01-12 15:41:20 -05:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 4.0
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-01-12 15:41:20 -05:00
|
|
|
*/
|
|
|
|
|
2017-02-04 15:18:34 -05:00
|
|
|
namespace Aviat\AnimeClient\API\MAL\Transformer;
|
2017-01-12 15:41:20 -05:00
|
|
|
|
2017-03-02 11:12:19 -05:00
|
|
|
use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus;
|
2018-08-15 16:19:07 -04:00
|
|
|
use Aviat\AnimeClient\Types\AnimeFormItem;
|
2017-01-12 15:41:20 -05:00
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transformer for updating MAL List
|
|
|
|
*/
|
2018-08-08 10:12:45 -04:00
|
|
|
final class AnimeListTransformer extends AbstractTransformer {
|
2017-02-14 15:29:13 -05:00
|
|
|
/**
|
2017-03-29 12:32:36 -04:00
|
|
|
* Identity transformation
|
2017-02-14 15:29:13 -05:00
|
|
|
*
|
|
|
|
* @param array $item
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-01-12 15:41:20 -05:00
|
|
|
public function transform($item)
|
|
|
|
{
|
2017-03-29 12:32:36 -04:00
|
|
|
return $item;
|
2017-01-12 15:41:20 -05:00
|
|
|
}
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-04 15:18:34 -05:00
|
|
|
/**
|
|
|
|
* Transform Kitsu episode data to MAL episode data
|
|
|
|
*
|
2017-03-02 11:12:19 -05:00
|
|
|
* @param array $item
|
2018-08-08 10:12:45 -04:00
|
|
|
* @return AnimeFormItem
|
2017-02-04 15:18:34 -05:00
|
|
|
*/
|
2018-08-08 10:12:45 -04:00
|
|
|
public function untransform(array $item): AnimeFormItem
|
2017-02-13 12:42:05 -05:00
|
|
|
{
|
2018-08-15 16:19:07 -04:00
|
|
|
$map = [
|
2017-02-04 15:18:34 -05:00
|
|
|
'id' => $item['mal_id'],
|
2018-08-15 16:19:07 -04:00
|
|
|
'data' => [],
|
|
|
|
];
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-13 12:42:05 -05:00
|
|
|
foreach($item['data'] as $key => $value)
|
2017-02-07 09:12:44 -05:00
|
|
|
{
|
2017-03-02 11:12:19 -05:00
|
|
|
switch($key)
|
2017-02-13 12:42:05 -05:00
|
|
|
{
|
2017-04-11 09:28:07 -04:00
|
|
|
case 'progress':
|
|
|
|
$map['data']['episode'] = $value;
|
|
|
|
break;
|
2018-08-08 10:12:45 -04:00
|
|
|
|
2017-02-13 12:42:05 -05:00
|
|
|
case 'notes':
|
|
|
|
$map['data']['comments'] = $value;
|
|
|
|
break;
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-13 12:42:05 -05:00
|
|
|
case 'rating':
|
|
|
|
$map['data']['score'] = $value * 2;
|
|
|
|
break;
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-13 13:33:01 -05:00
|
|
|
case 'reconsuming':
|
2017-02-13 12:42:05 -05:00
|
|
|
$map['data']['enable_rewatching'] = (bool) $value;
|
2017-02-08 00:44:57 -05:00
|
|
|
break;
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-13 12:42:05 -05:00
|
|
|
case 'reconsumeCount':
|
|
|
|
$map['data']['times_rewatched'] = $value;
|
2017-02-13 13:33:01 -05:00
|
|
|
break;
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-13 12:42:05 -05:00
|
|
|
case 'status':
|
2017-03-02 11:12:19 -05:00
|
|
|
$map['data']['status'] = AnimeWatchingStatus::KITSU_TO_MAL[$value];
|
2017-02-13 12:42:05 -05:00
|
|
|
break;
|
2017-03-02 11:12:19 -05:00
|
|
|
|
2017-02-13 12:42:05 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-02-07 09:12:44 -05:00
|
|
|
}
|
2017-02-13 12:42:05 -05:00
|
|
|
|
2018-08-15 16:19:07 -04:00
|
|
|
return new AnimeFormItem($map);
|
2017-02-04 15:18:34 -05:00
|
|
|
}
|
2017-01-12 15:41:20 -05:00
|
|
|
}
|