1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Model\Admin\Feedback; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\FeedbackAnswer; |
6
|
|
|
use Apps\Model\Front\Feedback\FormAnswerAdd as FrontAnswer; |
7
|
|
|
use Apps\Model\Front\Profile\EntityAddNotification; |
8
|
|
|
use Ffcms\Core\App; |
9
|
|
|
use Ffcms\Core\Helper\Text; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class FormAnswerAdd. Extend front model add answer |
13
|
|
|
* @package Apps\Model\Admin\Feedback |
14
|
|
|
*/ |
15
|
|
|
class FormAnswerAdd extends FrontAnswer |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
|
|
public function make() |
21
|
|
|
{ |
22
|
|
|
// update readed marker |
23
|
|
|
$this->_post->readed = 1; |
|
|
|
|
24
|
|
|
$this->_post->save(); |
25
|
|
|
|
26
|
|
|
// add new answer row in database |
27
|
|
|
$record = new FeedbackAnswer(); |
28
|
|
|
$record->feedback_id = $this->_post->id; |
29
|
|
|
$record->name = $this->name; |
30
|
|
|
$record->email = $this->email; |
31
|
|
|
$record->message = $this->message; |
32
|
|
|
$record->user_id = $this->_userId; |
33
|
|
|
$record->is_admin = 1; |
|
|
|
|
34
|
|
|
|
35
|
|
|
$record->ip = $this->_ip; |
36
|
|
|
$record->save(); |
37
|
|
|
|
38
|
|
|
// add user notification |
39
|
|
|
if ((int)$this->_post->user_id > 0 && $this->_userId !== (int)$this->_post->user_id) { |
40
|
|
|
$notify = new EntityAddNotification((int)$this->_post->user_id); |
|
|
|
|
41
|
|
|
$uri = '/feedback/read/' . $this->_post->id . '/' . $this->_post->hash . '#feedback-answer-' . $record->id; |
42
|
|
|
|
43
|
|
|
$notify->add($uri, EntityAddNotification::MSG_ADD_FEEDBACKANSWER, [ |
44
|
|
|
'snippet' => Text::snippet($this->message, 50), |
45
|
|
|
'post' => Text::snippet($this->_post->message, 50) |
46
|
|
|
]); |
47
|
|
|
} |
48
|
|
|
if (App::$Mailer) { |
49
|
|
|
// send email notification |
50
|
|
|
App::$Mailer->tpl('feedback/mail/newanswer', [ |
51
|
|
|
'record' => $record |
52
|
|
|
])->send($record->email, App::$Translate->get('Feedback', 'New answer in request #%id%', ['id' => $record->id])); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// unset message data |
56
|
|
|
$this->message = null; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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.