Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
4556ba75
Commit
4556ba75
authored
May 13, 2018
by
Mat
Browse files
fonction duplicate row
parent
6ac102da
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/PotageBundle/Controller/LegumeController.php
View file @
4556ba75
...
...
@@ -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
));
}
}
}
src/PotageBundle/Entity/Legume.php
View file @
4556ba75
...
...
@@ -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
;
}
}
src/PotageBundle/Repository/LegumeRepository.php
View file @
4556ba75
...
...
@@ -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
();
}
}
src/PotageBundle/Resources/config/routing.yml
View file @
4556ba75
...
...
@@ -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
src/PotageBundle/Resources/views/Legume/duplicate-modal.html.twig
View file @
4556ba75
...
...
@@ -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>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment