Version 5.1 - All the GraphQL #32
@ -122,7 +122,7 @@ class Anime extends BaseController {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add_form()
|
public function addForm()
|
||||||
{
|
{
|
||||||
$statuses = [
|
$statuses = [
|
||||||
AnimeWatchingStatus::WATCHING => 'Currently Watching',
|
AnimeWatchingStatus::WATCHING => 'Currently Watching',
|
||||||
@ -220,17 +220,17 @@ class Anime extends BaseController {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function form_update()
|
public function formUpdate()
|
||||||
{
|
{
|
||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
|
|
||||||
// Do some minor data manipulation for
|
// Do some minor data manipulation for
|
||||||
// large form-based updates
|
// large form-based updates
|
||||||
$transformer = new AnimeListTransformer();
|
$transformer = new AnimeListTransformer();
|
||||||
$post_data = $transformer->untransform($data);
|
$postData = $transformer->untransform($data);
|
||||||
$full_result = $this->model->updateLibraryItem($post_data);
|
$fullResult = $this->model->updateLibraryItem($postData);
|
||||||
|
|
||||||
if ($full_result['statusCode'] === 200)
|
if ($fullResult['statusCode'] === 200)
|
||||||
{
|
{
|
||||||
$this->set_flash_message("Successfully updated.", 'success');
|
$this->set_flash_message("Successfully updated.", 'success');
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
@ -291,12 +291,12 @@ class Anime extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* View details of an anime
|
* View details of an anime
|
||||||
*
|
*
|
||||||
* @param string $anime_id
|
* @param string $animeId
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function details($anime_id)
|
public function details($animeId)
|
||||||
{
|
{
|
||||||
$data = $this->model->getAnime($anime_id);
|
$data = $this->model->getAnime($animeId);
|
||||||
|
|
||||||
$this->outputHTML('anime/details', [
|
$this->outputHTML('anime/details', [
|
||||||
'title' => 'Anime · ' . $data['titles'][0],
|
'title' => 'Anime · ' . $data['titles'][0],
|
||||||
|
@ -91,17 +91,17 @@ class Collection extends BaseController {
|
|||||||
*/
|
*/
|
||||||
public function index($view)
|
public function index($view)
|
||||||
{
|
{
|
||||||
$view_map = [
|
$viewMap = [
|
||||||
'' => 'cover',
|
'' => 'cover',
|
||||||
'list' => 'list'
|
'list' => 'list'
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = $this->animeCollectionModel->get_collection();
|
$data = $this->animeCollectionModel->getCollection();
|
||||||
|
|
||||||
$this->outputHTML('collection/' . $view_map[$view], [
|
$this->outputHTML('collection/' . $viewMap[$view], [
|
||||||
'title' => $this->config->get('whose_list') . "'s Anime Collection",
|
'title' => $this->config->get('whose_list') . "'s Anime Collection",
|
||||||
'sections' => $data,
|
'sections' => $data,
|
||||||
'genres' => $this->animeCollectionModel->get_genre_list()
|
'genres' => $this->animeCollectionModel->getGenreList()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class Manga extends Controller {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add_form()
|
public function addForm()
|
||||||
{
|
{
|
||||||
$raw_status_list = MangaReadingStatus::getConstList();
|
$raw_status_list = MangaReadingStatus::getConstList();
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ class Manga extends Controller {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function form_update()
|
public function formUpdate()
|
||||||
{
|
{
|
||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ class AnimeCollection extends Collection {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_collection()
|
public function getCollection()
|
||||||
{
|
{
|
||||||
$raw_collection = $this->_get_collection();
|
$raw_collection = $this->_getCollection();
|
||||||
|
|
||||||
$collection = [];
|
$collection = [];
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ class AnimeCollection extends Collection {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_media_type_list()
|
public function getMediaTypeList()
|
||||||
{
|
{
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ class AnimeCollection extends Collection {
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_collection_entry($id)
|
public function getCollectionEntry($id)
|
||||||
{
|
{
|
||||||
$query = $this->db->from('anime_set')
|
$query = $this->db->from('anime_set')
|
||||||
->where('hummingbird_id', (int)$id)
|
->where('hummingbird_id', (int)$id)
|
||||||
@ -93,9 +93,9 @@ class AnimeCollection extends Collection {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function _get_collection()
|
private function _getCollection()
|
||||||
{
|
{
|
||||||
if ( ! $this->valid_database)
|
if ( ! $this->validDatabase)
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ class AnimeCollection extends Collection {
|
|||||||
*/
|
*/
|
||||||
public function add($data)
|
public function add($data)
|
||||||
{
|
{
|
||||||
$anime = (object)$this->anime_model->getAnimeById($data['id']);
|
$anime = (object)$this->animeModel->getAnimeById($data['id']);
|
||||||
$this->db->set([
|
$this->db->set([
|
||||||
'hummingbird_id' => $data['id'],
|
'hummingbird_id' => $data['id'],
|
||||||
'slug' => $anime->slug,
|
'slug' => $anime->slug,
|
||||||
@ -134,7 +134,7 @@ class AnimeCollection extends Collection {
|
|||||||
'notes' => $data['notes']
|
'notes' => $data['notes']
|
||||||
])->insert('anime_set');
|
])->insert('anime_set');
|
||||||
|
|
||||||
$this->update_genre($data['id']);
|
$this->updateGenre($data['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -201,13 +201,13 @@ class AnimeCollection extends Collection {
|
|||||||
* @param int $anime_id The current anime
|
* @param int $anime_id The current anime
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function update_genre($anime_id)
|
private function updateGenre($anime_id)
|
||||||
{
|
{
|
||||||
$genre_info = $this->get_genre_data();
|
$genre_info = $this->getGenreData();
|
||||||
extract($genre_info);
|
extract($genre_info);
|
||||||
|
|
||||||
// Get api information
|
// Get api information
|
||||||
$anime = $this->anime_model->getAnimeById($anime_id);
|
$anime = $this->animeModel->getAnimeById($anime_id);
|
||||||
|
|
||||||
foreach ($anime['genres'] as $genre)
|
foreach ($anime['genres'] as $genre)
|
||||||
{
|
{
|
||||||
@ -248,7 +248,7 @@ class AnimeCollection extends Collection {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function get_genre_data()
|
private function getGenreData()
|
||||||
{
|
{
|
||||||
$genres = [];
|
$genres = [];
|
||||||
$links = [];
|
$links = [];
|
||||||
|
@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
namespace Aviat\AnimeClient\Model;
|
namespace Aviat\AnimeClient\Model;
|
||||||
|
|
||||||
|
use Aviat\AnimeClient\Model\DB;
|
||||||
use Aviat\Ion\Di\ContainerAware;
|
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
|
||||||
use Aviat\Ion\Model\DB;
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
|
||||||
@ -32,15 +30,15 @@ class Collection extends DB {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Anime API Model
|
* Anime API Model
|
||||||
* @var object $anime_model
|
* @var object $animeModel
|
||||||
*/
|
*/
|
||||||
protected $anime_model;
|
protected $animeModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the database is valid for querying
|
* Whether the database is valid for querying
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $valid_database = FALSE;
|
protected $validDatabase = FALSE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new collection object
|
* Create a new collection object
|
||||||
@ -48,41 +46,39 @@ class Collection extends DB {
|
|||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
parent::__construct($container);
|
||||||
|
|
||||||
parent::__construct($container->get('config'));
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->db = \Query($this->db_config['collection']);
|
$this->db = \Query($this->dbConfig['collection']);
|
||||||
}
|
}
|
||||||
catch (PDOException $e)
|
catch (PDOException $e)
|
||||||
{
|
{
|
||||||
//$this->valid_database = FALSE;
|
//$this->validDatabase = FALSE;
|
||||||
//return FALSE;
|
//return FALSE;
|
||||||
}
|
}
|
||||||
$this->anime_model = $container->get('anime-model');
|
$this->animeModel = $container->get('anime-model');
|
||||||
|
|
||||||
// Is database valid? If not, set a flag so the
|
// Is database valid? If not, set a flag so the
|
||||||
// app can be run without a valid database
|
// app can be run without a valid database
|
||||||
if ($this->db_config['collection']['type'] === 'sqlite')
|
if ($this->dbConfig['collection']['type'] === 'sqlite')
|
||||||
{
|
{
|
||||||
$db_file_name = $this->db_config['collection']['file'];
|
$dbFileName = $this->dbConfig['collection']['file'];
|
||||||
|
|
||||||
if ($db_file_name !== ':memory:' && file_exists($db_file_name))
|
if ($dbFileName !== ':memory:' && file_exists($dbFileName))
|
||||||
{
|
{
|
||||||
$db_file = file_get_contents($db_file_name);
|
$dbFile = file_get_contents($dbFileName);
|
||||||
$this->valid_database = (strpos($db_file, 'SQLite format 3') === 0);
|
$this->validDatabase = (strpos($dbFile, 'SQLite format 3') === 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->valid_database = FALSE;
|
$this->validDatabase = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->valid_database = TRUE;
|
$this->validDatabase = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +88,7 @@ class Collection extends DB {
|
|||||||
* @param array $filter
|
* @param array $filter
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_genre_list($filter = [])
|
public function getGenreList($filter = [])
|
||||||
{
|
{
|
||||||
$this->db->select('hummingbird_id, genre')
|
$this->db->select('hummingbird_id, genre')
|
||||||
->from('genre_anime_set_link gl')
|
->from('genre_anime_set_link gl')
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
namespace Aviat\AnimeClient\Model;
|
namespace Aviat\AnimeClient\Model;
|
||||||
|
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
|
||||||
use Aviat\Ion\Model;
|
use Aviat\Ion\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base model for database interaction
|
* Base model for database interaction
|
||||||
*/
|
*/
|
||||||
class DB extends Model {
|
class DB extends Model {
|
||||||
use \Aviat\Ion\Di\ContainerAware;
|
use ContainerAware;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The query builder object
|
* The query builder object
|
||||||
@ -33,9 +33,9 @@ class DB extends Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The database connection information array
|
* The database connection information array
|
||||||
* @var array $db_config
|
* @var array $dbConfig
|
||||||
*/
|
*/
|
||||||
protected $db_config;
|
protected $dbConfig = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -44,7 +44,7 @@ class DB extends Model {
|
|||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->db_config = $container->get('config')->get('database');
|
$this->dbConfig = $container->get('config')->get('database');
|
||||||
$this->setContainer($container);
|
$this->setContainer($container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ class DispatcherTest extends AnimeClient_TestCase {
|
|||||||
|
|
||||||
public function dataGetControllerList()
|
public function dataGetControllerList()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'controller_list_sanity_check' => [
|
'controller_list_sanity_check' => [
|
||||||
'config' => [
|
'config' => [
|
||||||
'routes' => [
|
'routes' => [
|
||||||
@ -242,7 +242,7 @@ class DispatcherTest extends AnimeClient_TestCase {
|
|||||||
'collection' => 'Aviat\AnimeClient\Controller\Collection',
|
'collection' => 'Aviat\AnimeClient\Controller\Collection',
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user