More fixes and cleanup for version 4.1 #21
@ -141,6 +141,7 @@ final class AnimeCollection extends BaseController {
|
||||
$data = $this->request->getParsedBody();
|
||||
if (array_key_exists('hummingbird_id', $data))
|
||||
{
|
||||
// @TODO verify data was updated correctly
|
||||
$this->animeCollectionModel->update($data);
|
||||
$this->setFlashMessage('Successfully updated collection item.', 'success');
|
||||
}
|
||||
@ -165,8 +166,17 @@ final class AnimeCollection extends BaseController {
|
||||
$data = $this->request->getParsedBody();
|
||||
if (array_key_exists('id', $data))
|
||||
{
|
||||
$this->animeCollectionModel->add($data);
|
||||
$this->setFlashMessage('Successfully added collection item', 'success');
|
||||
// Check for existing entry
|
||||
if ($this->animeCollectionModel->get($data['id']) !== FALSE)
|
||||
{
|
||||
$this->setFlashMessage('Anime already exists, can not create duplicate', 'info');
|
||||
}
|
||||
else
|
||||
{
|
||||
// @TODO actually verify that collection item was added
|
||||
$this->animeCollectionModel->add($data);
|
||||
$this->setFlashMessage('Successfully added collection item', 'success');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -189,10 +199,11 @@ final class AnimeCollection extends BaseController {
|
||||
$this->redirect('/anime-collection/view', 303);
|
||||
}
|
||||
|
||||
// @TODO verify that item was actually deleted
|
||||
$this->animeCollectionModel->delete($data);
|
||||
$this->setFlashMessage('Successfully removed anime from collection.', 'success');
|
||||
|
||||
$this->redirect('/anime-collection/view', 303);
|
||||
}
|
||||
}
|
||||
// End of CollectionController.php
|
||||
// End of AnimeCollection.php
|
@ -112,7 +112,7 @@ final class AnimeCollection extends Collection {
|
||||
|
||||
// Add genres associated with each item
|
||||
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
$genres = $this->getGenresForList();
|
||||
$genres = $this->getGenreList();
|
||||
|
||||
foreach($rows as &$row)
|
||||
{
|
||||
@ -275,29 +275,6 @@ final class AnimeCollection extends Collection {
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of genres from the database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getGenresForList(): array
|
||||
{
|
||||
$query = $this->db->select('hummingbird_id, genre')
|
||||
->from('genres g')
|
||||
->join('genre_anime_set_link gasl', 'gasl.genre_id=g.id')
|
||||
->get();
|
||||
|
||||
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
$output = [];
|
||||
|
||||
foreach($rows as $row)
|
||||
{
|
||||
$output[$row['hummingbird_id']][] = $row['genre'];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update genre information for selected anime
|
||||
*
|
||||
@ -353,9 +330,16 @@ final class AnimeCollection extends Collection {
|
||||
* @return array
|
||||
*/
|
||||
private function getGenreData(): array
|
||||
{
|
||||
return [
|
||||
'genres' => $this->getExistingGenres(),
|
||||
'links' => $this->getExistingGenreLinkEntries(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getExistingGenres(): array
|
||||
{
|
||||
$genres = [];
|
||||
$links = [];
|
||||
|
||||
// Get existing genres
|
||||
$query = $this->db->select('id, genre')
|
||||
@ -366,7 +350,13 @@ final class AnimeCollection extends Collection {
|
||||
$genres[$genre['id']] = $genre['genre'];
|
||||
}
|
||||
|
||||
// Get existing link table entries
|
||||
return $genres;
|
||||
}
|
||||
|
||||
private function getExistingGenreLinkEntries(): array
|
||||
{
|
||||
$links = [];
|
||||
|
||||
$query = $this->db->select('hummingbird_id, genre_id')
|
||||
->from('genre_anime_set_link')
|
||||
->get();
|
||||
@ -375,17 +365,13 @@ final class AnimeCollection extends Collection {
|
||||
if (array_key_exists($link['hummingbird_id'], $links))
|
||||
{
|
||||
$links[$link['hummingbird_id']][] = $link['genre_id'];
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
$links[$link['hummingbird_id']] = [$link['genre_id']];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'genres' => $genres,
|
||||
'links' => $links
|
||||
];
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
// End of AnimeCollectionModel.php
|
@ -88,21 +88,6 @@ final class MangaCollection extends Collection {
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from collection for editing
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function getCollectionEntry($id): array
|
||||
{
|
||||
$query = $this->db->from('anime_set')
|
||||
->where('hummingbird_id', $id)
|
||||
->get();
|
||||
|
||||
return $query->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full collection from the database
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user