-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTicketBody.php
executable file
·132 lines (120 loc) · 3.99 KB
/
TicketBody.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
92
93
94
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
<?php
/************************************************************************************
*
* Copyright (c) 2018 Thanasis Vergoulis & Konstantinos Zagganas & Loukas Kavouras
* for the Information Management Systems Institute, "Athena" Research Center.
*
* This file is part of SCHeMa.
*
* SCHeMa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SCHeMa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <https://www.gnu.org/licenses/>.
*
************************************************************************************/
namespace app\models;
use components\Mailer;
use app\models\TicketConfig;
// use ricco\ticket\Module;
use Yii;
use app\models\User;
/**
* This is the model class for table "ticket_body".
*
* @property integer $id
* @property integer $id_head
* @property integer $client
* @property string $name_user
* @property string $text
* @property string $date
*
* @property TicketFile $file
* @property TicketHead[] $ticketHeads
*/
class TicketBody extends \yii\db\ActiveRecord
{
/** @var Module */
private $module;
const ADMIN = 1;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%ticket_body}}';
}
// public function init()
// {
// // $this->module = new TicketConfig;
// parent::init(); // TODO: Change the autogenerated stub
// }
/**
* @inheritdoc
*/
public function rules()
{
return [
[['text'], 'required'],
[['text'], 'string'],
[['date', 'name_user', 'id_head'], 'safe'],
[['name_user'], 'string', 'max' => 255],
[['name_user', 'text'], 'filter', 'filter' => 'strip_tags'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name_user' => 'Username',
'text' => 'Message',
'date' => 'Date',
];
}
/**
* Перед сохранением указываем имя пользователя который делает ответ
* Если ответ пишет администратор, делаем соответствующий статус
*
* @param bool $insert
* @return bool
*/
public function beforeSave($insert)
{
$this->name_user = Yii::$app->user->identity['username'];
if (in_array(Yii::$app->user->identity->getId(), User::getAdminIds())) {
$this->client = self::ADMIN;
}
/** @var TicketHead $ticketHead */
$ticketHead = TicketHead::find()->where("id = " . $this->id_head)->one();
/**
* Отправка уведомлений
*/
if (TicketConfig::mailSend !== false && $ticketHead->status != TicketHead::CLOSED) {
$userModel = User::$user;
(new Mailer())
->sendMailDataTicket($ticketHead->topic, $ticketHead->status, $ticketHead->id,
$this->text)
->setDataFrom($this->client == null ? Yii::$app->params['adminEmail'] : $userModel::findOne([
'id' => $ticketHead->user_id,
])['email'],
TicketConfig::subjectAnswer
)
->senda('mail');
}
return parent::beforeSave($insert); // TODO: Change the autogenerated stub
}
public function getFile()
{
return $this->hasMany(TicketFile::class, ['id_body' => 'id']);
}
}