Skip to content

Commit

Permalink
rename BaseApplication => Admin, add gallery management + Admin class
Browse files Browse the repository at this point in the history
  • Loading branch information
rande committed Mar 3, 2011
1 parent 2f610ef commit a3ae22a
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 43 deletions.
14 changes: 9 additions & 5 deletions Admin/GalleryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Sonata\MediaBundle\Admin;

use Sonata\BaseApplicationBundle\Admin\EntityAdmin as Admin;
use Sonata\BaseApplicationBundle\Form\FormMapper;
use Sonata\BaseApplicationBundle\Datagrid\DatagridMapper;
use Sonata\BaseApplicationBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Admin\EntityAdmin as Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;

class GalleryAdmin extends Admin
{
Expand All @@ -29,7 +29,11 @@ class GalleryAdmin extends Admin
'enabled',
'name',
'defaultFormat',
'galleryHasMedias' => array('edit' => 'inline', 'inline' => 'table'),
'galleryHasMedias' => array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position'
),
'code',
);

Expand Down
10 changes: 5 additions & 5 deletions Admin/GalleryHasMediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Sonata\MediaBundle\Admin;

use Sonata\BaseApplicationBundle\Admin\EntityAdmin as Admin;
use Sonata\BaseApplicationBundle\Form\FormMapper;
use Sonata\BaseApplicationBundle\Datagrid\DatagridMapper;
use Sonata\BaseApplicationBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Admin\EntityAdmin as Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;

