HummingBirdAnimeClient/src/Aviat/AnimeClient/Controller/Collection.php

165 lines
3.6 KiB
PHP
Raw Normal View History

2015-05-22 12:36:26 -04:00
<?php
/**
* Anime Collection Controller
*/
2015-05-22 12:36:26 -04:00
2015-09-14 19:54:34 -04:00
namespace Aviat\AnimeClient\Controller;
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;
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
/**
* Controller for Anime collection pages
*/
class Collection extends BaseController {
/**
* The anime collection model
* @var object $collection_model
*/
private $collection_model;
2015-05-22 12:36:26 -04:00
/**
* Data to ve sent to all routes in this controller
* @var array $base_data
*/
protected $base_data;
/**
* Url Generator class
* @var UrlGenerator
*/
protected $urlGenerator;
/**
* Route mapping for main navigation
* @var array $nav_routes
*/
private $nav_routes = [
'Watching' => '/anime/watching{/view}',
'Plan to Watch' => '/anime/plan_to_watch{/view}',
'On Hold' => '/anime/on_hold{/view}',
'Dropped' => '/anime/dropped{/view}',
'Completed' => '/anime/completed{/view}',
'Collection' => '/collection/view{/view}',
'All' => '/anime/all{/view}'
];
/**
* Constructor
2015-09-14 19:54:34 -04:00
*
* @param ContainerInterface $container
*/
2015-09-17 23:11:18 -04:00
public function __construct(ContainerInterface $container)
2015-05-22 12:36:26 -04:00
{
parent::__construct($container);
if ($this->config->show_anime_collection === FALSE)
{
unset($this->nav_routes['Collection']);
}
$this->urlGenerator = $container->get('url-generator');
2015-09-14 15:49:20 -04:00
$this->collection_model = new AnimeCollectionModel($container);
$this->base_data = array_merge($this->base_data, [
'message' => '',
'url_type' => 'anime',
'other_type' => 'manga',
'nav_routes' => $this->nav_routes,
'config' => $this->config,
2015-09-14 15:49:20 -04:00
]);
2015-05-22 12:36:26 -04:00
}
/**
* Search for anime
*
* @return void
*/
public function search()
{
$query = $this->request->query->get('query');
$this->outputJSON($this->model->search($query));
}
/**
* Show the anime collection page
*
2015-09-14 19:54:34 -04:00
* @param string $view
* @return void
*/
public function index($view)
2015-05-22 12:36:26 -04:00
{
$view_map = [
'' => 'cover',
'list' => 'list'
];
2015-06-11 12:54:54 -04:00
$data = $this->collection_model->get_collection();
$this->outputHTML('collection/' . $view_map[$view], [
'title' => $this->config->whose_list . "'s Anime Collection",
'sections' => $data,
'genres' => $this->collection_model->get_genre_list()
]);
}
2015-06-17 08:50:01 -04:00
/**
* Show the anime collection add/edit form
*
* @param int $id
* @return void
*/
public function form($id = NULL)
{
$action = (is_null($id)) ? "Add" : "Edit";
$this->outputHTML('collection/' . strtolower($action), [
'action' => $action,
'action_url' => $this->urlGenerator->full_url("collection/" . strtolower($action)),
'title' => $this->config->whose_list . " Anime Collection &middot; {$action}",
'media_items' => $this->collection_model->get_media_type_list(),
'item' => ($action === "Edit") ? $this->collection_model->get($id) : []
]);
}
/**
* Update a collection item
*
* @return void
*/
public function edit()
{
$data = $this->request->post->get();
if ( ! array_key_exists('hummingbird_id', $data))
{
$this->redirect("collection/view", 303, "anime");
}
$this->collection_model->update($data);
$this->redirect("collection/view", 303, "anime");
}
/**
* Add a collection item
*
* @return void
*/
public function add()
{
$data = $this->request->post->get();
if ( ! array_key_exists('id', $data))
{
$this->redirect("collection/view", 303, "anime");
}
$this->collection_model->add($data);
$this->redirect("collection/view", 303, "anime");
}
2015-05-22 12:36:26 -04:00
}
// End of CollectionController.php