Permalink
Browse files

fix_bulkupload + some cleanup

  • Loading branch information...
1 parent 94da9e9 commit 7154e6334ee6aaaa0c435fe30580a9f136811339 @krispypen krispypen committed Nov 20, 2012
@@ -28,7 +28,7 @@ public function chooserIndexAction()
$em = $this->getDoctrine()->getManager();
- /* @var Folder $firstGallery */
+ /* @var Folder $firstFolder */
$firstFolder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder(1);
//TODO get the first topfolder
@@ -62,13 +62,13 @@ public function deleteAction($folderId)
/* @var Folder $folder */
$folder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
$foldername = $folder->getName();
- $parentGallery = $folder->getParent();
+ $parentFolder = $folder->getParent();
$em->getRepository('KunstmaanMediaBundle:Folder')->delete($folder);
$this->get('session')->getFlashBag()->add('success', 'Folder \''.$foldername.'\' has been deleted!');
- return new RedirectResponse($this->generateUrl('KunstmaanMediaBundle_folder_show', array('folderId' => $parentGallery->getId())));
+ return new RedirectResponse($this->generateUrl('KunstmaanMediaBundle_folder_show', array('folderId' => $parentFolder->getId())));
}
/**
@@ -95,8 +95,6 @@ public function deleteAction($mediaId)
* @Template()
*
* @return array|RedirectResponse
- *
- * @throws \InvalidArgumentException when the gallery does not support bulk upload
*/
public function bulkUploadAction($folderId)
{
@@ -116,12 +114,12 @@ public function bulkUploadAction($folderId)
foreach ($helper->getFiles() as $file) {
/* @var Media $media */
$media = $this->get('kunstmaan_media.media_manager')->getHandler($file)->createNew($file);
- $media->setGallery($folder);
+ $media->setFolder($folder);
$em->getRepository('KunstmaanMediaBundle:Media')->save($media);
-
- $this->get('session')->getFlashBag()->add('success', 'New media has been uploaded!');
}
+ $this->get('session')->getFlashBag()->add('success', 'New media has been uploaded!');
+
return new RedirectResponse($this->generateUrl('KunstmaanMediaBundle_folder_show', array('folderId' => $folder->getId())));
}
}
@@ -144,8 +142,6 @@ public function bulkUploadAction($folderId)
* @Method({"GET", "POST"})
*
* @return array|RedirectResponse
- *
- * @throws \InvalidArgumentException when the gallery does not support bulk upload
*/
public function dropAction($folderId)
{
View
@@ -237,20 +237,6 @@ public function getParents()
}
/**
- * Add folder
- *
- * @param Folder $folder
- *
- * @return Folder
- */
- public function addGallery(Folder $folder)
- {
- $this->children[] = $folder;
-
- return $this;
- }
-
- /**
* Add a child
*
* @param Folder $child
@@ -67,13 +67,13 @@ public function getFormType()
}
/**
- * @param Media $media
+ * @param mixed $object
*
* @return bool
*/
- public function canHandle(Media $media)
+ public function canHandle($object)
{
- if (is_file($media->getContent()) || $media->getLocation() == 'local') {
+ if ($object instanceof File || ($object instanceof Media && (is_file($object->getContent()) || $object->getLocation() == 'local'))) {
return true;
}
@@ -2,6 +2,8 @@
namespace Kunstmaan\MediaBundle\Helper\Image;
+use Symfony\Component\HttpFoundation\File\File;
+
use Kunstmaan\MediaBundle\Helper\File\FileHandler;
use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
@@ -16,8 +18,7 @@ class ImageHandler extends FileHandler
protected $aviaryApiKey;
/**
- * @param ImageManipulatorInterface $imageManipulator The image manipulator
- * @param string $aviaryApiKey The aviary key
+ * @param string $aviaryApiKey The aviary key
*/
public function __construct($aviaryApiKey)
{
@@ -50,13 +51,13 @@ public function getType()
}
/**
- * @param Media $media
+ * @param mixed $object
*
* @return bool
*/
- public function canHandle(Media $media)
+ public function canHandle($object)
{
- if (parent::canHandle($media) && strpos($media->getContentType(), 'image') === 0) {
+ if (parent::canHandle($object) && ($object instanceof File || strpos($object->getContentType(), 'image') === 0)) {
return true;
}
@@ -28,9 +28,9 @@
public abstract function getFormType();
/**
- * @param Media $media
+ * @param mixed $media
*/
- public abstract function canHandle(Media $media);
+ public abstract function canHandle($media);
/**
* @param Media $media
@@ -33,7 +33,7 @@ public function addHandler(AbstractMediaHandler $handler)
*
* @throws \InvalidArgumentException when there is no context for this name
*/
- public function getHandler(Media $media)
+ public function getHandler($media)
{
foreach ($this->handlers as $handler) {
if ($handler->canHandle($media)) {
@@ -44,13 +44,13 @@ public function getFormType()
}
/**
- * @param Media $media
+ * @param mixed $object
*
* @return bool
*/
- public function canHandle(Media $media)
+ public function canHandle($object)
{
- if ($media->getContentType() == RemoteSlideHandler::CONTENT_TYPE) {
+ if ((is_string($object)) || ($object instanceof Media && $object->getContentType() == RemoteSlideHandler::CONTENT_TYPE)) {
return true;
}
@@ -151,7 +151,7 @@ public function createNew($data)
$slide = new RemoteSlideHelper($result);
$slide->setType('slideshare');
$json = json_decode(file_get_contents('http://www.slideshare.net/api/oembed/2?url='.$data.'&format=json'));
- $slide->setCode($json->slideshow_id);
+ $slide->setCode($json->{"slideshow_id"});
$result = $slide->getMedia();
$result->setName('SlideShare ' . $data);
break;
@@ -47,13 +47,13 @@ public function getFormType()
}
/**
- * @param Media $media
+ * @param mixed $object
*
* @return bool
*/
- public function canHandle(Media $media)
+ public function canHandle($object)
{
- if ($media->getContentType() == RemoteVideoHandler::CONTENT_TYPE) {
+ if ((is_string($object)) || ($object instanceof Media && $object->getContentType() == RemoteVideoHandler::CONTENT_TYPE)) {
return true;
}
@@ -94,7 +94,7 @@ public function prepareMedia(Media $media)
break;
case 'dailymotion':
$json = json_decode(file_get_contents("https://api.dailymotion.com/video/".$code."?fields=thumbnail_large_url"));
- $thumbnailUrl = $json->thumbnail_large_url;
+ $thumbnailUrl = $json->{"thumbnail_large_url"};
/* dirty hack to fix urls for imagine */
if (!$this->endsWith($thumbnailUrl, '.jpg') && !$this->endsWith($thumbnailUrl, '.png')) {
$thumbnailUrl = $thumbnailUrl.'&ext=.jpg';

0 comments on commit 7154e63

Please sign in to comment.