Skip to content
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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Add image uploads #76

wants to merge 21 commits into from

Conversation

angeluss88
Copy link

No description provided.

Copy link
Owner

@pilot pilot left a 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 .
Copy link
Owner

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/';
Copy link
Owner

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();
Copy link
Owner

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())){
Copy link
Owner

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

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());
Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add typehint

Copy link

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,
Copy link
Owner

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>
Copy link
Owner

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);
Copy link
Owner

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');
Copy link
Owner

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());
Copy link

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())){
Copy link

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()
Copy link

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);
Copy link

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;
Copy link

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param \DateTime $createdDate
* @return Media
*/
public function setCreatedDate($createdDate)
Copy link

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){

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+ }

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 */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all files. In PhpStorm:
image

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 |
Copy link
Contributor

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.');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be translatable

@pilot pilot mentioned this pull request Dec 11, 2017
2 tasks
@pilot
Copy link
Owner

pilot commented Dec 27, 2017

@angeluss88 replace filestack with https://uppy.io/

@pilot
Copy link
Owner

pilot commented Dec 27, 2017

add to the Wiki manual how to configure the uploader https://github.com/pilot/eventator/wiki/Uploader

]);
}

protected function checkAccessFolder($path){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants