2017-09-14 16:18:13 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime List Client
|
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2017-09-14 16:18:13 -04:00
|
|
|
*
|
2020-04-10 15:39:39 -04:00
|
|
|
* PHP version 7.4
|
2017-09-14 16:18:13 -04:00
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2020-01-08 15:39:49 -05:00
|
|
|
* @copyright 2015 - 2020 Timothy J. Warren
|
2017-09-14 16:18:13 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-04-10 15:39:39 -04:00
|
|
|
* @version 5
|
2017-09-14 16:18:13 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Controller;
|
|
|
|
|
2019-12-09 14:34:23 -05:00
|
|
|
use Aura\Router\Exception\RouteNotFound;
|
2017-09-14 16:18:13 -04:00
|
|
|
use Aviat\AnimeClient\Controller as BaseController;
|
2019-12-09 14:34:23 -05:00
|
|
|
use Aviat\Ion\Di\Exception\ContainerException;
|
|
|
|
use Aviat\Ion\Di\Exception\NotFoundException;
|
|
|
|
use Aviat\Ion\Exception\DoubleRenderException;
|
2017-09-14 16:18:13 -04:00
|
|
|
use Aviat\AnimeClient\Model\{
|
2018-01-16 14:58:07 -05:00
|
|
|
Manga as MangaModel,
|
|
|
|
MangaCollection as MangaCollectionModel
|
2017-09-14 16:18:13 -04:00
|
|
|
};
|
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
|
|
|
|
2019-12-09 14:34:23 -05:00
|
|
|
use InvalidArgumentException;
|
|
|
|
|
2017-09-14 16:18:13 -04:00
|
|
|
/**
|
|
|
|
* Controller for manga collection pages
|
|
|
|
*/
|
2018-08-08 10:12:45 -04:00
|
|
|
final class MangaCollection extends BaseController {
|
2017-09-14 16:18:13 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The manga collection model
|
2018-01-16 14:58:07 -05:00
|
|
|
* @var MangaCollectionModel $mangaCollectionModel
|
2017-09-14 16:18:13 -04:00
|
|
|
*/
|
|
|
|
private $mangaCollectionModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The manga API model
|
2018-01-16 14:58:07 -05:00
|
|
|
* @var MangaModel $mangaModel
|
2017-09-14 16:18:13 -04:00
|
|
|
*/
|
|
|
|
private $mangaModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
2018-02-02 09:50:58 -05:00
|
|
|
* @throws \InvalidArgumentException
|
2017-09-14 16:18:13 -04:00
|
|
|
*/
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
|
|
|
|
$this->mangaModel = $container->get('manga-model');
|
|
|
|
$this->mangaCollectionModel = $container->get('manga-collection-model');
|
|
|
|
$this->baseData = array_merge($this->baseData, [
|
|
|
|
'collection_type' => 'manga',
|
|
|
|
'menu_name' => 'manga-collection',
|
|
|
|
'other_type' => 'anime',
|
2018-12-21 15:52:34 -05:00
|
|
|
'url_type' => 'manga',
|
2017-09-14 16:18:13 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for manga
|
|
|
|
*
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws DoubleRenderException
|
2017-09-14 16:18:13 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-02-02 09:50:58 -05:00
|
|
|
public function search(): void
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
|
|
|
$queryParams = $this->request->getQueryParams();
|
|
|
|
$query = $queryParams['query'];
|
|
|
|
$this->outputJSON($this->mangaModel->search($query));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the manga collection page
|
|
|
|
*
|
|
|
|
* @param string $view
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @throws InvalidArgumentException
|
2017-09-14 16:18:13 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-02-02 09:50:58 -05:00
|
|
|
public function index($view): void
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
|
|
|
$viewMap = [
|
|
|
|
'' => 'cover',
|
|
|
|
'list' => 'list'
|
|
|
|
];
|
|
|
|
|
|
|
|
$data = $this->mangaCollectionModel->getCollection();
|
|
|
|
|
|
|
|
$this->outputHTML('collection/' . $viewMap[$view], [
|
|
|
|
'title' => $this->config->get('whose_list') . "'s Manga Collection",
|
|
|
|
'sections' => $data,
|
|
|
|
'genres' => $this->mangaCollectionModel->getGenreList()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the manga collection add/edit form
|
|
|
|
*
|
|
|
|
* @param integer|null $id
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @throws RouteNotFound
|
|
|
|
* @throws InvalidArgumentException
|
2017-09-14 16:18:13 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-02-02 09:50:58 -05:00
|
|
|
public function form($id = NULL): void
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
|
|
|
$this->setSessionRedirect();
|
|
|
|
|
2018-02-02 09:50:58 -05:00
|
|
|
$action = $id === NULL ? 'Add' : 'Edit';
|
2017-09-14 16:18:13 -04:00
|
|
|
$urlAction = strtolower($action);
|
|
|
|
|
|
|
|
$this->outputHTML('collection/' . $urlAction, [
|
|
|
|
'action' => $action,
|
|
|
|
'action_url' => $this->url->generate("manga.collection.{$urlAction}.post"),
|
|
|
|
'title' => $this->formatTitle(
|
|
|
|
$this->config->get('whose_list') . "'s manga Collection",
|
|
|
|
$action
|
|
|
|
),
|
|
|
|
'media_items' => $this->mangaCollectionModel->getMediaTypeList(),
|
2018-02-02 09:50:58 -05:00
|
|
|
'item' => ($action === 'Edit') ? $this->mangaCollectionModel->get($id) : []
|
2017-09-14 16:18:13 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a collection item
|
|
|
|
*
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @throws InvalidArgumentException
|
2017-09-14 16:18:13 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-09 10:38:35 -05:00
|
|
|
public function edit(): void
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
|
|
|
$data = $this->request->getParsedBody();
|
|
|
|
if (array_key_exists('hummingbird_id', $data))
|
|
|
|
{
|
|
|
|
$this->mangaCollectionModel->update($data);
|
|
|
|
$this->setFlashMessage('Successfully updated collection item.', 'success');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->setFlashMessage('Failed to update collection item', 'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->sessionRedirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a collection item
|
|
|
|
*
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @throws InvalidArgumentException
|
2017-09-14 16:18:13 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-09 10:38:35 -05:00
|
|
|
public function add(): void
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
|
|
|
$data = $this->request->getParsedBody();
|
|
|
|
if (array_key_exists('id', $data))
|
|
|
|
{
|
|
|
|
$this->mangaCollectionModel->add($data);
|
|
|
|
$this->setFlashMessage('Successfully added collection item', 'success');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->setFlashMessage('Failed to add collection item.', 'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->sessionRedirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a collection item
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-09 10:38:35 -05:00
|
|
|
public function delete(): void
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
|
|
|
$data = $this->request->getParsedBody();
|
|
|
|
if ( ! array_key_exists('hummingbird_id', $data))
|
|
|
|
{
|
2018-02-02 09:50:58 -05:00
|
|
|
$this->redirect('/manga-collection/view', 303);
|
2017-09-14 16:18:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->mangaCollectionModel->delete($data);
|
2018-02-02 09:50:58 -05:00
|
|
|
$this->setFlashMessage('Successfully removed manga from collection.', 'success');
|
2017-09-14 16:18:13 -04:00
|
|
|
|
2018-02-02 09:50:58 -05:00
|
|
|
$this->redirect('/manga-collection/view', 303);
|
2017-09-14 16:18:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of CollectionController.php
|