<?php
namespace App\Person;

use App\Core\AbstractController;

class PersonController extends AbstractController
{
    public function __construct(
      PersonRepository $personRepository,
      RemarkRepository $remarkRepository,
      PartnerRepository $partnerRepository,
      WohnorteRepository $wohnorteRepository,
      EreignisseRepository $ereignisseRepository,
      AdressenRepository $adressenRepository
      )
    {
      $this->personRepository = $personRepository;
      $this->remarkRepository = $remarkRepository;
      $this->partnerRepository = $partnerRepository;
      $this->wohnorteRepository = $wohnorteRepository;
      $this->ereignisseRepository = $ereignisseRepository;
      $this->adressenRepository = $adressenRepository;
    }

// ****************** functions ************************************************
// Returns true when the user is checked in, else false
    function is_checked_in() {
      if (isset($_SESSION['login'])) {
        return true;
      } else {
          header("Location: login");
          die();  // hier könnte auch eine exeption ausgeführt werden
        }
    }
// Returns true when the user is admin, else false
    function is_admin() {
      if (isset($_SESSION['login'])) {
        //echo "Login: ".$_SESSION['login']."<br>";
        if ($_SESSION['login'] == 'h.boergmann@t-online.de') {
          return true;}
      } else {
          //header("Location: login");
          header("Location: ./../../public/index.php/login");

          die();  // hier könnte auch eine exeption ausgeführt werden
        }
    }
// **************** End functions **********************************************
// ********************** start site *** ***************************************
    public function index() {
      $this->is_checked_in();         // returns true or goto login
      if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $_SESSION['id'] = $id;
      } else {
        if (isset($_SESSION['id'])) {
          $id = $_SESSION['id'];
        } else {
          $id = 2;
          $_SESSION['id'] = 2;
        }
      }
      $person = $this->personRepository->find($id);
      $persons = $this->personRepository->all();
      $this->render ("person/index",  [
        'person' => $person,
        'persons' => $persons
      ]);
    }

// ******************** show family tree ***************************************
    public function baum() {
      global $anz_gen, $partner, $ladezeit;
      $sql_start = microtime(1);      // ladezeit messen
      $this->is_checked_in();         // returns true or goto login
      if (isset($_GET['anz'])) {      // Anzahl Generationen
        $anz_gen = $_GET['anz'];
        $_SESSION['anz'] = $anz_gen;
      } else {
        if (isset($_SESSION['anz'])) {
          $anz_gen = $_SESSION['anz'];
        } else { $anz_gen = 4; }
      }
      if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $_SESSION['id'] = $id;
      } else {
        if (isset($_SESSION['id'])) {
          $id = $_SESSION['id'];
        } else { $id = 1; }
      }
      if (isset($_GET['baum'])) {       // beginn des stammbaums
        $baum = $_GET['baum'];
        $_SESSION['baum'] = $baum;
      } else {
        if (isset($_SESSION['baum'])) {
          $baum = $_SESSION['baum'];
        } else { $baum = 0; }
      }

      if ($anz_gen == 5) {      // Stammväter
        //echo $baum;die();
        $roots = $this->personRepository->get_root(0);        // alle roots
        //var_dump($roots); die();
        $root = $this->personRepository->get_root($baum);     // selected root
        //var_dump($root);die();
        $sex = 1;
        $persons = $this->personRepository->allByBirthday();  // nach Alter
        $person_man = $this->personRepository->allNamesBySex($sex);
        //var_dump($person_man); die();
        $family = [
          'persons' => $persons,
          'person_man' => $person_man,
          'roots' => $roots,              // all root persons
          'root' => $root,                // selected root
          'anz' => $anz_gen,              // Anzahl
          'baum' => $baum                 // SEESSION[baum]
          ];

      } else {
          $f_id = $m_id = ""; // dummy
          $family = $this->get_fam($f_id, $m_id, $id);
      }

        $sql_end = microtime(1);
        $ladezeit = $sql_end - $sql_start;
        //var_dump($partner);die();
      $this->render ("person/baum", $family);
    }


