Skip to content

Commit

Permalink
Merge pull request #155 from Kunstmaan/feature/extra-media-fields
Browse files Browse the repository at this point in the history
Feature/extra media fields
  • Loading branch information
Wim Vandersmissen committed Aug 7, 2014
2 parents 77dfc07 + b1a42e5 commit 0781410
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 285 deletions.
77 changes: 77 additions & 0 deletions Entity/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kunstmaan\MediaBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Kunstmaan\AdminBundle\Entity\AbstractEntity;

/**
Expand All @@ -14,6 +15,14 @@
*/
class Media extends AbstractEntity
{
/**
* @var string
*
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
protected $locale;

/**
* @var string
Expand All @@ -30,6 +39,22 @@ class Media extends AbstractEntity
*/
protected $name;

/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
* @Gedmo\Translatable
*/
protected $description;

/**
* @var string
*
* @ORM\Column(name="copyright", type="string", nullable=true)
* @Gedmo\Translatable
*/
protected $copyright;

/**
* @var string
*
Expand Down Expand Up @@ -110,6 +135,18 @@ public function __construct()
$this->deleted = false;
}

/**
* @param string $locale
*
* @return Media
*/
public function setTranslatableLocale($locale)
{
$this->locale = $locale;

return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -438,6 +475,46 @@ public function setUrl($url)
return $this;
}

/**
* @param string $copyright
*
* @return Media
*/
public function setCopyright($copyright)
{
$this->copyright = $copyright;

return $this;
}

/**
* @return string
*/
public function getCopyright()
{
return $this->copyright;
}

/**
* @param string $description
*
* @return Media
*/
public function setDescription($description)
{
$this->description = $description;

return $this;
}

/**
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* @return string
*/
Expand Down
20 changes: 10 additions & 10 deletions Form/BulkUploadType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public function __construct($accept = null)
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'files',
'file',
array(
'required' => false,
'attr' => array(
'accept' => $this->accept,
'multiple' => 'multiple',
),
'data_class' => null
)
'files',
'file',
array(
'required' => false,
'attr' => array(
'accept' => $this->accept,
'multiple' => 'multiple',
),
'data_class' => null
)
);
}

Expand Down
58 changes: 53 additions & 5 deletions Form/File/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* FileType
Expand All @@ -25,8 +28,53 @@ class FileType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', 'text', array('required' => false));
$builder->add('file', 'file');
$builder->add(
'name',
'text',
array(
'required' => false
)
);
$builder->add(
'file',
'file',
array(
'required' => false
)
);
$builder->add(
'copyright',
'text',
array(
'required' => false
)
);
$builder->add(
'description',
'textarea',
array(
'required' => false
)
);
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) {
$helper = $event->getData();
$form = $event->getForm();

// Only add file field as required field when creating new objects
if (!$helper || null === $helper->getMedia()->getId()) {
$form->add(
'file',
'file',
array(
'constraints' => array(new NotBlank()),
'required' => true
)
);
}
}
);
}

/**
Expand All @@ -47,9 +95,9 @@ public function getName()
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Kunstmaan\MediaBundle\Helper\File\FileHelper',
)
array(
'data_class' => 'Kunstmaan\MediaBundle\Helper\File\FileHelper',
)
);
}
}
66 changes: 33 additions & 33 deletions Form/FolderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,39 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$folder = $this->folder;
$type = $this;
$builder
->add('name')
->add(
'rel',
'choice',
array(
'choices' => array(
'media' => 'media',
'image' => 'image',
'slideshow' => 'slideshow',
'video' => 'video'
),
->add('name')
->add(
'rel',
'choice',
array(
'choices' => array(
'media' => 'media',
'image' => 'image',
'slideshow' => 'slideshow',
'video' => 'video'
),
)
)
)
->add(
'parent',
'entity',
array(
'class' => 'Kunstmaan\MediaBundle\Entity\Folder',
'required' => true,
'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($folder, $type) {
$qb = $er->createQueryBuilder('folder');
->add(
'parent',
'entity',
array(
'class' => 'Kunstmaan\MediaBundle\Entity\Folder',
'required' => true,
'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($folder, $type) {
$qb = $er->createQueryBuilder('folder');

if ($folder != null && $folder->getId() != null) {
$ids = "folder.id != " . $folder->getId();
$ids .= $type->addChildren($folder);
$qb->andwhere($ids);
}
$qb->andWhere('folder.deleted != true');
if ($folder != null && $folder->getId() != null) {
$ids = "folder.id != " . $folder->getId();
$ids .= $type->addChildren($folder);
$qb->andwhere($ids);
}
$qb->andWhere('folder.deleted != true');

return $qb;
}
)
);
return $qb;
}
)
);
}

/**
Expand Down Expand Up @@ -112,9 +112,9 @@ public function getName()
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Kunstmaan\MediaBundle\Entity\Folder',
)
array(
'data_class' => 'Kunstmaan\MediaBundle\Entity\Folder',
)
);
}
}
53 changes: 42 additions & 11 deletions Form/RemoteAudio/RemoteAudioType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* RemoteAudioType
Expand All @@ -26,15 +27,45 @@ class RemoteAudioType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'text')
->add('code', 'text')
->add(
'type',
'choice',
array(
'choices' => array('soundcloud' => 'soundcloud')
->add(
'name',
'text',
array(
'constraints' => array(new NotBlank()),
'required' => true
)
)
->add(
'code',
'text',
array(
'constraints' => array(new NotBlank()),
'required' => true
)
)
->add(
'type',
'choice',
array(
'choices' => array('soundcloud' => 'soundcloud'),
'constraints' => array(new NotBlank()),
'required' => true
)
)
);
->add(
'copyright',
'text',
array(
'required' => false
)
)
->add(
'description',
'textarea',
array(
'required' => false
)
);
}

/**
Expand All @@ -55,9 +86,9 @@ public function getName()
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'Kunstmaan\MediaBundle\Helper\RemoteAudio\RemoteAudioHelper',
)
array(
'data_class' => 'Kunstmaan\MediaBundle\Helper\RemoteAudio\RemoteAudioHelper',
)
);
}
}
Loading

0 comments on commit 0781410

Please sign in to comment.