app/Module/InteractiveTree/TreeView.php
public function getPersons(Tree $tree, string $request): string
    {
        $json_requests = explode(';', $request);
        $r    = [];
        foreach ($json_requests as $json_request) {
            $firstLetter = substr($json_request, 0, 1);
            $json_request = substr($json_request, 1);

            switch ($firstLetter) {
                case 'c':
                    $families = Collection::make(explode(',', $json_request))
                        ->map(static function (string $xref) use ($tree): ?Family {
                            return Family::getInstance($xref, $tree);
                        })
                        ->filter();

                    $r[] = $this->drawChildren($families, 1, true);
                    break;

                case 'p':
                    [$xref, $order] = explode('@', $json_request);

                    $family = Family::getInstance($xref, $tree);
                    if ($family instanceof Family) {
                        // Prefer the paternal line
                        $parent = $family->husband() ?? $family->wife();

                        // The family may have no parents (just children).
                        if ($parent instanceof Individual) {
                            $r[] = $this->drawPerson($parent, 0, 1, $family, $order, false);
                        }
                    }
                    break;
            }
        }

        return json_encode($r);
    }
public function getPersons(Tree $tree, string $request): string
    {
        $json_requests = explode(';', $request);
        $r    = [];
        foreach ($json_requests as $json_request) {
            $firstLetter = substr($json_request, 0, 1);
            $json_request = substr($json_request, 1);

            switch ($firstLetter) {
                case 'c':
                    $families = Collection::make(explode(',', $json_request))
                        ->map(static function (string $xref) use ($tree): ?Family {
                            return Family::getInstance($xref, $tree);
                        })
                        ->filter();

                    $r[] = $this->drawChildren($families, 1, true);
                    break;

                case 'p':
                    [$xref, $order] = explode('@', $json_request);

                    $family = Family::getInstance($xref, $tree);
                    if ($family instanceof Family) {
                        // Prefer the paternal line
                        $parent = $family->husband() ?? $family->wife();

                        // The family may have no parents (just children).
                        if ($parent instanceof Individual) {
                            $r[] = $this->drawPerson($parent, 0, 1, $family, $order, false);
                        }
                    }
                    break;
            }
        }

        return json_encode($r);
    }
public function getPersons ( Tree $ tree , string $ request ) : string { $ json_requests = explode ( ';' , $ request ) ; $ r = [ ] ; foreach ( $ json_requests as $ json_request ) { $ firstLetter = substr ( $ json_request , 0 , 1 ) ; $ json_request = substr ( $ json_request , 1 ) ; switch ( $ firstLetter ) { case 'c' : $ families = Collection :: make ( explode ( ',' , $ json_request ) ) -> map ( static function ( string $ xref ) use ( $ tree ) : ? Family { return Family :: getInstance ( $ xref , $ tree ) ; } ) -> filter ( ) ; $ r [ ] = $ this -> drawChildren ( $ families , 1 , true ) ; break ; case 'p' : [ $ xref , $ order ] = explode ( '@' , $ json_request ) ; $ family = Family :: getInstance ( $ xref , $ tree ) ; if ( $ family instanceof Family ) { // Prefer the paternal line $ parent = $ family -> husband ( ) ?? $ family -> wife ( ) ; // The family may have no parents (just children). if ( $ parent instanceof Individual ) { $ r [ ] = $ this -> drawPerson ( $ parent , 0 , 1 , $ family , $ order , false ) ; } } break ; } } return json_encode ( $ r ) ; }
Return a JSON structure to a JSON request

@param Tree   $tree
@param string $request list of JSON requests

@return string
Return a JSON structure to a JSON request