/**
  * @param Folder $folder
  */
 private function deleteChildren(Folder $folder)
 {
     $em = $this->getEntityManager();
     /** @var Folder $child */
     foreach ($folder->getChildren() as $child) {
         $this->deleteMedia($child);
         $this->deleteChildren($child);
         $child->setDeleted(true);
         $em->persist($child);
     }
 }
 /**
  * @param QueryBuilder $queryBuilder
  */
 public function adaptQueryBuilder(QueryBuilder $queryBuilder)
 {
     $queryBuilder->andWhere('b.folder = :folder')->setParameter('folder', $this->folder->getId())->andWhere('b.deleted = 0')->orderBy('b.updatedAt', 'DESC');
     if ($this->request->get('_route') == 'KunstmaanMediaBundle_chooser_show_folder') {
         $type = $this->request->query->get('type');
         if ($type) {
             switch ($type) {
                 case 'file':
                     $queryBuilder->andWhere('b.location = :location')->setParameter('location', 'local');
                     break;
                 case 'image':
                     $queryBuilder->andWhere('b.contentType LIKE :ctype')->setParameter('ctype', '%image%');
                     break;
                 case RemoteAudioHandler::TYPE:
                     $queryBuilder->andWhere('b.contentType = :ctype')->setParameter('ctype', RemoteAudioHandler::CONTENT_TYPE);
                     break;
                 case RemoteSlideHandler::TYPE:
                     $queryBuilder->andWhere('b.contentType = :ctype')->setParameter('ctype', RemoteSlideHandler::CONTENT_TYPE);
                     break;
                 case RemoteVideoHandler::TYPE:
                     $queryBuilder->andWhere('b.contentType = :ctype')->setParameter('ctype', RemoteVideoHandler::CONTENT_TYPE);
                     break;
             }
         }
     }
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  * @covers Kunstmaan\MediaBundle\Helper\FolderManager::__construct
  */
 protected function setUp()
 {
     $this->repository = $this->getMockBuilder('Kunstmaan\\MediaBundle\\Repository\\FolderRepository')->disableOriginalConstructor()->getMock();
     $this->repository->expects($this->any())->method('getParentIds')->will($this->returnValue(array(1, 2)));
     $folder1 = new Folder();
     $folder1->setId(1);
     $folder2 = new Folder();
     $folder2->setId(2);
     $this->parents = array($folder1, $folder2);
     $this->repository->expects($this->any())->method('getPath')->will($this->returnValue(array($folder1, $folder2)));
     $rootFolder = new Folder();
     $rootFolder->setId(1);
     $this->repository->expects($this->any())->method('getFolder')->with($this->equalTo(1))->will($this->returnValue($rootFolder));
     $this->folder = new Folder();
     $this->folder->setId(3);
     $this->object = new FolderManager($this->repository);
 }
 /**
  * Add a child
  *
  * @param Folder $child
  *
  * @return Folder
  */
 public function addChild(Folder $child)
 {
     $this->children[] = $child;
     $child->setParent($this);
     return $this;
 }
 /**
  * @covers Kunstmaan\MediaBundle\Entity\Folder::getOptionLabel
  */
 public function testGetOptionLabel()
 {
     $this->object->setName('Test')->setLevel(2);
     $this->assertEquals('-- Test', $this->object->getOptionLabel());
 }
 /**
  * @param Request $request
  * @param int     $folderId The folder id
  *
  * @Route("/chooser/{folderId}", requirements={"folderId" = "\d+"}, name="KunstmaanMediaBundle_chooser_show_folder")
  * @Template()
  *
  * @return array
  */
 public function chooserShowFolderAction(Request $request, $folderId)
 {
     $em = $this->getDoctrine()->getManager();
     $session = $request->getSession();
     $type = $request->get('type');
     $cKEditorFuncNum = $request->get('CKEditorFuncNum');
     $linkChooser = $request->get('linkChooser');
     // Remember the last visited folder in the session
     $session->set('last-media-folder', $folderId);
     // Check when user switches between thumb -and list view
     $viewMode = $request->query->get('viewMode');
     if ($viewMode && $viewMode == 'list-view') {
         $session->set('media-list-view', true);
     } elseif ($viewMode && $viewMode == 'thumb-view') {
         $session->remove('media-list-view');
     }
     /* @var MediaManager $mediaHandler */
     $mediaHandler = $this->get('kunstmaan_media.media_manager');
     /* @var Folder $folder */
     $folder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
     /** @var AbstractMediaHandler $handler */
     $handler = null;
     if ($type) {
         $handler = $mediaHandler->getHandlerForType($type);
     }
     /* @var MediaManager $mediaManager */
     $mediaManager = $this->get('kunstmaan_media.media_manager');
     $adminListConfigurator = new MediaAdminListConfigurator($em, $mediaManager, $folder, $request);
     $adminList = $this->get('kunstmaan_adminlist.factory')->createList($adminListConfigurator);
     $adminList->bindRequest($request);
     $sub = new Folder();
     $sub->setParent($folder);
     $subForm = $this->createForm(new FolderType($sub), $sub);
     $linkChooserLink = null;
     if (!empty($linkChooser)) {
         $params = array();
         if (!empty($cKEditorFuncNum)) {
             $params['CKEditorFuncNum'] = $cKEditorFuncNum;
             $routeName = 'KunstmaanNodeBundle_ckselecturl';
         } else {
             $routeName = 'KunstmaanNodeBundle_selecturl';
         }
         $linkChooserLink = $this->generateUrl($routeName, $params);
     }
     $viewVariabels = array('cKEditorFuncNum' => $cKEditorFuncNum, 'linkChooser' => $linkChooser, 'linkChooserLink' => $linkChooserLink, 'mediamanager' => $mediaManager, 'foldermanager' => $this->get('kunstmaan_media.folder_manager'), 'handler' => $handler, 'type' => $type, 'folder' => $folder, 'adminlist' => $adminList, 'subform' => $subForm->createView());
     /* generate all forms */
     $forms = array();
     foreach ($mediaManager->getFolderAddActions() as $addAction) {
         $forms[$addAction['type']] = $this->createTypeFormView($mediaHandler, $addAction['type']);
     }
     $viewVariabels['forms'] = $forms;
     return $viewVariabels;
 }
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $gal = new Folder();
     $gal->setRel('media');
     $gal->setName('Media');
     $gal->setTranslatableLocale('en');
     $manager->persist($gal);
     $manager->flush();
     $this->addReference('media-folder-en', $gal);
     $gal->setTranslatableLocale('nl');
     $manager->refresh($gal);
     $gal->setName('Media');
     $manager->persist($gal);
     $manager->flush();
     $gal->setTranslatableLocale('fr');
     $manager->refresh($gal);
     $gal->setName('Média');
     $manager->persist($gal);
     $manager->flush();
     $subgal = new Folder();
     $subgal->setParent($gal);
     $subgal->setRel('image');
     $subgal->setName('Images');
     $subgal->setTranslatableLocale('en');
     $manager->persist($subgal);
     $manager->flush();
     $this->addReference('images-folder-en', $subgal);
     $subgal->setTranslatableLocale('nl');
     $manager->refresh($subgal);
     $subgal->setName('Afbeeldingen');
     $manager->persist($subgal);
     $manager->flush();
     $subgal->setTranslatableLocale('fr');
     $manager->refresh($subgal);
     $subgal->setName('Images');
     $manager->persist($subgal);
     $manager->flush();
     $subgal = new Folder();
     $subgal->setParent($gal);
     $subgal->setRel('files');
     $subgal->setName('Files');
     $subgal->setTranslatableLocale('en');
     $manager->persist($subgal);
     $manager->flush();
     $this->addReference('files-folder-en', $subgal);
     $subgal->setTranslatableLocale('nl');
     $manager->refresh($subgal);
     $subgal->setName('Bestanden');
     $manager->persist($subgal);
     $manager->flush();
     $subgal->setTranslatableLocale('fr');
     $manager->refresh($subgal);
     $subgal->setName('Fichiers');
     $manager->persist($subgal);
     $manager->flush();
     $subgal = new Folder();
     $subgal->setParent($gal);
     $subgal->setRel('slideshow');
     $subgal->setName('Slides');
     $subgal->setTranslatableLocale('en');
     $manager->persist($subgal);
     $manager->flush();
     $this->addReference('slides-folder-en', $subgal);
     $subgal->setTranslatableLocale('nl');
     $manager->refresh($subgal);
     $subgal->setName('Presentaties');
     $manager->persist($subgal);
     $manager->flush();
     $subgal->setTranslatableLocale('fr');
     $manager->refresh($subgal);
     $subgal->setName('Presentations');
     $manager->persist($subgal);
     $manager->flush();
     $subgal = new Folder();
     $subgal->setParent($gal);
     $subgal->setRel('video');
     $subgal->setName('Videos');
     $subgal->setTranslatableLocale('en');
     $manager->persist($subgal);
     $manager->flush();
     $this->addReference('videos-folder-en', $subgal);
     $subgal->setTranslatableLocale('nl');
     $manager->refresh($subgal);
     $subgal->setName('Video\'s');
     $manager->persist($subgal);
     $manager->flush();
     $subgal->setTranslatableLocale('fr');
     $manager->refresh($subgal);
     $subgal->setName('Vidéos');
     $manager->persist($subgal);
     $manager->flush();
 }
 /**
  * @param Request $request
  * @param int     $folderId
  *
  * @Route("/subcreate/{folderId}", requirements={"folderId" = "\d+"}, name="KunstmaanMediaBundle_folder_sub_create")
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @return Response
  */
 public function subCreateAction(Request $request, $folderId)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     /* @var Folder $parent */
     $parent = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
     $folder = new Folder();
     $folder->setParent($parent);
     $form = $this->createForm(FolderType::class, $folder);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em->getRepository('KunstmaanMediaBundle:Folder')->save($folder);
             $this->get('session')->getFlashBag()->add('success', 'Folder \'' . $folder->getName() . '\' has been created!');
             if (strpos($_SERVER['HTTP_REFERER'], 'chooser') !== false) {
                 $redirect = 'KunstmaanMediaBundle_chooser_show_folder';
             } else {
                 $redirect = 'KunstmaanMediaBundle_folder_show';
             }
             $type = $request->get('type');
             return new RedirectResponse($this->generateUrl($redirect, array('folderId' => $folder->getId(), 'type' => $type)));
         }
     }
     $galleries = $em->getRepository('KunstmaanMediaBundle:Folder')->getAllFolders();
     return $this->render('KunstmaanMediaBundle:Folder:addsub-modal.html.twig', array('subform' => $form->createView(), 'galleries' => $galleries, 'folder' => $folder, 'parent' => $parent));
 }
 /**
  * @covers Kunstmaan\MediaBundle\Entity\Media::getFolder
  * @covers Kunstmaan\MediaBundle\Entity\Media::setFolder
  */
 public function testGetSetFolder()
 {
     $folder = new Folder();
     $folder->setId(45);
     $this->object->setFolder($folder);
     $this->assertEquals(45, $this->object->getFolder()->getId());
 }
 /**
  * @param Request $request
  * @param int     $folderId
  *
  * @Route("/subcreate/{folderId}", requirements={"folderId" = "\d+"}, name="KunstmaanMediaBundle_folder_sub_create")
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @return Response
  */
 public function subCreateAction(Request $request, $folderId)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     /* @var Folder $parent */
     $parent = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
     $folder = new Folder();
     $folder->setParent($parent);
     $form = $this->createForm(new FolderType(), $folder);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em->getRepository('KunstmaanMediaBundle:Folder')->save($folder);
             $this->get('session')->getFlashBag()->add('success', 'Folder \'' . $folder->getName() . '\' has been created!');
             return new Response('<script>window.location="' . $this->generateUrl('KunstmaanMediaBundle_folder_show', array('folderId' => $folder->getId())) . '"</script>');
         }
     }
     $galleries = $em->getRepository('KunstmaanMediaBundle:Folder')->getAllFolders();
     return $this->render('KunstmaanMediaBundle:Folder:addsub-modal.html.twig', array('subform' => $form->createView(), 'galleries' => $galleries, 'folder' => $folder, 'parent' => $parent));
 }