<?php
namespace App\Controller;
use App\ClassTheatre\asides;
use App\ClassTheatre\TheatreController;
use App\Exception\RedirectException;
use App\Service\Functions;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use TheatreCore\Entity\BookmarkExtranetuser;
use TheatreCore\Entity\Contents;
use TheatreCore\Entity\Dvds;
use TheatreCore\Entity\Extranetusers;
use TheatreCore\Entity\Spectacles;
class DvdController extends TheatreController
{
// asides
protected $asides = "";
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, TokenStorageInterface $tokenStorage, Functions $func)
{
// surbrillance du menu principal (thnet)
$GLOBALS['rub_courante'] = 'dvd';
parent::__construct($translator, $tokenStorage);
$this->em = $em;
$this->func = $func;
$this->view->include_header = 'spectacles/spectacle_entete.inc.html.twig';
$this->asides = new asides();
}
public function InitController($slug = null, $action = null)
{
$this->context['action'] = $action;
$this->RouterOptions($slug, $action, $GLOBALS['rub_courante']);
$this->view->controller = $GLOBALS['rub_courante'];
// charger swfobject
$this->view->jquery_flash = true;
$params['iddvd'] = $this->iddvd = $this->id;
// si id spectacle n'existe pas, on renvoi sur une page d'erreur (a faire !!!)
if (empty($params['iddvd'])) {
throw new RedirectException($this->generateUrl('erreur'));
}
}
/**
* @Route("/dvd/{slug}", name="dvd_slug")
*/
public function action_view($slug = null)
{
$this->InitController($slug, 'view');
$dvds = $this->em->getRepository(Dvds::class);
$iddvd = $this->iddvd;
// video
$dvd = $dvds->getInfosDvd(
$iddvd,
array('all' => true, 'multimedias' => true), // ttes les données et les vidéos associées
array('vignette_format' => array('width'=>300,'height'=>300,'direction'=>'thumb')) // taille de la vignette
);
if (!empty($dvd['multimedias'])) {
// voir si il y a de la VOD dans le tas
foreach($dvd['multimedias'] as $k=>$v) {
if ($v['status']==5) {
$this->view->vod = $v;
}
}
}
// récupèrer les infos sur le spectacle
if (!empty($dvd['dvd_spectacle'])) {
$spectacles = $this->em->getRepository(Spectacles::class);
foreach($dvd['dvd_spectacle'] as $s) {
// infos sur le spectacle
$dvd['spectacles'][$s['idspectacle']] = $spectacles->getInfosSpectacle($s['idspectacle']);
// recuperer la liste des comediens (idrole=5)
$dvd['spectacles'][$s['idspectacle']]['personnages'] = $this->func->noPunct($spectacles->getPersonsByRole($s['idspectacle'],'actors'));
// recuperer la liste des producteurs/co-producteur/producteur delegue
// (idrole=17/18/19, pas de type et recherche dans contacts)
$dvd['spectacles'][$s['idspectacle']]['producteurs'] = $this->func->noPunct($spectacles->getContactsByRole($s['idspectacle'],17));
$dvd['spectacles'][$s['idspectacle']]['coproducteurs'] = $this->func->noPunct($spectacles->getContactsByRole($s['idspectacle'],18));
$dvd['spectacles'][$s['idspectacle']]['producteurs_delegues'] = $this->func->noPunct($spectacles->getContactsByRole($s['idspectacle'],19));
// recuperer la liste des autres postes (idrole=0 et type=1)
$dvd['spectacles'][$s['idspectacle']]['others'] = $this->func->noPunct($spectacles->getPersonsByRole($s['idspectacle'],'distributions'));
// autres roles
$contents = $this->em->getRepository(Contents::class);
$others_distrib = $contents->getAssociateContent($s['idspectacle'],'spectacles','class_distribution');
if (!empty($others_distrib)) {
$others_distrib['text'] = $contents->wikiTransform($others_distrib['text']);
$others_distrib['text'] = preg_replace('#</?p>#i','',$others_distrib['text']);
$dvd['spectacles'][$s['idspectacle']]['others_distrib'] = $others_distrib;
}
}
}
// si URL de vente = copat
if (!empty($dvd['urlVente']) && strpos($dvd['urlVente'],'copat')!==false) {
$dvd['url_vente_copat'] = $dvd['urlVente'];
$dvd['url_vente_bis_copat'] = str_replace('copat.fr/', 'copat.fr/enseignement/', $dvd['urlVente']);
}
if (!empty($dvd['url_vente_bis']) && strpos($dvd['url_vente_bis'],'copat')!==false) {
$dvd['url_vente_bis_copat'] = $dvd['url_vente_bis'];
}
//setDebug($dvd);
// spectacle en premier dans les blocs
$this->view->first_spectacles = true;
// meta keywords et comments
if (empty($meta_keywords)) $meta_keywords = '';
// ajout des noms des auteurs et metteurs en scène aux keywords
foreach(array('authors', 'directors') as $field) {
if (!empty($dvd[$field])) {
// ajout des auteurs aux keywords
foreach($dvd[$field] as $k => $v) {
$meta_keywords .= ' '.$v['lastname'];
}
}
}
// ajout du lieu aux keywords
if (!empty($dvd['lieu_shooting'])) $meta_keywords .= ' '.$dvd['lieu_shooting'];
// ajout des titres de spectacles aux keywords
if (!empty($dvd['spectacles'])) {
foreach($dvd['spectacles'] as $k => $v) {
$meta_keywords .= ' '.$v['title'];
}
}
// afficher les titres
$this->view->only_title = true;
$this->view->dvd = $dvd;
$title_page = $dvd['title'];
// autres infos
$this->view->mtinfos = array('object' => 'dvds', 'idobject' => $iddvd, 'urifrom' => '/dvd/'.$dvd['urlClean'], 'info_rub' => 'ce DVD', 'special_pattern' => 'admin_barre');
// voir si l'objet est bookmarke
if ($this->context['session'] instanceof Extranetusers){
$bookmark = $this->em->getRepository(BookmarkExtranetuser::class);
if ($bookmark->isBookmark($iddvd,'dvds',$this->getUser()->getIdextranetuser())) {
$this->view->is_bookmark = true;
}
}
// action pour add/delete bookmark
if (isset($_GET['bookmark'])) {
$this->view->bookmark = true;
$do_action = $_GET['do_action'];
$this->view->$do_action = true;
$this->view->fem='e';
}
//setDebug($this->view->dvd);
$this->asides->load('ajoutez_MT.inc');
$this->asides->load('dvd_thumbnail');
$this->context['view']->aside = $this->asides->view();
// bouton de partage
$this->view->use_addthis = true;
return $this->view('dvd/view.html.twig', [
]);
}
}