-
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?
Changes from 20 commits
df90aa0
d3b3925
c5276ff
ab7a33d
a549fcd
8a2f928
cacf24d
a0b7304
140b42d
7b6fb6b
a499660
1d5d286
9e36ac6
826e648
212596e
13b55ff
f0e0ac9
5a6b01d
5cd69f6
f0a9bd0
c6dbfed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ app/config/parameters.yml | |
|
||
composer.phar | ||
behat.yml | ||
.idea | ||
!web/uploads/.gitkeep | ||
!web/uploads/media/.gitkeep |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
@backend | ||
Feature: Media settings | ||
In order to update media settings | ||
As an admin | ||
I should be able to edit media settings | ||
|
||
Background: | ||
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:8080 | | ||
| event3 | His event | His another awesome event! | 2016-04-01 10:00 | 2016-04-01 18:00 | Kuala-lumpur Tower | eventator@gmail.com | http://event.com | | ||
And following "EventTranslation": | ||
| event | locale | | ||
| event | ru_RU | | ||
| event | de_DE | | ||
| event2 | ru_RU | | ||
| event2 | de_DE | | ||
| event3 | ru_RU | | ||
And following "Organizer": | ||
| ref | title | description | isActive | events | | ||
| organizer | My organizer | My another awesome organizer! | 1 | event,event2,event3 | | ||
| organizer2 | His organizer | His another awesome organizer! | 1 | event2,event3 | | ||
And following "OrganizerTranslation": | ||
| organizer | locale | | ||
| organizer | ru_RU | | ||
| organizer2 | de_DE | | ||
And following "Speech": | ||
| ref | title | description | language | event | | ||
| speech | symfony propagation | world symfony expansion | ru | event | | ||
| speech2 | php servers piece | php most popular language | en | event | | ||
| speech3 | doctrine must have | what you docrtine project should have | en | event | | ||
| speech4 | symfony propagation2 | world symfony expansion2 | en | event2 | | ||
| speech5 | php servers piece2 | php most popular language2 | en | event2 | | ||
| speech6 | doctrine must have2 | what you docrtine project should have2 | en | event2 | | ||
| speech7 | symfony propagation2 | world symfony expansion2 | en | event3 | | ||
| speech8 | php servers piece2 | php most popular language2 | en | event3 | | ||
| speech9 | doctrine must have2 | what you docrtine project should have2 | en | event3 | | ||
|
||
And following "SpeechTranslation": | ||
| speech | locale | | ||
| speech | ru_RU | | ||
| speech2 | de_DE | | ||
| speech3 | de_DE | | ||
| speech4 | ru_RU | | ||
| speech5 | de_DE | | ||
| speech6 | de_DE | | ||
| speech7 | ru_RU | | ||
| speech8 | de_DE | | ||
| speech9 | de_DE | | ||
And following "Program": | ||
| ref | title | isTopic | isActive | startDate | endDate | events | speech | | ||
| program | keynote | 1 | 1 | 2016-03-01 10:00 | 2016-03-01 10:30 | event | | | ||
| program2 | alex_symfony | 0 | 1 | 2016-03-01 10:30 | 2016-03-01 11:30 | event | speech | | ||
| program3 | phil_php | 0 | 1 | 2016-03-01 11:30 | 2016-03-01 12:30 | event | speech2 | | ||
| program4 | coffee1 | 1 | 1 | 2016-03-01 12:30 | 2016-03-01 13:00 | event | | | ||
| program5 | phil_doctrine | 0 | 1 | 2016-03-01 13:00 | 2016-03-01 14:30 | event | speech3 | | ||
| program6 | end_keynote | 1 | 1 | 2016-03-01 14:30 | 2016-03-01 15:00 | event | | | ||
| program7 | after_party | 1 | 1 | 2016-03-01 15:00 | 2016-03-01 18:00 | event | | | ||
| program8 | keynote | 1 | 1 | 2016-04-01 10:00 | 2016-04-01 10:30 | event2 | | | ||
| program9 | alex_symfony | 0 | 1 | 2016-04-01 10:30 | 2016-04-01 11:30 | event2 | speech4 | | ||
| program10 | phil_php | 0 | 1 | 2016-04-01 11:30 | 2016-04-01 12:30 | event2 | speech5 | | ||
| program11 | coffee1 | 1 | 1 | 2016-04-01 12:30 | 2016-04-01 13:00 | event2 | | | ||
| program12 | phil_doctrine | 0 | 1 | 2016-04-01 13:00 | 2016-04-01 14:30 | event2 | speech6 | | ||
| program13 | end_keynote | 1 | 1 | 2016-04-01 14:30 | 2016-04-01 15:00 | event2 | | | ||
| program14 | after_party | 1 | 1 | 2016-04-01 15:00 | 2016-04-01 18:00 | event2 | | | ||
| program15 | keynote | 1 | 1 | 2016-04-01 10:00 | 2016-04-01 10:30 | event3 | | | ||
| program16 | alex_symfony | 0 | 1 | 2016-04-01 10:30 | 2016-04-01 11:30 | event3 | speech7 | | ||
| program17 | phil_php | 0 | 1 | 2016-04-01 11:30 | 2016-04-01 12:30 | event3 | speech8 | | ||
| program18 | coffee1 | 1 | 1 | 2016-04-01 12:30 | 2016-04-01 13:00 | event3 | | | ||
| program19 | phil_doctrine | 0 | 1 | 2016-04-01 13:00 | 2016-04-01 14:30 | event3 | speech9 | | ||
| program20 | end_keynote | 1 | 1 | 2016-04-01 14:30 | 2016-04-01 15:00 | event3 | | | ||
| program21 | after_party | 1 | 1 | 2016-04-01 15:00 | 2016-04-01 18:00 | event3 | | | ||
And following "ProgramTranslation": | ||
| program | locale | | ||
| program | ru_RU | | ||
| program2 | de_DE | | ||
| program3 | de_DE | | ||
| program4 | de_DE | | ||
| program5 | de_DE | | ||
| program6 | de_DE | | ||
| program7 | de_DE | | ||
| program8 | de_DE | | ||
| program9 | de_DE | | ||
| program10 | de_DE | | ||
| program11 | de_DE | | ||
| program12 | de_DE | | ||
| program13 | de_DE | | ||
| program14 | de_DE | | ||
| program15 | de_DE | | ||
| program16 | de_DE | | ||
| program17 | de_DE | | ||
| program18 | de_DE | | ||
| program19 | de_DE | | ||
| program20 | de_DE | | ||
| program21 | de_DE | | ||
And following "Speaker": | ||
| ref | firstName | lastName | Company | email | homepage | twitter | events | speeches | | ||
| speaker | Phill | Pilow | Reseach Supplier | | | | event,event2,event3 | speech2,speech3,speech5,speech6,speech8,speech9 | | ||
| speaker2 | Alex | Demchenko | KnpLabs | | http://451f.com.ua | https://twitter.com/twitter | event,event2,event3 | speech,speech4,speech7 | | ||
And following "SpeakerTranslation": | ||
| speaker | locale | | ||
| speaker | ru_RU | | ||
| speaker2 | de_DE | | ||
And following "Sponsor": | ||
| ref | company | description | homepage | type | isActive | events | | ||
| sponsor | Reseach Supplier | NASA research center | http://nasa.gov.us | 1 | 1 | event,event2,event3 | | ||
| sponsor2 | KnpLabs | Happy awesome developer | http://knplabs.com | 2 | 1 | event | | ||
And following "SponsorTranslation": | ||
| sponsor | locale | | ||
| sponsor | de_DE | | ||
| sponsor2 | de_DE | | ||
And following "Media": | ||
| title | filename | created_date | updated_date | | ||
| Media1 | logo.png | 2017-10-27 16:02 | 2017-10-27 16:02 | | ||
| Media2 | logo.png | 2017-10-27 17:02 | 2017-10-27 17:02 | | ||
|
||
@javascript | ||
Scenario: Admin should have access to the media manage | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I should see the row containing "1;Media1" | ||
And I should see the row containing "2;Media2" | ||
When I click "Edit" on the row containing "1;Media1" | ||
Then I wait for a form | ||
Then I should see "Media settings" | ||
|
||
@javascript | ||
Scenario: Admin should be able to add media | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I click "Add Media" | ||
Then I wait for a form | ||
Then I should see "Media settings" | ||
And I fill in "Title" with "Media3" | ||
And I press "Upload file" | ||
Then I wait "10" seconds | ||
Then I should see " My Device " | ||
And I attach the file "test.png" to "fsp-fileUpload" | ||
Then I should see "Edit Image" | ||
Then I wait "15" seconds | ||
And I click on the element with css selector ".fsp-button--primary" | ||
Then I wait "10" seconds | ||
And I press "Add" | ||
Then I wait for a form | ||
Then I should see "Media Media3 added." | ||
Then I should see the row containing "3;Media3" | ||
|
||
@javascript | ||
Scenario: Admin should be able to update media settings | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I should see the row containing "2;Media2" | ||
When I click "Edit" on the row containing "2;Media2" | ||
Then I wait for a form | ||
Then I should see "Media settings" | ||
And I fill in "Title" with "Media2_1" | ||
And I fill in "Media Description" with "Awesome media" | ||
And I fill in "Copyright Info" with "Test media" | ||
And I press "Update" | ||
Then I wait for a form | ||
Then I should see "Media Media2_1 updated." | ||
Then I should see the row containing "2;Media2_1" | ||
|
||
@javascript | ||
Scenario: Admin should be delete to the media | ||
Given I am sign in as admin | ||
When I click "Media" | ||
Then I wait for a form | ||
Then I should see "Add Media" | ||
And I should see the row containing "1;Media1" | ||
Then I delete the record with id "1" | ||
Then I wait for a form | ||
Then I should see "Media deleted." | ||
Then I should not see the row containing "1;Media1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace Event\EventBundle\Controller\Backend; | ||
|
||
use Guzzle\Http\Client; | ||
use Symfony\Component\Config\Definition\Exception\Exception; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Filesystem\Exception\IOExceptionInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Event\EventBundle\Controller\Controller; | ||
use Event\EventBundle\Entity\Media; | ||
use Event\EventBundle\Form\Type\MediaType; | ||
|
||
class MediaController extends Controller | ||
{ | ||
|
||
public function getUploadPath() | ||
{ | ||
return $this->container->getParameter('media.uploadPath'); | ||
} | ||
|
||
public function getUploadUrl(){ | ||
return $this->container->getParameter('media.uploadUrl'); | ||
} | ||
|
||
public function indexAction() | ||
{ | ||
return $this->render('EventEventBundle:Backend/Media:index.html.twig', array( | ||
'media' => $this->getRepository('EventEventBundle:Media')->findAll(), | ||
'uploadPath' => $this->getUploadPath(), | ||
'uploadUrl' => $this->getUploadUrl() | ||
)); | ||
} | ||
|
||
public function manageAction(Request $request, $id = null) | ||
{ | ||
$oldFileName = ''; | ||
if ($id === null) { | ||
$media = new Media(); | ||
} else { | ||
$media = $this->findOr404('EventEventBundle:Media', $id); | ||
$oldFileName = $media->getFilename(); | ||
} | ||
|
||
$form = $this->createForm(MediaType::class, $media); | ||
|
||
if ($request->getMethod() === 'POST') { | ||
$form->handleRequest($request); | ||
|
||
if ($form->isValid()) { | ||
$media->setUpdated(new \DateTime()); | ||
|
||
if ($oldFileName !== $media->getFilename()) { | ||
$url = $request->request->get('file_url'); | ||
$path = $this->getUploadPath(); | ||
$media->setFilename(time() . '_' . $media->getFilename()); | ||
$file = $this->getFile($url); | ||
|
||
$fs = new Filesystem(); | ||
|
||
try { | ||
$fs->dumpFile($path . $media->getFilename(), $file, 0777); | ||
} catch (IOExceptionInterface $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
} | ||
|
||
$this->getManager()->persist($media); | ||
$this->getManager()->flush(); | ||
|
||
$successFlashText = sprintf('Media %s updated.', $media->getTitle()); | ||
if (!$id) { | ||
$successFlashText = sprintf('Media %s added.', $media->getTitle()); | ||
} | ||
$this->setSuccessFlash($successFlashText); | ||
|
||
return $this->redirectToRoute('backend_media'); | ||
} | ||
} | ||
|
||
return $this->render('EventEventBundle:Backend/Media:manage.html.twig', [ | ||
'media' => $media, | ||
'form' => $form->createView(), | ||
'fs_api' => $this->container->getParameter('filestack.api_key'), | ||
]); | ||
} | ||
|
||
protected function checkAccessFolder($path){ | ||
if(is_dir($path)){ | ||
chmod($path, 0777); | ||
} else { | ||
mkdir($path, 0777, true); | ||
} | ||
} | ||
|
||
protected function getFile($url) | ||
{ | ||
$client = new Client(); | ||
$file = $client->createRequest('GET', $url)->send()->getBody(true); | ||
|
||
return $file; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CS, add nl above the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to use Guzzle or similar http client for requests |
||
} | ||
|
||
public function deleteAction($id) | ||
{ | ||
$this->isGrantedAdmin(); | ||
|
||
$entity = $this->findOr404('EventEventBundle:Media', $id); | ||
$file = $this->getUploadPath() . $entity->getFilename(); | ||
$this->getManager()->remove($entity); | ||
$this->getManager()->flush(); | ||
if (is_file($file)) { | ||
unlink($file); | ||
} | ||
|
||
$this->setSuccessFlash('Media deleted.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. translation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be translatable |
||
|
||
return $this->redirectToRoute('backend_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.
CS fix