18add1155SRico Sonntag<?php 23976b470SGreg Roach 38add1155SRico Sonntag/** 48add1155SRico Sonntag * webtrees: online genealogy 5*0dcd9387SGreg Roach * Copyright (C) 2020 webtrees development team 68add1155SRico Sonntag * This program is free software: you can redistribute it and/or modify 78add1155SRico Sonntag * it under the terms of the GNU General Public License as published by 88add1155SRico Sonntag * the Free Software Foundation, either version 3 of the License, or 98add1155SRico Sonntag * (at your option) any later version. 108add1155SRico Sonntag * This program is distributed in the hope that it will be useful, 118add1155SRico Sonntag * but WITHOUT ANY WARRANTY; without even the implied warranty of 128add1155SRico Sonntag * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138add1155SRico Sonntag * GNU General Public License for more details. 148add1155SRico Sonntag * You should have received a copy of the GNU General Public License 158add1155SRico Sonntag * along with this program. If not, see <http://www.gnu.org/licenses/>. 168add1155SRico Sonntag */ 17fcfa147eSGreg Roach 188add1155SRico Sonntagdeclare(strict_types=1); 198add1155SRico Sonntag 208add1155SRico Sonntagnamespace Fisharebest\Webtrees\Statistics\Repository; 218add1155SRico Sonntag 228add1155SRico Sonntaguse Fisharebest\Webtrees\Auth; 238add1155SRico Sonntaguse Fisharebest\Webtrees\I18N; 248add1155SRico Sonntaguse Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule; 253caaa4d2SGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 268add1155SRico Sonntaguse Fisharebest\Webtrees\Module\UserFavoritesModule; 274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 288add1155SRico Sonntaguse Fisharebest\Webtrees\Statistics\Repository\Interfaces\FavoritesRepositoryInterface; 298add1155SRico Sonntaguse Fisharebest\Webtrees\Tree; 308add1155SRico Sonntag 3171378461SGreg Roachuse function count; 3271378461SGreg Roach 338add1155SRico Sonntag/** 348add1155SRico Sonntag * A repository providing methods for favorites related statistics. 358add1155SRico Sonntag */ 368add1155SRico Sonntagclass FavoritesRepository implements FavoritesRepositoryInterface 378add1155SRico Sonntag{ 388add1155SRico Sonntag /** 398add1155SRico Sonntag * @var Tree 408add1155SRico Sonntag */ 41fd9aba47SGreg Roach 428add1155SRico Sonntag private $tree; 43fd9aba47SGreg Roach /** 44fd9aba47SGreg Roach * @var ModuleService 45fd9aba47SGreg Roach */ 46fd9aba47SGreg Roach private $module_service; 478add1155SRico Sonntag 488add1155SRico Sonntag /** 498add1155SRico Sonntag * Constructor. 508add1155SRico Sonntag * 518add1155SRico Sonntag * @param Tree $tree 52fd9aba47SGreg Roach * @param ModuleService $module_service 538add1155SRico Sonntag */ 54fd9aba47SGreg Roach public function __construct(Tree $tree, ModuleService $module_service) 558add1155SRico Sonntag { 568add1155SRico Sonntag $this->tree = $tree; 57fd9aba47SGreg Roach $this->module_service = $module_service; 588add1155SRico Sonntag } 598add1155SRico Sonntag 608add1155SRico Sonntag /** 61*0dcd9387SGreg Roach * @return string 628add1155SRico Sonntag */ 638add1155SRico Sonntag public function gedcomFavorites(): string 648add1155SRico Sonntag { 65fd9aba47SGreg Roach $module = $this->module_service 667ef4c0b1SGreg Roach ->findByInterface(FamilyTreeFavoritesModule::class) 677ef4c0b1SGreg Roach ->first(); 688add1155SRico Sonntag 698add1155SRico Sonntag if ($module instanceof FamilyTreeFavoritesModule) { 703caaa4d2SGreg Roach return $module->getBlock($this->tree, 0, ModuleBlockInterface::CONTEXT_EMBED); 718add1155SRico Sonntag } 728add1155SRico Sonntag 738add1155SRico Sonntag return ''; 748add1155SRico Sonntag } 758add1155SRico Sonntag 768add1155SRico Sonntag /** 77*0dcd9387SGreg Roach * @return string 788add1155SRico Sonntag */ 798add1155SRico Sonntag public function userFavorites(): string 808add1155SRico Sonntag { 81fd9aba47SGreg Roach $module = $this->module_service 827ef4c0b1SGreg Roach ->findByInterface(UserFavoritesModule::class) 837ef4c0b1SGreg Roach ->first(); 848add1155SRico Sonntag 858add1155SRico Sonntag if ($module instanceof UserFavoritesModule) { 863caaa4d2SGreg Roach return $module->getBlock($this->tree, 0, ModuleBlockInterface::CONTEXT_EMBED); 878add1155SRico Sonntag } 888add1155SRico Sonntag 898add1155SRico Sonntag return ''; 908add1155SRico Sonntag } 918add1155SRico Sonntag 928add1155SRico Sonntag /** 93*0dcd9387SGreg Roach * @return string 948add1155SRico Sonntag */ 958add1155SRico Sonntag public function totalGedcomFavorites(): string 968add1155SRico Sonntag { 978add1155SRico Sonntag $count = 0; 98fd9aba47SGreg Roach $module = $this->module_service 997ef4c0b1SGreg Roach ->findByInterface(FamilyTreeFavoritesModule::class) 1007ef4c0b1SGreg Roach ->first(); 1018add1155SRico Sonntag 1028add1155SRico Sonntag if ($module instanceof FamilyTreeFavoritesModule) { 1036ccdf4f0SGreg Roach $count = count($module->getFavorites($this->tree)); 1048add1155SRico Sonntag } 1058add1155SRico Sonntag 1068add1155SRico Sonntag return I18N::number($count); 1078add1155SRico Sonntag } 1088add1155SRico Sonntag 1098add1155SRico Sonntag /** 110*0dcd9387SGreg Roach * @return string 1118add1155SRico Sonntag */ 1128add1155SRico Sonntag public function totalUserFavorites(): string 1138add1155SRico Sonntag { 1148add1155SRico Sonntag $count = 0; 115fd9aba47SGreg Roach $module = $this->module_service 1167ef4c0b1SGreg Roach ->findByInterface(UserFavoritesModule::class) 1177ef4c0b1SGreg Roach ->first(); 1188add1155SRico Sonntag 1198add1155SRico Sonntag if ($module instanceof UserFavoritesModule) { 1206ccdf4f0SGreg Roach $count = count($module->getFavorites($this->tree, Auth::user())); 1218add1155SRico Sonntag } 1228add1155SRico Sonntag 1238add1155SRico Sonntag return I18N::number($count); 1248add1155SRico Sonntag } 1258add1155SRico Sonntag} 126