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
2693c8d5
Commit
2693c8d5
authored
Aug 23, 2018
by
Mat
Browse files
init une page today, avec les offres pour un utilisateur (WIP)
parent
b0663093
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/config/security.yml
View file @
2693c8d5
...
...
@@ -18,7 +18,7 @@ security:
csrf_token_generator
:
security.csrf.token_manager
login_path
:
fos_user_security_login
check_path
:
fos_user_security_check
default_target_path
:
potage_
homepage
default_target_path
:
potage_
today
use_referer
:
true
logout
:
path
:
fos_user_security_logout
...
...
@@ -29,6 +29,7 @@ security:
-
{
path
:
^/login$
,
role
:
IS_AUTHENTICATED_ANONYMOUSLY
}
-
{
path
:
^/register
,
role
:
IS_AUTHENTICATED_ANONYMOUSLY
}
-
{
path
:
^/resetting
,
role
:
IS_AUTHENTICATED_ANONYMOUSLY
}
#- { path: ^/member/, role: ROLE_USER }
-
{
path
:
^/admin/
,
role
:
ROLE_ADMIN
}
-
{
path
:
^/API/
,
role
:
ROLE_ADMIN
}
...
...
src/PotageBundle/Controller/DefaultController.php
View file @
2693c8d5
...
...
@@ -22,4 +22,71 @@ class DefaultController extends MasterController
{
return
$this
->
render
(
'@Potage/Default/test.html.twig'
);
}
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public
function
todayAction
()
{
///// 1. session
/*
$session = $this->get('session');
//$session->set('test', 'oups');
//dump($session->has('test'));
//dump($session->get('test'));
dump($session);
*/
///// 2. securite user, version longue
/*
$security = $this->container->get('security.token_storage');
$token = $security->getToken();
if ($token !== null)
{
$user = $token->getUser();
dump($user);
// Si l'utilisateur courant est anonyme, $user vaut « anon. »
// Sinon, c'est une instance de notre entité User, on peut l'utiliser normalement
//$user->getUsername();
}
*/
///// 3. en plus court..
$user
=
$this
->
getUser
();
if
(
$user
!==
null
)
{
// récupère l'id de l'utilisateur
$id_utilisateur
=
$user
->
getUtilisateur
()
->
getId
();
dump
(
$id_utilisateur
);
// récupère les groupes de l'utilisateur
$groupes
=
$this
->
getDoctrine
()
->
getRepository
(
'PotageBundle:Utilisateur'
)
->
findAllGroups
(
$id_utilisateur
);
foreach
(
$groupes
as
$k
=>
$groupe
)
{
// récupère les lettres d'un groupe
$lettres
=
$this
->
getDoctrine
()
->
getRepository
(
'PotageBundle:Lettre'
)
->
findAllByGroupAndByStatus
(
$groupe
[
'id'
],
'sent'
);
$groupes
[
$k
][
'lettres'
]
=
$lettres
;
//dump($lettres);
}
}
return
$this
->
render
(
'@Potage/Default/today.html.twig'
,
array
(
'groupes'
=>
$groupes
));
}
}
src/PotageBundle/Repository/LettreRepository.php
View file @
2693c8d5
...
...
@@ -208,4 +208,25 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @param $id_groupe
* @param $status
* @return array
*/
public
function
findAllByGroupAndByStatus
(
$id_groupe
,
$status
)
{
$qb
=
$this
->
createQueryBuilder
(
'l'
)
->
select
(
'l.id'
,
'l.reference'
,
'l.startedAt'
,
'l.endedAt'
,
'l.status'
)
->
join
(
'l.groupe'
,
'g'
)
->
innerJoin
(
'l.offre'
,
'o'
)
->
addSelect
(
'o.id id_offre'
)
->
where
(
'g.id = :id'
)
->
andWhere
(
'l.status = :status'
)
->
setParameters
(
array
(
':id'
=>
$id_groupe
,
':status'
=>
$status
));
return
$qb
->
getQuery
()
->
getResult
();
}
}
src/PotageBundle/Repository/UtilisateurRepository.php
View file @
2693c8d5
...
...
@@ -100,4 +100,21 @@ class UtilisateurRepository extends \Doctrine\ORM\EntityRepository
->
setParameter
(
':string'
,
'%'
.
$string
.
'%'
)
->
getResult
();
}
/**
* Les groupes d'un utilisateur
* @param $id
* @return array
*/
public
function
findAllGroups
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'u'
)
->
join
(
'u.groupes'
,
'g'
)
->
join
(
'g.depot'
,
'd'
)
->
select
(
'g.id'
,
'g.nom'
,
'd.jourPanier'
,
'd.heurePanier'
,
'd.localisation'
,
'd.responsable'
)
->
where
(
'u.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getResult
();
}
}
src/PotageBundle/Resources/config/routing.yml
View file @
2693c8d5
...
...
@@ -8,6 +8,12 @@ potage_test:
defaults
:
_controller
:
PotageBundle:Default:test
potage_today
:
path
:
/member/today
defaults
:
_controller
:
PotageBundle:Default:today
methods
:
[
GET
]
### les routes des pages qui interrogent l'APIBundle
potage_legume_ajax_display
:
...
...
src/PotageBundle/Resources/views/Default/today.html.twig
0 → 100755
View file @
2693c8d5
{%
extends
'@Potage/layout.html.twig'
%}
{%
block
title
%}
Aujourd'hui sur Potage !
{%
endblock
%}
{%
block
searchbar
%}{%
endblock
searchbar
%}
{%
block
content
%}
<div
class=
"row"
>
<div
class=
"col-md-10 offset-md-1 bloc"
>
{%
if
app.user
%}
id:
{{
app.user.id
}}
<br>
username:
{{
app.user.username
}}
<br>
email:
{{
app.user.email
}}
<br>
roles:
{%
for
roles
in
app.token.roles
%}{{
roles.role
}}
,
{%
endfor
%}
<br>
dernière connexion:
{{
app.user.lastLogin
|
date
(
"d M Y, à H:i:s"
)
}}
<br>
nom:
{{
app.user.utilisateur.prenom
}}
{{
app.user.utilisateur.nom
}}
<br>
<hr>
{%
endif
%}
{{
dump
()
}}
{#
groupes: {% for groupe in groupes %}{{ groupe.nom }}, {% endfor %}<br>
#}
</div>
</div>
{%
endblock
%}
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