.
*/
namespace Fisharebest\Webtrees\Functions;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Theme;
/**
* Class FunctionsCharts - common functions
*/
class FunctionsCharts {
/**
* print a table cell with sosa number
*
* @param int $sosa
* @param string $pid optional pid
* @param string $arrowDirection direction of link arrow
*/
public static function printSosaNumber($sosa, $pid = "", $arrowDirection = "up") {
if (substr($sosa, -1, 1) == ".") {
$personLabel = substr($sosa, 0, -1);
} else {
$personLabel = $sosa;
}
if ($arrowDirection == "blank") {
$visibility = "hidden";
} else {
$visibility = "normal";
}
echo "
';
}
/**
* print the parents table for a family
*
* @param Family $family family gedcom ID
* @param int $sosa child sosa number
* @param string $label indi label (descendancy booklet)
* @param string $parid parent ID (descendancy booklet)
* @param string $gparid gd-parent ID (descendancy booklet)
* @param int $show_full large or small box
*/
public static function printFamilyParents(Family $family, $sosa = 0, $label = '', $parid = '', $gparid = '', $show_full = 1) {
if ($show_full) {
$pbheight = Theme::theme()->parameter('chart-box-y') + 14;
} else {
$pbheight = Theme::theme()->parameter('compact-chart-box-y') + 14;
}
$husb = $family->getHusband();
if ($husb) {
echo '';
} else {
$husb = new Individual('M', "0 @M@ INDI\n1 SEX M", null, $family->getTree());
}
$wife = $family->getWife();
if ($wife) {
echo '';
} else {
$wife = new Individual('F', "0 @F@ INDI\n1 SEX F", null, $family->getTree());
}
if ($sosa) {
echo '', $family->getFullName(), '
';
}
/**
* husband side
*/
echo '';
echo '';
if ($parid) {
if ($husb->getXref() == $parid) {
self::printSosaNumber($label);
} else {
self::printSosaNumber($label, '', 'blank');
}
} elseif ($sosa) {
self::printSosaNumber($sosa * 2);
}
if ($husb->isPendingAddtion()) {
echo '';
} elseif ($husb->isPendingDeletion()) {
echo ' | ';
} else {
echo ' | ';
}
FunctionsPrint::printPedigreePerson($husb, $show_full);
echo ' | ';
echo ' | ';
// husband’s parents
$hfam = $husb->getPrimaryChildFamily();
if ($hfam) {
// remove the|| test for $sosa
echo ' | | ';
echo ' | ';
// husband’s father
if ($hfam && $hfam->getHusband()) {
echo '';
if ($sosa > 0) {
self::printSosaNumber($sosa * 4, $hfam->getHusband()->getXref(), 'down');
}
if (!empty($gparid) && $hfam->getHusband()->getXref() == $gparid) {
self::printSosaNumber(trim(substr($label, 0, -3), '.') . '.');
}
echo '';
FunctionsPrint::printPedigreePerson($hfam->getHusband(), $show_full);
echo ' | ';
} elseif ($hfam && !$hfam->getHusband()) {
// Empty box for grandfather
echo '';
echo '';
FunctionsPrint::printPedigreePerson($hfam->getHusband(), $show_full);
echo ' | ';
}
echo ' | ';
}
if ($hfam && ($sosa != -1)) {
echo '';
self::printUrlArrow(($sosa == 0 ? '?famid=' . $hfam->getXref() . '&ged=' . $hfam->getTree()->getNameUrl() : '#' . $hfam->getXref()), $hfam->getXref(), 1);
echo ' | ';
}
if ($hfam) {
// husband’s mother
echo '
| ';
if ($hfam && $hfam->getWife()) {
echo '';
if ($sosa > 0) {
self::printSosaNumber($sosa * 4 + 1, $hfam->getWife()->getXref(), 'down');
}
if (!empty($gparid) && $hfam->getWife()->getXref() == $gparid) {
self::printSosaNumber(trim(substr($label, 0, -3), '.') . '.');
}
echo '';
FunctionsPrint::printPedigreePerson($hfam->getWife(), $show_full);
echo ' | ';
} elseif ($hfam && !$hfam->getWife()) {
// Empty box for grandmother
echo '';
echo '';
FunctionsPrint::printPedigreePerson($hfam->getWife(), $show_full);
echo ' | ';
}
echo ' | ';
}
echo '
';
if ($sosa && $family->canShow()) {
foreach ($family->getFacts(WT_EVENTS_MARR) as $fact) {
echo '';
echo str_repeat(' ', 10);
echo $fact->summary();
echo '';
}
} else {
echo '
';
}
/**
* wife side
*/
echo '';
echo '';
if ($parid) {
if ($wife->getXref() == $parid) {
self::printSosaNumber($label);
} else {
self::printSosaNumber($label, '', 'blank');
}
} elseif ($sosa) {
self::printSosaNumber($sosa * 2 + 1);
}
if ($wife->isPendingAddtion()) {
echo '';
} elseif ($wife->isPendingDeletion()) {
echo ' | ';
} else {
echo ' | ';
}
FunctionsPrint::printPedigreePerson($wife, $show_full);
echo ' | ';
echo ' | ';
// wife’s parents
$hfam = $wife->getPrimaryChildFamily();
if ($hfam) {
echo ' | | ';
echo ' | ';
// wife’s father
if ($hfam && $hfam->getHusband()) {
echo '';
if ($sosa > 0) {
self::printSosaNumber($sosa * 4 + 2, $hfam->getHusband()->getXref(), 'down');
}
if (!empty($gparid) && $hfam->getHusband()->getXref() == $gparid) {
self::printSosaNumber(trim(substr($label, 0, -3), '.') . '.');
}
echo '';
FunctionsPrint::printPedigreePerson($hfam->getHusband(), $show_full);
echo ' | ';
} elseif ($hfam && !$hfam->getHusband()) {
// Empty box for grandfather
echo '';
echo '';
FunctionsPrint::printPedigreePerson($hfam->getHusband(), $show_full);
echo ' | ';
}
echo ' | ';
}
if ($hfam && ($sosa != -1)) {
echo '';
self::printUrlArrow(($sosa == 0 ? '?famid=' . $hfam->getXref() . '&ged=' . $hfam->getTree()->getNameUrl() : '#' . $hfam->getXref()), $hfam->getXref(), 1);
echo ' | ';
}
if ($hfam) {
// wife’s mother
echo '
| ';
if ($hfam && $hfam->getWife()) {
echo '';
if ($sosa > 0) {
self::printSosaNumber($sosa * 4 + 3, $hfam->getWife()->getXref(), 'down');
}
if (!empty($gparid) && $hfam->getWife()->getXref() == $gparid) {
self::printSosaNumber(trim(substr($label, 0, -3), '.') . '.');
}
echo '';
FunctionsPrint::printPedigreePerson($hfam->getWife(), $show_full);
echo ' | ';
} elseif ($hfam && !$hfam->getWife()) {
// Empty box for grandmother
echo '';
echo '';
FunctionsPrint::printPedigreePerson($hfam->getWife(), $show_full);
echo ' | ';
}
echo ' | ';
}
echo '
';
}
/**
* print the children table for a family
*
* @param Family $family family
* @param string $childid child ID
* @param int $sosa child sosa number
* @param string $label indi label (descendancy booklet)
* @param int $show_cousins display cousins on chart
* @param int $show_full large or small box
*/
public static function printFamilyChildren(Family $family, $childid = '', $sosa = 0, $label = '', $show_cousins = 0, $show_full = 1) {
if ($show_full) {
$bheight = Theme::theme()->parameter('chart-box-y');
} else {
$bheight = Theme::theme()->parameter('compact-chart-box-y');
}
$pbheight = $bheight + 14;
$children = $family->getChildren();
$numchil = count($children);
echo '';
if ($sosa > 0) {
echo ' | ';
}
echo '';
if ($sosa == 0 && Auth::isEditor($family->getTree())) {
echo ' ';
echo "getXref(), "', 'U');\">" . I18N::translate('Add a child to this family') . "";
echo ' ';
echo ' ';
echo '
';
}
echo ' | ';
if ($sosa > 0) {
echo ' | | ';
}
echo '
';
$nchi = 1;
if ($children) {
foreach ($children as $child) {
echo '';
if ($sosa != 0) {
if ($child->getXref() == $childid) {
self::printSosaNumber($sosa, $childid);
} elseif (empty($label)) {
self::printSosaNumber("");
} else {
self::printSosaNumber($label . ($nchi++) . ".");
}
}
if ($child->isPendingAddtion()) {
echo '';
} elseif ($child->isPendingDeletion()) {
echo ' | ';
} else {
echo ' | ';
}
FunctionsPrint::printPedigreePerson($child, $show_full);
echo ' | ';
if ($sosa != 0) {
// loop for all families where current child is a spouse
$famids = $child->getSpouseFamilies();
$maxfam = count($famids) - 1;
for ($f = 0; $f <= $maxfam; $f++) {
$famid_child = $famids[$f]->getXref();
// multiple marriages
if ($f > 0) {
echo '
| ';
echo '';
//find out how many cousins there are to establish vertical line on second families
$fchildren = $famids[$f]->getChildren();
$kids = count($fchildren);
$Pheader = ($bheight - 1) * $kids;
$PBadj = 6; // default
if ($show_cousins > 0) {
if ($kids) {
$PBadj = max(0, $Pheader / 2 + $kids * 4.5);
}
}
if ($f == $maxfam) {
echo '';
echo ' | ';
}
echo '';
$spouse = $famids[$f]->getSpouse($child);
$marr = $famids[$f]->getFirstFact('MARR');
$div = $famids[$f]->getFirstFact('DIV');
if ($marr) {
// marriage date
echo $marr->getDate()->minimumDate()->format('%Y');
// divorce date
if ($div) {
echo '–', $div->getDate()->minimumDate()->format('%Y');
}
}
echo " parameter('image-hline') . "\" alt=\"\">";
echo " | ";
// spouse information
echo "";
} else {
echo "\">";
}
FunctionsPrint::printPedigreePerson($spouse, $show_full);
echo " | ";
// cousins
if ($show_cousins) {
self::printCousins($famid_child, $show_full);
}
}
}
echo "
";
}
} elseif ($sosa < 1) {
// message 'no children' except for sosa
if (preg_match('/\n1 NCHI (\d+)/', $family->getGedcom(), $match) && $match[1] == 0) {
echo ' ' . I18N::translate('This family remained childless') . ' |
';
}
}
echo "
";
}
/**
* print a family with Sosa-Stradonitz numbering system
* ($rootid=1, father=2, mother=3 ...)
*
* @param string $famid family gedcom ID
* @param string $childid tree root ID
* @param int $sosa starting sosa number
* @param string $label indi label (descendancy booklet)
* @param string $parid parent ID (descendancy booklet)
* @param string $gparid gd-parent ID (descendancy booklet)
* @param int $show_cousins display cousins on chart
* @param int $show_full large or small box
*/
public static function printSosaFamily($famid, $childid, $sosa, $label = '', $parid = '', $gparid = '', $show_cousins = 0, $show_full = 1) {
global $WT_TREE;
echo '
';
echo '';
if (!empty($famid)) {
echo '';
}
self::printFamilyParents(Family::getInstance($famid, $WT_TREE), $sosa, $label, $parid, $gparid, $show_full);
echo '
';
echo '
';
self::printFamilyChildren(Family::getInstance($famid, $WT_TREE), $childid, $sosa, $label, $show_cousins, $show_full);
echo ' |
';
echo '
';
}
/**
* print an arrow to a new url
*
* @param string $url target url
* @param string $label arrow label
* @param int $dir arrow direction 0=left 1=right 2=up 3=down (default=2)
*/
public static function printUrlArrow($url, $label, $dir = 2) {
if ($url === '') {
return;
}
// arrow direction
$adir = $dir;
if (I18N::direction() === 'rtl' && $dir === 0) {
$adir = 1;
}
if (I18N::direction() === 'rtl' && $dir === 1) {
$adir = 0;
}
// arrow style 0 1 2 3
$array_style = array('icon-larrow', 'icon-rarrow', 'icon-uarrow', 'icon-darrow');
$astyle = $array_style[$adir];
// Labels include people’s names, which may contain markup
echo '';
}
/**
* builds and returns sosa relationship name in the active language
*
* @param string $sosa sosa number
*
* @return string
*/
public static function getSosaName($sosa) {
$path = '';
while ($sosa > 1) {
if ($sosa % 2 == 1) {
$sosa -= 1;
$path = 'mot' . $path;
} else {
$path = 'fat' . $path;
}
$sosa /= 2;
}
return Functions::getRelationshipNameFromPath($path, null, null);
}
/**
* print cousins list
*
* @param string $famid family ID
* @param int $show_full large or small box
*/
public static function printCousins($famid, $show_full = 1) {
global $WT_TREE;
if ($show_full) {
$bheight = Theme::theme()->parameter('chart-box-y');
} else {
$bheight = Theme::theme()->parameter('compact-chart-box-y');
}
$family = Family::getInstance($famid, $WT_TREE);
$fchildren = $family->getChildren();
$kids = count($fchildren);
echo '';
if ($kids) {
echo '';
if ($kids > 1) {
echo ' | ';
}
$ctkids = count($fchildren);
$i = 1;
foreach ($fchildren as $fchil) {
if ($i == 1) {
echo ' | ';
FunctionsPrint::printPedigreePerson($fchil, $show_full);
echo ' | ';
if ($i < $ctkids) {
echo '';
$i++;
}
}
echo ' ';
} else {
// If there is known that there are no children (as opposed to no known children)
if (preg_match('/\n1 NCHI (\d+)/', $family->getGedcom(), $match) && $match[1] == 0) {
echo ' ';
}
}
echo ' | ';
}
}