/**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $channel = new Channel();
     $channel->setName('Write a blog post');
     $channel->setDescription('');
     return $this->render('default/index.html.twig', ['base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..')]);
 }
 /**
  * @Route("/channel/create", name="channel_create")
  */
 public function createChannelAction()
 {
     $request = Request::createFromGlobals();
     $name = $request->request->get('name');
     $description = $request->request->get('description');
     $stream = $request->request->get('stream');
     $channel = new Channel();
     $channel->setName($name);
     $channel->setStream($stream);
     $channel->setDescription($description);
     $em = $this->getDoctrine()->getManager();
     $em->persist($channel);
     $em->flush();
     return $this->redirectToRoute('channel_show');
 }
 private function buildPlaylist(Channel $channel)
 {
     $em = $this->getDoctrine()->getManager();
     $channelName = $channel->getName();
     $items = $em->getRepository('AppBundle:ScheduleItem')->findBy(array('channel' => $channel), array('sequence' => 'ASC'));
     //->findByChannel($channel);
     $playlist = array();
     //need to think about the ordering and include items from inherited channel.
     if ($channel->getInherits()) {
         $masterItems = $em->getRepository('AppBundle:ScheduleItem')->findBy(array('channel' => $channel->getInherits()), array('sequence' => 'ASC'));
         //->findByChannel($channel->getInherits());
         //$items = array_merge($items, $masterItems);
         $items = $this->array_mix($masterItems, $items);
     }
     $i = 0;
     foreach ($items as $item) {
         $helper = $this->container->get('vich_uploader.templating.helper.uploader_helper');
         $path = $helper->asset($item->getAsset(), 'uriFile');
         $url = $this->get('liip_imagine.cache.manager')->getBrowserPath($path, '1080');
         $webPath = $this->get('kernel')->getRootDir() . '/../web' . $this->getRequest()->getBasePath();
         $playlist[$i]['uri'] = $item->getAsset()->getUri();
         $playlist[$i]['type'] = $item->getAsset()->getMimeType();
         $playlist[$i]['url'] = $url;
         $playlist[$i]['start'] = $item->getStart()->format('c');
         $playlist[$i]['stop'] = $item->getStop()->format('c');
         $playlist[$i]['duration'] = $item->getDuration() ? $item->getDuration() : $channel->getDuration();
         //$playlist[$i]['hash'] = md5_file("$webPath$path");
         $i++;
     }
     $data = array('meta' => array('id' => $channel->getId(), 'name' => $channel->getName()), 'playlist' => $playlist);
     return $data;
 }
 /**
  * Creates a form to delete a Channel entity.
  *
  * @param Channel $channel The Channel entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Channel $channel)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('channel_delete', array('id' => $channel->getId())))->setMethod('DELETE')->getForm();
 }