|
@@ 1878-1958 (lines=81) @@
|
| 1875 |
|
* |
| 1876 |
|
* @return array|string |
| 1877 |
|
*/ |
| 1878 |
|
public function statsBirthQuery($simple = true, $sex = false, $year1 = -1, $year2 = -1, $params = []) { |
| 1879 |
|
$WT_STATS_CHART_COLOR1 = Theme::theme()->parameter('distribution-chart-no-values'); |
| 1880 |
|
$WT_STATS_CHART_COLOR2 = Theme::theme()->parameter('distribution-chart-high-values'); |
| 1881 |
|
$WT_STATS_S_CHART_X = Theme::theme()->parameter('stats-small-chart-x'); |
| 1882 |
|
$WT_STATS_S_CHART_Y = Theme::theme()->parameter('stats-small-chart-y'); |
| 1883 |
|
|
| 1884 |
|
if ($simple) { |
| 1885 |
|
$sql = |
| 1886 |
|
"SELECT SQL_CACHE FLOOR(d_year/100+1) AS century, COUNT(*) AS total FROM `##dates` " . |
| 1887 |
|
"WHERE " . |
| 1888 |
|
"d_file = {$this->tree->getTreeId()} AND " . |
| 1889 |
|
"d_year <> 0 AND " . |
| 1890 |
|
"d_fact='BIRT' AND " . |
| 1891 |
|
"d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 1892 |
|
} elseif ($sex) { |
| 1893 |
|
$sql = |
| 1894 |
|
"SELECT SQL_CACHE d_month, i_sex, COUNT(*) AS total FROM `##dates` " . |
| 1895 |
|
"JOIN `##individuals` ON d_file = i_file AND d_gid = i_id " . |
| 1896 |
|
"WHERE " . |
| 1897 |
|
"d_file={$this->tree->getTreeId()} AND " . |
| 1898 |
|
"d_fact='BIRT' AND " . |
| 1899 |
|
"d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 1900 |
|
} else { |
| 1901 |
|
$sql = |
| 1902 |
|
"SELECT SQL_CACHE d_month, COUNT(*) AS total FROM `##dates` " . |
| 1903 |
|
"WHERE " . |
| 1904 |
|
"d_file={$this->tree->getTreeId()} AND " . |
| 1905 |
|
"d_fact='BIRT' AND " . |
| 1906 |
|
"d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 1907 |
|
} |
| 1908 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 1909 |
|
$sql .= " AND d_year BETWEEN '{$year1}' AND '{$year2}'"; |
| 1910 |
|
} |
| 1911 |
|
if ($simple) { |
| 1912 |
|
$sql .= " GROUP BY century ORDER BY century"; |
| 1913 |
|
} else { |
| 1914 |
|
$sql .= " GROUP BY d_month"; |
| 1915 |
|
if ($sex) { |
| 1916 |
|
$sql .= ", i_sex"; |
| 1917 |
|
} |
| 1918 |
|
} |
| 1919 |
|
$rows = $this->runSql($sql); |
| 1920 |
|
if ($simple) { |
| 1921 |
|
if (isset($params[0]) && $params[0] != '') { |
| 1922 |
|
$size = strtolower($params[0]); |
| 1923 |
|
} else { |
| 1924 |
|
$size = $WT_STATS_S_CHART_X . 'x' . $WT_STATS_S_CHART_Y; |
| 1925 |
|
} |
| 1926 |
|
if (isset($params[1]) && $params[1] != '') { |
| 1927 |
|
$color_from = strtolower($params[1]); |
| 1928 |
|
} else { |
| 1929 |
|
$color_from = $WT_STATS_CHART_COLOR1; |
| 1930 |
|
} |
| 1931 |
|
if (isset($params[2]) && $params[2] != '') { |
| 1932 |
|
$color_to = strtolower($params[2]); |
| 1933 |
|
} else { |
| 1934 |
|
$color_to = $WT_STATS_CHART_COLOR2; |
| 1935 |
|
} |
| 1936 |
|
$sizes = explode('x', $size); |
| 1937 |
|
$tot = 0; |
| 1938 |
|
foreach ($rows as $values) { |
| 1939 |
|
$tot += $values['total']; |
| 1940 |
|
} |
| 1941 |
|
// Beware divide by zero |
| 1942 |
|
if ($tot == 0) { |
| 1943 |
|
return ''; |
| 1944 |
|
} |
| 1945 |
|
$centuries = ''; |
| 1946 |
|
$counts = []; |
| 1947 |
|
foreach ($rows as $values) { |
| 1948 |
|
$counts[] = round(100 * $values['total'] / $tot, 0); |
| 1949 |
|
$centuries .= $this->centuryName($values['century']) . ' - ' . I18N::number($values['total']) . '|'; |
| 1950 |
|
} |
| 1951 |
|
$chd = $this->arrayToExtendedEncoding($counts); |
| 1952 |
|
$chl = rawurlencode(substr($centuries, 0, -1)); |
| 1953 |
|
|
| 1954 |
|
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('Births by century') . '" title="' . I18N::translate('Births by century') . '" />'; |
| 1955 |
|
} else { |
| 1956 |
|
return $rows; |
| 1957 |
|
} |
| 1958 |
|
} |
| 1959 |
|
|
| 1960 |
|
/** |
| 1961 |
|
* Create a chart of death places. |
|
@@ 1971-2051 (lines=81) @@
|
| 1968 |
|
* |
| 1969 |
|
* @return array|string |
| 1970 |
|
*/ |
| 1971 |
|
public function statsDeathQuery($simple = true, $sex = false, $year1 = -1, $year2 = -1, $params = []) { |
| 1972 |
|
$WT_STATS_CHART_COLOR1 = Theme::theme()->parameter('distribution-chart-no-values'); |
| 1973 |
|
$WT_STATS_CHART_COLOR2 = Theme::theme()->parameter('distribution-chart-high-values'); |
| 1974 |
|
$WT_STATS_S_CHART_X = Theme::theme()->parameter('stats-small-chart-x'); |
| 1975 |
|
$WT_STATS_S_CHART_Y = Theme::theme()->parameter('stats-small-chart-y'); |
| 1976 |
|
|
| 1977 |
|
if ($simple) { |
| 1978 |
|
$sql = |
| 1979 |
|
"SELECT SQL_CACHE FLOOR(d_year/100+1) AS century, COUNT(*) AS total FROM `##dates` " . |
| 1980 |
|
"WHERE " . |
| 1981 |
|
"d_file={$this->tree->getTreeId()} AND " . |
| 1982 |
|
'd_year<>0 AND ' . |
| 1983 |
|
"d_fact='DEAT' AND " . |
| 1984 |
|
"d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 1985 |
|
} elseif ($sex) { |
| 1986 |
|
$sql = |
| 1987 |
|
"SELECT SQL_CACHE d_month, i_sex, COUNT(*) AS total FROM `##dates` " . |
| 1988 |
|
"JOIN `##individuals` ON d_file = i_file AND d_gid = i_id " . |
| 1989 |
|
"WHERE " . |
| 1990 |
|
"d_file={$this->tree->getTreeId()} AND " . |
| 1991 |
|
"d_fact='DEAT' AND " . |
| 1992 |
|
"d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 1993 |
|
} else { |
| 1994 |
|
$sql = |
| 1995 |
|
"SELECT SQL_CACHE d_month, COUNT(*) AS total FROM `##dates` " . |
| 1996 |
|
"WHERE " . |
| 1997 |
|
"d_file={$this->tree->getTreeId()} AND " . |
| 1998 |
|
"d_fact='DEAT' AND " . |
| 1999 |
|
"d_type IN ('@#DGREGORIAN@', '@#DJULIAN@')"; |
| 2000 |
|
} |
| 2001 |
|
if ($year1 >= 0 && $year2 >= 0) { |
| 2002 |
|
$sql .= " AND d_year BETWEEN '{$year1}' AND '{$year2}'"; |
| 2003 |
|
} |
| 2004 |
|
if ($simple) { |
| 2005 |
|
$sql .= " GROUP BY century ORDER BY century"; |
| 2006 |
|
} else { |
| 2007 |
|
$sql .= " GROUP BY d_month"; |
| 2008 |
|
if ($sex) { |
| 2009 |
|
$sql .= ", i_sex"; |
| 2010 |
|
} |
| 2011 |
|
} |
| 2012 |
|
$rows = $this->runSql($sql); |
| 2013 |
|
if ($simple) { |
| 2014 |
|
if (isset($params[0]) && $params[0] != '') { |
| 2015 |
|
$size = strtolower($params[0]); |
| 2016 |
|
} else { |
| 2017 |
|
$size = $WT_STATS_S_CHART_X . 'x' . $WT_STATS_S_CHART_Y; |
| 2018 |
|
} |
| 2019 |
|
if (isset($params[1]) && $params[1] != '') { |
| 2020 |
|
$color_from = strtolower($params[1]); |
| 2021 |
|
} else { |
| 2022 |
|
$color_from = $WT_STATS_CHART_COLOR1; |
| 2023 |
|
} |
| 2024 |
|
if (isset($params[2]) && $params[2] != '') { |
| 2025 |
|
$color_to = strtolower($params[2]); |
| 2026 |
|
} else { |
| 2027 |
|
$color_to = $WT_STATS_CHART_COLOR2; |
| 2028 |
|
} |
| 2029 |
|
$sizes = explode('x', $size); |
| 2030 |
|
$tot = 0; |
| 2031 |
|
foreach ($rows as $values) { |
| 2032 |
|
$tot += $values['total']; |
| 2033 |
|
} |
| 2034 |
|
// Beware divide by zero |
| 2035 |
|
if ($tot == 0) { |
| 2036 |
|
return ''; |
| 2037 |
|
} |
| 2038 |
|
$centuries = ''; |
| 2039 |
|
$counts = []; |
| 2040 |
|
foreach ($rows as $values) { |
| 2041 |
|
$counts[] = round(100 * $values['total'] / $tot, 0); |
| 2042 |
|
$centuries .= $this->centuryName($values['century']) . ' - ' . I18N::number($values['total']) . '|'; |
| 2043 |
|
} |
| 2044 |
|
$chd = $this->arrayToExtendedEncoding($counts); |
| 2045 |
|
$chl = rawurlencode(substr($centuries, 0, -1)); |
| 2046 |
|
|
| 2047 |
|
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('Deaths by century') . '" title="' . I18N::translate('Deaths by century') . '" />'; |
| 2048 |
|
} |
| 2049 |
|
|
| 2050 |
|
return $rows; |
| 2051 |
|
} |
| 2052 |
|
|
| 2053 |
|
/** |
| 2054 |
|
* Find the earliest birth. |