// ******************** show family on one sheet *******************************
    public function familienblatt() {
      global $ladezeit;
      $sql_start = microtime(1);
      $this->is_checked_in();         // returns true or goto login
      if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $_SESSION['id'] = $id;
        $person = $this->personRepository->find($id); // Person finden
      }
      $gender = $person['gender'];
      $fa_id = $mo_id = ""; // dummy
      $family = $this->get_fam($fa_id,$mo_id,$id);
      $sql_end = microtime(1);
      $ladezeit = $sql_end - $sql_start;
      $this->render ("person/familienblatt", $family);
    }

// ******************* show family table ***************************************
    public function familientafel() {
      global $ladezeit;
      $sql_start = microtime(1);
      $this->is_checked_in();         // returns true or goto login
      //var_dump($_GET);die();
      if (isset($_GET['id'])) {         // neue Person
        $id = $_GET['id'];
        $_SESSION['id'] = $id;
        $person = $this->personRepository->find($id);
        $gender = $person['gender'];
        $fa_id = 0;   //müssen gesetzt sein
        $mo_id = 0;
        $family = $this->get_fam($fa_id,$mo_id,$id);
      }
      if (isset($_GET['fam_id'])) {     // neue Familie: Person wird zu Vater
        $id = $_GET['fam_id'];
        $_SESSION['id'] = $id;
        $child = $this->personRepository->find($id); // load child fam_id
        $gend = $child['gender'];
        $id = $child['member_id'];      // load partner of child (new mother)
        $person = $this->personRepository->find($id); //neuer Vater oder Mutter
        //var_dump($person);die();

        $partner = $this->partnerRepository->allByPartner($id, $gend); // Partner laden
        if (!empty($partner)) {
          $anz = count($partner)-1; // letzter Partner (-1)
          $fa_id = $partner[$anz]['man_id'];
          $mo_id = $partner[$anz]['woman_id'];
          $family = $this->get_fam_by_parents($fa_id, $mo_id); // load family
        } else {
          $fa_id = $id; $mo_id = "";
          $family = $this->get_fam_by_parents($fa_id, $mo_id);
        }
      }
      $sql_end = microtime(1);
      $ladezeit = $sql_end - $sql_start;
      $this->render ("person/familientafel", $family);
    }
    // ******************** show progenies (nachfahren) ****************************
        public function nachkommen() {
          global $ladezeit;
          $sql_start = microtime(1);      // ladezeit messen
          $this->is_checked_in();         // returns true or goto login
          $gen_00 = $gen_10 = $gen_20 = $gen_30 = $gen_40 = $gen_50 = array();  // male
          $gen_01 = $gen_11 = $gen_21 = $gen_31 = $gen_41 = $gen_51 = array();  // female
          $gen_300 = $gen_301 = $gen_400 = $gen_401 = $gen_500 = $gen_501 = $part = array();    // children
          $partner_c = array();

          if (isset($_GET['mid'])) {
            $mid = $_GET['mid'];          //
            $childs = $this->personRepository->children($mid);    // children Grandmother

            $id = $childs[0]['member_id'];                        // child of grandmother
          } else {
            if (isset($_GET['id'])) { $id = $_GET['id']; }
          }

          if (!empty($id) OR $id!=0) {
            $person = $this->personRepository->find($id);              // Person
            $f_id = $person['father_id'];                              // Vater der Personn
            $m_id = $person['mother_id'];                              // Mutter der Person
          } else { $person = array();}                                 // no Person

          if ($f_id != 0){
            $father = $this->personRepository->find($f_id);            // father
            $gf_id = $father['father_id'];                             // Großvaters id
          } else { $father = array(); }

          if ($m_id != 0){
            $mother = $this->personRepository->find($m_id);            // mother
            $gm_id = $mother['mother_id'];                             // Großmutters id
          } else { $mother = array(); }

          // ******************** Großeltern väterlich
          if (!empty($father)) {
            $gff_id = $father['father_id'];                     // grandfather by father
            $gffather = $this->personRepository->find($gff_id);
            $gmf_id = $father['mother_id'];                     // grandmother by father
            $gmfather = $this->personRepository->find($gmf_id);
          } else { $gffather = array(); $gmfather = array(); }

          if (!empty($gffather)) { // grandfather by grandfatherfather
            $gen_00[] = $this->personRepository->find($gffather['father_id']);
          } else { $gen_00 = array(); }

          if (!empty($gffather)) { // grandfather by grandfatherfather
            $gen_01[] = $this->personRepository->find($gffather['mother_id']);
          } else { $gen_01 = array(); }

          if (!empty($gff_id)){
            $siblings_f = $this->personRepository->siblings($gff_id,$f_id);  // siblings of father
          } else { $siblings_f = array(); }

    // ****************** (gen_300) siblings + person ******************************
          $siblings = $this->personRepository->siblings($f_id, $id);  // siblings of person (3. Generation)
          array_unshift ($siblings, $person);    // include person (first position)
          $gen_30[] = $siblings;                 //Person und geschwister

    // ************* gen_200 Father, his siblings and their children (Gen_300) *****
          foreach ($siblings_f as $sib_f) {   // ohne Vater
            if (!empty($sib_f)) {
              $gen_20[] = $sib_f;             // siblings of father

              $id_0 = $sib_f['member_id'];    // children of father and his siblings
              $childs = $this->personRepository->children($id_0);   // children of siblings_f and cousins
              $gen_30[] = $childs;                                 // childs of person and their siblings
            }
          }
    // ********************** partner of gen_30 ************************************
          //echo "<br><br><br><br><br><br><br><br><br><br>";
          foreach ($gen_30 as $g300) {
            $anz = count($g300);              // Kinder
            for ($a = 0; $a < $anz; $a++){
              $gend = $g300[$a]['gender'];
              $id = $g300[$a]['member_id'];   // load partner der Kinder
              $gen_31[] = $this->partnerRepository->allByPartner($id, $gend); // Partner laden
              $childs = $this->personRepository->children($id);
              $gen_40[] = $childs;                      // Enkel
              $anz_c = count($childs);                  // Anz. Enkel
              if ($anz_c == 0){ $partner_c[] = array();
                } else {
                for ($c = 0; $c < $anz_c; $c++){
                  $gend_c = $childs[$c]['gender'];
                  $id_c = $childs[$c]['member_id'];     // Kinder von Person
                  $partner_c[] = $this->partnerRepository->allByPartner($id_c, $gend_c); // Partner Kind laden
                }
              }
              $gen_41[] = $partner_c;
              $partner_c = array();
            }
            $gen_301[] = $gen_31;
            $gen_400[] = $gen_40;
            $gen_401[] = $gen_41;
            $gen_31 = $gen_40  = $gen_41 = array();
          }

          // Kindeskinder vorhanden?
          $g_500 = array();
          foreach ($gen_400 as $g_40){
            foreach ($g_40 as $g_4){
              foreach ($g_4 as $g_4000){
                $id_cc = $g_4000['member_id'];
                $gen_cc = $g_4000['gender'];
                $child_childs = $this->personRepository->child_children($id_cc);   // children of siblings_f and cousins
                $gen_500[] = $child_childs;
                $anz_cc = count($child_childs);                  // Anz. Enkel
                  for ($c = 0; $c < $anz_cc; $c++){
                    $gend_cc = $child_childs[$c]['gender'];
                    $id_cc = $child_childs[$c]['member_id'];     // Kinder von Person
                    $gen_51[] = $partner_cc = $this->partnerRepository->allByPartner($id_cc, $gend_cc); // Partner Kind laden
                  }
                $partner_cc = array();
              }
            }
          }
  //      die();
    // ****** Father gen_20 + siblings ; Partner (Mother) gen_21********************
          array_unshift ($gen_20, $father); //echo "</br></br>";
          $i = 0;
          $a = $anz = 0;
          if (!empty($gen_20[0]->member_id)){
            $anz = count($gen_20);
            for ($a = 0; $a < $anz; $a++){
              $gend = $gen_20[$a]['gender'];
              $id = $gen_20[$a]['member_id'];      // load partner (new mother)
              $gen_21[] = $this->partnerRepository->allByPartner($id, $gend); // Partner laden
            }
          }
    // ******************* Grandfather gen_10; Grandmother_11 **********************
          $gen_10[] = $gffather;
          $gen_11[] = $gmfather;

    // *****************************************************************************
          $persons = $this->personRepository->all();                  // all persons
          $sql_end = microtime(1);
          //echo $ladezeit = $sql_end - $sql_start;
          //die();
          $family = [
            'persons' => $persons,
            'person' => $person,
            'gen_00' => $gen_00,
            'gen_01' => $gen_01,
            'gen_10' => $gen_10,             // grandfather
            'gen_11' => $gen_11,
            'gen_20' => $gen_20,             // father
            'gen_21' => $gen_21,
            'gen_30' => $gen_30,
            'gen_301' => $gen_301,
            'gen_40' => $gen_400,             // grandchild
            'gen_401' => $gen_401,
            'gen_500' => $gen_500,
            'gen_51' => $gen_51
          ];
          $this->render ("person/nachkommen", $family);
        }
    //

