/**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     $context = $blockContext->getBlock()->getSetting('context');
     $criteria = array('mode' => $blockContext->getSetting('mode'), 'context' => $context);
     $order = array($blockContext->getSetting('order') => $blockContext->getSetting('sort'));
     return $this->renderResponse($blockContext->getTemplate(), array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'pager' => $this->galleryManager->getPager($criteria, 1, $blockContext->getSetting('number'), $order)), $response);
 }
 public function testExecute()
 {
     $pager = $this->getMock('Sonata\\DatagridBundle\\Pager\\PagerInterface');
     $this->galleryManager->expects($this->once())->method('getPager')->will($this->returnValue($pager));
     $block = new Block();
     $blockContext = new BlockContext($block, array('number' => 15, 'mode' => 'public', 'order' => 'createdAt', 'sort' => 'desc', 'context' => false, 'title' => 'Gallery List', 'template' => 'SonataMediaBundle:Block:block_gallery_list.html.twig'));
     $blockService = new GalleryListBlockService('block.service', $this->templating, $this->galleryManager, $this->pool);
     $blockService->execute($blockContext);
     $this->assertSame('SonataMediaBundle:Block:block_gallery_list.html.twig', $this->templating->view);
     $this->assertSame($blockContext, $this->templating->parameters['context']);
     $this->assertInternalType('array', $this->templating->parameters['settings']);
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $this->templating->parameters['block']);
     $this->assertSame($pager, $this->templating->parameters['pager']);
 }
 /**
  * Write a Gallery, this method is used by both POST and PUT action methods.
  *
  * @param Request  $request Symfony request
  * @param int|null $id      A Gallery identifier
  *
  * @return \FOS\RestBundle\View\View|FormInterface
  */
 protected function handleWriteGallery($request, $id = null)
 {
     $gallery = $id ? $this->getGallery($id) : null;
     $form = $this->formFactory->createNamed(null, 'sonata_media_api_form_gallery', $gallery, array('csrf_protection' => false));
     $form->bind($request);
     if ($form->isValid()) {
         $gallery = $form->getData();
         $this->galleryManager->save($gallery);
         $view = FOSRestView::create($gallery);
         $serializationContext = SerializationContext::create();
         $serializationContext->setGroups(array('sonata_api_read'));
         $serializationContext->enableMaxDepthChecks();
         $view->setSerializationContext($serializationContext);
         return $view;
     }
     return $form;
 }