Youtubecom.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Muzich\CoreBundle\Factory\Elements;
  3. use Muzich\CoreBundle\Factory\ElementFactory;
  4. use Muzich\CoreBundle\Entity\Element;
  5. use Muzich\CoreBundle\Factory\UrlMatchs;
  6. use Symfony\Component\DependencyInjection\Container;
  7. use Doctrine\ORM\EntityManager;
  8. class Youtubecom extends ElementFactory
  9. {
  10. public function __construct(Element $element, Container $container, EntityManager $entity_manager)
  11. {
  12. $this->url_matchs = UrlMatchs::$youtube;
  13. parent::__construct($element, $container, $entity_manager);
  14. }
  15. public function proceedDatas()
  16. {
  17. $this->setElementDatasWithApi();
  18. $this->proceedEmbedCode();
  19. $this->proceedThumbnailUrl();
  20. }
  21. protected function setElementDatasWithApi()
  22. {
  23. $response = $this->getApiConnector()->getResponseForUrl('https://www.googleapis.com/youtube/v3/videos?id='
  24. .$this->url_analyzer->getRefId().'&key=AIzaSyC1DjeoUerFTUDdf2Rw8L8znEWbueGeykg&part=snippet,contentDetails,statistics,status');
  25. $this->getApiConnector()->setElementDatasWithResponse($response, array(
  26. Element::DATA_THUMB_URL => array('items' => array(0 => array('thumbnails' => 'medium'))),
  27. Element::DATA_TITLE => array('items' => array(0 => array('snippet' => 'title'))),
  28. ));
  29. }
  30. public function proceedEmbedCode()
  31. {
  32. if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
  33. {
  34. $width = $this->container->getParameter('youtube_player_width');
  35. $height = $this->container->getParameter('youtube_player_height');
  36. $this->element->setEmbed(
  37. '<iframe width="'.$width.'" height="'.$height.'" '
  38. .'src="http://www.youtube.com/embed/'.$ref_id.'" '
  39. .'frameborder="0" allowfullscreen></iframe>'
  40. );
  41. }
  42. }
  43. public function proceedThumbnailUrl()
  44. {
  45. if (($ref_id = $this->element->getData(Element::DATA_REF_ID)))
  46. {
  47. $this->element->setThumbnailUrl(
  48. 'http://img.youtube.com/vi/'.$ref_id.'/default.jpg'
  49. );
  50. }
  51. }
  52. }