// ************** get partner of a group like children and siblings ************
    public function getPartnerOf($group, $member) {
      $group_p = array();
      $zero = array();
      $zero[] = 0;
      if (!empty($member)) {$group_p[] = $member;}   // insert father or mother
      foreach ($group as $part) {
        if (!empty($part)) {
          $p_id = $part['member_id'];
          $gen = $part['gender'];
          $partner = $this->partnerRepository->allByPartner($p_id, $gen);
          if (!(empty($partner))) {
            echo $anz_p = count($partner)."<br>";
            //foreach ($partner as $p){
            for ($a=0; $a < $anz_p; $a++) {
              $group_p[] = $partner[$a];
            }
          } else { $group_p[] = $zero; }
        }
      }
      return $group_p;   // array with partners of a group of people
    }

// ******************** display variant lists **********************************
    public function showlist() {
      global $ladezeit;
      $sql_start = microtime(1);
      $this->is_checked_in();         // returns true or goto login
      $persons = $this->personRepository->all();
      if (isset($_GET['zeichen'])) { // zeichen: Anfangsbuchstabe Nachname
        $zeichen = $_GET['zeichen'];
        $_SESSION['zeichen'] = $zeichen;
      } else {
        if (isset($_session['zeichen'])) {
          $zeichen = $_session['zeichen'];
        } else {
          $zeichen = "alle";
          $zeichen = "B";
          $_session['zeichen'] = $zeichen;
        }
      }
      $persons_char = $this->personRepository->findBy($zeichen);
      if (isset($_GET['liste'])) {  // liste: Auswahl für verschiedene Listen
        $liste = $_GET['liste'];
        $_SESSION['liste'] = $liste;
      } else {
        if (isset($_SESSION['liste'])) {
          $liste = $_SESSION['liste'];
        } else {
          $liste = 6;                   // Standardliste beim ersten Aufruf
          $_SESSION['liste'] = $liste;
        }
      }
      // empty arrays for unmarried men and women
      $ledige_men = $ledige_women = array();  // empty array for women
      $couples = $partners = array();      // empty array for partners
      $mothers = $fathers = array();       // empty array for fathers
      $parents = $parent = array();        // empty array for parent
      $children_all = $family = array();
      $remarks = array();

      switch($liste) {
        case 1:     // Liste 1: ledige men nach Anfangsbuchstaben
          $sex = 1;
          $ledige_men = $this->partnerRepository->ledige_char($sex,$zeichen);
          break;
        case 2:     // Liste 2 ledige women
          $sex = 2;
          $ledige_women = $this->partnerRepository->ledige_char($sex,$zeichen);
          break;
        case 3:     // Liste 3: cuples
          $couples = $this->personRepository->couples($zeichen);
          break;
        case 4:     // Liste 4: parents
          $parents = $this->personRepository->parents($zeichen);  //($persons_char);
          //$sql_end = microtime(1); $sql_time = $sql_end - $sql_start; echo $sql_time; die();
          break;
        case 5:     // Liste 5: persons grouped by last_name
          $persons = $this->personRepository->all();
          break;
        case 6:     // Liste 6: families
          $sql_start = microtime(1);
          $parents = $this->personRepository->parents($zeichen);
          foreach ($parents as $par) {
            $id = $par['member_id'];
            $gender = $par['gender'];
            $children = $this->personRepository->children($id);  // children
            $children_all[] = $children;
            $partner = $this->partnerRepository->allByPartner($id, $gender);
            $partners[] = $partner;
          }
          break;
        case 7:
          $remarks = $this->remarkRepository->every_remark();
          break;
      }

      $listen = [
        'persons' => $persons,
        'partners' => $partners,
        'fathers' => $fathers,
        'mothers' => $mothers,
        'persons_char' => $persons_char,
        'couples' => $couples,
        'parents' => $parents,
        'children_all' => $children_all,
        'ledige_men' => $ledige_men,
        'ledige_women' => $ledige_women,
        'ledige' => $ledige,
        'remarks' => $remarks,
        'zeichen' => $zeichen,
        'liste' => $liste,
        //'family' => $family
      ];
      $sql_end = microtime(1);
      $ladezeit = $sql_end - $sql_start;
      $this->render ("person/showlist", $listen);
    }

