Newer
Older
<?php
/**
* Art-ER Attrattività, ricerca e territorio dell’Emilia-Romagna
* OPEN 2.0
*
*
* @category CategoryName
* @author Elite Division S.r.l.
*/
use arter\amos\core\interfaces\ModelGrammarInterface;
use arter\amos\core\interfaces\ModelLabelsInterface;
use arter\amos\core\user\User;
use arter\amos\notificationmanager\AmosNotify;
use arter\amos\notificationmanager\models\ChangeStatusEmail;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
*/
class CustomMailBuilder extends AMailBuilder
{
/**
* @var ChangeStatusEmail $emailConf
*/
public $emailConf;
/**
* @var string $endStatus
*/
public $endStatus;
/**
* @var string $template
*/
private $template;
/**
* @var array $params
*/
private $params = [];
/**
* @return string
*/
public function getTemplate()
{
return $this->template;
}
/**
* @param string $template
*/
public function setTemplate($template)
{
$this->template = $template;
}
/**
* @return array
*/
public function getParams()
{
return $this->params;
}
/**
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!is_null($this->emailConf)) {
$email = $this->emailConf;
if ($email->template) {
$this->setTemplate($email->template);
} elseif ($email->toCreator) {
$this->setTemplate("@vendor/arter/amos-" . AmosNotify::getModuleName() . "/src/views/email/validated");
$this->setTemplate("@vendor/arter/amos-" . AmosNotify::getModuleName() . "/src/views/email/validator");
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
}
if (count($email->params)) {
$this->setParams($email->params);
}
}
}
/**
* @inheritdoc
*/
public function getSubject(array $resultset)
{
$stdMsg = AmosNotify::t('amosnotify', "Content has been validated");
$model = reset($resultset);
//check if customized subject
if (!is_null($this->emailConf) && !is_null($this->emailConf->subject)) {
$stdMsg = $this->emailConf->subject;
} elseif ($model instanceof ModelLabelsInterface) {
$grammar = $model->getGrammar();
if (!is_null($grammar) && ($grammar instanceof ModelGrammarInterface)) {
$stdMsg = AmosNotify::t('amosnotify', '#publication_email_subject', ['contentName' => $grammar->getModelSingularLabel()]);
}
}
return $stdMsg;
}
/**
* @inheritdoc
*/
public function renderEmail(array $resultset, User $user)
{
$ris = "";
$model = reset($resultset);
try {
$userid = $model->getStatusLastUpdateUser($this->endStatus);
if (!is_null($userid)) {
$user = User::findOne($userid);
$comment = $model->getStatusLastUpdateComment($this->endStatus);
$controller = \Yii::$app->controller;
if (!count($this->getParams())) {
$this->setParams([
'model' => $model,
'validator' => $user->getUserProfile()->one(),
'comment' => $comment
]);
}
$ris = $controller->renderPartial($this->getTemplate(), $this->getParams());
}
} catch (\Exception $ex) {
Yii::getLogger()->log($ex->getTraceAsString(), \yii\log\Logger::LEVEL_ERROR);
}
return $ris;
}
}