<?php
namespace App\Person;
use PDO;
use App\Core\AbstractRepository;

class AdressenRepository extends AbstractRepository {

  public function getTableName() {
    return "gen_adresse";
  }

  public function getModelName() {
    return "App\\Person\\AdressenModel";
  }

  public function allByPerson($id) {
      $table = $this->getTableName();
      $model = $this->getModelName();

      $strSQL = "SELECT * FROM `$table` WHERE adr_id = $id";
      $stmt = $this->pdo->query($strSQL);
      $adresse = $stmt->fetchALL(PDO::FETCH_CLASS, $model);
      return $adresse;
  }


  public function getAdrAll() {
      $table = $this->getTableName();
      $model = $this->getModelName();

      $strSQL = "SELECT * FROM `$table` ORDER BY adr_ort";
      $stmt = $this->pdo->query($strSQL);
      $adressen = $stmt->fetchALL(PDO::FETCH_CLASS, $model);
      return $adressen;
  }

  public function insertForAdresse() {
      $table = $this->getTableName();
      $model = $this->getModelName();

      $adr_id = test_input($_POST['adr_id']);
      $adr_plz = test_input($_POST['adr_plz']);
      $adr_ort = test_input($_POST['adr_ort']);
      $adr_strasse = test_input($_POST['adr_strasse']);
      $adr_land = test_input($_POST['adr_land']);
      $adr_phone = "";  //test_input($_POST['adr_land']);


       if ($_POST['submit'] == "submit") {
         $strSQL = "INSERT INTO gen_adresse (adr_plz, adr_ort, adr_strasse, adr_land)
                     VALUES ('".$adr_plz."', '".$adr_ort."', '".$adr_strasse."', '".$adr_land."')";
      }

      if ($_POST['submit'] == "update") {
        $strSQL = "UPDATE gen_adresse
                    SET adr_plz='".$adr_plz."', adr_ort='".$adr_ort."', adr_strasse='".$adr_strasse."', adr_land='".$adr_land."'
                    WHERE adr_id ='".$adr_id."'";
      }

      $stmt = $this->pdo->prepare($strSQL);
      $stmt->execute();
  }
}
 ?>
