1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| session_start();
require_once "../../config.php";
require_once "../../define.php";
require_once DIR_ROOT."model/model.php";
require_once DIR_ROOT."view/lang/{$_SESSION['language']}.php";
//.............................................
// this function is in '/model/model.php'
function getChildren(int $parentId): array|false {
$db = dbConnect(); // Contient les paramètres PDO et retourne la base de données
$sql = <<<SQL
SELECT id, gender, firstname, lastname, CONCAT( firstname, ' ', UPPER(lastname) ) AS fullname, middlename,
CASE WHEN birthyear IS NULL THEN ''
ELSE CONCAT( COALESCE(birthday, '--'), '/', COALESCE(birthmonth, '--'), '/', COALESCE(birthyear, '----') ) END AS birthdate,
CASE WHEN deathyear IS NULL THEN ''
ELSE CONCAT( COALESCE(deathday, '--'), '/', COALESCE(deathmonth, '--'), '/', COALESCE(deathyear, '----') ) END AS deathdate,
birthplace, birthorder
FROM dat_persons
WHERE id_father=:id_parent XOR id_mother=:id_parent
ORDER BY birthyear, birthmonth, birthday
SQL;
$stmt = $db->prepare($sql);
$stmt->execute([':id_parent'=>$parentId]);
return $stmt->fetchAll();
}
function getDescent($parentId, $parentGender, $ol='', $tab=-1)
{
$Data = getChildren($parentId);
//only if at least one child
if( isset($Data[0]) ) {
$tab++;
$indent='';
for ($i=0; $i<$tab; $i++) {
$indent .= "\t";
}
$ol .= $indent."<ol>\n";
$indent_li = $indent."\t";
foreach ($Data as $row) {
$ol .= "$indent_li<li><a href='parentPage.php?childPageKey=2&idMain={$row['id']}>{$row['fullname']} ({$row['birthdate']} - {$row['deathdate']})</a></li>\n";
$ol = getDescent($row['id'], $ol, $tab);
}
$ol .= $indent."</ol>\n";
}
var_dump($ol); // 0, 0, 0, 0</ol>
return $ol;
}
//.............................................
$idMain = $_SESSION['idMain'];
$Data = getPerson($idMain);
$root = "0. {$Data['fullname']} {$Data['birthdate']} - {$Data['deathdate']}";
$RecursiveList = getDescent($idMain, $Data['gender']);
var_dump($RecursiveList); |
Partager