<?php
namespace AppBundle\Controller;
use AppBundle\Entity\HomepageTile;
use AppBundle\Entity\Page;
use AppBundle\Service\BannerCarouselService;
use AppBundle\Util\ChromeItemsHelperTrait;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller
{
use ChromeItemsHelperTrait;
/**
* @Route("/", name="index")
*/
public function index(Request $request, BannerCarouselService $carouselService, Translator $translator)
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Page::class)
->findOneBy(['type' => Page::HOMEPAGE]);
if ($page === null) {
// in case if homepage is not specified in admin dashboard
return $this->render('AppBundle::index.html.twig');
}
$homepageTiles = $em->getRepository(HomepageTile::class)
->getSortedTiles();
$blockPosts = $em->getRepository(Page::class)
->getNewsPages();
$ctx = [
'page' => $page,
'homepageTiles' => $homepageTiles,
'blogPosts' => $blockPosts,
];
$this->prepareItemsInController($request, $page, $em, $translator, $ctx);
return $this->render('AppBundle:Page:homepage.html.twig', $ctx);
}
/**
* @Route("/browse-resources/select", name="browse-resources")
*/
public function browseResourcesAction()
{
$images = $this->getDoctrine()
->getRepository('AppBundle:File')
->findImagesAndVideos();
return $this->render('@App/browse-images.html.twig', [
"images" => $images
]);
$galleryStruct = $this->getDoctrine()
->getRepository('AppBundle:Gallery')
->findAllFormatStructure();
$files = $this->getDoctrine()
->getRepository('AppBundle:File')
->findAllAndFormatIt();
$videos = $this->getDoctrine()
->getRepository('AppBundle:Video')
->findAllFormatStructure();
$audios = $this->getDoctrine()
->getRepository('AppBundle:Audio')
->findAllFormatStructure();
$documents = $this->getDoctrine()
->getRepository('AppBundle:Document')
->findAllFormatStructure();
$banners = $this->getDoctrine()
->getRepository('AppBundle:Media')
->findAllFormatStructure();
$flipbook = $this->getDoctrine()
->getRepository('AppBundle:Flipbook')
->findAllFormatStructure();
return $this->render('AppBundle:Form:ckeditor_widget.html.twig', [
'galleryStruct' => $galleryStruct,
'files' => $files,
'docs' => $documents,
'videos' => $videos,
'audios' => $audios,
'banners' => $banners,
'flipbook' => $flipbook,
]);
}
/**
* @Route("/gallery/{id}", name="gallery")
*/
public function galleryAction($id = null)
{
$galleryId = $id;
$files = [];
$repo = $this->getDoctrine()->getRepository('AppBundle:Gallery');
$repoF = $this->getDoctrine()->getRepository('AppBundle:File');
$gallery = $repo->find($galleryId);
$structure = $gallery->getStructure();
$current = $structure['current'];
$filesId = $structure['structure'][$current];
foreach ($filesId as $fid) {
$files[] = $repoF->find($fid);
}
return $this->render('AppBundle::gallery.html.twig', [
'gallery' => $gallery,
'files' => $files
]);
}
/**
* @Route("/updatedb", name="update-database")
*/
public function updateDbAction()
{
$dbUpdater = $this->get('app.dbupdaterservice');
$dbUpdater->update();
return new Response('DB updated', Response::HTTP_OK);
}
/**
* @Route("/resources-to-files", name="resources-to-file")
*/
public function resourcesToFile()
{
}
}