From cce18f6516813521646310ee8dc2f8abba4636a0 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 25 Oct 2022 15:51:51 +0200 Subject: [PATCH] added update() --- src/Repository/AddressRepository.php | 45 ++++++++++++---------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/Repository/AddressRepository.php b/src/Repository/AddressRepository.php index 53582d3..3179dd8 100644 --- a/src/Repository/AddressRepository.php +++ b/src/Repository/AddressRepository.php @@ -11,7 +11,6 @@ namespace App\Repository; use App\Entity\AddressBookEntry; use App\Service\DatabaseConnection; -use App\Entity\User; use PDO; use PDOException; @@ -27,7 +26,6 @@ class AddressRepository public function findAll(string $orderBy = 'last'): array { - $users = []; $sql = " SELECT id, owner, first, last, street, zip, city, phone FROM " . DatabaseConnection::TABLE_ADDRESSES . " @@ -54,7 +52,7 @@ class AddressRepository { $sql = " SELECT id, owner, first, last, street, zip, city, phone - FROM " . DatabaseConnection::TABLE_USERS . " + FROM " . DatabaseConnection::TABLE_ADDRESSES . " WHERE id = :id"; try { @@ -104,39 +102,36 @@ class AddressRepository } - public function update(Address $address): bool|int + public function update(AddressBookEntry $address): bool|int { - /* - $id = $user->getId(); - $nick = $user->getNick(); - $first = $user->getFirst(); - $last = $user->getLast(); - $isAdmin = $user->isAdmin() ? 1 : 0; - - if ($user->getPassword()) { - $password = $user->getPassword(); - } else { - $current = $this->findByID(id: $id); - $password = $current->getPassword(); - } + $id = $address->getId(); + $owner = $address->getOwner(); + $first = $address->getFirst(); + $last = $address->getLast(); + $street = $address->getStreet(); + $zip = $address->getZip(); + $city = $address->getCity(); + $phone = $address->getPhone(); $sql = " - UPDATE " . DatabaseConnection::TABLE_USERS . " SET - nick = :nick, - password = :password, + UPDATE " . DatabaseConnection::TABLE_ADDRESSES . " SET first = :first, last = :last, - is_admin = :is_admin + street = :street, + zip = :zip, + city = :city, + phone = :phone WHERE id = :id"; try { $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $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: '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(); return $statement->rowCount(); @@ -144,8 +139,6 @@ class AddressRepository echo $e->getMessage(); return false; } - */ - return false; }