Skip to content

Commit

Permalink
Merge pull request #143 from Kunstmaan/fix-foldertype-parent-required
Browse files Browse the repository at this point in the history
code reformatting/cleanup & fix parent required in foldertype
  • Loading branch information
Wim Vandersmissen committed Apr 7, 2014
2 parents 93ff857 + f3d24c7 commit 29a7940
Show file tree
Hide file tree
Showing 23 changed files with 514 additions and 414 deletions.
4 changes: 2 additions & 2 deletions AdminList/ItemAction/MediaDeleteItemAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function __construct($redirectUrl)
public function getUrlFor($item)
{
return array(
'path' => 'KunstmaanMediaBundle_media_delete',
'params' => array('mediaId' => $item->getId(), 'redirectUrl' => $this->redirectUrl)
'path' => 'KunstmaanMediaBundle_media_delete',
'params' => array('mediaId' => $item->getId(), 'redirectUrl' => $this->redirectUrl)
);
}

Expand Down
4 changes: 2 additions & 2 deletions AdminList/ItemAction/MediaEditItemAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MediaEditItemAction implements ItemActionInterface
public function getUrlFor($item)
{
return array(
'path' => 'KunstmaanMediaBundle_media_show',
'params' => array('mediaId' => $item->getId())
'path' => 'KunstmaanMediaBundle_media_show',
'params' => array('mediaId' => $item->getId())
);
}

Expand Down
37 changes: 21 additions & 16 deletions AdminList/MediaAdminListConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM;
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractDoctrineORMAdminListConfigurator;
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM;
use Kunstmaan\MediaBundle\AdminList\ItemAction\MediaDeleteItemAction;
use Kunstmaan\MediaBundle\AdminList\ItemAction\MediaEditItemAction;
use Kunstmaan\MediaBundle\AdminList\ItemAction\MediaSelectItemAction;
Expand Down Expand Up @@ -40,12 +40,17 @@ class MediaAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurato
* @param Folder $folder The current folder
* @param Request $request The request object
*/
public function __construct(EntityManager $em, AclHelper $aclHelper = null, MediaManager $mediaManager, Folder $folder, Request $request)
{
public function __construct(
EntityManager $em,
AclHelper $aclHelper = null,
MediaManager $mediaManager,
Folder $folder,
Request $request
) {
parent::__construct($em, $aclHelper);

$this->setAdminType(new MediaType($mediaManager, $em));
$this->folder = $folder;
$this->folder = $folder;
$this->request = $request;
}

Expand All @@ -68,7 +73,7 @@ public function buildFilters()
$this->addFilter('name', new ORM\StringFilterType('name'), 'Name');
$this->addFilter('contentType', new ORM\StringFilterType('contentType'), 'Type');
$this->addFilter('updatedAt', new ORM\NumberFilterType('updatedAt'), 'Date');
$this->addFilter('filesize', new ORM\NumberFilterType('filesize'), 'Filsize (in bytes)');
$this->addFilter('filesize', new ORM\NumberFilterType('filesize'), 'Filesize (in bytes)');
}

/**
Expand All @@ -79,8 +84,8 @@ public function buildFilters()
public function getIndexUrl()
{
return array(
'path' => 'KunstmaanMediaBundle_folder_show',
'params' => array('folderId' => $this->folder->getId())
'path' => 'KunstmaanMediaBundle_folder_show',
'params' => array('folderId' => $this->folder->getId())
);
}

Expand Down Expand Up @@ -153,33 +158,33 @@ public function getEntityName()
public function adaptQueryBuilder(QueryBuilder $queryBuilder)
{
$queryBuilder->andWhere('b.folder = :folder')
->setParameter('folder', $this->folder->getId())
->andWhere('b.deleted = 0')
->orderBy('b.updatedAt', 'DESC');
->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');
->setParameter('location', 'local');
break;
case 'image':
$queryBuilder->andWhere('b.contentType LIKE :ctype')
->setParameter('ctype', '%image%');
->setParameter('ctype', '%image%');
break;
case RemoteAudioHandler::TYPE:
$queryBuilder->andWhere('b.contentType = :ctype')
->setParameter('ctype', RemoteAudioHandler::CONTENT_TYPE);
->setParameter('ctype', RemoteAudioHandler::CONTENT_TYPE);
break;
case RemoteSlideHandler::TYPE:
$queryBuilder->andWhere('b.contentType = :ctype')
->setParameter('ctype', RemoteSlideHandler::CONTENT_TYPE);
->setParameter('ctype', RemoteSlideHandler::CONTENT_TYPE);
break;
case RemoteVideoHandler::TYPE:
$queryBuilder->andWhere('b.contentType = :ctype')
->setParameter('ctype', RemoteVideoHandler::CONTENT_TYPE);
->setParameter('ctype', RemoteVideoHandler::CONTENT_TYPE);
break;
}
}
Expand Down
23 changes: 14 additions & 9 deletions Controller/AviaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Kunstmaan\MediaBundle\Controller;


use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Kunstmaan\MediaBundle\Entity\Folder;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Kunstmaan\MediaBundle\Entity\Media;
use Kunstmaan\MediaBundle\Helper\MediaManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* controllerclass which Aviary can use to upload the edited image and add it to the database
Expand All @@ -17,13 +18,14 @@ class AviaryController extends Controller
{

/**
* @param int $folderId The id of the Folder
* @param int $mediaId The id of the image
* @param Request $request
* @param int $folderId The id of the Folder
* @param int $mediaId The id of the image
*
* @Route("/aviary/{folderId}/{mediaId}", requirements={"folderId" = "\d+", "mediaId" = "\d+"}, name="KunstmaanMediaBundle_aviary")
* @return RedirectResponse
*/
public function indexAction($folderId, $mediaId)
public function indexAction(Request $request, $folderId, $mediaId)
{
$em = $this->getDoctrine()->getManager();

Expand All @@ -34,14 +36,17 @@ public function indexAction($folderId, $mediaId)
/* @var MediaManager $mediaManager */
$mediaManager = $this->get('kunstmaan_media.media_manager');

$handler = $mediaManager->getHandler($media);
$handler = $mediaManager->getHandler($media);
$fileHelper = $handler->getFormHelper($media);
$fileHelper->getMediaFromUrl($this->getRequest()->get('url'));
$fileHelper->getMediaFromUrl($request->get('url'));
$media = $fileHelper->getMedia();

$em->persist($media);
$em->flush();

return new RedirectResponse($this->generateUrl('KunstmaanMediaBundle_folder_show', array('folderId' => $folder->getId())));
return new RedirectResponse($this->generateUrl(
'KunstmaanMediaBundle_folder_show',
array('folderId' => $folder->getId())
));
}
}
73 changes: 38 additions & 35 deletions Controller/ChooserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

