xref: /webtrees/app/Statistics/Repository/NewsRepository.php (revision 89f7189b61a494347591c99bdb92afb7d8b66e1b)
18add1155SRico Sonntag<?php
23976b470SGreg Roach
38add1155SRico Sonntag/**
48add1155SRico Sonntag * webtrees: online genealogy
5*89f7189bSGreg Roach * Copyright (C) 2021 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
15*89f7189bSGreg Roach * along with this program. If not, see <https://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\Statistics\Repository\Interfaces\NewsRepositoryInterface;
258add1155SRico Sonntaguse Fisharebest\Webtrees\Tree;
268add1155SRico Sonntaguse Illuminate\Database\Capsule\Manager as DB;
278add1155SRico Sonntag
288add1155SRico Sonntag/**
298add1155SRico Sonntag * A repository providing methods for news related statistics.
308add1155SRico Sonntag */
318add1155SRico Sonntagclass NewsRepository implements NewsRepositoryInterface
328add1155SRico Sonntag{
338add1155SRico Sonntag    /**
348add1155SRico Sonntag     * @var Tree
358add1155SRico Sonntag     */
368add1155SRico Sonntag    private $tree;
378add1155SRico Sonntag
388add1155SRico Sonntag    /**
398add1155SRico Sonntag     * Constructor.
408add1155SRico Sonntag     *
418add1155SRico Sonntag     * @param Tree $tree
428add1155SRico Sonntag     */
438add1155SRico Sonntag    public function __construct(Tree $tree)
448add1155SRico Sonntag    {
458add1155SRico Sonntag        $this->tree = $tree;
468add1155SRico Sonntag    }
478add1155SRico Sonntag
488add1155SRico Sonntag    /**
490dcd9387SGreg Roach     * @return string
508add1155SRico Sonntag     */
518add1155SRico Sonntag    public function totalUserJournal(): string
528add1155SRico Sonntag    {
538add1155SRico Sonntag        $number = DB::table('news')
548add1155SRico Sonntag            ->where('user_id', '=', Auth::id())
558add1155SRico Sonntag            ->count();
568add1155SRico Sonntag
578add1155SRico Sonntag        return I18N::number($number);
588add1155SRico Sonntag    }
598add1155SRico Sonntag
608add1155SRico Sonntag    /**
610dcd9387SGreg Roach     * @return string
628add1155SRico Sonntag     */
638add1155SRico Sonntag    public function totalGedcomNews(): string
648add1155SRico Sonntag    {
658add1155SRico Sonntag        $number = DB::table('news')
668add1155SRico Sonntag            ->where('gedcom_id', '=', $this->tree->id())
678add1155SRico Sonntag            ->count();
688add1155SRico Sonntag
698add1155SRico Sonntag        return I18N::number($number);
708add1155SRico Sonntag    }
718add1155SRico Sonntag}
72