Hide missing table error on noninitialized collection, see #20

This commit is contained in:
Timothy Warren 2019-01-08 15:52:53 -05:00
parent 42ec5faa4a
commit aec9a2f2b8
3 changed files with 58 additions and 57 deletions

View File

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

View File

@ -18,6 +18,7 @@ namespace Aviat\AnimeClient\Model;
use Aviat\Ion\Di\ContainerInterface;
use PDO;
use PDOException;
/**
* Model for getting anime collection data
@ -226,6 +227,60 @@ final class AnimeCollection extends Collection {
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
*

View File

@ -74,54 +74,5 @@ class Collection extends DB {
$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