summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Module/StatisticsChartModule.php10
-rw-r--r--app/Statistics.php18
-rw-r--r--app/Statistics/Repository/FamilyRepository.php78
3 files changed, 59 insertions, 47 deletions
diff --git a/app/Module/StatisticsChartModule.php b/app/Module/StatisticsChartModule.php
index 4f06afb032..f080c81b4a 100644
--- a/app/Module/StatisticsChartModule.php
+++ b/app/Module/StatisticsChartModule.php
@@ -372,7 +372,7 @@ class StatisticsChartModule extends AbstractModule implements ModuleChartInterfa
switch ($z_axis_type) {
case self::Z_AXIS_ALL:
$z_axis = $this->axisAll();
- $rows = $statistics->statsMarrQuery();
+ $rows = $statistics->statsMarriageQuery()->get();
foreach ($rows as $row) {
$this->fillYData($row->d_month, 0, $row->total, $x_axis, $z_axis, $ydata);
}
@@ -382,7 +382,7 @@ class StatisticsChartModule extends AbstractModule implements ModuleChartInterfa
$z_axis = $this->axisYears($boundaries_csv);
$prev_boundary = 0;
foreach (array_keys($z_axis) as $boundary) {
- $rows = $statistics->statsMarrQuery(false, $prev_boundary, $boundary);
+ $rows = $statistics->statsMarriageQuery($prev_boundary, $boundary)->get();
foreach ($rows as $row) {
$this->fillYData($row->d_month, $boundary, $row->total, $x_axis, $z_axis, $ydata);
}
@@ -431,7 +431,7 @@ class StatisticsChartModule extends AbstractModule implements ModuleChartInterfa
$z_axis = $this->axisYears($boundaries_csv);
$prev_boundary = 0;
foreach (array_keys($z_axis) as $boundary) {
- $rows = $statistics->statsMarrQuery(false, $prev_boundary, $boundary);
+ $rows = $statistics->statsMarriageQuery($prev_boundary, $boundary)->get();
foreach ($rows as $row) {
$this->fillYData($row->d_month, $boundary, $row->total, $x_axis, $z_axis, $ydata);
}
@@ -463,7 +463,7 @@ class StatisticsChartModule extends AbstractModule implements ModuleChartInterfa
switch ($z_axis_type) {
case self::Z_AXIS_ALL:
$z_axis = $this->axisAll();
- $rows = $statistics->statsMarrQuery(true);
+ $rows = $statistics->statsFirstMarriageQuery()->get();
$indi = [];
$fam = [];
foreach ($rows as $row) {
@@ -481,7 +481,7 @@ class StatisticsChartModule extends AbstractModule implements ModuleChartInterfa
$indi = [];
$fam = [];
foreach (array_keys($z_axis) as $boundary) {
- $rows = $statistics->statsMarrQuery(true, $prev_boundary, $boundary);
+ $rows = $statistics->statsFirstMarriageQuery($prev_boundary, $boundary)->get();
foreach ($rows as $row) {
if (!\in_array($row->indi, $indi, true) && !\in_array($row->fams, $fam, true)) {
$this->fillYData($row->month, $boundary, 1, $x_axis, $z_axis, $ydata);
diff --git a/app/Statistics.php b/app/Statistics.php
index ccabdac2bf..ccc533cdac 100644
--- a/app/Statistics.php
+++ b/app/Statistics.php
@@ -52,6 +52,7 @@ use Fisharebest\Webtrees\Statistics\Repository\NewsRepository;
use Fisharebest\Webtrees\Statistics\Repository\PlaceRepository;
use Fisharebest\Webtrees\Statistics\Repository\ServerRepository;
use Fisharebest\Webtrees\Statistics\Repository\UserRepository;
+use Illuminate\Database\Query\Builder;
use ReflectionMethod;
/**
@@ -98,7 +99,6 @@ class Statistics implements
'statsPlaces',
'statsBirthQuery',
'statsDeathQuery',
- 'statsMarrQuery',
'statsAgeQuery',
'monthFirstChildQuery',
'statsChildrenQuery',
@@ -233,7 +233,7 @@ class Statistics implements
foreach (get_class_methods($this) as $method) {
$reflection = new ReflectionMethod($this, $method);
- if ($reflection->isPublic() && !\in_array($method, self::$public_but_not_allowed, true)) {
+ if ($reflection->isPublic() && !\in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
$examples[$method] = $this->$method();
}
}
@@ -260,7 +260,7 @@ class Statistics implements
foreach (get_class_methods($this) as $method) {
$reflection = new ReflectionMethod($this, $method);
- if ($reflection->isPublic() && !\in_array($method, self::$public_but_not_allowed, true)) {
+ if ($reflection->isPublic() && !\in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
$examples[$method] = $method;
}
}
@@ -1437,9 +1437,17 @@ class Statistics implements
/**
* @inheritDoc
*/
- public function statsMarrQuery(bool $first = false, int $year1 = -1, int $year2 = -1): array
+ public function statsMarriageQuery(int $year1 = -1, int $year2 = -1): Builder
{
- return $this->familyRepository->statsMarrQuery($first, $year1, $year2);
+ return $this->familyRepository->statsMarriageQuery($year1, $year2);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function statsFirstMarriageQuery(int $year1 = -1, int $year2 = -1): Builder
+ {
+ return $this->familyRepository->statsFirstMarriageQuery($year1, $year2);
}
/**
diff --git a/app/Statistics/Repository/FamilyRepository.php b/app/Statistics/Repository/FamilyRepository.php
index 7188733ec6..03975584b1 100644
--- a/app/Statistics/Repository/FamilyRepository.php
+++ b/app/Statistics/Repository/FamilyRepository.php
@@ -1658,46 +1658,13 @@ class FamilyRepository
/**
* General query on marriages.
*
- * @param bool $first_marriage
* @param int $year1
* @param int $year2
*
- * @return array
+ * @return Builder
*/
- public function statsMarrQuery(bool $first_marriage = false, int $year1 = -1, int $year2 = -1): array
+ public function statsMarriageQuery(int $year1 = -1, int $year2 = -1): Builder
{
- if ($first_marriage) {
- $query = DB::table('families')
- ->join('dates', function (JoinClause $join): void {
- $join
- ->on('d_gid', '=', 'f_id')
- ->on('d_file', '=', 'f_file')
- ->where('d_fact', '=', 'MARR')
- ->where('d_julianday2', '<>', 0);
- })->join('individuals', function (JoinClause $join): void {
- $join
- ->on('i_file', '=', 'f_file');
- })
- ->where('f_file', '=', $this->tree->id())
- ->where(function (Builder $query): void {
- $query
- ->whereColumn('i_id', '=', 'f_husb')
- ->orWhereColumn('i_id', '=', 'f_wife');
- });
-
- if ($year1 >= 0 && $year2 >= 0) {
- $query->whereBetween('d_year', [$year1, $year2]);
- }
-
- return $query
- ->select(['f_id AS fams', 'f_husb', 'f_wife', 'd_julianday2 AS age', 'd_month AS month', 'i_id AS indi'])
- ->orderBy('f_id')
- ->orderBy('i_id')
- ->orderBy('d_julianday2')
- ->get()
- ->all();
- }
-
$query = DB::table('dates')
->where('d_file', '=', $this->tree->id())
->where('d_fact', '=', 'MARR')
@@ -1708,9 +1675,46 @@ class FamilyRepository
$query->whereBetween('d_year', [$year1, $year2]);
}
+ return $query;
+ }
+
+ /**
+ * General query on marriages.
+ *
+ * @param int $year1
+ * @param int $year2
+ *
+ * @return Builder
+ */
+ public function statsFirstMarriageQuery(int $year1 = -1, int $year2 = -1): Builder
+ {
+ $query = DB::table('families')
+ ->join('dates', function (JoinClause $join): void {
+ $join
+ ->on('d_gid', '=', 'f_id')
+ ->on('d_file', '=', 'f_file')
+ ->where('d_fact', '=', 'MARR')
+ ->where('d_julianday2', '<>', 0);
+ })->join('individuals', function (JoinClause $join): void {
+ $join
+ ->on('i_file', '=', 'f_file');
+ })
+ ->where('f_file', '=', $this->tree->id())
+ ->where(function (Builder $query): void {
+ $query
+ ->whereColumn('i_id', '=', 'f_husb')
+ ->orWhereColumn('i_id', '=', 'f_wife');
+ });
+
+ if ($year1 >= 0 && $year2 >= 0) {
+ $query->whereBetween('d_year', [$year1, $year2]);
+ }
+
return $query
- ->get()
- ->all();
+ ->select(['f_id AS fams', 'f_husb', 'f_wife', 'd_julianday2 AS age', 'd_month AS month', 'i_id AS indi'])
+ ->orderBy('f_id')
+ ->orderBy('i_id')
+ ->orderBy('d_julianday2');
}
/**