Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
3 changed files with 58 additions and 57 deletions
Showing only changes of commit aec9a2f2b8 - Show all commits

View File

@ -79,16 +79,11 @@ final class Settings extends BaseController {
$post = $this->request->getParsedBody(); $post = $this->request->getParsedBody();
unset($post['settings-tabs']); unset($post['settings-tabs']);
// dump($post);
$saved = $this->settingsModel->saveSettingsFile($post); $saved = $this->settingsModel->saveSettingsFile($post);
if ($saved) $saved
{ ? $this->setFlashMessage('Saved config settings.', 'success')
$this->setFlashMessage('Saved config settings.', 'success'); : $this->setFlashMessage('Failed to save config file.', 'error');
} else
{
$this->setFlashMessage('Failed to save config file.', 'error');
}
$this->redirect($this->url->generate('settings'), 303); $this->redirect($this->url->generate('settings'), 303);
} }

View File

@ -18,6 +18,7 @@ namespace Aviat\AnimeClient\Model;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
use PDO; use PDO;
use PDOException;
/** /**
* Model for getting anime collection data * Model for getting anime collection data
@ -226,6 +227,60 @@ final class AnimeCollection extends Collection {
return $query->fetch(PDO::FETCH_ASSOC); return $query->fetch(PDO::FETCH_ASSOC);
} }
/**
* Get genres for anime collection items
*
* @param array $filter
* @return array
*/
public function getGenreList(array $filter = []): array
{
$output = [];
// Catch the missing table PDOException
// so that the collection does not show an
// error by default
try
{
$this->db->select('hummingbird_id, genre')
->from('genre_anime_set_link gl')
->join('genres g', 'g.id=gl.genre_id', 'left');
if ( ! empty($filter))
{
$this->db->whereIn('hummingbird_id', $filter);
}
$query = $this->db->orderBy('hummingbird_id')
->orderBy('genre')
->get();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$id = $row['hummingbird_id'];
$genre = $row['genre'];
// Empty genre names aren't useful
if (empty($genre))
{
continue;
}
if (array_key_exists($id, $output))
{
$output[$id][] = $genre;
} else
{
$output[$id] = [$genre];
}
}
}
catch (PDOException $e) {}
return $output;
}
/** /**
* Get the list of genres from the database * Get the list of genres from the database
* *

View File

@ -74,54 +74,5 @@ class Collection extends DB {
$this->validDatabase = FALSE; $this->validDatabase = FALSE;
} }
} }
/**
* Get genres for anime collection items
*
* @param array $filter
* @return array
*/
public function getGenreList(array $filter = []): array
{
$this->db->select('hummingbird_id, genre')
->from('genre_anime_set_link gl')
->join('genres g', 'g.id=gl.genre_id', 'left');
if ( ! empty($filter))
{
$this->db->whereIn('hummingbird_id', $filter);
}
$query = $this->db->orderBy('hummingbird_id')
->orderBy('genre')
->get();
$output = [];
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$id = $row['hummingbird_id'];
$genre = $row['genre'];
// Empty genre names aren't useful
if (empty($genre))
{
continue;
}
if (array_key_exists($id, $output))
{
$output[$id][] = $genre;
}
else
{
$output[$id] = [$genre];
}
}
return $output;
}
} }
// End of Collection.php // End of Collection.php