Passed
Push — master ( ef8807...c1ca83 )
by Mihail
05:17
created

Apps/Model/Admin/Feedback/FormAnswerAdd.php (2 issues)

1
<?php
2
3
namespace Apps\Model\Admin\Feedback;
4
5
use Apps\ActiveRecord\FeedbackAnswer;
6
use Apps\ActiveRecord\FeedbackPost;
7
use Apps\Model\Front\Feedback\FormAnswerAdd as FrontAnswer;
8
use Apps\Model\Front\Profile\EntityAddNotification;
9
use Ffcms\Core\App;
10
use Ffcms\Core\Helper\Text;
11
12
/**
13
 * Class FormAnswerAdd. Extend front model add answer
14
 * @package Apps\Model\Admin\Feedback
15
 */
16
class FormAnswerAdd extends FrontAnswer
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function make()
22
    {
23
        // update readed marker
24
        $this->_post->readed = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $readed was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
25
        $this->_post->save();
26
27
        // add new answer row in database
28
        $record = new FeedbackAnswer();
29
        $record->feedback_id = $this->_post->id;
30
        $record->name = $this->name;
31
        $record->email = $this->email;
32
        $record->message = $this->message;
33
        $record->user_id = $this->_userId;
34
        $record->is_admin = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $is_admin was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
35
36
        $record->ip = $this->_ip;
37
        $record->save();
38
39
        // add user notification
40
        if ((int)$this->_post->user_id > 0 && $this->_userId !== (int)$this->_post->user_id) {
41
            $notify = new EntityAddNotification((int)$this->_post->user_id);
42
            $uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id;
43
44
            $notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, [
45
                'snippet' => Text::snippet($this->message, 50),
46
                'post' => Text::snippet($this->_post->message, 50)
47
            ]);
48
        }
49
50
        // send email notification
51
        App::$Mailer->tpl('feedback/mail/newanswer', [
52
            'record' => $record
53
        ])->send($record->email, App::$Translate->get('Feedback', 'New answer in request #%id%', ['id' => $record->id]));
54
55
        // unset message data
56
        $this->message = null;
57
    }
58
}
59