// *************** show list of persons ****************************************
    public function showlist_1() {
      global $ladezeit, $sql_start;
      $sql_start = microtime(1);
      $this->is_checked_in();         // returns true or goto login
      if ($_SESSION['rechte'] == "admin") {
        $persons = $this->personRepository->all();
        $this->render ("person/showlist_1",  [
          'persons' => $persons
        ]);
      }else{
        header("Location: login");
        die();
      }
    }

// ******************** show remarks to each person ****************************
    //public function show() {
    public function comment() {
      $sql_start = microtime(1);
      //die();
      $this->is_checked_in();         // returns true or goto login
      if (isset($_GET['id'])) {
        $id = $_GET['id'];
        if (isset($_POST['content'])) {
          $id = $_POST['member_id_f'];
          $date = $_POST['rem_date'];
          $remarks = $_POST['content'];
          $this->remarkRepository->insertForRemark($id, $date, $remarks);
        }
        $persons = $this->personRepository->all();
        $person = $this->personRepository->find($id);
        $remarks = $this->remarkRepository->allByPerson($id);
        $sql_end = microtime(1);
        $ladezeit = $sql_end - $sql_start;
        //$this->render ("person/show",  [
        $this->render ("person/comment",  [
          'persons' => $persons,
          'person' => $person,
          'remarks' => $remarks,
          'ladezeit' => $ladezeit
        ]);
      }
    }


