xref: /webtrees/app/TreeUser.php (revision e93a8df2f8d797005750082cc3766c0e80799688)
1e5a6b4d4SGreg Roach<?php
23976b470SGreg Roach
3e5a6b4d4SGreg Roach/**
4e5a6b4d4SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6e5a6b4d4SGreg Roach * This program is free software: you can redistribute it and/or modify
7e5a6b4d4SGreg Roach * it under the terms of the GNU General Public License as published by
8e5a6b4d4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9e5a6b4d4SGreg Roach * (at your option) any later version.
10e5a6b4d4SGreg Roach * This program is distributed in the hope that it will be useful,
11e5a6b4d4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12e5a6b4d4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13e5a6b4d4SGreg Roach * GNU General Public License for more details.
14e5a6b4d4SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16e5a6b4d4SGreg Roach */
17fcfa147eSGreg Roach
18e5a6b4d4SGreg Roachdeclare(strict_types=1);
19e5a6b4d4SGreg Roach
20e5a6b4d4SGreg Roachnamespace Fisharebest\Webtrees;
21e5a6b4d4SGreg Roach
22e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
23502cab90SGreg Roachuse Fisharebest\Webtrees\Services\UserService;
24e5a6b4d4SGreg Roach
25e5a6b4d4SGreg Roach/**
26e5a6b4d4SGreg Roach * A tree can act as a user, for example to send email.
27e5a6b4d4SGreg Roach */
28e5a6b4d4SGreg Roachclass TreeUser implements UserInterface
29e5a6b4d4SGreg Roach{
3043f2f523SGreg Roach    private Tree $tree;
31e5a6b4d4SGreg Roach
32e5a6b4d4SGreg Roach    /**
33e5a6b4d4SGreg Roach     * @param Tree $tree
34e5a6b4d4SGreg Roach     */
35e5a6b4d4SGreg Roach    public function __construct(Tree $tree)
36e5a6b4d4SGreg Roach    {
37e5a6b4d4SGreg Roach        $this->tree = $tree;
38e5a6b4d4SGreg Roach    }
39e5a6b4d4SGreg Roach
40e5a6b4d4SGreg Roach    /**
41e5a6b4d4SGreg Roach     * The user‘s internal identifier.
42e5a6b4d4SGreg Roach     *
43e5a6b4d4SGreg Roach     * @return int
44e5a6b4d4SGreg Roach     */
45e5a6b4d4SGreg Roach    public function id(): int
46e5a6b4d4SGreg Roach    {
47e5a6b4d4SGreg Roach        return 0;
48e5a6b4d4SGreg Roach    }
49e5a6b4d4SGreg Roach
50e5a6b4d4SGreg Roach    /**
51e5a6b4d4SGreg Roach     * The users email address.
52e5a6b4d4SGreg Roach     *
53e5a6b4d4SGreg Roach     * @return string
54e5a6b4d4SGreg Roach     */
55e5a6b4d4SGreg Roach    public function email(): string
56e5a6b4d4SGreg Roach    {
57*d35568b4SGreg Roach        $user_service = Registry::container()->get(UserService::class);
58502cab90SGreg Roach        $contact_id   = (int) $this->getPreference('CONTACT_USER_ID');
59502cab90SGreg Roach
60e2c25bffSGreg Roach        if ($contact_id !== 0) {
61502cab90SGreg Roach            $contact = $user_service->find($contact_id);
62502cab90SGreg Roach
63502cab90SGreg Roach            if ($contact instanceof User) {
64502cab90SGreg Roach                return $contact->email();
65502cab90SGreg Roach            }
66e2c25bffSGreg Roach        }
67502cab90SGreg Roach
68e2c25bffSGreg Roach        return Site::getPreference('SMTP_FROM_NAME');
69502cab90SGreg Roach    }
70502cab90SGreg Roach
71502cab90SGreg Roach    /**
72502cab90SGreg Roach     * @param string $setting_name
73502cab90SGreg Roach     * @param string $default
74502cab90SGreg Roach     *
75502cab90SGreg Roach     * @return string
76502cab90SGreg Roach     */
77502cab90SGreg Roach    public function getPreference(string $setting_name, string $default = ''): string
78502cab90SGreg Roach    {
79502cab90SGreg Roach        return $default;
80e5a6b4d4SGreg Roach    }
81e5a6b4d4SGreg Roach
82e5a6b4d4SGreg Roach    /**
83e5a6b4d4SGreg Roach     * The user‘s real name.
84e5a6b4d4SGreg Roach     *
85e5a6b4d4SGreg Roach     * @return string
86e5a6b4d4SGreg Roach     */
87e5a6b4d4SGreg Roach    public function realName(): string
88e5a6b4d4SGreg Roach    {
89e5a6b4d4SGreg Roach        return $this->tree->title();
90e5a6b4d4SGreg Roach    }
91e5a6b4d4SGreg Roach
92e5a6b4d4SGreg Roach    /**
93e5a6b4d4SGreg Roach     * The user‘s login name.
94e5a6b4d4SGreg Roach     *
95e5a6b4d4SGreg Roach     * @return string
96e5a6b4d4SGreg Roach     */
97e5a6b4d4SGreg Roach    public function userName(): string
98e5a6b4d4SGreg Roach    {
99e5a6b4d4SGreg Roach        return '';
100e5a6b4d4SGreg Roach    }
101e5a6b4d4SGreg Roach
102e5a6b4d4SGreg Roach    /**
103e5a6b4d4SGreg Roach     * @param string $setting_name
104e5a6b4d4SGreg Roach     * @param string $setting_value
105e5a6b4d4SGreg Roach     *
1067c4add84SGreg Roach     * @return void
107e5a6b4d4SGreg Roach     */
1087c4add84SGreg Roach    public function setPreference(string $setting_name, string $setting_value): void
109e5a6b4d4SGreg Roach    {
110e5a6b4d4SGreg Roach    }
111e5a6b4d4SGreg Roach}
112