class GalleryHasMediaAdmin extends Admin
{
Expand All @@ -28,8 +28,8 @@ class GalleryHasMediaAdmin extends Admin

protected $form = array(
'media' => array('edit' => 'list'),
'position',
'enabled',
'position',
);

public function configureFormFields(FormMapper $form)
Expand Down
8 changes: 4 additions & 4 deletions Admin/MediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Sonata\MediaBundle\Admin;

use Sonata\BaseApplicationBundle\Admin\EntityAdmin as Admin;
use Sonata\BaseApplicationBundle\Form\FormMapper;
use Sonata\BaseApplicationBundle\Datagrid\DatagridMapper;
use Sonata\BaseApplicationBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Admin\EntityAdmin as Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;

class MediaAdmin extends Admin
{
Expand Down
2 changes: 1 addition & 1 deletion Controller/GalleryAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Sonata\MediaBundle\Controller;

use Sonata\BaseApplicationBundle\Controller\CRUDController as Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;


Expand Down
2 changes: 1 addition & 1 deletion Controller/GalleryHasMediaAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Sonata\MediaBundle\Controller;

use Sonata\BaseApplicationBundle\Controller\CRUDController as Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;


Expand Down
10 changes: 5 additions & 5 deletions Controller/MediaAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Sonata\MediaBundle\Controller;

use Sonata\BaseApplicationBundle\Controller\CRUDController as Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\RedirectResponse;

class MediaAdminController extends Controller
{
Expand Down Expand Up @@ -75,11 +75,11 @@ public function createAction($form = null)
$this->admin->getEntityManager()->flush();
$this->get('media.provider')->postPersist($media);

if ($this->get('request')->isXmlHttpRequest()) {
if ($this->isXmlHttpRequest()) {
return $this->renderJson(array('result' => 'ok', 'objectId' => $media->getId()));
}

return $this->redirect($this->admin->generateUrl('edit', array('id' => $media->getId())));
return new RedirectResponse($this->admin->generateUrl('edit', array('id' => $media->getId())));
}
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public function updateAction()
$this->admin->getEntityManager()->flush();
$this->get('media.provider')->postUpdate($media);

return $this->redirect($this->admin->generateUrl('edit', array(
return new RedirectResponse($this->admin->generateUrl('edit', array(
'id' => $media->getId(),
'params' => $this->getParameters()
)));
Expand Down
5 changes: 5 additions & 0 deletions Entity/BaseGalleryHasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public function preUpdate()
{
$this->updatedAt = new \DateTime();
}

public function __toString()
{
return $this->getGallery().' | '.$this->getMedia();
}
}
5 changes: 3 additions & 2 deletions Provider/BaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sonata\MediaBundle\Provider;

use Sonata\MediaBundle\Entity\BaseMedia as Media;
use Symfony\Component\Form\Form;

abstract class BaseProvider
{
Expand Down Expand Up @@ -140,13 +141,13 @@ abstract function postRemove(Media $media);
* build the related create form
*
*/
abstract function buildCreateForm($form);
abstract function buildCreateForm(Form $form);

/**
* build the related create form
*
*/
abstract function buildEditForm($form);
abstract function buildEditForm(Form $form);


/**
Expand Down
6 changes: 3 additions & 3 deletions Provider/DailyMotionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Sonata\MediaBundle\Provider;


use Sonata\MediaBundle\Entity\BaseMedia as Media;
use Symfony\Component\Form\Form;

class DailyMotionProvider extends BaseProvider
{
Expand All @@ -33,7 +33,7 @@ public function getAbsolutePath(Media $media)
* build the related create form
*
*/
function buildEditForm($form)
function buildEditForm(Form $form)
{
$form->add(new \Symfony\Component\Form\TextField('name'));
$form->add(new \Symfony\Component\Form\CheckboxField('enabled'));
Expand All @@ -50,7 +50,7 @@ function buildEditForm($form)
* build the related create form
*
*/
function buildCreateForm($form)
function buildCreateForm(Form $form)
{
$form->add(new \Symfony\Component\Form\TextField('binary_content'));
}
Expand Down
7 changes: 4 additions & 3 deletions Provider/FileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
namespace Sonata\MediaBundle\Provider;

use Sonata\MediaBundle\Entity\BaseMedia as Media;

use Symfony\Component\Form\Form;

class FileProvider extends BaseProvider
{

Expand Down Expand Up @@ -39,7 +40,7 @@ public function requireThumbnails()
* build the related create form
*
*/
function buildEditForm($form)
function buildEditForm(Form $form)
{
$form->add(new \Symfony\Component\Form\TextField('name'));
$form->add(new \Symfony\Component\Form\CheckboxField('enabled'));
Expand All @@ -58,7 +59,7 @@ function buildEditForm($form)
* build the related create form
*
*/
function buildCreateForm($form)
function buildCreateForm(Form $form)
{
$form->add(new \Symfony\Component\Form\FileField('binary_content', array(
'secret' => 'file'
Expand Down
25 changes: 21 additions & 4 deletions Provider/YouTubeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,41 @@
namespace Sonata\MediaBundle\Provider;

use Sonata\MediaBundle\Entity\BaseMedia as Media;
use Symfony\Component\Form\Form;

class YouTubeProvider extends BaseProvider
{

/**
* Return the reference image
*
* @param \Sonata\MediaBundle\Entity\BaseMedia $media
* @return null
*/
public function getReferenceImage(Media $media)
{

return $media->getMetadataValue('thumbnail_url');
}


/**
* return the absolute path of source media
*
* @param \Sonata\MediaBundle\Entity\BaseMedia $media
* @return string
*/
public function getAbsolutePath(Media $media)
{

return sprintf('http://www.youtube.com/v/%s', $media->getProviderReference());
}

/**
* @param \Sonata\MediaBundle\Entity\BaseMedia $media
* @param string $format
* @param array $options
* @return array
*/
public function getHelperProperties(Media $media, $format, $options = array())
{

Expand Down Expand Up @@ -139,7 +157,7 @@ public function getHelperProperties(Media $media, $format, $options = array())
* build the related create form
*
*/
function buildEditForm($form)
function buildEditForm(Form $form)
{
$form->add(new \Symfony\Component\Form\TextField('name'));
$form->add(new \Symfony\Component\Form\CheckboxField('enabled'));
Expand All @@ -156,7 +174,7 @@ function buildEditForm($form)
* build the related create form
*
*/
function buildCreateForm($form)
function buildCreateForm(Form $form)
{
$form->add(new \Symfony\Component\Form\TextField('binary_content'));
}
Expand Down Expand Up @@ -241,7 +259,6 @@ public function postRemove(Media $media)
$files[] = $this->generatePrivateUrl($media, $format);
}


foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
small: { width: 100 }
big: { width: 500 }

* Add these lines into your admin.yml file (BaseApplicationBundle)
* Add these lines into your admin.yml file (AdminBundle)

media:
label: Media
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/reference/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Next, be sure to enable the bundles in your application kernel:
Configuration
-------------

To use the ``BaseApplicationBundle``, add the following to your application
To use the ``AdminBundle``, add the following to your application
configuration file.

.. code-block:: yaml
Expand Down Expand Up @@ -78,7 +78,7 @@ configuration file.

The bundle contains admin class to manage the different entities :

- Add the BaseApplicationBundle's admin definition
- Add the AdminBundle's admin definition

.. code-block:: yaml
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/MediaAdmin/list_custom.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ file that was distributed with this source code.
#}

{% extends 'SonataBaseApplicationBundle:CRUD:base_list_field.html.twig' %}
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
<div>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/MediaAdmin/list_image.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ file that was distributed with this source code.
#}

{% extends 'SonataBaseApplicationBundle:CRUD:base_list_field.html.twig' %}
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
<a href="{{ admin.generateUrl('edit', {'id' : object.id}) }}">{% thumbnail object, 'admin' with {'width': 75, 'height': 60} %}</a>
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/MediaAdmin/provider_create.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ file that was distributed with this source code.

<div class="sonata-actions">
<ul>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('create', params) }}">{% trans "link_action_create" from "BaseApplicationBundle" %}</a></li>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('list', params) }}">{% trans "link_action_list" from "BaseApplicationBundle" %}</a></li>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('create', params) }}">{% trans "link_action_create" from "AdminBundle" %}</a></li>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('list', params) }}">{% trans "link_action_list" from "AdminBundle" %}</a></li>
</ul>
</div>

Expand Down
1 change: 0 additions & 1 deletion Resources/views/MediaAdmin/provider_create_file.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ file that was distributed with this source code.

<input type="submit" value="{% trans 'btn_create' from 'MediaBundle' %}" />
</form>

{% endblock %}
4 changes: 2 additions & 2 deletions Resources/views/MediaAdmin/provider_edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ file that was distributed with this source code.
{% block actions %}
<div class="sonata-actions">
<ul>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('create', params) }}">{% trans "link_action_create" from "BaseApplicationBundle" %}</a></li>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('list', params) }}">{% trans "link_action_list" from "BaseApplicationBundle" %}</a></li>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('create', params) }}">{% trans "link_action_create" from "AdminBundle" %}</a></li>
<li class="sonata-action-element"><a href="{{ admin.generateUrl('list', params) }}">{% trans "link_action_list" from "AdminBundle" %}</a></li>
</ul>
</div>
{% endblock %}

0 comments on commit a3ae22a

Please sign in to comment.