/** * @Route("/{id}", name="view", requirements={"id"="\d+"}) */ public function viewAction($id) { $artist = Artist::query()->where('id = ?', [$id])->related('album')->first(); $request = App::request(); if (is_null($artist)) { $request->getSession()->getFlashBag()->add('error', __('Tried to view an non-existing Artist')); return App::response()->redirect('@shoutzor/artist/index'); } $topTracks = $artist->getTopMedia(); return ['$view' => ['title' => 'Artist: ' . $artist->name, 'name' => 'shoutzor:views/artist/view.php'], 'image' => is_null($artist->image) || empty($artist->image) ? App::url()->getStatic('shoutzor:assets/images/profile-placeholder.png') : App::url()->getStatic('shoutzor:' . App::module('shoutzor')->config('shoutzor')['imageDir'] . '/' . $artist->image), 'summary' => empty($artist->summary) ? __('No summary for this artist is available') : $artist->summary, 'artist' => $artist, 'topTracks' => $topTracks, 'albums' => $artist->getAlbums()]; }
/** * @Route("/search", name="search", methods="GET") * @Request({"q":"string", "page":"int"}) */ public function searchAction($q = "", $page = 1) { $query = Artist::query()->select('*'); $request = App::request(); if (empty($q)) { return ['$view' => ['title' => 'Search', 'name' => 'shoutzor:views/search_error.php']]; } $query = Media::query()->select('m.*')->from('@shoutzor_media m')->leftJoin('@shoutzor_media_artist ma', 'ma.media_id = m.id')->leftJoin('@shoutzor_artist a', 'a.id = ma.artist_id')->where('m.status = :status AND (m.title LIKE :search OR a.name LIKE :search OR m.filename LIKE :search)', ['status' => Media::STATUS_FINISHED, 'search' => "%{$q}%"])->orderBy('m.title', 'DESC'); $limit = 20; $count = $query->count(); $total = ceil($count / $limit); $page = max(1, min($total, $page)); $results = $query->offset(($page - 1) * $limit)->limit($limit)->orderBy('name', 'ASC')->related(['artist', 'album'])->get(); return ['$view' => ['title' => 'Search', 'name' => 'shoutzor:views/search.php'], 'searchterm' => htmlspecialchars($q), 'page' => $page, 'totalPage' => $total, 'resultCount' => $count, 'results' => $results]; }
public function addArtist(Media $media, $name) { $name = ucfirst(strtolower($name)); $artist = Artist::query()->where('name = :name', ['name' => $name]); if ($artist->count() > 0) { $artist = $artist->first(); } else { $info = true; //Check if the LastFM integration is enabled if ($this->lastfm->isEnabled()) { $data = $this->lastfm->getArtistInfo($name); if ($data === false) { $info = false; } else { $summary = $data['bio']['summary']; $image = $this->downloadImage($data['image']); if ($image === false) { $image = ''; } } } else { $info = false; } if ($info === false) { $summary = ''; $image = ''; } $artist = Artist::create(); $artist->save(['name' => $name, 'summary' => $summary, 'image' => $image]); } //Dirty hack to create an insert query App::db()->createQueryBuilder()->select('1; INSERT INTO @shoutzor_media_artist (media_id, artist_id) VALUES (' . $media->id . ', ' . $artist->id . ') ON DUPLICATE KEY UPDATE media_id=media_id;--')->execute(); return $artist; }