public function save(Guest $guest) { if (is_null($guest->id())) { // insert $stmt = $this->pdo->prepare('INSERT INTO guests (firstName, lastName, emailAddress, phoneNumber, address, paymentAmount) VALUES (:firstName, :lastName, :emailAddress, :phoneNumber, :address, :paymentAmount)'); } else { // update $stmt = $this->pdo->prepare('UPDATE guests SET firstName = :firstName, lastName = :lastName, emailAddress = :emailAddress, phoneNumber = :phoneNumber, address = :address, paymentAmount = :paymentAmount WHERE id = :guestId'); $stmt->bindValue('guestId', $guest->id()); } $stmt->bindValue('firstName', $guest->firstName()); $stmt->bindValue('lastName', $guest->lastName()); $stmt->bindValue('emailAddress', $guest->emailAddress()); $stmt->bindValue('phoneNumber', $guest->phoneNumber()); $stmt->bindValue('address', $guest->address()); $stmt->bindValue('paymentAmount', $guest->paymentAmount()->getConvertedAmount()); return $stmt->execute(); }
public function getByGuest(Guest $guest) { $stmt = $this->pdo->prepare('SELECT * FROM transactions WHERE guestId = :guestId'); $stmt->bindValue(':guestId', $guest->id()); $stmt->execute(); $res = []; foreach ($stmt->fetchAll(PDO::FETCH_OBJ) as $transaction) { $res[] = $this->mapper($transaction); } return $res; }