/** * @param AlbumModel $albumModel * @param string $terms * @param array $tracks * * @return array */ protected function saveTrackList(AlbumModel $albumModel, $terms = '', $tracks = array()) { $trackList = array(); if ($albumModel->getId()) { foreach ($tracks as $position => $title) { if ("titre inconnu" == trim(strtolower($title))) { $this->logger->info(sprintf('IGNORING %s - %s TRACK INFOS while processsing %s (album #%s) track list', $terms, $title, $albumModel->getId())); continue; } try { $this->logger->info(sprintf('Trying to SAVE %s - %s TRACK INFOS using the TrackRetriever', $terms, $title)); $trackModel = new Track(); $trackModel->fromAlbum($albumModel, $title, $position + 1); // position is an index's an index $this->entityManager->persist($trackModel); $this->entityManager->flush(); $trackList[] = $trackModel; } catch (InvalidAlbumInputException $e) { $this->logger->error(sprintf('An error occurred : %s', $e)); } } } return $trackList; }
/** * @param Album $album * @param string $title * @param int $position * * @return $this * * @throws InvalidAlbumInputException */ public function fromAlbum(Album $album, $title = "", $position = null) { $this->setArtist($album->getArtist()); $this->setLabel($album->getLabel()); $this->setManufacturer($album->getManufacturer()); $this->setPublisher($album->getPublisher()); $this->setReleaseDate($album->getReleaseDate()); $this->setStudio($album->getStudio()); $this->setAlbum($album); if (!empty($title)) { $this->setTitle($title); } if ($position >= 0) { $this->setTrackSequence($position); } return $this; }
/** * Show album from its id */ public function showAction(Album $album) { //$album = $this->getDoctrine()->getRepository('ProgramBundle:Album')->findPublishedBySlug($slug); if (!$album) { throw $this->createNotFoundException('L’album est introuvable.'); } // hide content if not published and user not logged if (!$album->getPublished() && !$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { throw $this->createNotFoundException('L’album est indisponible.'); } if ($seoPage = $this->get('sonata.seo.page')) { $seoPage->addTitle(sprintf('%s - %s', $album->getArtist(), $album->getTitle()))->addMeta('name', 'description', $album->getResume())->addMeta('property', 'og:title', sprintf('%s - %s', $album->getArtist(), $album->getTitle()))->addMeta('property', 'og:type', 'article')->addMeta('property', 'og:url', $this->generateUrl('album', array('slug' => $album->getSlug()), true))->addMeta('property', 'og:description', $album->getResume()); } $breadcrumbs = $this->get("white_october_breadcrumbs"); $breadcrumbs->addItem('Musique'); $breadcrumbs->addRouteItem('L’album de la semaine', 'albums'); $breadcrumbs->addItem($album->getArtist() . ' - ' . $album->getTitle()); return $this->render('ProgramBundle:Album:show.html.twig', compact('album')); }