Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thesowah
Created November 26, 2013 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thesowah/7658460 to your computer and use it in GitHub Desktop.
Save thesowah/7658460 to your computer and use it in GitHub Desktop.
<?php
//...
class Person
{
/* @var \Doctrine\Common\Collections\Collection */
private $talents
/* @var string */
private $gender
/* @var string */
private $name
/* Constructor */
public function __contruct()
{
$this->talents = new \Doctrine\Common\Collections\ArrayCollection();
}
/* Add talents
* @param \Company\MyBundle\Entity\Talent $talents */
public function addTalent(\Company\MyBundle\Entity\Talent $talents)
{
$talents->setPerson($this);
$this->talents->add($talents);
}
/* Set talents
* @param \Company\MyBundle\Entity\Talent $talents
* @return Person */
public function setTalents(\Company\MyBundle\Entity\Talent $talents)
{
$this->talents = new \Doctrine\Common\Collections\ArrayCollection();
foreach($talents as $talent)
{
$this->addTalent($talent);
}
return $this;
}
/* Remove farm
* @param \Company\MyBundle\Entity\Talent $talent */
public function removeTalent(\Company\MyBundle\Entity\Talent $talent)
{
$this->talents->removeElement($talent);
}
// ...
// setter & getter for $gender and $name
/* */
public static function getGenderList()
{
return array(
'male' => 'Male',
'female' => 'Female'
);
}
/* */
public static function getGenderValues(){
return array(self::getGenderList());
}
/* @var string */
public function __toString(){
return $this->getName()?:'';
}
}
<?php
//...
class PersonAdmin extends Admin
{
//...
/* @param FormMapper $formMapper */
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('gender', 'choice', array(
'choices' => Person::getGenderList(),
//'expanded' => true,
))
->add('talents', 'sonata_type_collection', array('required' => false), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
))
;
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment