Commit 4556ba75 authored by Mat's avatar Mat
Browse files

fonction duplicate row

parent 6ac102da
......@@ -105,7 +105,8 @@ class LegumeController extends Controller
$em = $this->getDoctrine()->getManager();
$legume = $em->getRepository('PotageBundle:Legume')->findOneByDelete($id);
if ($legume !== null) {
if ($legume !== null)
{
$em->remove($legume);
$em->flush();
......@@ -114,4 +115,24 @@ class LegumeController extends Controller
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\Response
*
*/
public function duplicateAction($id)
{
$em = $this->getDoctrine()->getManager();
$legume = $em->getRepository('PotageBundle:Legume')->findOneByDuplicate($id);
if ($legume !== null)
{
$newRow = clone $legume;
$em->detach($newRow);
$em->persist($newRow);
$em->flush();
return $this->redirectToRoute('potage_legume_read', array('page'=> 1));
}
}
}
......@@ -77,6 +77,13 @@ class Legume
*/
private $prixUnitaire;
/**
*
*/
public function __clone()
{
$this->id = null;
}
/**
* Get id
......@@ -280,4 +287,3 @@ class Legume
return $this->prixUnitaire;
}
}
......@@ -22,7 +22,7 @@ class LegumeRepository extends \Doctrine\ORM\EntityRepository
{
$qb = $this->createQueryBuilder('l')
->orderBy('l.id' , 'ASC')
->getQuery();
->getQuery();
$qb
->setFirstResult(($page-1)* $nbPerPage)
->setMaxResults($nbPerPage);
......@@ -59,4 +59,19 @@ class LegumeRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @var id
* @return Legume
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByDuplicate($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -24,3 +24,8 @@ potage_legume_delete:
path: /legume/supprimer/{id}
defaults:
_controller: PotageBundle:Legume:delete
potage_legume_duplicate:
path: /legume/dupliquer/{id}
defaults:
_controller: PotageBundle:Legume:duplicate
......@@ -14,8 +14,8 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
<a class="btn btn-danger" role="button" href="">
Oui, effacer !
<a class="btn btn-primary" role="button" href="{{ path('potage_legume_duplicate', {'id': legume.id }) }}">
Dupliquer
</a>
</div>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment