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
LQDN Adminsys
don
Commits
7fa005ef
Commit
7fa005ef
authored
Oct 07, 2021
by
Bastien Le Querrec
Browse files
do not prevent use of existing address
Multiple users should be able to share one address.
parent
ad1b9d08
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/controller/perso.php
View file @
7fa005ef
...
...
@@ -288,24 +288,19 @@ class Perso extends Controller
$f3
->
push
(
'SESSION.message'
,
_
(
"Adresse ajoutée à votre profil"
));
break
;
case
'UPDATE'
:
try
{
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
AddressUpdateCommand
(
\
Utils
::
asl
(
$f3
->
get
(
'id'
)),
\
Utils
::
asl
(
$f3
->
get
(
'SESSION.id'
)),
\
Utils
::
asl
(
$f3
->
get
(
'nom'
)),
\
Utils
::
asl
(
$f3
->
get
(
'adresse'
)),
\
Utils
::
asl
(
$f3
->
get
(
'adresse2'
)),
\
Utils
::
asl
(
$f3
->
get
(
'codepostal'
)),
\
Utils
::
asl
(
$f3
->
get
(
'ville'
)),
\
Utils
::
asl
(
$f3
->
get
(
'pays'
)),
\
Utils
::
asl
(
$f3
->
get
(
'state'
))
)
);
}
catch
(
AddressAlreadyExistsException
$e
)
{
$f3
->
set
(
"error"
,
_
(
"Cette adresse existe déjà."
));
$f3
->
error
(
'403'
);
}
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
AddressUpdateCommand
(
\
Utils
::
asl
(
$f3
->
get
(
'id'
)),
\
Utils
::
asl
(
$f3
->
get
(
'SESSION.id'
)),
\
Utils
::
asl
(
$f3
->
get
(
'nom'
)),
\
Utils
::
asl
(
$f3
->
get
(
'adresse'
)),
\
Utils
::
asl
(
$f3
->
get
(
'adresse2'
)),
\
Utils
::
asl
(
$f3
->
get
(
'codepostal'
)),
\
Utils
::
asl
(
$f3
->
get
(
'ville'
)),
\
Utils
::
asl
(
$f3
->
get
(
'pays'
)),
\
Utils
::
asl
(
$f3
->
get
(
'state'
))
)
);
$f3
->
push
(
'SESSION.message'
,
_
(
"Adresse du profil modifiée."
));
break
;
case
'DELETE'
:
...
...
src/LQDN/Handler/AddressHandler.php
View file @
7fa005ef
...
...
@@ -63,6 +63,25 @@ EOF;
$stmt
->
execute
();
}
/**
* Check if an adress is used.
*
* @param int $addressId
*
* @return bool
*/
private
function
addressUsed
(
$addressId
)
{
$count
=
(
int
)
$this
->
connection
->
fetchColumn
(
"SELECT count(1) FROM contreparties, dons WHERE contreparties.adresse_id = :id AND contreparties.status = 1;"
,
[
'id'
=>
$addressId
,
],
0
);
return
(
$count
>
0
);
}
/**
* Update an address.
*
...
...
@@ -73,12 +92,6 @@ EOF;
$addressId
=
$command
->
getAddressId
();
$userId
=
$command
->
getUserId
();
// Let's check if the address is used
if
(
$this
->
addressUsed
(
$addressId
)
==
true
)
{
// The address is used somehow
throw
new
AddressUsedException
();
};
$query
=
<<<EOF
UPDATE adresses
SET nom = :name, adresse = :address, adresse2 = :address2, codepostal = :postal_code, ville = :city, etat = :state, pays = :country
...
...
@@ -97,41 +110,4 @@ EOF;
$stmt
->
bindValue
(
'country'
,
$command
->
getCountry
());
$stmt
->
execute
();
}
/**
* Check if an address already exists.
*
* @param int $userId
*
* @return bool
*/
private
function
addressExists
(
$userId
)
{
return
(
bool
)
$this
->
connection
->
fetchColumn
(
"SELECT 1 FROM adresses WHERE user_id = :user_id"
,
[
'user_id'
=>
$userId
,
],
0
);
}
/**
* Check if an adress is used.
*
* @param int $addressId
*
* @return bool
*/
private
function
addressUsed
(
$addressId
)
{
$count
=
(
int
)
$this
->
connection
->
fetchColumn
(
"SELECT count(1) FROM contreparties, dons WHERE contreparties.adresse_id = :id AND contreparties.status = 1;"
,
[
'id'
=>
$addressId
,
],
0
);
return
(
$count
>
0
);
}
}
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