// ************** update data **************************************************
    public function update() {
      global $ladezeit;
      $sql_start = microtime(1);
      $this->is_checked_in();
//******************** get id of affected person ******************************
      if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $_SESSION['id'] = $id;
      } else {
        if (isset($_SESSION['id'])) {
          $id = $_SESSION['id'];
        } else {
          $id = 2;
          $_SESSION['id'] = 2;
        }
      }

// ******************* update father *******************************************
      if (isset($_GET['va_id'])) {      // Auswahl Vater
        $va_id = $_GET['va_id'];
        $this->personRepository->updateForFather($id, $va_id);
      }
// ******************* update mother *******************************************
      if (isset($_GET['ma_id'])) {      // Auswahl Mutter
        $ma_id = $_GET['ma_id'];
        $this->personRepository->updateForMother($id, $ma_id);
      }
// ******************* insert data *********************************************

      if($_SERVER['REQUEST_METHOD']=="POST") {
        //var_dump($_POST);echo "</br></br>";die();
        switch($_POST['who']) {
        case 1:
          $this->personRepository->insertForPerson();
          break;
        case 2:
          $this->partnerRepository->insertForPartner();   //
          break;
        case 3:
          $this->ereignisseRepository->insertForIssue();  // ok
          break;
        case 4:
          $this->wohnorteRepository->insertForPlace();    // ok
          break;
        case 5:
          $this->adressenRepository->insertForAdresse();  //
          break;
        case 6:
          $this->remarkRepository->insertUpdateForRemark();     //
          break;
        case 7:
          $this->userRepository->insertForUser();     //
          break;
        }
      }
      // ****************** get person *****************************************
      $person = $this->personRepository->find($id);
      $fa_id = $mo_id = ""; // dummy
      $family = $this->get_fam($fa_id, $mo_id, $id);
      $sql_end = microtime(1);
      $ladezeit = $sql_end - $sql_start;

      $this->render ("person/update", $family);
    }

