Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos-tav
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
agplv3
kohinos-tav
Commits
89114128
Commit
89114128
authored
May 02, 2024
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent deleting user if has flux to its account OR its adherent account
parent
70f6b7d9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
+36
-4
CRUDController.php
src/Controller/CRUD/CRUDController.php
+13
-4
FluxRepository.php
src/Repository/FluxRepository.php
+23
-0
No files found.
src/Controller/CRUD/CRUDController.php
View file @
89114128
...
...
@@ -232,12 +232,21 @@ class CRUDController extends Controller
}
// Prevent deleting user if flux related to its Adherent account exist
if
(
$object
instanceof
User
&&
$object
->
getAdherent
())
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByAdherent
(
$object
->
getAdherent
());
if
(
null
!=
$query
&&
count
(
$query
->
getResult
())
>
0
)
{
if
(
$object
instanceof
User
)
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByUser
(
$object
);
$hasFluxAdherent
=
false
;
if
(
$object
->
getAdherent
())
{
$queryAdherent
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByAdherent
(
$object
->
getAdherent
());
if
(
null
!=
$queryAdherent
&&
count
(
$queryAdherent
->
getResult
())
>
0
)
{
$hasFluxAdherent
=
true
;
}
}
if
(
null
!=
$query
&&
count
(
$query
->
getResult
())
>
0
||
$hasFluxAdherent
)
{
$this
->
addFlash
(
'sonata_flash_error'
,
'Vous ne pouvez pas supprimer ce compte utilisateur
car des flux en relation à son compte Adhérent existent
.'
'Vous ne pouvez pas supprimer ce compte utilisateur
: des flux en relation à son compte sont enregistrés
.'
);
return
$this
->
redirectTo
(
$object
);
...
...
src/Repository/FluxRepository.php
View file @
89114128
...
...
@@ -7,6 +7,7 @@ use App\Entity\Comptoir;
use
App\Entity\Flux
;
use
App\Entity\Groupe
;
use
App\Entity\Prestataire
;
use
App\Entity\User
;
use
Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository
;
use
Doctrine\Persistence\ManagerRegistry
;
...
...
@@ -237,6 +238,28 @@ class FluxRepository extends ServiceEntityRepository
;
}
/**
* @param User $user
*
* @return Query Returns a query fo finding an array of Flux
*/
public
function
getQueryByUser
(
User
$user
)
{
$sqlQuery
=
"SELECT f.id FROM
{
$this
->
tableName
}
f WHERE f.user_id = :id"
;
$statement
=
$this
->
connection
->
prepare
(
$sqlQuery
);
$statement
->
bindValue
(
':id'
,
$user
->
getId
());
$statement
->
execute
();
$results
=
$statement
->
fetchAll
();
$qb
=
$this
->
createQueryBuilder
(
'f'
);
return
$qb
->
where
(
$qb
->
expr
()
->
in
(
'f.id'
,
':ids'
))
->
setParameter
(
'ids'
,
$results
)
->
orderBy
(
'f.createdAt'
,
'DESC'
)
->
getQuery
()
;
}
public
function
getTotalVenteAchat
()
{
$qb
=
$this
->
createQueryBuilder
(
'f'
);
...
...
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