container = $_container; $this->entityManager = $_container->get('doctrine.orm.entity_manager'); //TODO a charger depuis les parameters du projet $this->langs = ['fr','en','es']; $this->resolutions = ['s','m','l','xl']; $this->repository = $this->entityManager->getRepository(AGridModule::class); } /** * @param AGridModule $element * @return bool */ public function quickUpdate(AGridModule $element): bool { try { if (!$this->entityManager->contains($element)) { if ($element) $this->entityManager->persist($element); else return false; } $this->entityManager->flush(); } catch (OptimisticLockException $e) { return false; } catch (ORMException $e) { return false; } return true; } public function youtubeVideoManager(AGridModule $module, array $data){ $autoplay = ($data['autoplay'] == 'true') ? 1 : 0; $allowFullScreen = ($data['allowfullscreen'] == 'true') ? 1 : 0; preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $data['url'], $match); if($data['video_id'] != $match[1]){ $data['video_id'] = $match[1]; //appel curl $url = 'https://www.youtube.com/oembed'; $curl_response = $this->container->get('net15.core.curl_manager')->curl('GET',$url,['url'=> $data['url'],'format'=>'json'],[],[]); $response = json_decode($curl_response); foreach ($response as $key => $value) $module->addParameter($key, $value); $module->addParameter("original_url", $match[0]); $module->addParameter("video_id", $match[1]); $module->addParameter("autoplay", $autoplay); $module->addParameter("allowfullscreen", $allowFullScreen); if (array_key_exists('mode', $data)) $module->addParameter('mode', $data['mode']); if (array_key_exists('twig', $data)) $module->addParameter('twig', $data['twig']); if (array_key_exists('lang', $data)) $module->addParameter('lang', $data['lang']); $url = $module->getParameter('provider_url').'embed/'.$module->getParameter('video_id').'?autoplay='.$module->getParameter('autoplay').'&rel=0'; $module->addParameter("url", $url); } return $module; } }