Newscoop\GimmeBundle\Controller\ArticlesListController::updatePlaylistAction PHP Méthode

updatePlaylistAction() public méthode

Update playlist.
public updatePlaylistAction ( Request $request, $id )
$request Symfony\Component\HttpFoundation\Request
    public function updatePlaylistAction(Request $request, $id)
    {
        $user = $this->container->get('user')->getCurrentUser();
        if (!$user->hasPermission('ManagePlaylist')) {
            throw new AccessDeniedException('You do not have the right to manage playlists.');
        }
        $em = $this->container->get('em');
        $playlist = $em->getRepository('Newscoop\\Entity\\Playlist')->getPlaylist($id)->getOneOrNullResult();
        if (!$playlist) {
            throw new NotFoundHttpException('Result was not found.');
        }
        $oldMaxItems = $playlist->getMaxItems();
        $form = $this->createForm(new PlaylistType(), $playlist, array('method' => $request->getMethod()));
        $form->handleRequest($request);
        if ($form->isValid()) {
            $em->persist($playlist);
            $em->flush();
            if ($oldMaxItems != $playlist->getMaxItems()) {
                $playlistService = $this->get('playlists');
                $playlistService->removeLeftItems($playlist);
                $playlist = $em->getRepository('Newscoop\\Entity\\Playlist')->getPlaylist($playlist->getId())->getOneOrNullResult();
            }
            $view = FOSView\View::create($playlist, 201);
            $view->setHeader('X-Location', $this->generateUrl('newscoop_gimme_articles_lists_getlist', array('id' => $playlist->getId()), true));
            return $view;
        }
        return $form;
    }