2017 © Pedro Peláez
 

symfony-bundle simple-media-bundle

Symfony SimpleMediaBundle

image

idci/simple-media-bundle

Symfony SimpleMediaBundle

  • Friday, April 6, 2018
  • by idciconsulting
  • Repository
  • 3 Watchers
  • 3 Stars
  • 122 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

SimpleMediaBundle

Symfony2 simple media bundle, (*1)

Installation

To install this bundle please follow the next steps:, (*2)

First add the dependencies to your composer.json file:, (*3)

"require": {
    ...
    "idci/simple-media-bundle":     "dev-master"
},

Then install the bundle with the command:, (*4)

php composer update

Enable the bundle in your application kernel:, (*5)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new IDCI\Bundle\SimpleMediaBundle\IDCISimpleMediaBundle(),
    );
}

Include a resource in your config.yml, (*6)

imports:
    ....
    - { resource: @IDCISimpleMediaBundle/Resources/config/config.yml }

Now the Bundle is installed., (*7)

Configure your database parameters in the app/config/parameters.yml then run, (*8)

php app/console doctrine:schema:update --force

How to create a Media

To associate a media with an object, simply implements MediaAssociableInterface, (*9)

<?php
...
use IDCI\Bundle\SimpleMediaBundle\Entity\MediaAssociableInterface;

/**
 * Object
 */
class MyObject implements MediaAssociableInterface
{
    ...

Then when you wish to upload and associate a media, simply call the idci_simplemedia.manager service to create a form and process it as explain below:, (*10)

// This classic form creation
// $form = $this->createForm(new MyObjectType(), $myObject);

// Now work like this:
$form = $this->get('idci_simplemedia.manager')->createForm(
    new MyObjectType(),
    $myObject,
    array('provider' => 'file')
);

As you can see, the third parameter allow you to choose a provider. For the moment only the file provider is ready to use., (*11)

To save and associate a media with your object, call the processForm function like this:, (*12)

if ($this->getRequest()->isMethod('POST')) {
    $form->bind($this->getRequest());
    if ($form->isValid()) {
        $myObject = $this->get('idci_simplemedia.manager')->processForm($form);

        return $this->redirect($this->generateUrl(...));
    }
}

How to retrive and display medias

Controller

In the following exemples, $obj has to be an instance of a class which implement the MediaAssociableInterface. So to retrieve a set of media:, (*13)

// Related to an object
$medias = $this->get('idci_simplemedia.manager')->getMedias($obj);

// Related to an object filter on tags
$medias = $this->get('idci_simplemedia.manager')->getMedias($obj, array('tag1', 'tag2'));

// Related to tags
$medias = $this->get('idci_simplemedia.manager')->getMedias(null, array('tag1', 'tag2'));

To remove all medias in association with your object $obj, use the removeAssociatedMedias function available throw the service like this:, (*14)

$this->get('idci_simplemedia.manager')->removeAssociatedMedias($obj);
$this->getDoctrine()->getManager()->flush();

To remove just one media:, (*15)

$this->get('idci_simplemedia.manager')->removeMedia($media);
$em->flush();

VIEW

To display media in a twig template, (*16)




    {% for media in medias(object) %}
  • {% endfor %}
    {% for media in medias(object, ['tag']) %}
  • {% endfor %}
    {% for media in medias(null, ['tag1', 'tag2']) %}
  • {% endfor %}

How to retrive and display medias tags

Controller

In the following exemples, $obj has to be an instance of a class which implement the MediaAssociableInterface. So to retrieve a set of media:, (*17)

// All tags
$tags = $this->get('idci_simplemedia.manager')->getTags();

// Related to an object
$tags = $this->get('idci_simplemedia.manager')->getTags($obj);

VIEW

To retrieve tags in a twig template, (*18)




    {% for tag in medias_tags %}
  • {{ tag }}
  • {% endfor %}
    {% for tag in medias_tags(object) %}
  • {{ tag }}
  • {% endfor %}

The Versions

06/04 2018

dev-fix/dependency-sf3

dev-fix/dependency-sf3

Symfony SimpleMediaBundle

  Sources   Download

GPL-3.0+

The Requires

 

media images videos uploaded files

05/08 2013

dev-master

9999999-dev

Symfony SimpleMediaBundle

  Sources   Download

GPL-3.0+

The Requires

 

media images videos uploaded files

16/04 2013

2.1.x-dev

2.1.9999999.9999999-dev

Symfony SimpleMediaBundle

  Sources   Download

GPL-3.0+

The Requires

 

media images videos uploaded files

16/04 2013

v2.1.0

2.1.0.0

Symfony SimpleMediaBundle

  Sources   Download

GPL-3.0+

The Requires

 

media images videos uploaded files