/**
  * 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::getParents
  */
 public function testGetParents()
 {
     $root = new Folder();
     $root->setId(1);
     $subFolder = new Folder();
     $subFolder->setId(2);
     $subFolder->setParent($root);
     $subSubFolder = new Folder();
     $subSubFolder->setId(3);
     $subSubFolder->setParent($subFolder);
     $parents = array($root, $subFolder);
     $this->assertEquals($parents, $subSubFolder->getParents());
 }
 /**
  * @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));
 }
 /**
  * @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));
 }