Skip to content

Instantly share code, notes, and snippets.

@j
Created June 22, 2011 22:13
Show Gist options
  • Save j/1041388 to your computer and use it in GitHub Desktop.
Save j/1041388 to your computer and use it in GitHub Desktop.
<?php
[...]
/**
* @Extra\Route("/offer/{offerId}/creative", name="admin_offer_creative")
* @Extra\Route("/offer/{offerId}/creative/{creativeId}", name="admin_offer_creative_edit")
* @Extra\Template()
*/
public function creativeAction($offerId = null, $creativeId = null)
{
// Get Offer
$offer = $this->_getObject('Offer', $offerId);
if (null === $offer->getId()) throw new NotFoundHttpException('The page you requested does not exist!');
// Get Creative
$creative = $this->_getObject('Creative', $creativeId);
// Set offer to creative
$creative->setOffer($offer);
// Get form and handler
$form = $this->get('form.factory')->create(new Form\CreativeType(), $creative);
$formHandler = $this->get('form.handler')->create(new Form\CreativeHandler(), $form);
[...]
}
protected function _getObject($entityName, $id = null)
{
// Find object
if (null !== $id) {
if (!$object = $this->get('doctrine')->getEntityManager()->find('ZGOffersMainBundle:' . $entityName, $id)) {
throw new NotFoundHttpException('The page you requested does not exist!');
}
return $object;
}
// Initialize new object
$entityName = 'JStout\MainBundle\Entity\\' . $entityName;
if (class_exists($entityName)) {
return new $entityName();
}
throw new NotFoundHttpException('The page you requested does not exist!');
}
[...]
<?php
[...]
class Creative
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Offer", cascade={"persist"})
*/
protected $offer;
/**
* @ORM\OneToMany(targetEntity="CreativeQuestion", mappedBy="creative", cascade={"persist"})
*/
protected $creativeQuestions;
[...]
<?php
[...]
class CreativeQuestion
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Creative", cascade={"persist"})
*/
protected $creative;
/**
* @ORM\ManyToOne(targetEntity="Question", cascade={"persist"})
*/
protected $question;
/**
* @ORM\Column(type="integer")
*/
protected $pos;
[...]
<?php
namespace JStout\MainBundle\Form;
use Symfony\Component\Form\AbstractType,
Symfony\Component\Form\FormBuilder;
class CreativeType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('name')
->add('title')
->add('description')
->add('body')
->add('body')
->add('script')
->add('creativeQuestions') // how do i populate list with "Questions" then insert into creative_question?
->add('active');
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'JStout\MainBundle\Entity\Creative'
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment