123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Repository;
- use App\Model\Pharmacy;
- class PharmacyRepository extends RepositoryAbstract
- {
- public function __construct()
- {
- parent::__construct();
- $this->entityName = 'pharmacy';
- }
- /**
- * @param $id
- * @return null|Pharmacy
- */
- public function findById($id)
- {
- $stmt = $this->pdo->prepare("SELECT * FROM {$this->entityName} WHERE Id = :id");
- $stmt->execute(['id' => $id]);
- foreach ($stmt as $row) {
- return new Pharmacy($row['Name'], $row['City'], $row['Street'], $row['House'], $row['Phone'], $row['Id']);
- }
- return null;
- }
- /**
- * @return Pharmacy[] array
- */
- public function findAll(): array
- {
- $stmt = $this->pdo->prepare("SELECT * FROM {$this->entityName}");
- $stmt->execute();
- $pharmacies = [];
- foreach ($stmt as $row) {
- $pharmacies[] = new Pharmacy($row['Name'], $row['City'], $row['Street'], $row['House'], $row['Phone'], $row['Id']);
- }
- return $pharmacies;
- }
- /**
- * @param Pharmacy $pharmacy
- */
- public function save(Pharmacy $pharmacy)
- {
- $stmt = $this->pdo->prepare("INSERT INTO {$this->entityName} (Name, City, Street, House, Phone) VALUES(:Name, :City, :Street, :House, :Phone)");
- $stmt->execute([
- 'Name' => $pharmacy->name,
- 'City' => $pharmacy->city,
- 'Street' => $pharmacy->street,
- 'House' => $pharmacy->house,
- 'Phone' => $pharmacy->phone
- ]);
- }
- /**
- * @param Pharmacy $pharmacy
- */
- public function update(Pharmacy $pharmacy)
- {
- $stmt = $this->pdo->prepare("UPDATE {$this->entityName} SET Name = :Name, City = :City, Street = :Street, House = :House, Phone = :Phone WHERE Id = :id");
- $stmt->execute([
- 'id' => $pharmacy->id,
- 'Name' => $pharmacy->name,
- 'City' => $pharmacy->city,
- 'Street' => $pharmacy->street,
- 'House' => $pharmacy->house,
- 'Phone' => $pharmacy->phone
- ]);
- }
- /**
- * @param int $id
- */
- public function delete(int $id)
- {
- $stmt = $this->pdo->prepare("DELETE FROM {$this->entityName} WHERE Id = :id");
- $stmt->execute(['id' => $id]);
- }
- }
|