.
*/
declare(strict_types=1);
namespace Fisharebest\Webtrees;
use Fisharebest\Webtrees\Module\ModuleBlockInterface;
use Fisharebest\Webtrees\Module\ModuleInterface;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Services\UserService;
use Fisharebest\Webtrees\Statistics\Repository\BrowserRepository;
use Fisharebest\Webtrees\Statistics\Repository\ContactRepository;
use Fisharebest\Webtrees\Statistics\Repository\EventRepository;
use Fisharebest\Webtrees\Statistics\Repository\FamilyDatesRepository;
use Fisharebest\Webtrees\Statistics\Repository\FamilyRepository;
use Fisharebest\Webtrees\Statistics\Repository\FavoritesRepository;
use Fisharebest\Webtrees\Statistics\Repository\GedcomRepository;
use Fisharebest\Webtrees\Statistics\Repository\HitCountRepository;
use Fisharebest\Webtrees\Statistics\Repository\IndividualRepository;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\BrowserRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ContactRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\EventRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\FamilyDatesRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\FavoritesRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\GedcomRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\HitCountRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\IndividualRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\LatestUserRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\MediaRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\MessageRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\NewsRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\PlaceRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ServerRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\Interfaces\UserRepositoryInterface;
use Fisharebest\Webtrees\Statistics\Repository\LatestUserRepository;
use Fisharebest\Webtrees\Statistics\Repository\MediaRepository;
use Fisharebest\Webtrees\Statistics\Repository\MessageRepository;
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 Fisharebest\Webtrees\Statistics\Service\CountryService;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
use ReflectionNamedType;
use function call_user_func;
use function count;
use function in_array;
use function str_contains;
/**
* A selection of pre-formatted statistical queries.
* These are primarily used for embedded keywords on HTML blocks, but
* are also used elsewhere in the code.
*/
class Statistics implements
GedcomRepositoryInterface,
IndividualRepositoryInterface,
EventRepositoryInterface,
MediaRepositoryInterface,
UserRepositoryInterface,
ServerRepositoryInterface,
BrowserRepositoryInterface,
HitCountRepositoryInterface,
LatestUserRepositoryInterface,
FavoritesRepositoryInterface,
NewsRepositoryInterface,
MessageRepositoryInterface,
ContactRepositoryInterface,
FamilyDatesRepositoryInterface,
PlaceRepositoryInterface
{
/**
* Generate statistics for a specified tree.
*
* @var Tree
*/
private $tree;
/**
* @var GedcomRepository
*/
private $gedcomRepository;
/**
* @var IndividualRepository
*/
private $individualRepository;
/**
* @var FamilyRepository
*/
private $familyRepository;
/**
* @var MediaRepository
*/
private $mediaRepository;
/**
* @var EventRepository
*/
private $eventRepository;
/**
* @var UserRepository
*/
private $userRepository;
/**
* @var ServerRepository
*/
private $serverRepository;
/**
* @var BrowserRepository
*/
private $browserRepository;
/**
* @var HitCountRepository
*/
private $hitCountRepository;
/**
* @var LatestUserRepository
*/
private $latestUserRepository;
/**
* @var FavoritesRepository
*/
private $favoritesRepository;
/**
* @var NewsRepository
*/
private $newsRepository;
/**
* @var MessageRepository
*/
private $messageRepository;
/**
* @var ContactRepository
*/
private $contactRepository;
/**
* @var FamilyDatesRepository
*/
private $familyDatesRepository;
/**
* @var PlaceRepository
*/
private $placeRepository;
/**
* @var ModuleService
*/
private $module_service;
/**
* Create the statistics for a tree.
*
* @param CountryService $country_service
* @param ModuleService $module_service
* @param Tree $tree Generate statistics for this tree
* @param UserService $user_service
*/
public function __construct(
CountryService $country_service,
ModuleService $module_service,
Tree $tree,
UserService $user_service
) {
$this->tree = $tree;
$this->gedcomRepository = new GedcomRepository($tree);
$this->individualRepository = new IndividualRepository($tree);
$this->familyRepository = new FamilyRepository($tree);
$this->familyDatesRepository = new FamilyDatesRepository($tree);
$this->mediaRepository = new MediaRepository($tree);
$this->eventRepository = new EventRepository($tree);
$this->userRepository = new UserRepository($tree, $user_service);
$this->serverRepository = new ServerRepository();
$this->browserRepository = new BrowserRepository();
$this->hitCountRepository = new HitCountRepository($tree, $user_service);
$this->latestUserRepository = new LatestUserRepository($user_service);
$this->favoritesRepository = new FavoritesRepository($tree, $module_service);
$this->newsRepository = new NewsRepository($tree);
$this->messageRepository = new MessageRepository();
$this->contactRepository = new ContactRepository($tree, $user_service);
$this->placeRepository = new PlaceRepository($tree, $country_service);
$this->module_service = $module_service;
}
/**
* Return a string of all supported tags and an example of its output in table row form.
*
* @return string
*/
public function getAllTagsTable(): string
{
try {
$class = new ReflectionClass($this);
$public_methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
$examples = Collection::make($public_methods)
->filter(static function (ReflectionMethod $method): bool {
return !in_array($method->getName(), ['embedTags', 'getAllTagsTable'], true);
})
->filter(static function (ReflectionMethod $method): bool {
$type = $method->getReturnType();
return $type instanceof ReflectionNamedType && $type->getName() === 'string';
})
->sort(static function (ReflectionMethod $x, ReflectionMethod $y): int {
return $x->getName() <=> $y->getName();
})
->map(function (ReflectionMethod $method): string {
$tag = $method->getName();
return '
#' . $tag . '#
' . call_user_func([$this, $tag]) . '
';
});
return '
' . $examples->implode('') . '
';
} catch (ReflectionException $ex) {
return $ex->getMessage();
}
}
/**
* Embed tags in text
*
* @param string $text
*
* @return string
*/
public function embedTags(string $text): string
{
if (str_contains($text, '#')) {
$text = strtr($text, $this->getTags($text));
}
return $text;
}
/**
* @return string
*/
public function gedcomFilename(): string
{
return $this->gedcomRepository->gedcomFilename();
}
/**
* @return int
*/
public function gedcomId(): int
{
return $this->gedcomRepository->gedcomId();
}
/**
* @return string
*/
public function gedcomTitle(): string
{
return $this->gedcomRepository->gedcomTitle();
}
/**
* @return string
*/
public function gedcomCreatedSoftware(): string
{
return $this->gedcomRepository->gedcomCreatedSoftware();
}
/**
* @return string
*/
public function gedcomCreatedVersion(): string
{
return $this->gedcomRepository->gedcomCreatedVersion();
}
/**
* @return string
*/
public function gedcomDate(): string
{
return $this->gedcomRepository->gedcomDate();
}
/**
* @return string
*/
public function gedcomUpdated(): string
{
return $this->gedcomRepository->gedcomUpdated();
}
/**
* @return string
*/
public function gedcomRootId(): string
{
return $this->gedcomRepository->gedcomRootId();
}
/**
* @return string
*/
public function totalRecords(): string
{
return $this->individualRepository->totalRecords();
}
/**
* @return string
*/
public function totalIndividuals(): string
{
return $this->individualRepository->totalIndividuals();
}
/**
* @return string
*/
public function totalIndisWithSources(): string
{
return $this->individualRepository->totalIndisWithSources();
}
/**
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
*/
public function chartIndisWithSources(
string $color_from = null,
string $color_to = null
): string {
return $this->individualRepository->chartIndisWithSources($color_from, $color_to);
}
/**
* @return string
*/
public function totalIndividualsPercentage(): string
{
return $this->individualRepository->totalIndividualsPercentage();
}
/**
* @return string
*/
public function totalFamilies(): string
{
return $this->individualRepository->totalFamilies();
}
/**
* @return string
*/
public function totalFamiliesPercentage(): string
{
return $this->individualRepository->totalFamiliesPercentage();
}
/**
* @return string
*/
public function totalFamsWithSources(): string
{
return $this->individualRepository->totalFamsWithSources();
}
/**
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
*/
public function chartFamsWithSources(
string $color_from = null,
string $color_to = null
): string {
return $this->individualRepository->chartFamsWithSources($color_from, $color_to);
}
/**
* @return string
*/
public function totalSources(): string
{
return $this->individualRepository->totalSources();
}
/**
* @return string
*/
public function totalSourcesPercentage(): string
{
return $this->individualRepository->totalSourcesPercentage();
}
/**
* @return string
*/
public function totalNotes(): string
{
return $this->individualRepository->totalNotes();
}
/**
* @return string
*/
public function totalNotesPercentage(): string
{
return $this->individualRepository->totalNotesPercentage();
}
/**
* @return string
*/
public function totalRepositories(): string
{
return $this->individualRepository->totalRepositories();
}
/**
* @return string
*/
public function totalRepositoriesPercentage(): string
{
return $this->individualRepository->totalRepositoriesPercentage();
}
/**
* @param array ...$params
*
* @return string
*/
public function totalSurnames(...$params): string
{
return $this->individualRepository->totalSurnames(...$params);
}
/**
* @param array ...$params
*
* @return string
*/
public function totalGivennames(...$params): string
{
return $this->individualRepository->totalGivennames(...$params);
}
/**
* @param array $events
*
* @return string
*/
public function totalEvents(array $events = []): string
{
return $this->eventRepository->totalEvents($events);
}
/**
* @return string
*/
public function totalEventsBirth(): string
{
return $this->eventRepository->totalEventsBirth();
}
/**
* @return string
*/
public function totalBirths(): string
{
return $this->eventRepository->totalBirths();
}
/**
* @return string
*/
public function totalEventsDeath(): string
{
return $this->eventRepository->totalEventsDeath();
}
/**
* @return string
*/
public function totalDeaths(): string
{
return $this->eventRepository->totalDeaths();
}
/**
* @return string
*/
public function totalEventsMarriage(): string
{
return $this->eventRepository->totalEventsMarriage();
}
/**
* @return string
*/
public function totalMarriages(): string
{
return $this->eventRepository->totalMarriages();
}
/**
* @return string
*/
public function totalEventsDivorce(): string
{
return $this->eventRepository->totalEventsDivorce();
}
/**
* @return string
*/
public function totalDivorces(): string
{
return $this->eventRepository->totalDivorces();
}
/**
* @return string
*/
public function totalEventsOther(): string
{
return $this->eventRepository->totalEventsOther();
}
/**
* @return string
*/
public function totalSexMales(): string
{
return $this->individualRepository->totalSexMales();
}
/**
* @return string
*/
public function totalSexMalesPercentage(): string
{
return $this->individualRepository->totalSexMalesPercentage();
}
/**
* @return string
*/
public function totalSexFemales(): string
{
return $this->individualRepository->totalSexFemales();
}
/**
* @return string
*/
public function totalSexFemalesPercentage(): string
{
return $this->individualRepository->totalSexFemalesPercentage();
}
/**
* @return string
*/
public function totalSexUnknown(): string
{
return $this->individualRepository->totalSexUnknown();
}
/**
* @return string
*/
public function totalSexUnknownPercentage(): string
{
return $this->individualRepository->totalSexUnknownPercentage();
}
/**
* @param string|null $color_female
* @param string|null $color_male
* @param string|null $color_unknown
*
* @return string
*/
public function chartSex(
string $color_female = null,
string $color_male = null,
string $color_unknown = null
): string {
return $this->individualRepository->chartSex($color_female, $color_male, $color_unknown);
}
/**
* @return string
*/
public function totalLiving(): string
{
return $this->individualRepository->totalLiving();
}
/**
* @return string
*/
public function totalLivingPercentage(): string
{
return $this->individualRepository->totalLivingPercentage();
}
/**
* @return string
*/
public function totalDeceased(): string
{
return $this->individualRepository->totalDeceased();
}
/**
* @return string
*/
public function totalDeceasedPercentage(): string
{
return $this->individualRepository->totalDeceasedPercentage();
}
/**
* @param string|null $color_living
* @param string|null $color_dead
*
* @return string
*/
public function chartMortality(string $color_living = null, string $color_dead = null): string
{
return $this->individualRepository->chartMortality($color_living, $color_dead);
}
/**
* @return string
*/
public function totalMedia(): string
{
return $this->mediaRepository->totalMedia();
}
/**
* @return string
*/
public function totalMediaAudio(): string
{
return $this->mediaRepository->totalMediaAudio();
}
/**
* @return string
*/
public function totalMediaBook(): string
{
return $this->mediaRepository->totalMediaBook();
}
/**
* @return string
*/
public function totalMediaCard(): string
{
return $this->mediaRepository->totalMediaCard();
}
/**
* @return string
*/
public function totalMediaCertificate(): string
{
return $this->mediaRepository->totalMediaCertificate();
}
/**
* @return string
*/
public function totalMediaCoatOfArms(): string
{
return $this->mediaRepository->totalMediaCoatOfArms();
}
/**
* @return string
*/
public function totalMediaDocument(): string
{
return $this->mediaRepository->totalMediaDocument();
}
/**
* @return string
*/
public function totalMediaElectronic(): string
{
return $this->mediaRepository->totalMediaElectronic();
}
/**
* @return string
*/
public function totalMediaMagazine(): string
{
return $this->mediaRepository->totalMediaMagazine();
}
/**
* @return string
*/
public function totalMediaManuscript(): string
{
return $this->mediaRepository->totalMediaManuscript();
}
/**
* @return string
*/
public function totalMediaMap(): string
{
return $this->mediaRepository->totalMediaMap();
}
/**
* @return string
*/
public function totalMediaFiche(): string
{
return $this->mediaRepository->totalMediaFiche();
}
/**
* @return string
*/
public function totalMediaFilm(): string
{
return $this->mediaRepository->totalMediaFilm();
}
/**
* @return string
*/
public function totalMediaNewspaper(): string
{
return $this->mediaRepository->totalMediaNewspaper();
}
/**
* @return string
*/
public function totalMediaPainting(): string
{
return $this->mediaRepository->totalMediaPainting();
}
/**
* @return string
*/
public function totalMediaPhoto(): string
{
return $this->mediaRepository->totalMediaPhoto();
}
/**
* @return string
*/
public function totalMediaTombstone(): string
{
return $this->mediaRepository->totalMediaTombstone();
}
/**
* @return string
*/
public function totalMediaVideo(): string
{
return $this->mediaRepository->totalMediaVideo();
}
/**
* @return string
*/
public function totalMediaOther(): string
{
return $this->mediaRepository->totalMediaOther();
}
/**
* @return string
*/
public function totalMediaUnknown(): string
{
return $this->mediaRepository->totalMediaUnknown();
}
/**
* @param string|null $color_from
* @param string|null $color_to
*
* @return string
*/
public function chartMedia(string $color_from = null, string $color_to = null): string
{
return $this->mediaRepository->chartMedia($color_from, $color_to);
}
/**
* @param string $what
* @param string $fact
* @param int $parent
* @param bool $country
*
* @return array