Skip to content
GitLab
Menu
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
af915e72
Commit
af915e72
authored
Jun 16, 2018
by
Mat
Browse files
init CRUD pour les entités Groupe et Dépôt
parent
87a93977
Changes
15
Hide whitespace changes
Inline
Side-by-side
src/APIBundle/Controller/DepotAPIController.php
0 → 100644
View file @
af915e72
<?php
namespace
APIBundle\Controller
;
use
APIBundle\Form\DepotAPIType
;
use
PotageBundle\Entity\Depot
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
class
DepotAPIController
extends
MasterAPIController
{
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public
function
createAction
(
Request
$request
)
{
$depot
=
new
Depot
();
$form
=
$this
->
createForm
(
DepotAPIType
::
class
,
$depot
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$em
->
persist
(
$depot
);
$em
->
flush
();
return
$this
->
api
(
$depot
);
}
return
$this
->
api
(
$form
,
Response
::
HTTP_BAD_REQUEST
);
}
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public
function
readAction
()
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$depots
=
$em
->
getRepository
(
'PotageBundle:Depot'
)
->
findAllForAPIRead
();
return
$this
->
api
(
$depots
);
}
/**
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
updateAction
(
Request
$request
,
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$depot
=
$em
->
getRepository
(
'PotageBundle:Depot'
)
->
findOneForUpdateAPI
(
$id
);
if
(
$depot
===
null
)
{
return
$this
->
api
(
'Not found'
,
Response
::
HTTP_NOT_FOUND
);
}
$form
=
$this
->
createForm
(
DepotAPIType
::
class
,
$depot
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
->
flush
();
return
$this
->
api
(
$depot
);
}
return
$this
->
api
(
$form
,
Response
::
HTTP_BAD_REQUEST
);
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
deleteAction
(
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$depot
=
$em
->
getRepository
(
'PotageBundle:Depot'
)
->
findOneForDeleteAPI
(
$id
);
if
(
$depot
!==
null
)
{
$em
->
remove
(
$depot
);
$em
->
flush
();
}
return
$this
->
api
([]);
}
}
src/APIBundle/Controller/GroupeAPIController.php
0 → 100644
View file @
af915e72
<?php
namespace
APIBundle\Controller
;
use
APIBundle\Form\GroupeAPIType
;
use
PotageBundle\Entity\Groupe
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
class
GroupeAPIController
extends
MasterAPIController
{
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public
function
createAction
(
Request
$request
)
{
$groupe
=
new
Groupe
();
$form
=
$this
->
createForm
(
GroupeAPIType
::
class
,
$groupe
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$em
->
persist
(
$groupe
);
$em
->
flush
();
return
$this
->
api
(
$groupe
);
}
return
$this
->
api
(
$form
,
Response
::
HTTP_BAD_REQUEST
);
}
/**
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public
function
readAction
()
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$groupes
=
$em
->
getRepository
(
'PotageBundle:Groupe'
)
->
findAllForAPIRead
();
return
$this
->
api
(
$groupes
);
}
/**
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
updateAction
(
Request
$request
,
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$groupe
=
$em
->
getRepository
(
'PotageBundle:Groupe'
)
->
findOneForUpdateAPI
(
$id
);
if
(
$groupe
===
null
)
{
return
$this
->
api
(
'Not found'
,
Response
::
HTTP_NOT_FOUND
);
}
$form
=
$this
->
createForm
(
GroupeAPIType
::
class
,
$groupe
);
$form
->
handleRequest
(
$request
);
if
(
$form
->
isSubmitted
()
&&
$form
->
isValid
())
{
$em
->
flush
();
return
$this
->
api
(
$groupe
);
}
return
$this
->
api
(
$form
,
Response
::
HTTP_BAD_REQUEST
);
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
deleteAction
(
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$groupe
=
$em
->
getRepository
(
'PotageBundle:Groupe'
)
->
findOneForDeleteAPI
(
$id
);
if
(
$groupe
!==
null
)
{
$em
->
remove
(
$groupe
);
$em
->
flush
();
}
return
$this
->
api
([]);
}
}
src/APIBundle/Form/DepotAPIType.php
0 → 100755
View file @
af915e72
<?php
namespace
APIBundle\Form
;
use
PotageBundle\Form\Depot\DepotType
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
class
DepotAPIType
extends
DepotType
{
/**
* @param OptionsResolver $resolver
*/
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
parent
::
configureOptions
(
$resolver
);
$resolver
->
setDefault
(
'csrf_protection'
,
false
);
// TODO temporaire, le temps de régler les validations au niveau des Asserts et des FormType
$resolver
->
setDefault
(
'attr'
,
array
(
'novalidate'
=>
true
));
}
}
src/APIBundle/Form/GroupeAPIType.php
0 → 100755
View file @
af915e72
<?php
namespace
APIBundle\Form
;
use
PotageBundle\Form\Groupe\GroupeType
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
class
GroupeAPIType
extends
GroupeType
{
/**
* @param OptionsResolver $resolver
*/
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
parent
::
configureOptions
(
$resolver
);
$resolver
->
setDefault
(
'csrf_protection'
,
false
);
// TODO temporaire, le temps de régler les validations au niveau des Asserts et des FormType
$resolver
->
setDefault
(
'attr'
,
array
(
'novalidate'
=>
true
));
}
}
src/APIBundle/Resources/config/routing.yml
View file @
af915e72
...
...
@@ -153,3 +153,65 @@ api_info_create:
_controller
:
APIBundle:InfoAPI:create
methods
:
[
POST
]
## CRUD GroupeAPI
api_groupe_create
:
path
:
/groupe/ajouter
defaults
:
_controller
:
APIBundle:Groupe:create
methods
:
[
POST
]
api_groupe_read
:
path
:
/groupes
defaults
:
_controller
:
APIBundle:Groupe:read
methods
:
[
GET
]
api_groupe_update
:
path
:
/groupe/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:Groupe:update
methods
:
[
POST
]
api_groupe_delete
:
path
:
/groupe/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:Groupe:delete
methods
:
[
DELETE
]
## CRUD DepotAPI
api_depot_create
:
path
:
/depot/ajouter
defaults
:
_controller
:
APIBundle:Depot:create
methods
:
[
POST
]
api_depot_read
:
path
:
/depots
defaults
:
_controller
:
APIBundle:Depot:read
methods
:
[
GET
]
api_depot_update
:
path
:
/depot/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:Depot:update
methods
:
[
POST
]
api_depot_delete
:
path
:
/depot/{id}
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:Depot:delete
methods
:
[
DELETE
]
src/PotageBundle/Controller/DepotController.php
0 → 100644
View file @
af915e72
<?php
namespace
PotageBundle\Controller
;
use
APIBundle\Form\DepotAPIType
;
class
DepotController
extends
MasterController
{
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public
function
ajaxDisplayAction
()
{
$form
=
$this
->
createForm
(
DepotAPIType
::
class
);
return
$this
->
render
(
'PotageBundle:Depot:ajaxDisplay.html.twig'
,
array
(
'formDepot'
=>
$form
->
createView
()
));
}
}
src/PotageBundle/Controller/GroupeController.php
0 → 100644
View file @
af915e72
<?php
namespace
PotageBundle\Controller
;
use
APIBundle\Form\GroupeAPIType
;
class
GroupeController
extends
MasterController
{
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public
function
ajaxDisplayAction
()
{
$form
=
$this
->
createForm
(
GroupeAPIType
::
class
);
return
$this
->
render
(
'PotageBundle:Groupe:ajaxDisplay.html.twig'
,
array
(
'formGroupe'
=>
$form
->
createView
()
));
}
}
src/PotageBundle/Form/Depot/DepotType.php
0 → 100755
View file @
af915e72
<?php
namespace
PotageBundle\Form\Depot
;
use
PotageBundle\Entity\Depot
;
use
Symfony\Component\Form\Extension\Core\Type\SubmitType
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
class
DepotType
extends
AbstractType
{
public
function
buildForm
(
FormBuilderInterface
$builder
,
array
$options
)
{
/* TODO les champs en plus
*/
$builder
->
add
(
'sauver'
,
SubmitType
::
class
,
array
(
'label'
=>
'Enregistrer'
,
'attr'
=>
array
(
'class'
=>
'btn btn-dark mb-2'
)
));
}
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
parent
::
configureOptions
(
$resolver
);
$resolver
->
setDefault
(
'data_class'
,
Depot
::
class
);
$resolver
->
setDefault
(
'attr'
,
array
(
'class'
=>
'formulaire formulaire_depot'
,
));
}
public
function
getBlockPrefix
()
{
return
'depot'
;
}
}
src/PotageBundle/Form/Groupe/GroupeType.php
0 → 100755
View file @
af915e72
<?php
namespace
PotageBundle\Form\Groupe
;
use
PotageBundle\Entity\Groupe
;
use
Symfony\Component\Form\Extension\Core\Type\SubmitType
;
use
Symfony\Component\Form\AbstractType
;
use
Symfony\Component\Form\FormBuilderInterface
;
use
Symfony\Component\OptionsResolver\OptionsResolver
;
class
GroupeType
extends
AbstractType
{
public
function
buildForm
(
FormBuilderInterface
$builder
,
array
$options
)
{
/* TODO les champs en plus
*/
$builder
->
add
(
'sauver'
,
SubmitType
::
class
,
array
(
'label'
=>
'Enregistrer'
,
'attr'
=>
array
(
'class'
=>
'btn btn-dark mb-2'
)
));
}
public
function
configureOptions
(
OptionsResolver
$resolver
)
{
parent
::
configureOptions
(
$resolver
);
$resolver
->
setDefault
(
'data_class'
,
Groupe
::
class
);
$resolver
->
setDefault
(
'attr'
,
array
(
'class'
=>
'formulaire formulaire_groupe'
,
));
}
public
function
getBlockPrefix
()
{
return
'groupe'
;
}
}
src/PotageBundle/Repository/DepotRepository.php
View file @
af915e72
...
...
@@ -10,4 +10,42 @@ namespace PotageBundle\Repository;
*/
class
DepotRepository
extends
\
Doctrine\ORM\EntityRepository
{
/**
* @return array
*/
public
function
findAllForAPIRead
()
{
$qb
=
$this
->
createQueryBuilder
(
'd'
)
->
orderBy
(
'd.nom, ASC'
);
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForUpdateAPI
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'd'
)
->
where
(
'd.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForDeleteAPI
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'd'
)
->
where
(
'd.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
}
src/PotageBundle/Repository/GroupeRepository.php
View file @
af915e72
...
...
@@ -10,4 +10,44 @@ namespace PotageBundle\Repository;
*/
class
GroupeRepository
extends
\
Doctrine\ORM\EntityRepository
{
/**
* @return array
*/
public
function
findAllForAPIRead
()
{
$qb
=
$this
->
createQueryBuilder
(
'g'
)
->
orderBy
(
'g.nom, ASC'
);
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForUpdateAPI
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'g'
)
->
where
(
'g.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForDeleteAPI
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'g'
)
->
where
(
'g.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
}
src/PotageBundle/Resources/config/routing.yml
View file @
af915e72
...
...
@@ -37,3 +37,14 @@ potage_info_ajax_display:
_controller
:
PotageBundle:Info:ajaxDisplay
methods
:
[
GET
]
potage_groupe_ajax_display
:
path
:
/admin/groupes
defaults
:
_controller
:
PotageBundle:Groupe:ajaxDisplay
methods
:
[
GET
]
potage_depot_ajax_display
:
path
:
/admin/depots
defaults
:
_controller
:
PotageBundle:Depot:ajaxDisplay
methods
:
[
GET
]
src/PotageBundle/Resources/views/Default/navbar.html.twig
View file @
af915e72
...
...
@@ -46,7 +46,8 @@
<div
class=
"dropdown-divider"
></div>
<a
class=
"dropdown-item disabled"
href=
"#"
>
Les utilisateurs
</a>
<a
class=
"dropdown-item disabled"
href=
"#"
>
Les groupes
</a>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'potage_groupe_ajax_display'
)
}}
"
>
Les groupes
</a>
<a
class=
"dropdown-item"
href=
"
{{
path
(
'potage_depot_ajax_display'
)
}}
"
>
Les points de dépôt
</a>
</div>
</li>
...
...
src/PotageBundle/Resources/views/Depot/ajaxDisplay.html.twig
0 → 100644
View file @
af915e72
{%
extends
'@Potage/layout.html.twig'
%}
{%
block
title
%}
Les points de dépôt
{%
endblock
%}
{%
block
body
%}
{{
block
(
'breadcrumb'
)
}}
<h1>
{{
block
(
'title'
)
}}
</h1>
{{
form
(
formDepot
)
}}
{%
endblock
%}
\ No newline at end of file
src/PotageBundle/Resources/views/Groupe/ajaxDisplay.html.twig
0 → 100644
View file @
af915e72
{%
extends
'@Potage/layout.html.twig'
%}
{%
block
title
%}
Les groupes
{%
endblock
%}
{%
block
body
%}
{{
block
(
'breadcrumb'
)
}}
<h1>
{{
block
(
'title'
)
}}
</h1>
{{
form
(
formGroupe
)
}}
{%
endblock
%}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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