Add image uploads#76
Conversation
pilot
left a comment
There was a problem hiding this comment.
- Please add tests with behat
- add screenshots, or video set how does it work
|
|
||
| public function getUploadPath() | ||
| { | ||
| return $this->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . |
There was a problem hiding this comment.
should be taken from the paramters.yml
| } | ||
|
|
||
| public function getUploadUrl(){ | ||
| return '/uploads/media/'; |
There was a problem hiding this comment.
should be taken from the paramters.yml
| { | ||
| $oldFileName = ''; | ||
| if ($id === null) { | ||
| $entity = new Media(); |
There was a problem hiding this comment.
$entity is not yet defined, as well use user-friendly naming, not entity but $media
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isValid()) { | ||
| if(is_null($entity->getId())){ |
There was a problem hiding this comment.
check CS (code style) for all files what you added
if ( should be with the space, use code sniffer from sensiolab
There was a problem hiding this comment.
There was a problem hiding this comment.
I think this condition in general is excess here
| if($oldFileName !== $entity->getFilename()) { | ||
| $url = $request->request->get('file_url'); | ||
| $path = $this->getUploadPath(); | ||
| $entity->setFilename( time() . '_' . $entity->getFilename()); |
| * @param \DateTime $createdDate | ||
| * @return Media | ||
| */ | ||
| public function setCreatedDate($createdDate) |
There was a problem hiding this comment.
I would replace setCreated and setUpdated with Gedmo Timestampable
|
|
||
| if ( 0 < elementsCount) { | ||
| $('#media-table').dataTable({ | ||
| "iDisplayLength": 50, |
| {% block javascripts %} | ||
| {{ parent() }} | ||
|
|
||
| <script type="text/javascript" src="https://static.filestackapi.com/v3/filestack.js"></script> |
There was a problem hiding this comment.
to use filestack we should be specify that in the Readmy
| accept: 'image/*', | ||
| }).then(function(result) { | ||
| var file = result.filesUploaded[0]; | ||
| // var file = JSON.stringify(result.filesUploaded); |
|
|
||
| <script type="text/javascript" src="https://static.filestackapi.com/v3/filestack.js"></script> | ||
| <script> | ||
| var client = filestack.init('A3w1aZwZmQBibC09rAcZnz'); |
There was a problem hiding this comment.
should be taken from parameters.yml at least for now, or better add event settings page where this is can be specified
|
|
||
| if ($form->isValid()) { | ||
| if(is_null($entity->getId())){ | ||
| $entity->setCreatedDate(new \DateTime()); |
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isValid()) { | ||
| if(is_null($entity->getId())){ |
There was a problem hiding this comment.
I think this condition in general is excess here
| return '/uploads/media/' . $this->filename; | ||
| } | ||
|
|
||
| public function __construct() |
There was a problem hiding this comment.
@pilot why?
here should be
$this->created = new \DateTime();
$this->updated = new \DateTime();
| $('#media_filename').val(file.filename); | ||
| $('#file_url').val(file.url); | ||
|
|
||
| console.log(file.filename); |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| $file = curl_exec($ch); | ||
| curl_close($ch); | ||
| return $file; |
There was a problem hiding this comment.
maybe better to use Guzzle or similar http client for requests
| $entity->setFilename( time() . '_' . $entity->getFilename()); | ||
| $file = $this->getFile($url); | ||
| file_put_contents($path . $entity->getFilename(), $file); | ||
| chmod($path . $entity->getFilename(), 0777); |
There was a problem hiding this comment.
use for this Symfony Filesystem component
| * @param \DateTime $createdDate | ||
| * @return Media | ||
| */ | ||
| public function setCreatedDate($createdDate) |
There was a problem hiding this comment.
I would replace setCreated and setUpdated with Gedmo Timestampable
| ]); | ||
| } | ||
|
|
||
| protected function getFile($url){ |
| backend_media_delete: | ||
| path: /media/delete/{id} | ||
| defaults: { _controller: EventEventBundle:Backend/Media:delete } | ||
| requirements: { id: \d+ } No newline at end of file |
There was a problem hiding this comment.
Have to be one empty line at the end of file
| #media_title { | ||
| width: 530px; | ||
| } | ||
| /* backend media uploader */ No newline at end of file |
| Given following "Event": | ||
| | ref | title | description | startDate | endDate | venue | email | host | | ||
| | event | My event | My another awesome event! | 2016-03-01 10:00 | 2016-03-01 18:00 | Burj Khalifa Tower | eventator@email.com | http://localhost:8000 | | ||
| | event2 | My other event | My other awesome event! | 2016-03-01 10:00 | 2016-03-01 18:00 | Burj Khalifa Tower | eventator@gmail.com | http://eventator.loc | |
There was a problem hiding this comment.
Please check https://github.com/pilot/eventator/blob/master/var/ci/eventator.loc.conf
In this config u can see port 8080, not 80! 😃 But in the event2 host value i see 80 port (!) That's the main reason why your test is fail.
| unlink($file); | ||
| } | ||
|
|
||
| $this->setSuccessFlash('Media deleted.'); |
|
@angeluss88 replace filestack with https://uppy.io/ |
|
add to the Wiki manual how to configure the uploader https://github.com/pilot/eventator/wiki/Uploader |
| ]); | ||
| } | ||
|
|
||
| protected function checkAccessFolder($path){ |

No description provided.