Example #1
0
 /**
  * @param Symfony\Component\HttpFoundation\Request $request
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function imageAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $splash = new SplashbasePictureFinder();
         $response = new JsonResponse();
         $response->setData($splash->getRandom());
         return $response;
     } else {
         return $this->throw404();
     }
 }
 /**
  * Download a random document.
  *
  * @return RZ\Roadiz\Core\Entities\Document
  */
 public function randomDocument($folderId = null)
 {
     $finder = new SplashbasePictureFinder();
     $document = $finder->createDocumentFromFeed($this->getContainer());
     if (null !== $document && null !== $folderId && $folderId > 0) {
         $folder = $this->getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Folder', (int) $folderId);
         $document->addFolder($folder);
         $folder->addDocument($document);
         $this->getService('em')->flush();
     }
     return $document;
 }