/**
* ChooserController.
Expand All @@ -20,16 +21,18 @@ class ChooserController extends Controller
/**
* @Route("/chooser", name="KunstmaanMediaBundle_chooser")
*
* @param Request $request
*
* @return RedirectResponse
*/
public function chooserIndexAction()
public function chooserIndexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$session = $this->getRequest()->getSession();
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();

$type = $this->getRequest()->get('type');
$cKEditorFuncNum = $this->getRequest()->get('CKEditorFuncNum');
$linkChooser = $this->getRequest()->get('linkChooser');
$type = $request->get('type');
$cKEditorFuncNum = $request->get('CKEditorFuncNum');
$linkChooser = $request->get('linkChooser');

// Go to the last visited folder
if ($session->get('last-media-folder')) {
Expand All @@ -38,36 +41,36 @@ public function chooserIndexAction()
// Redirect to the first top folder
/* @var Folder $firstFolder */
$firstFolder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFirstTopFolder();
$folderId = $firstFolder->getId();
$folderId = $firstFolder->getId();
}

$params = array(
'folderId' => $folderId,
'type' => $type,
'CKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser
'folderId' => $folderId,
'type' => $type,
'CKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser
);

return $this->redirect($this->generateUrl('KunstmaanMediaBundle_chooser_show_folder', $params));
}

/**
* @param int $folderId The folder id
* @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($folderId)
public function chooserShowFolderAction(Request $request, $folderId)
{
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();

$type = $this->getRequest()->get('type');
$cKEditorFuncNum = $this->getRequest()->get('CKEditorFuncNum');
$linkChooser = $this->getRequest()->get('linkChooser');
$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);
Expand Down Expand Up @@ -97,35 +100,35 @@ public function chooserShowFolderAction($folderId)
$mediaManager = $this->get('kunstmaan_media.media_manager');

$adminListConfigurator = new MediaAdminListConfigurator($em, null, $mediaManager, $folder, $request);
$adminList = $this->get('kunstmaan_adminlist.factory')->createList($adminListConfigurator);
$adminList = $this->get('kunstmaan_adminlist.factory')->createList($adminListConfigurator);
$adminList->bindRequest($request);

$linkChooserLink = null;
if (!empty($linkChooser)) {
$params = array();
if (!empty($cKEditorFuncNum)) {
$params['CKEditorFuncNum'] = $cKEditorFuncNum;
$routeName = 'KunstmaanNodeBundle_ckselecturl';
$routeName = 'KunstmaanNodeBundle_ckselecturl';
} else {
$routeName = 'KunstmaanNodeBundle_selecturl';
}
$linkChooserLink = $this->generateUrl($routeName, $params);
}

return array(
'cKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser,
'linkChooserLink' => $linkChooserLink,
'mediamanager' => $mediaHandler,
'handler' => $handler,
'type' => $type,
'folder' => $folder,
'folders' => $folders,
'adminlist' => $adminList,
'fileform' => $this->createTypeFormView($mediaHandler, "file"),
'videoform' => $this->createTypeFormView($mediaHandler, "video"),
'slideform' => $this->createTypeFormView($mediaHandler, "slide"),
'audioform' => $this->createTypeFormView($mediaHandler, "audio")
'cKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser,
'linkChooserLink' => $linkChooserLink,
'mediamanager' => $mediaHandler,
'handler' => $handler,
'type' => $type,
'folder' => $folder,
'folders' => $folders,
'adminlist' => $adminList,
'fileform' => $this->createTypeFormView($mediaHandler, "file"),
'videoform' => $this->createTypeFormView($mediaHandler, "video"),
'slideform' => $this->createTypeFormView($mediaHandler, "slide"),
'audioform' => $this->createTypeFormView($mediaHandler, "audio")
);
}

Expand All @@ -138,8 +141,8 @@ public function chooserShowFolderAction($folderId)
private function createTypeFormView(MediaManager $mediaManager, $type)
{
$handler = $mediaManager->getHandlerForType($type);
$media = new Media();
$helper = $handler->getFormHelper($media);
$media = new Media();
$helper = $handler->getFormHelper($media);

return $this->createForm($handler->getFormType(), $helper)->createView();
}
Expand Down
Loading

0 comments on commit 29a7940

Please sign in to comment.