added update()
This commit is contained in:
parent
a973a4362f
commit
cce18f6516
|
@ -11,7 +11,6 @@ namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\AddressBookEntry;
|
use App\Entity\AddressBookEntry;
|
||||||
use App\Service\DatabaseConnection;
|
use App\Service\DatabaseConnection;
|
||||||
use App\Entity\User;
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@ class AddressRepository
|
||||||
|
|
||||||
public function findAll(string $orderBy = 'last'): array
|
public function findAll(string $orderBy = 'last'): array
|
||||||
{
|
{
|
||||||
$users = [];
|
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, owner, first, last, street, zip, city, phone
|
SELECT id, owner, first, last, street, zip, city, phone
|
||||||
FROM " . DatabaseConnection::TABLE_ADDRESSES . "
|
FROM " . DatabaseConnection::TABLE_ADDRESSES . "
|
||||||
|
@ -54,7 +52,7 @@ class AddressRepository
|
||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT id, owner, first, last, street, zip, city, phone
|
SELECT id, owner, first, last, street, zip, city, phone
|
||||||
FROM " . DatabaseConnection::TABLE_USERS . "
|
FROM " . DatabaseConnection::TABLE_ADDRESSES . "
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -104,39 +102,36 @@ class AddressRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function update(Address $address): bool|int
|
public function update(AddressBookEntry $address): bool|int
|
||||||
{
|
{
|
||||||
/*
|
$id = $address->getId();
|
||||||
$id = $user->getId();
|
$owner = $address->getOwner();
|
||||||
$nick = $user->getNick();
|
$first = $address->getFirst();
|
||||||
$first = $user->getFirst();
|
$last = $address->getLast();
|
||||||
$last = $user->getLast();
|
$street = $address->getStreet();
|
||||||
$isAdmin = $user->isAdmin() ? 1 : 0;
|
$zip = $address->getZip();
|
||||||
|
$city = $address->getCity();
|
||||||
if ($user->getPassword()) {
|
$phone = $address->getPhone();
|
||||||
$password = $user->getPassword();
|
|
||||||
} else {
|
|
||||||
$current = $this->findByID(id: $id);
|
|
||||||
$password = $current->getPassword();
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
UPDATE " . DatabaseConnection::TABLE_USERS . " SET
|
UPDATE " . DatabaseConnection::TABLE_ADDRESSES . " SET
|
||||||
nick = :nick,
|
|
||||||
password = :password,
|
|
||||||
first = :first,
|
first = :first,
|
||||||
last = :last,
|
last = :last,
|
||||||
is_admin = :is_admin
|
street = :street,
|
||||||
|
zip = :zip,
|
||||||
|
city = :city,
|
||||||
|
phone = :phone
|
||||||
WHERE id = :id";
|
WHERE id = :id";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||||
$statement->bindParam(param: 'id', var: $id);
|
$statement->bindParam(param: 'id', var: $id);
|
||||||
$statement->bindParam(param: 'nick', var: $nick);
|
|
||||||
$statement->bindParam(param: 'password', var: $password);
|
|
||||||
$statement->bindParam(param: 'first', var: $first);
|
$statement->bindParam(param: 'first', var: $first);
|
||||||
$statement->bindParam(param: 'last', var: $last);
|
$statement->bindParam(param: 'last', var: $last);
|
||||||
$statement->bindParam(param: 'is_admin', var: $isAdmin);
|
$statement->bindParam(param: 'street', var: $street);
|
||||||
|
$statement->bindParam(param: 'zip', var: $zip);
|
||||||
|
$statement->bindParam(param: 'city', var: $city);
|
||||||
|
$statement->bindParam(param: 'phone', var: $phone);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
|
|
||||||
return $statement->rowCount();
|
return $statement->rowCount();
|
||||||
|
@ -144,8 +139,6 @@ class AddressRepository
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue