Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace Ylly\Extension\SiteCustomerBundle\Controller;
use Ylly\CmsBundle\Controller\AdminBaseController;
use Ylly\Extension\SiteCustomerBundle\Entity\SiteCustomer;
use Ylly\Extension\SiteCustomerBundle\Form\SiteCustomerForm;
use Ylly\Extension\SiteCustomerBundle\Form\AdminCreateForm;
class AdminController extends AdminBaseController
{
public function indexAction()
{
$site = $this->getSite();
$siteCustomers = $this->getSiteCustomerRepo()->findBySite($site->getId());
$empty = (empty($siteCustomers)) ? true : false;
return $this->render('SiteCustomerBundle:Admin:index.html.twig', array(
'siteCustomers' => $siteCustomers,
'site' => $site,
'empty' => $empty,
));
}
public function editAction()
{
$site = $this->getSite();
$siteCustomer = $this->getSiteCustomerRepo()->findOneBy(array(
'site' => $site->getId(),
'id' => $this->get('request')->get('site_customer_id')
));
$form = SiteCustomerForm::create(
$this->get('old_form.context'),
'site_customer_edit',
array(
'entity_manager' => $this->getEm(),
'site' => $this->getSite(),
)
);
$form->setData($siteCustomer);
$form->bind($this->get('request'));
if ($this->processForm($form, 'SITE_CUSTOMER_UPDATED')) {
return $this->redirectToWhence($this->generateUrl('site_customer', array('site_id' => $site->get('id'))));
}
return $this->render('SiteCustomerBundle:Admin:edit.html.twig', array(
'form' => $form,
'site' => $site,
'customer' => $siteCustomer,
));
}
public function deleteAction()
{
$site = $this->getSite();
$siteCustomer = $this->getSiteCustomerRepo()->findOneBy(array(
'site' => $site->getId(),
'id' => $this->get('request')->get('site_customer_id')
));
try {
$this->getEm()->remove($siteCustomer);
$this->getEm()->flush();
$this->addNotification('SITE_CUSTOMER_DELETED');
} catch (\Exception $e) {
$this->addNotification('CANNOT_DELETE_THIS_CUSTOMER');
}
return $this->redirectToWhence($this->generateUrl('site_customer', array('site_id' => $site->get('id'))));
}
protected function getSiteCustomerRepo()
{
return $this->getRepo('Ylly\Extension\SiteCustomerBundle\Entity\SiteCustomer');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.