diff --git a/app/views/manga/edit.php b/app/views/manga/edit.php
index e74a1331..22bf95ca 100644
--- a/app/views/manga/edit.php
+++ b/app/views/manga/edit.php
@@ -74,6 +74,7 @@
+
@@ -92,6 +93,7 @@
+
diff --git a/app/views/manga/list.php b/app/views/manga/list.php
index 1c28fdcb..e9f4169f 100644
--- a/app/views/manga/list.php
+++ b/app/views/manga/list.php
@@ -18,6 +18,7 @@
Completed Chapters
# of Volumes
Type
+ Genres
@@ -40,6 +41,9 @@
= $item['chapters']['read'] ?> / = $item['chapters']['total'] ?>
= $item['volumes']['total'] ?>
= $item['manga']['type'] ?>
+
+ = implode(', ', $item['manga']['genres']) ?>
+
diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php
index 5247286c..f2111acc 100644
--- a/src/API/Kitsu/Model.php
+++ b/src/API/Kitsu/Model.php
@@ -530,7 +530,7 @@ class Model {
'media_type' => 'Manga',
'status' => $status,
],
- 'include' => 'media',
+ 'include' => 'media,media.genres,media.mappings',
'page' => [
'offset' => $offset,
'limit' => $limit
@@ -544,9 +544,16 @@ class Model {
if ( ! $cacheItem->isHit())
{
$data = $this->getRequest('library-entries', $options);
- $data = JsonAPI::inlineRawIncludes($data, 'manga');
- $transformed = $this->mangaListTransformer->transformCollection($data);
+ $included = JsonAPI::organizeIncludes($data['included']);
+ $included = JsonAPI::inlineIncludedRelationships($included, 'manga');
+
+ foreach($data['data'] as $i => &$item)
+ {
+ $item['included'] = $included;
+ }
+
+ $transformed = $this->mangaListTransformer->transformCollection($data['data']);
$cacheItem->set($transformed);
$cacheItem->save();
diff --git a/src/API/Kitsu/Transformer/MangaListTransformer.php b/src/API/Kitsu/Transformer/MangaListTransformer.php
index 6a63b970..462702ae 100644
--- a/src/API/Kitsu/Transformer/MangaListTransformer.php
+++ b/src/API/Kitsu/Transformer/MangaListTransformer.php
@@ -35,22 +35,42 @@ class MangaListTransformer extends AbstractTransformer {
*/
public function transform($item)
{
- $manga =& $item['manga'];
+ $included = $item['included'];
+ $mangaId = $item['relationships']['media']['data']['id'];
+ $manga = $included['manga'][$mangaId];
+
+ $genres = array_column($manga['relationships']['genres'], 'name') ?? [];
+ sort($genres);
$rating = (is_numeric($item['attributes']['rating']))
? intval(2 * $item['attributes']['rating'])
: '-';
- $totalChapters = ($manga['attributes']['chapterCount'] > 0)
- ? $manga['attributes']['chapterCount']
+ $totalChapters = ($manga['chapterCount'] > 0)
+ ? $manga['chapterCount']
: '-';
- $totalVolumes = ($manga['attributes']['volumeCount'] > 0)
- ? $manga['attributes']['volumeCount']
+ $totalVolumes = ($manga['volumeCount'] > 0)
+ ? $manga['volumeCount']
: '-';
+ $MALid = NULL;
+
+ if (array_key_exists('mappings', $manga['relationships']))
+ {
+ foreach ($manga['relationships']['mappings'] as $mapping)
+ {
+ if ($mapping['externalSite'] === 'myanimelist/manga')
+ {
+ $MALid = $mapping['externalId'];
+ break;
+ }
+ }
+ }
+
$map = [
'id' => $item['id'],
+ 'mal_id' => $MALid,
'chapters' => [
'read' => $item['attributes']['progress'],
'total' => $totalChapters
@@ -60,13 +80,13 @@ class MangaListTransformer extends AbstractTransformer {
'total' => $totalVolumes
],
'manga' => [
- 'titles' => Kitsu::filterTitles($manga['attributes']),
+ 'titles' => Kitsu::filterTitles($manga),
'alternate_title' => NULL,
- 'slug' => $manga['attributes']['slug'],
- 'url' => 'https://kitsu.io/manga/' . $manga['attributes']['slug'],
- 'type' => $manga['attributes']['mangaType'],
- 'image' => $manga['attributes']['posterImage']['small'],
- 'genres' => [], //$manga['genres'],
+ 'slug' => $manga['slug'],
+ 'url' => 'https://kitsu.io/manga/' . $manga['slug'],
+ 'type' => $manga['mangaType'],
+ 'image' => $manga['posterImage']['small'],
+ 'genres' => $genres,
],
'reading_status' => $item['attributes']['status'],
'notes' => $item['attributes']['notes'],
@@ -90,6 +110,7 @@ class MangaListTransformer extends AbstractTransformer {
$map = [
'id' => $item['id'],
+ 'mal_id' => $item['mal_id'],
'data' => [
'status' => $item['status'],
'progress' => (int)$item['chapters_read'],
diff --git a/src/API/MAL/Model.php b/src/API/MAL/Model.php
index 7ef64243..d9677769 100644
--- a/src/API/MAL/Model.php
+++ b/src/API/MAL/Model.php
@@ -17,7 +17,11 @@
namespace Aviat\AnimeClient\API\MAL;
use Amp\Artax\Request;
-use Aviat\AnimeClient\API\MAL\{ListItem, Transformer\AnimeListTransformer};
+use Aviat\AnimeClient\API\MAL\{
+ ListItem,
+ Transformer\AnimeListTransformer,
+ Transformer\MangaListTransformer
+};
use Aviat\AnimeClient\API\XML;
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
use Aviat\Ion\Di\ContainerAware;
@@ -33,7 +37,7 @@ class Model {
* @var AnimeListTransformer
*/
protected $animeListTransformer;
-
+
/**
* @var ListItem
*/
@@ -47,6 +51,7 @@ class Model {
public function __construct(ListItem $listItem)
{
$this->animeListTransformer = new AnimeListTransformer();
+ $this->mangaListTransformer = new MangaListTransformer();
$this->listItem = $listItem;
}
@@ -83,9 +88,7 @@ class Model {
];
}
-
-
- return $this->listItem->create($createData);
+ return $this->listItem->create($createData, $type);
}
public function getMangaList(): array
@@ -103,15 +106,23 @@ class Model {
return [];
}
- public function updateListItem(array $data): Request
+ public function updateListItem(array $data, string $type = 'anime'): Request
{
- $updateData = $this->animeListTransformer->untransform($data);
- return $this->listItem->update($updateData['id'], $updateData['data']);
+ if ($type === 'anime')
+ {
+ $updateData = $this->animeListTransformer->untransform($data);
+ }
+ else if ($type === 'manga')
+ {
+ $updateData = $this->mangaListTransformer->untransform($data);
+ }
+
+ return $this->listItem->update($updateData['id'], $updateData['data'], $type);
}
- public function deleteListItem(string $id): Request
+ public function deleteListItem(string $id, string $type = 'anime'): Request
{
- return $this->listItem->delete($id);
+ return $this->listItem->delete($id, $type);
}
private function getList(string $type): array
diff --git a/src/Model/Manga.php b/src/Model/Manga.php
index a772faca..e909089a 100644
--- a/src/Model/Manga.php
+++ b/src/Model/Manga.php
@@ -22,6 +22,7 @@ use Aviat\AnimeClient\API\{
ParallelAPIRequest
};
use Aviat\Ion\Di\ContainerInterface;
+use Aviat\Ion\Json;
/**
* Model for handling requests dealing with the manga list
@@ -83,17 +84,6 @@ class Manga extends API
return $this->kitsuModel->getManga($manga_id);
}
- /**
- * Create a new manga list item
- *
- * @param array $data
- * @return bool
- */
- public function createLibraryItem(array $data): bool
- {
- return $this->kitsuModel->createListItem($data);
- }
-
/**
* Get information about a specific list item
* for editing/updating that item
@@ -106,6 +96,35 @@ class Manga extends API
return $this->kitsuModel->getListItem($itemId);
}
+ /**
+ * Create a new manga list item
+ *
+ * @param array $data
+ * @return bool
+ */
+ public function createLibraryItem(array $data): bool
+ {
+ $requester = new ParallelAPIRequest();
+
+ if ($this->useMALAPI)
+ {
+ $malData = $data;
+ $malId = $this->kitsuModel->getMalIdForManga($malData['id']);
+
+ if ( ! is_null($malId))
+ {
+ $malData['id'] = $malId;
+ $requester->addRequest($this->malModel->createListItem($malData, 'manga'), 'mal');
+ }
+ }
+
+ $requester->addRequest($this->kitsuModel->createListItem($data), 'kitsu');
+
+ $results = $requester->makeRequests(TRUE);
+
+ return count($results[1]) > 0;
+ }
+
/**
* Update a list entry
*
@@ -114,18 +133,44 @@ class Manga extends API
*/
public function updateLibraryItem(array $data): array
{
- return $this->kitsuModel->updateListItem($data);
+ $requester = new ParallelAPIRequest();
+
+ if ($this->useMALAPI)
+ {
+ $requester->addRequest($this->malModel->updateListItem($data, 'manga'), 'mal');
+ }
+
+ $requester->addRequest($this->kitsuModel->updateListItem($data), 'kitsu');
+
+ $results = $requester->makeRequests(TRUE);
+
+ return [
+ 'body' => Json::decode($results[1]['kitsu']->getBody()),
+ 'statusCode' => $results[1]['kitsu']->getStatus()
+ ];
}
/**
- * Remove a list entry
+ * Delete a list entry
*
- * @param string $itemId
+ * @param string $id
+ * @param string|null $malId
* @return bool
*/
- public function deleteLibraryItem(string $itemId): bool
+ public function deleteLibraryItem(string $id, string $malId = NULL): bool
{
- return $this->kitsuModel->deleteListItem($itemId);
+ $requester = new ParallelAPIRequest();
+
+ if ($this->useMALAPI && ! is_null($malId))
+ {
+ $requester->addRequest($this->malModel->deleteListItem($malId, 'manga'), 'MAL');
+ }
+
+ $requester->addRequest($this->kitsuModel->deleteListItem($id), 'kitsu');
+
+ $results = $requester->makeRequests(TRUE);
+
+ return count($results[1]) > 0;
}
/**