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

class EreignisseRepository extends AbstractRepository
{

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

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

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

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

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

      $issue_id = test_input($_POST['issue_id']);
      $member_id_f = test_input($_POST['member_id_f']);
      $issue_date = test_input($_POST['issue_date']);
      $issue_text = test_input($_POST['issue']);

      if ($_POST['submit'] == "update") {
        $strSQL = "UPDATE gen_ereignis
                 SET issue_date='".$issue_date."', issue='".$issue_text."'
                 WHERE issue_id ='".$issue_id."'";
      }
      if ($_POST['submit'] == "submit") {
      $strSQL = "INSERT INTO gen_ereignis (member_id_f, issue_date, issue)
              VALUES ('".$member_id_f."', '".$issue_date."', '".$issue_text."')";
      }
      $stmt = $this->pdo->prepare($strSQL);
      $stmt->execute();
  }

}

 ?>
