Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
É
Éco-presto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLINOT Baptiste
Éco-presto
Commits
d1cbeb8f
Commit
d1cbeb8f
authored
1 year ago
by
YvanSv
Browse files
Options
Downloads
Patches
Plain Diff
ajout d'un bouton like aux annonces sur l'accueil
parent
9a308fb1
No related branches found
No related tags found
1 merge request
!66
Master
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/styles/app.css
+1
-1
1 addition, 1 deletion
assets/styles/app.css
src/Controller/HomePageController.php
+44
-2
44 additions, 2 deletions
src/Controller/HomePageController.php
templates/home_page/index.html.twig
+11
-0
11 additions, 0 deletions
templates/home_page/index.html.twig
with
56 additions
and
3 deletions
assets/styles/app.css
+
1
−
1
View file @
d1cbeb8f
...
...
@@ -316,7 +316,7 @@ button {
}
.btn-like
{
background-color
:
#ffffff
;
background-color
:
transparent
;
border
:
0px
#ccc
;
padding
:
5px
10px
;
cursor
:
pointer
;
...
...
This diff is collapsed.
Click to expand it.
src/Controller/HomePageController.php
+
44
−
2
View file @
d1cbeb8f
...
...
@@ -7,15 +7,27 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\Routing\Annotation\Route
;
use
Doctrine\Persistence\ManagerRegistry
;
use
App\Entity\Notification
;
use
App\Entity\Prestations
;
use
DateTime
;
class
HomePageController
extends
AbstractController
{
private
$doctrine
;
public
function
__construct
(
ManagerRegistry
$doctrine
)
{
$this
->
doctrine
=
$doctrine
;
}
#[Route('', name: 'app_home_page')]
public
function
index
(
Request
$request
,
PrestationsRepository
$prestationsRepository
):
Response
{
$prestations
=
$prestationsRepository
->
findFilteredPrestations
();
$user
=
$this
->
getUser
();
return
$this
->
render
(
'home_page/index.html.twig'
,
[
'prestations'
=>
$prestations
'prestations'
=>
$prestations
,
'user'
=>
$user
]);
}
...
...
@@ -30,9 +42,39 @@ class HomePageController extends AbstractController
if
(
$prixMax
==
''
)
$prixMax
=
null
;
$prestations
=
$prestationsRepository
->
findFilteredPrestations
(
$keyword
,
$prixMin
,
$prixMax
,
$typePrestation
);
$user
=
$this
->
getUser
();
return
$this
->
render
(
'home_page/index.html.twig'
,
[
'prestations'
=>
$prestations
'prestations'
=>
$prestations
,
'user'
=>
$user
]);
}
#[Route('/aimer/{id}', name: 'app_like_home_page')]
public
function
aimerPrestation
(
$id
,
PrestationsRepository
$prestationsRepository
):
Response
{
$user
=
$this
->
getUser
();
$entityManager
=
$this
->
doctrine
->
getManager
();
$prestation
=
$entityManager
->
getRepository
(
Prestations
::
class
)
->
find
(
$id
);
if
(
$user
!=
null
)
{
$notification
=
new
Notification
();
$notification
->
setDescription
(
$user
->
getLogin
()
.
" a aimé votre annonce "
.
$prestation
->
getTitre
());
$notification
->
setType
(
"Annonce aimée"
);
$notification
->
setDate
(
new
DateTime
());
$notification
->
setUserId
(
$prestation
->
getProprietaire
());
$this
->
doctrine
->
getManager
()
->
persist
(
$notification
);
$prestation
->
setIdClient
(
null
);
}
else
return
$this
->
redirectToRoute
(
'app_login'
);
if
(
$user
->
getPrestationsAimees
()
->
contains
(
$prestation
))
{
$user
->
removePrestationsAimee
(
$prestation
);
$prestation
->
removeUtilisateursAimant
(
$user
);
}
else
{
$user
->
addPrestationsAimee
(
$prestation
);
$prestation
->
addUtilisateursAimant
(
$user
);
}
$entityManager
->
flush
();
return
$this
->
redirectToRoute
(
'app_home_page'
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
templates/home_page/index.html.twig
+
11
−
0
View file @
d1cbeb8f
...
...
@@ -47,6 +47,17 @@
{%
if
is_granted
(
'ROLE_ADMIN'
)
%}
<p
class=
"tag_litige"
id=
"tag"
>
{{
prestation.litiges
|
length
}}
</p>
{%
endif
%}
{%
if
user
and
not
is_granted
(
"ROLE_ADMIN"
)
%}
{%
if
user.id
!=
prestation.proprietaire.id
%}
<a
href=
"
{{
path
(
'app_like_home_page'
,
{
'id'
:
prestation.id
}
)
}}
"
><button
class=
"btn-like"
>
{%
if
user.aimePrestation
(
prestation
)
%}
<span
class=
"aime"
>
❤
</span>
{%
else
%}
<span
class=
"non_aime"
>
❤
</span>
{%
endif
%}
</button></a>
{%
endif
%}
{%
endif
%}
{%
if
prestation.getType
()
==
'Pret'
%}
<p
class=
"tag_pret"
id=
"tag"
>
Prêt
</p>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment