Skip to content

Add image uploads#76

Open
angeluss88 wants to merge 21 commits into
masterfrom
add-image-uploads
Open

Add image uploads#76
angeluss88 wants to merge 21 commits into
masterfrom
add-image-uploads

Conversation

@angeluss88

Copy link
Copy Markdown

No description provided.

@pilot pilot left a comment

Copy link
Copy Markdown
Owner

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

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
Copy Markdown
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

Comment thread src/Event/EventBundle/Entity/Media.php Outdated
* @param \DateTime $createdDate
* @return Media
*/
public function setCreatedDate($createdDate)

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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/Event/EventBundle/Entity/Media.php Outdated
* @param \DateTime $createdDate
* @return Media
*/
public function setCreatedDate($createdDate)

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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+ } No newline at end of file

Copy link
Copy Markdown

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 */ No newline at end of file

Copy link
Copy Markdown

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

Comment thread 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 | 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 |

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

pilot commented Dec 27, 2017

Copy link
Copy Markdown
Owner

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

@pilot

pilot commented Dec 27, 2017

Copy link
Copy Markdown
Owner

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

]);
}

protected function checkAccessFolder($path){

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