// ***************** ende update ***********************************************

// ****************** get family data ******************************************
    // by parents
    public function get_fam_by_parents($fa_id, $mo_id) {
      $f_id = $fa_id;
      $m_id = $mo_id;
      $id = 0;
      $family = $this->get_fam($f_id, $m_id, $id);
      return $family;
    }
    // by person
    public function get_fam_by_person($id) {
      $person = $this->personRepository->find($id);              // Person
      $f_id = $person['father_id'];
      $m_id = $person['mother_id'];
      $id = 0;
      $family = $this->get_fam($f_id, $m_id, $id);
      return $family;
    }

    // *************************************************************************
    public function get_fam($f_id, $m_id, $id) {
      global $partner;
      if (!empty($id) OR $id!= 0) {                         // id # 0 or empty
        $person = $this->personRepository->find($id);       // Person
        //$gender = $person['gender'];
        //$partner = $this->partnerRepository->allByPartner($id, $gender);
        $f_id = $person['father_id'];
        $m_id = $person['mother_id'];
      } else { $person = array();}
// ************************ Parents
      if ($f_id != 0){
        $father = $this->personRepository->find($f_id);            // father
        } else {$father = array();}
      if ($m_id != 0){
        $mother = $this->personRepository->find($m_id);            // mother
        } else { $mother = array();}

// ************************* Grand_parents(father) *****************************
      if (!empty($father)) {
        $gff_id = $father['father_id'];          // grandfather father
        $gffather = $this->personRepository->find($father['father_id']);

        $gmf_id = $father['mother_id'];          // grandmother father
        $gmfather = $this->personRepository->find($father['mother_id']);
        } else { $gffather=array(); $gmfather=array(); }

// ************************* Grand_parents(mother) *****************************
      if (!empty($mother)) {
        $gfm_id = $mother['father_id'];          // grandfather mother
        $gfmother = $this->personRepository->find($mother['father_id']);

        $gmm_id = $mother['mother_id'];          // grandmother mother
        $gmmother = $this->personRepository->find($mother['mother_id']);
        } else { $gfmother=array(); $gmmother= array();}

// *************************** Parents of Grand_parents(father) ****************
      if (!empty($gffather)) {
        // father grandfather father
        $f_gffather = $this->personRepository->find($gffather['father_id']);

        // mother grandmother father
        $m_gffather = $this->personRepository->find($gffather['mother_id']);

      } else { $f_gffather=array(); $m_gffather=array(); }

// *************************** Parents of Grand_parents(mother)
      if (!empty($gfmother)) {
        // father grandfather mother
        $f_gfmother = $this->personRepository->find($gfmother['father_id']);
        // mother grandmother mother
        $m_gfmother = $this->personRepository->find($gfmother['mother_id']);
      } else {$f_gfmother=array(); $m_gfmother= array();}

// *************************** Parents of Grand_parents(father)
      if (!empty($gmfather)) {
        // father grandfather father
        $f_gmfather = $this->personRepository->find($gmfather['father_id']);
        // mother grandmother father
        $m_gmfather = $this->personRepository->find($gmfather['mother_id']);
      } else { $f_gmfather=array(); $m_gmfather=array(); }

// ************************** Parents of Grand_parents(mother)
      if (!empty($gmmother)) {
        // father grandfather mother
        $f_gmmother = $this->personRepository->find($gmmother['father_id']);
        // mother grandmother mother
        $m_gmmother = $this->personRepository->find($gmmother['mother_id']);
      } else {$m_gmmother=array(); $f_gmmother= array();}

// *************************** all persons *************************************
      $persons = $this->personRepository->all();
// *************************** siblings of person ******************************
      $siblings = $this->personRepository->siblings($f_id,$id);
// *************************** children of person
      if (!empty($id)) {
        $children = $this->personRepository->children($id);
        } else { $children = array(); }

// **************************** siblings of father
      if (!empty($gff_id)){
        $siblings_f = $this->personRepository->siblings($gff_id,$f_id);
        } else { $siblings_f = array(); }

// ***************************** siblings of mother
      if (!empty($gfm_id)){
        $siblings_m = $this->personRepository->siblings($gfm_id,$m_id);
        } else { $siblings_m = array(); }

      if (!empty($id)){
        $gender = $person['gender'];
        $partner = $this->partnerRepository->allByPartner($id, $gender);
        $adressen = $this->adressenRepository->getAdrAll();
        $wohnorte = $this->wohnorteRepository->allByMember($id);
        $orte = $this->wohnorteRepository->allByMemberId($id);
        $ereignisse = $this->ereignisseRepository->allByMember($id);
        $bemerkungen = $this->remarkRepository->allByPerson($id);
      } else {
        $partner=array(); $adressen=array(); $wohnorte=array();
        $orte=array(); $ereignisse=array(); $bemerkungen=array();
      }
      //var_dump($partner);die();
      $family = [
        'person' => $person,           // persons (by id)
        'partner' => $partner,         // Partner of person
        'persons' => $persons,         // persons (all)
        'father' => $father,           // father
        'mother' => $mother,           // mother
        'gffather' => $gffather,       // father of father
        'gfmother' => $gfmother,       // mother of father
        'gmfather' => $gmfather,       // father of mother
        'gmmother' => $gmmother,       // mother of mother
        'f_gffather' => $f_gffather,       // father of grand father (father)
        'm_gffather' => $m_gffather,       // mother of grand father (father)
        'f_gfmother' => $f_gfmother,       // father of grand mother (father)
        'm_gfmother' => $m_gfmother,       // mother of grand mother (father)
        'f_gmfather' => $f_gmfather,       // father of grand father (mother)
        'm_gmfather' => $m_gmfather,       // mother of grand father (mother)
        'f_gmmother' => $f_gmmother,       // father of grand mother (mother)
        'm_gmmother' => $m_gmmother,       // mother of grand mother (mother)
        'children' => $children,       // children of person
        'siblings' => $siblings,       // Geschwister of person
        'siblings_m' => $siblings_m,   // Geschwister väterlich
        'siblings_f' => $siblings_f,   // Geschwister mütterlich

        'wohnorte' => $wohnorte,       // Wohnorte
        'orte' => $orte,               // Orte
        'adressen' => $adressen,       // Adressen
        'ereignisse' => $ereignisse,   // Ereignisse
        'bemerkungen' => $bemerkungen  // Bemerkungen
      ];
      //echo "hier";
      //var_dump($partner);die();
      return $family;
    }
  }
?>
