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