xref: /webtrees/app/Statistics/Repository/NewsRepository.php (revision 5bfc689774bb9a6401271c4ed15a6d50652c991b)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Statistics\Repository;
21
22use Fisharebest\Webtrees\Auth;
23use Fisharebest\Webtrees\I18N;
24use Fisharebest\Webtrees\Statistics\Repository\Interfaces\NewsRepositoryInterface;
25use Fisharebest\Webtrees\Tree;
26use Illuminate\Database\Capsule\Manager as DB;
27
28/**
29 * A repository providing methods for news related statistics.
30 */
31class NewsRepository implements NewsRepositoryInterface
32{
33    private Tree $tree;
34
35    /**
36     * @param Tree $tree
37     */
38    public function __construct(Tree $tree)
39    {
40        $this->tree = $tree;
41    }
42
43    /**
44     * @return string
45     */
46    public function totalUserJournal(): string
47    {
48        $number = DB::table('news')
49            ->where('user_id', '=', Auth::id())
50            ->count();
51
52        return I18N::number($number);
53    }
54
55    /**
56     * @return string
57     */
58    public function totalGedcomNews(): string
59    {
60        $number = DB::table('news')
61            ->where('gedcom_id', '=', $this->tree->id())
62            ->count();
63
64        return I18N::number($number);
65    }
66}
67