public function viewAction(Request $request, Application $app)
 {
     $artist = $request->attributes->get('artist');
     if (!$artist) {
         $app->abort(404, 'The requested artist was not found.');
     }
     // Replace with the current user.
     $user = $app['repository.user']->find(2);
     $token = $app['security']->getToken();
     $user = $token->getUser();
     $commentFormView = NULL;
     if ($user != 'anon.') {
         // Provide and handle the add comment form.
         $comment = new Comment();
         $comment->setArtist($artist);
         $comment->setUser($user);
         // @todo Provide the option for comments to be initially unpublished.
         $comment->setPublished(TRUE);
         $commentForm = $app['form.factory']->create(new CommentType(), $comment);
         if ($request->isMethod('POST')) {
             $commentForm->bind($request);
             if ($commentForm->isValid()) {
                 // Save the comment.
                 $app['repository.comment']->save($comment);
                 // Send an email notification.
                 $this->sendNotification($comment, $app);
                 $app['session']->getFlashBag()->add('success', 'Your comment has been added.');
             }
         }
         $commentFormView = $commentForm->createView();
     }
     // @todo Might be a good idea to have pagination on comments.
     $comments = $app['repository.comment']->findAllByArtist($artist->getId(), 50);
     $data = array('artist' => $artist, 'soundcloudWidget' => $app['soundcloud']->getWidget($artist->getSoundCloudUrl()), 'comments' => $comments, 'newCommentForm' => $commentFormView);
     return $app['twig']->render('artist.html.twig', $data);
 }
 /**
  * Instantiates a comment entity and sets its properties using db data.
  *
  * @param array $commentData
  *   The array of db data.
  *
  * @return \MusicBox\Entity\Comment
  */
 protected function buildComment($commentData)
 {
     // Load the related artist and user.
     $artist = $this->artistRepository->find($commentData['artist_id']);
     $user = $this->userRepository->find($commentData['user_id']);
     $comment = new Comment();
     $comment->setId($commentData['comment_id']);
     $comment->setArtist($artist);
     $comment->setUser($user);
     $comment->setComment($commentData['comment']);
     $comment->setPublished($commentData['published']);
     $createdAt = new \DateTime('@' . $commentData['created_at']);
     $comment->setCreatedAt($createdAt);
     return $comment;
 }