|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\models; |
|
4
|
|
|
|
|
5
|
|
|
use app\properties\AbstractModel; |
|
6
|
|
|
use app\properties\HasProperties; |
|
7
|
|
|
use Yii; |
|
8
|
|
|
use yii\data\ActiveDataProvider; |
|
9
|
|
|
use yii\helpers\ArrayHelper; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* This is the model class for table "submission". |
|
13
|
|
|
* @property integer $id |
|
14
|
|
|
* @property integer $form_id |
|
15
|
|
|
* @property string $date_received |
|
16
|
|
|
* @property string $ip |
|
17
|
|
|
* @property string $user_agent |
|
18
|
|
|
* @property string $piwik_visitor_id |
|
19
|
|
|
* @property string $additional_information |
|
20
|
|
|
* @property string $date_viewed |
|
21
|
|
|
* @property string $date_processed |
|
22
|
|
|
* @property integer $processed_by_user_id |
|
23
|
|
|
* @property integer $processed |
|
24
|
|
|
* @property string $internal_comment |
|
25
|
|
|
* @property string $submission_referrer |
|
26
|
|
|
* @property string $visitor_referrer |
|
27
|
|
|
* @property string $visitor_landing |
|
28
|
|
|
* @property string $visit_start_date |
|
29
|
|
|
* @property integer $form_fill_time |
|
30
|
|
|
* @property integer $is_deleted |
|
31
|
|
|
* @property bool $spam |
|
32
|
|
|
* @property int $sending_status |
|
33
|
|
|
* @property AbstractModel $abstractModel |
|
34
|
|
|
* @property Form $form |
|
35
|
|
|
*/ |
|
36
|
|
|
class Submission extends \yii\db\ActiveRecord |
|
37
|
|
|
{ |
|
38
|
|
|
const STATUS_NEW = 0; |
|
39
|
|
|
const STATUS_SUCCESS = 1; |
|
40
|
|
|
const STATUS_ERROR = -1; |
|
41
|
|
|
const STATUS_HOPELESS_ERROR = -2; |
|
42
|
|
|
const STATUS_FATAL_ERROR = -3; |
|
43
|
|
|
|
|
44
|
|
|
protected $subject = null; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return null |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public function getSubject() |
|
50
|
|
|
{ |
|
51
|
|
|
$message = $this->form->subject_template; |
|
52
|
|
|
$params = array_reduce( |
|
53
|
|
|
array_keys($this->abstractModel->getAttributes()), |
|
54
|
|
|
function ($arr, $i) { |
|
55
|
|
|
$arr[$i] = $this->property($i); |
|
56
|
|
|
return $arr; |
|
57
|
|
|
}, |
|
58
|
|
|
[] |
|
59
|
|
|
); |
|
60
|
|
|
$params['id'] = $this->id; |
|
61
|
|
|
$params['form_name'] = $this->form->name; |
|
62
|
|
|
$p = []; |
|
63
|
|
|
foreach ((array)$params as $name => $value) { |
|
64
|
|
|
$p['{' . $name . '}'] = $value; |
|
65
|
|
|
} |
|
66
|
|
|
return ($p === []) ? $message : strtr($message, $p); |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param null $subject |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setSubject($subject) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->subject = $subject; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritdoc |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function tableName() |
|
82
|
|
|
{ |
|
83
|
|
|
return '{{%submission}}'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @inheritdoc |
|
88
|
|
|
*/ |
|
89
|
|
|
public function rules() |
|
90
|
|
|
{ |
|
91
|
|
|
return [ |
|
92
|
|
|
[['form_id'], 'required'], |
|
93
|
|
|
[ |
|
94
|
|
|
['form_id', 'processed_by_user_id', 'processed', 'form_fill_time', 'is_deleted', 'sending_status'], |
|
95
|
|
|
'integer' |
|
96
|
|
|
], |
|
97
|
|
|
[['date_received', 'date_viewed', 'date_processed', 'visit_start_date'], 'safe'], |
|
98
|
|
|
[ |
|
99
|
|
|
[ |
|
100
|
|
|
'ip', |
|
101
|
|
|
'user_agent', |
|
102
|
|
|
'piwik_visitor_id', |
|
103
|
|
|
'additional_information', |
|
104
|
|
|
'internal_comment', |
|
105
|
|
|
'submission_referrer', |
|
106
|
|
|
'visitor_referrer', |
|
107
|
|
|
'visitor_landing' |
|
108
|
|
|
], |
|
109
|
|
|
'string' |
|
110
|
|
|
], |
|
111
|
|
|
[['spam'], 'integer'] |
|
112
|
|
|
]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function behaviors() |
|
116
|
|
|
{ |
|
117
|
|
|
return [ |
|
118
|
|
|
[ |
|
119
|
|
|
'class' => HasProperties::className(), |
|
120
|
|
|
], |
|
121
|
|
|
[ |
|
122
|
|
|
'class' => \devgroup\TagDependencyHelper\ActiveRecordHelper::className(), |
|
123
|
|
|
], |
|
124
|
|
|
]; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @inheritdoc |
|
129
|
|
|
*/ |
|
130
|
|
|
public function attributeLabels() |
|
131
|
|
|
{ |
|
132
|
|
|
return [ |
|
133
|
|
|
'id' => Yii::t('app', 'ID'), |
|
134
|
|
|
'form_id' => Yii::t('app', 'Form ID'), |
|
135
|
|
|
'date_received' => Yii::t('app', 'Date Received'), |
|
136
|
|
|
'ip' => Yii::t('app', 'Ip'), |
|
137
|
|
|
'user_agent' => Yii::t('app', 'User Agent'), |
|
138
|
|
|
'piwik_visitor_id' => Yii::t('app', 'Piwik Visitor ID'), |
|
139
|
|
|
'additional_information' => Yii::t('app', 'Additional Information'), |
|
140
|
|
|
'date_viewed' => Yii::t('app', 'Date Viewed'), |
|
141
|
|
|
'date_processed' => Yii::t('app', 'Date Processed'), |
|
142
|
|
|
'processed_by_user_id' => Yii::t('app', 'Processed By User ID'), |
|
143
|
|
|
'processed' => Yii::t('app', 'Processed'), |
|
144
|
|
|
'internal_comment' => Yii::t('app', 'Internal Comment'), |
|
145
|
|
|
'submission_referrer' => Yii::t('app', 'Submission Referrer'), |
|
146
|
|
|
'visitor_referrer' => Yii::t('app', 'Visitor Referrer'), |
|
147
|
|
|
'visitor_landing' => Yii::t('app', 'Visitor Landing'), |
|
148
|
|
|
'visit_start_date' => Yii::t('app', 'Visit Start Date'), |
|
149
|
|
|
'form_fill_time' => Yii::t('app', 'Form Fill Time'), |
|
150
|
|
|
'spam' => Yii::t('app', 'Spam Info'), |
|
151
|
|
|
'is_deleted' => Yii::t('app', 'Is deleted'), |
|
152
|
|
|
'sending_status' => Yii::t('app', 'Sending status'), |
|
153
|
|
|
]; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function search($params, $form_id = null, $show_deleted = 0) |
|
157
|
|
|
{ |
|
158
|
|
|
/* @var $query \yii\db\ActiveQuery */ |
|
159
|
|
|
$query = self::find(); |
|
160
|
|
|
if ($form_id != null) { |
|
161
|
|
|
$query->andWhere('form_id = :form_id', [':form_id' => $form_id]); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
$query->andFilterWhere(['is_deleted' => $show_deleted]); |
|
165
|
|
|
|
|
166
|
|
|
$dataProvider = new ActiveDataProvider( |
|
167
|
|
|
[ |
|
168
|
|
|
'query' => $query, |
|
169
|
|
|
'pagination' => [ |
|
170
|
|
|
'pageSize' => 10, |
|
171
|
|
|
], |
|
172
|
|
|
] |
|
173
|
|
|
); |
|
174
|
|
|
if (!($this->load($params))) { |
|
175
|
|
|
return $dataProvider; |
|
176
|
|
|
} |
|
177
|
|
|
$query->andFilterWhere(['id' => $this->id]); |
|
178
|
|
|
$query->andFilterWhere(['like', 'ip', $this->ip]); |
|
179
|
|
|
$query->andFilterWhere(['like', 'user_agent', $this->user_agent]); |
|
180
|
|
|
return $dataProvider; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function getForm() |
|
|
|
|
|
|
184
|
|
|
{ |
|
185
|
|
|
return $this->hasOne(Form::className(), ['id' => 'form_id']); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
View Code Duplication |
public static function getStatuses() |
|
189
|
|
|
{ |
|
190
|
|
|
return [ |
|
191
|
|
|
self::STATUS_NEW => Yii::t('app', 'New'), |
|
192
|
|
|
self::STATUS_SUCCESS => Yii::t('app', 'Success'), |
|
193
|
|
|
self::STATUS_ERROR => Yii::t('app', 'Error'), |
|
194
|
|
|
self::STATUS_FATAL_ERROR => Yii::t('app', 'Fatal error'), |
|
195
|
|
|
self::STATUS_HOPELESS_ERROR => Yii::t('app', 'Hopeless error'), |
|
196
|
|
|
]; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.