-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add image uploads #76
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be taken from the paramters.yml
} | ||
|
||
public function getUploadUrl(){ | ||
return '/uploads/media/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be taken from the paramters.yml
{ | ||
$oldFileName = ''; | ||
if ($id === null) { | ||
$entity = new Media(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFilename(time()
no space, CS
* @param \DateTime $createdDate | ||
* @return Media | ||
*/ | ||
public function setCreatedDate($createdDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add typehint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace setCreated
and setUpdated
with Gedmo Timestampable
|
||
if ( 0 < elementsCount) { | ||
$('#media-table').dataTable({ | ||
"iDisplayLength": 50, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use single quotes
{% block javascripts %} | ||
{{ parent() }} | ||
|
||
<script type="text/javascript" src="https://static.filestackapi.com/v3/filestack.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
|
||
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set it in entity constructor
$form->handleRequest($request); | ||
|
||
if ($form->isValid()) { | ||
if(is_null($entity->getId())){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this condition in general is excess here
return '/uploads/media/' . $this->filename; | ||
} | ||
|
||
public function __construct() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm all console.log
too
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
$file = curl_exec($ch); | ||
curl_close($ch); | ||
return $file; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use for this Symfony Filesystem component
* @param \DateTime $createdDate | ||
* @return Media | ||
*/ | ||
public function setCreatedDate($createdDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace setCreated
and setUpdated
with Gedmo Timestampable
]); | ||
} | ||
|
||
protected function getFile($url){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be on a new line
backend_media_delete: | ||
path: /media/delete/{id} | ||
defaults: { _controller: EventEventBundle:Backend/Media:delete } | ||
requirements: { id: \d+ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have to be one empty line at the end of file
#media_title { | ||
width: 530px; | ||
} | ||
/* backend media uploader */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
features/backend/media.feature
Outdated
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 | [email protected] | http://localhost:8000 | | ||
| event2 | My other event | My other awesome event! | 2016-03-01 10:00 | 2016-03-01 18:00 | Burj Khalifa Tower | [email protected] | http://eventator.loc | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be translatable
@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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CS fix
No description provided.