Created
November 25, 2012 15:48
-
-
Save ahsio/4144126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @ORM\Table(name="room") | |
* @ORM\Entity(repositoryClass="Ahsio\StackBundle\Repository\RoomRepository") | |
*/ | |
class Room | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(type="string", length="255", name="name") | |
*/ | |
protected $name; | |
/** | |
* @ORM\Column(type="text", name="description") | |
*/ | |
protected $description; | |
/** | |
* @ORM\OneToMany(targetEntity="Ahsio\StackBundle\Entity\Workstation", mappedBy="room", cascade={"persist", "remove"}, orphanRemoval=true) | |
*/ | |
protected $workstations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* (non-PHPdoc) | |
* @see Symfony\Component\Form.AbstractType::buildForm() | |
*/ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('name', 'text', array( | |
'label' => 'toto')) | |
->add('description') | |
->add('workstations', 'entity', array( | |
'multiple' => true, | |
'expanded' => true, | |
'property' => 'number', | |
'class' => 'Ahsio\StackBundle\Entity\Workstation', | |
'query_builder' => function(\Ahsio\StackBundle\Repository\WorkstationRepository $wr) { | |
return $wr->createQueryBuilder('w') | |
->orderBy('w.number', 'ASC'); }, | |
)) | |
; | |
} | |
/** | |
* (non-PHPdoc) | |
* @see Symfony\Component\Form.AbstractType::getDefaultOptions() | |
*/ | |
public function getDefaultOptions(array $options) | |
{ | |
return array( | |
'data_class' => 'Ahsio\StackBundle\Entity\Room', | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" action="{{ path('stack_room_create') }}" {{ form_enctype(form) }} > | |
{{ form_row(form.name) }} | |
{{ form_row(form.description) }} | |
{% for field in form.workstations %} | |
<li> | |
{{ form_widget(field) }} | |
{{ form_label(field) }} | |
</li> | |
{% endfor %} | |
{{ form_rest(form) }} | |
<input type="submit" value="save"/> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @ORM\Table(name="workstation") | |
* @ORM\Entity(repositoryClass="Ahsio\StackBundle\Repository\WorkstationRepository") | |
*/ | |
class Workstation | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @ORM\ManyToOne(targetEntity="Ahsio\StackBundle\Entity\Room") | |
* @ORM\JoinColumn(name="room_id", referencedColumnName="id", nullable=false) | |
*/ | |
private $room; | |
/** | |
* @ORM\Column(name="number", type="integer", nullable=true) | |
*/ | |
private $number; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment