|
@@ 3460-3545 (lines=86) @@
|
| 3457 |
|
* |
| 3458 |
|
* @return string|array |
| 3459 |
|
*/ |
| 3460 |
|
public function statsMarrQuery($simple = true, $first = false, $year1 = -1, $year2 = -1, $params = []) { |
| 3461 |
|
$WT_STATS_CHART_COLOR1 = Theme::theme()->parameter('distribution-chart-no-values'); |
| 3462 |
|
$WT_STATS_CHART_COLOR2 = Theme::theme()->parameter('distribution-chart-high-values'); |
| 3463 |
|
$WT_STATS_S_CHART_X = Theme::theme()->parameter('stats-small-chart-x'); |
| 3464 |
|
$WT_STATS_S_CHART_Y = Theme::theme()->parameter('stats-small-chart-y'); |
| 3465 |
|
|
| 3466 |
|
if ($simple) { |
| 3467 |
|
$sql = |
| 3468 |
|
"SELECT SQL_CACHE FLOOR(d_year/100+1) AS century, COUNT(*) AS total" . |
| 3469 |
|
" FROM `##dates`" . |
| 3470 |
|
" WHERE d_file={$this->tree->getTreeId()} AND d_year<>0 AND d_fact='MARR' AND d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 3471 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 3472 |
|
$sql .= " AND d_year BETWEEN '{$year1}' AND '{$year2}'"; |
| 3473 |
|
} |
| 3474 |
|
$sql .= " GROUP BY century ORDER BY century"; |
| 3475 |
|
} elseif ($first) { |
| 3476 |
|
$years = ''; |
| 3477 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 3478 |
|
$years = " married.d_year BETWEEN '{$year1}' AND '{$year2}' AND"; |
| 3479 |
|
} |
| 3480 |
|
$sql = |
| 3481 |
|
" SELECT SQL_CACHE fam.f_id AS fams, fam.f_husb, fam.f_wife, married.d_julianday2 AS age, married.d_month AS month, indi.i_id AS indi" . |
| 3482 |
|
" FROM `##families` AS fam" . |
| 3483 |
|
" LEFT JOIN `##dates` AS married ON married.d_file = {$this->tree->getTreeId()}" . |
| 3484 |
|
" LEFT JOIN `##individuals` AS indi ON indi.i_file = {$this->tree->getTreeId()}" . |
| 3485 |
|
" WHERE" . |
| 3486 |
|
" married.d_gid = fam.f_id AND" . |
| 3487 |
|
" fam.f_file = {$this->tree->getTreeId()} AND" . |
| 3488 |
|
" married.d_fact = 'MARR' AND" . |
| 3489 |
|
" married.d_julianday2 <> 0 AND" . |
| 3490 |
|
$years . |
| 3491 |
|
" (indi.i_id = fam.f_husb OR indi.i_id = fam.f_wife)" . |
| 3492 |
|
" ORDER BY fams, indi, age ASC"; |
| 3493 |
|
} else { |
| 3494 |
|
$sql = |
| 3495 |
|
"SELECT SQL_CACHE d_month, COUNT(*) AS total" . |
| 3496 |
|
" FROM `##dates`" . |
| 3497 |
|
" WHERE d_file={$this->tree->getTreeId()} AND d_fact='MARR'"; |
| 3498 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 3499 |
|
$sql .= " AND d_year BETWEEN '{$year1}' AND '{$year2}'"; |
| 3500 |
|
} |
| 3501 |
|
$sql .= " GROUP BY d_month"; |
| 3502 |
|
} |
| 3503 |
|
$rows = $this->runSql($sql); |
| 3504 |
|
if (!isset($rows)) { |
| 3505 |
|
return ''; |
| 3506 |
|
} |
| 3507 |
|
if ($simple) { |
| 3508 |
|
if (isset($params[0]) && $params[0] != '') { |
| 3509 |
|
$size = strtolower($params[0]); |
| 3510 |
|
} else { |
| 3511 |
|
$size = $WT_STATS_S_CHART_X . 'x' . $WT_STATS_S_CHART_Y; |
| 3512 |
|
} |
| 3513 |
|
if (isset($params[1]) && $params[1] != '') { |
| 3514 |
|
$color_from = strtolower($params[1]); |
| 3515 |
|
} else { |
| 3516 |
|
$color_from = $WT_STATS_CHART_COLOR1; |
| 3517 |
|
} |
| 3518 |
|
if (isset($params[2]) && $params[2] != '') { |
| 3519 |
|
$color_to = strtolower($params[2]); |
| 3520 |
|
} else { |
| 3521 |
|
$color_to = $WT_STATS_CHART_COLOR2; |
| 3522 |
|
} |
| 3523 |
|
$sizes = explode('x', $size); |
| 3524 |
|
$tot = 0; |
| 3525 |
|
foreach ($rows as $values) { |
| 3526 |
|
$tot += (int) $values['total']; |
| 3527 |
|
} |
| 3528 |
|
// Beware divide by zero |
| 3529 |
|
if ($tot === 0) { |
| 3530 |
|
return ''; |
| 3531 |
|
} |
| 3532 |
|
$centuries = ''; |
| 3533 |
|
$counts = []; |
| 3534 |
|
foreach ($rows as $values) { |
| 3535 |
|
$counts[] = round(100 * $values['total'] / $tot, 0); |
| 3536 |
|
$centuries .= $this->centuryName($values['century']) . ' - ' . I18N::number($values['total']) . '|'; |
| 3537 |
|
} |
| 3538 |
|
$chd = $this->arrayToExtendedEncoding($counts); |
| 3539 |
|
$chl = substr($centuries, 0, -1); |
| 3540 |
|
|
| 3541 |
|
return "<img src=\"https://chart.googleapis.com/chart?cht=p3&chd=e:{$chd}&chs={$size}&chco={$color_from},{$color_to}&chf=bg,s,ffffff00&chl={$chl}\" width=\"{$sizes[0]}\" height=\"{$sizes[1]}\" alt=\"" . I18N::translate('Marriages by century') . '" title="' . I18N::translate('Marriages by century') . '" />'; |
| 3542 |
|
} |
| 3543 |
|
|
| 3544 |
|
return $rows; |
| 3545 |
|
} |
| 3546 |
|
|
| 3547 |
|
/** |
| 3548 |
|
* General query on divorces. |
|
@@ 3558-3642 (lines=85) @@
|
| 3555 |
|
* |
| 3556 |
|
* @return string|array |
| 3557 |
|
*/ |
| 3558 |
|
private function statsDivQuery($simple = true, $first = false, $year1 = -1, $year2 = -1, $params = []) { |
| 3559 |
|
$WT_STATS_CHART_COLOR1 = Theme::theme()->parameter('distribution-chart-no-values'); |
| 3560 |
|
$WT_STATS_CHART_COLOR2 = Theme::theme()->parameter('distribution-chart-high-values'); |
| 3561 |
|
$WT_STATS_S_CHART_X = Theme::theme()->parameter('stats-small-chart-x'); |
| 3562 |
|
$WT_STATS_S_CHART_Y = Theme::theme()->parameter('stats-small-chart-y'); |
| 3563 |
|
|
| 3564 |
|
if ($simple) { |
| 3565 |
|
$sql = |
| 3566 |
|
"SELECT SQL_CACHE FLOOR(d_year/100+1) AS century, COUNT(*) AS total" . |
| 3567 |
|
" FROM `##dates`" . |
| 3568 |
|
" WHERE d_file={$this->tree->getTreeId()} AND d_year<>0 AND d_fact = 'DIV' AND d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 3569 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 3570 |
|
$sql .= " AND d_year BETWEEN '{$year1}' AND '{$year2}'"; |
| 3571 |
|
} |
| 3572 |
|
$sql .= " GROUP BY century ORDER BY century"; |
| 3573 |
|
} elseif ($first) { |
| 3574 |
|
$years = ''; |
| 3575 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 3576 |
|
$years = " divorced.d_year BETWEEN '{$year1}' AND '{$year2}' AND"; |
| 3577 |
|
} |
| 3578 |
|
$sql = |
| 3579 |
|
" SELECT SQL_CACHE fam.f_id AS fams, fam.f_husb, fam.f_wife, divorced.d_julianday2 AS age, divorced.d_month AS month, indi.i_id AS indi" . |
| 3580 |
|
" FROM `##families` AS fam" . |
| 3581 |
|
" LEFT JOIN `##dates` AS divorced ON divorced.d_file = {$this->tree->getTreeId()}" . |
| 3582 |
|
" LEFT JOIN `##individuals` AS indi ON indi.i_file = {$this->tree->getTreeId()}" . |
| 3583 |
|
" WHERE" . |
| 3584 |
|
" divorced.d_gid = fam.f_id AND" . |
| 3585 |
|
" fam.f_file = {$this->tree->getTreeId()} AND" . |
| 3586 |
|
" divorced.d_fact = 'DIV' AND" . |
| 3587 |
|
" divorced.d_julianday2 <> 0 AND" . |
| 3588 |
|
$years . |
| 3589 |
|
" (indi.i_id = fam.f_husb OR indi.i_id = fam.f_wife)" . |
| 3590 |
|
" ORDER BY fams, indi, age ASC"; |
| 3591 |
|
} else { |
| 3592 |
|
$sql = |
| 3593 |
|
"SELECT SQL_CACHE d_month, COUNT(*) AS total FROM `##dates` " . |
| 3594 |
|
"WHERE d_file={$this->tree->getTreeId()} AND d_fact = 'DIV'"; |
| 3595 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 3596 |
|
$sql .= " AND d_year BETWEEN '{$year1}' AND '{$year2}'"; |
| 3597 |
|
} |
| 3598 |
|
$sql .= " GROUP BY d_month"; |
| 3599 |
|
} |
| 3600 |
|
$rows = $this->runSql($sql); |
| 3601 |
|
if (!isset($rows)) { |
| 3602 |
|
return ''; |
| 3603 |
|
} |
| 3604 |
|
if ($simple) { |
| 3605 |
|
if (isset($params[0]) && $params[0] != '') { |
| 3606 |
|
$size = strtolower($params[0]); |
| 3607 |
|
} else { |
| 3608 |
|
$size = $WT_STATS_S_CHART_X . 'x' . $WT_STATS_S_CHART_Y; |
| 3609 |
|
} |
| 3610 |
|
if (isset($params[1]) && $params[1] != '') { |
| 3611 |
|
$color_from = strtolower($params[1]); |
| 3612 |
|
} else { |
| 3613 |
|
$color_from = $WT_STATS_CHART_COLOR1; |
| 3614 |
|
} |
| 3615 |
|
if (isset($params[2]) && $params[2] != '') { |
| 3616 |
|
$color_to = strtolower($params[2]); |
| 3617 |
|
} else { |
| 3618 |
|
$color_to = $WT_STATS_CHART_COLOR2; |
| 3619 |
|
} |
| 3620 |
|
$sizes = explode('x', $size); |
| 3621 |
|
$tot = 0; |
| 3622 |
|
foreach ($rows as $values) { |
| 3623 |
|
$tot += (int) $values['total']; |
| 3624 |
|
} |
| 3625 |
|
// Beware divide by zero |
| 3626 |
|
if ($tot === 0) { |
| 3627 |
|
return ''; |
| 3628 |
|
} |
| 3629 |
|
$centuries = ''; |
| 3630 |
|
$counts = []; |
| 3631 |
|
foreach ($rows as $values) { |
| 3632 |
|
$counts[] = round(100 * $values['total'] / $tot, 0); |
| 3633 |
|
$centuries .= $this->centuryName($values['century']) . ' - ' . I18N::number($values['total']) . '|'; |
| 3634 |
|
} |
| 3635 |
|
$chd = $this->arrayToExtendedEncoding($counts); |
| 3636 |
|
$chl = substr($centuries, 0, -1); |
| 3637 |
|
|
| 3638 |
|
return "<img src=\"https://chart.googleapis.com/chart?cht=p3&chd=e:{$chd}&chs={$size}&chco={$color_from},{$color_to}&chf=bg,s,ffffff00&chl={$chl}\" width=\"{$sizes[0]}\" height=\"{$sizes[1]}\" alt=\"" . I18N::translate('Divorces by century') . '" title="' . I18N::translate('Divorces by century') . '" />'; |
| 3639 |
|
} |
| 3640 |
|
|
| 3641 |
|
return $rows; |
| 3642 |
|
} |
| 3643 |
|
|
| 3644 |
|
/** |
| 3645 |
|
* Find the earliest marriage. |