Esempio n. 1
0
 /**
  * Creates a form to delete a Product entity.
  *
  * @param Product $product The Product entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Product $product)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('product_delete', array('id' => $product->getId())))->setMethod('DELETE')->getForm();
 }
Esempio n. 2
0
 /**
  * Find a product from the same category
  *
  * @param Product $product
  * @param string  $direction
  *
  * @return Product|null
  */
 public function findSameCategoryProduct($product, $direction)
 {
     $qb = $this->getQueryBuilder()->select('p')->andWhere('p.category = :category')->setMaxResults(1)->setParameter('category', $product->getCategory());
     if ('next' == $direction) {
         $qb->andWhere('p.id > :id')->orderBy('p.id', 'asc');
     } else {
         $qb->andWhere('p.id < :id')->orderBy('p.id', 'desc');
     }
     $qb->setParameter('id', $product->getId());
     if (0 == count($qb->getQuery()->getResult())) {
         return null;
     }
     return $qb->getQuery()->getSingleResult();
 }