2015-05-22 12:36:26 -04:00
|
|
|
<?php
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
2015-11-16 11:40:01 -05:00
|
|
|
* Hummingbird Anime Client
|
|
|
|
*
|
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists
|
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2015
|
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
|
|
|
* @license MIT
|
2015-06-16 11:11:35 -04:00
|
|
|
*/
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-09-14 19:54:34 -04:00
|
|
|
namespace Aviat\AnimeClient\Controller;
|
2015-09-14 10:54:50 -04:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
2015-09-15 13:19:29 -04:00
|
|
|
use Aviat\AnimeClient\Controller as BaseController;
|
|
|
|
use Aviat\AnimeClient\Config;
|
2015-09-16 12:25:35 -04:00
|
|
|
use Aviat\AnimeClient\UrlGenerator;
|
2015-09-14 19:54:34 -04:00
|
|
|
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
|
|
|
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
|
2015-06-26 16:39:10 -04:00
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
2015-09-14 10:54:50 -04:00
|
|
|
* Controller for Anime collection pages
|
2015-06-11 16:44:52 -04:00
|
|
|
*/
|
2015-09-14 10:54:50 -04:00
|
|
|
class Collection extends BaseController {
|
2015-06-11 16:44:52 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The anime collection model
|
2015-10-09 14:34:55 -04:00
|
|
|
* @var object $anime_collection_model
|
2015-06-11 16:44:52 -04:00
|
|
|
*/
|
2015-10-09 14:34:55 -04:00
|
|
|
private $anime_collection_model;
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
|
|
|
* Data to ve sent to all routes in this controller
|
|
|
|
* @var array $base_data
|
|
|
|
*/
|
2015-06-24 16:01:35 -04:00
|
|
|
protected $base_data;
|
2015-06-16 11:11:35 -04:00
|
|
|
|
2015-09-16 12:25:35 -04:00
|
|
|
/**
|
|
|
|
* Url Generator class
|
|
|
|
* @var UrlGenerator
|
|
|
|
*/
|
|
|
|
protected $urlGenerator;
|
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
|
|
|
* Constructor
|
2015-09-14 19:54:34 -04:00
|
|
|
*
|
2015-10-06 10:24:48 -04:00
|
|
|
* @param ContainerInterface $container
|
2015-06-11 16:44:52 -04:00
|
|
|
*/
|
2015-09-17 23:11:18 -04:00
|
|
|
public function __construct(ContainerInterface $container)
|
2015-05-22 12:36:26 -04:00
|
|
|
{
|
2015-09-14 10:54:50 -04:00
|
|
|
parent::__construct($container);
|
2015-06-16 11:21:22 -04:00
|
|
|
|
2015-09-16 12:25:35 -04:00
|
|
|
$this->urlGenerator = $container->get('url-generator');
|
2015-12-08 16:39:49 -05:00
|
|
|
$this->anime_model = $container->get('anime-model');
|
|
|
|
$this->anime_collection_model = $container->get('anime-collection-model');
|
2015-09-14 15:49:20 -04:00
|
|
|
$this->base_data = array_merge($this->base_data, [
|
2015-10-09 14:34:55 -04:00
|
|
|
'menu_name' => 'collection',
|
2015-06-24 16:01:35 -04:00
|
|
|
'message' => '',
|
2015-06-16 11:11:35 -04:00
|
|
|
'url_type' => 'anime',
|
|
|
|
'other_type' => 'manga',
|
2015-07-02 14:04:04 -04:00
|
|
|
'config' => $this->config,
|
2015-09-14 15:49:20 -04:00
|
|
|
]);
|
2015-05-22 12:36:26 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 14:04:04 -04:00
|
|
|
/**
|
|
|
|
* Search for anime
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function search()
|
|
|
|
{
|
|
|
|
$query = $this->request->query->get('query');
|
2015-12-08 14:52:59 -05:00
|
|
|
$this->outputJSON($this->anime_model->search($query));
|
2015-07-02 14:04:04 -04:00
|
|
|
}
|
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
2015-09-14 10:54:50 -04:00
|
|
|
* Show the anime collection page
|
2015-06-11 16:44:52 -04:00
|
|
|
*
|
2015-09-14 19:54:34 -04:00
|
|
|
* @param string $view
|
2015-06-11 16:44:52 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-09-14 10:54:50 -04:00
|
|
|
public function index($view)
|
2015-05-22 12:36:26 -04:00
|
|
|
{
|
2015-06-16 11:11:35 -04:00
|
|
|
$view_map = [
|
|
|
|
'' => 'cover',
|
|
|
|
'list' => 'list'
|
|
|
|
];
|
|
|
|
|
2015-10-09 14:34:55 -04:00
|
|
|
$data = $this->anime_collection_model->get_collection();
|
2015-06-09 18:18:53 -04:00
|
|
|
|
2015-09-14 10:54:50 -04:00
|
|
|
$this->outputHTML('collection/' . $view_map[$view], [
|
2015-10-06 11:38:20 -04:00
|
|
|
'title' => $this->config->get('whose_list') . "'s Anime Collection",
|
2015-07-02 14:04:04 -04:00
|
|
|
'sections' => $data,
|
2015-10-09 14:34:55 -04:00
|
|
|
'genres' => $this->anime_collection_model->get_genre_list()
|
2015-06-24 16:01:35 -04:00
|
|
|
]);
|
2015-06-09 18:18:53 -04:00
|
|
|
}
|
2015-06-17 08:50:01 -04:00
|
|
|
|
2015-07-02 14:04:04 -04:00
|
|
|
/**
|
|
|
|
* Show the anime collection add/edit form
|
|
|
|
*
|
2015-10-12 14:27:20 -04:00
|
|
|
* @param integer|null $id
|
2015-07-02 14:04:04 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-10-06 10:24:48 -04:00
|
|
|
public function form($id = NULL)
|
2015-07-02 14:04:04 -04:00
|
|
|
{
|
|
|
|
$action = (is_null($id)) ? "Add" : "Edit";
|
|
|
|
|
2015-10-06 10:24:48 -04:00
|
|
|
$this->outputHTML('collection/' . strtolower($action), [
|
2015-07-02 14:04:04 -04:00
|
|
|
'action' => $action,
|
2015-09-16 12:25:35 -04:00
|
|
|
'action_url' => $this->urlGenerator->full_url("collection/" . strtolower($action)),
|
2015-12-08 14:52:59 -05:00
|
|
|
'title' => $this->config->get('whose_list') . " Anime Collection · {$action}",
|
2015-10-09 14:34:55 -04:00
|
|
|
'media_items' => $this->anime_collection_model->get_media_type_list(),
|
|
|
|
'item' => ($action === "Edit") ? $this->anime_collection_model->get($id) : []
|
2015-07-02 14:04:04 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a collection item
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-09-14 10:54:50 -04:00
|
|
|
public function edit()
|
2015-07-02 14:04:04 -04:00
|
|
|
{
|
|
|
|
$data = $this->request->post->get();
|
|
|
|
if ( ! array_key_exists('hummingbird_id', $data))
|
|
|
|
{
|
|
|
|
$this->redirect("collection/view", 303, "anime");
|
|
|
|
}
|
|
|
|
|
2015-10-09 14:34:55 -04:00
|
|
|
$this->anime_collection_model->update($data);
|
2015-07-02 14:04:04 -04:00
|
|
|
|
|
|
|
$this->redirect("collection/view", 303, "anime");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a collection item
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-09-14 10:54:50 -04:00
|
|
|
public function add()
|
2015-07-02 14:04:04 -04:00
|
|
|
{
|
|
|
|
$data = $this->request->post->get();
|
|
|
|
if ( ! array_key_exists('id', $data))
|
|
|
|
{
|
|
|
|
$this->redirect("collection/view", 303, "anime");
|
|
|
|
}
|
|
|
|
|
2015-10-09 14:34:55 -04:00
|
|
|
$this->anime_collection_model->add($data);
|
2015-07-02 14:04:04 -04:00
|
|
|
|
|
|
|
$this->redirect("collection/view", 303, "anime");
|
|
|
|
}
|
2015-05-22 12:36:26 -04:00
|
|
|
}
|
2015-09-14 10:54:50 -04:00
|
|
|
// End of CollectionController.php
|