1<?php
2
3/**
4 * The notification class for phpMyFAQ.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2012-2020 phpMyFAQ Team
13 * @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2012-08-30
16 */
17
18namespace phpMyFAQ;
19
20/**
21 * Class Notification
22 *
23 * @package phpMyFAQ
24 */
25class Notification
26{
27    /**
28     * @var Configuration
29     */
30    private $config;
31
32    /**
33     * Mail object.
34     *
35     * @var Mail
36     */
37    private $mail;
38
39    /**
40     * Language strings.
41     *
42     * @var string
43     */
44    private $pmfStr;
45
46    /**
47     * Constructor.
48     *
49     * @param Configuration
50     */
51    public function __construct(Configuration $config)
52    {
53        global $PMF_LANG;
54
55        $this->config = $config;
56        $this->pmfStr = $PMF_LANG;
57        $this->mail = new Mail($this->config);
58        $this->mail->setReplyTo(
59            $this->config->get('main.administrationMail'),
60            $this->config->get('main.titleFAQ')
61        );
62    }
63
64    /**
65     * Sends a notification to user who added a question.
66     *
67     * @param string $email    Email address of the user
68     * @param string $userName Name of the user
69     * @param string $url      URL of answered FAQ
70     */
71    public function sendOpenQuestionAnswered(string $email, string $userName, string $url)
72    {
73        $this->mail->addTo($email, $userName);
74        $this->mail->subject = $this->config->get('main.titleFAQ') . ' - ' . $this->pmfStr['msgQuestionAnswered'];
75        $this->mail->message = sprintf(
76            $this->pmfStr['msgMessageQuestionAnswered'],
77            $this->config->get('main.titleFAQ')
78        ) . "\n\r" . $url;
79        $this->mail->send();
80    }
81}
82