1 | <?php |
||
2 | |||
3 | namespace execut\import\models; |
||
4 | |||
5 | use execut\crudFields\Behavior; |
||
6 | use execut\crudFields\BehaviorStub; |
||
7 | use execut\crudFields\fields\Boolean; |
||
8 | use execut\crudFields\fields\DropDown; |
||
9 | use execut\crudFields\fields\Email; |
||
10 | use execut\crudFields\fields\Group; |
||
11 | use execut\crudFields\fields\HasManyMultipleInput; |
||
12 | use execut\crudFields\fields\NumberField; |
||
13 | use execut\crudFields\ModelsHelperTrait; |
||
14 | use execut\import\components\Source; |
||
15 | use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior; |
||
16 | use Yii; |
||
17 | use yii\behaviors\TimestampBehavior; |
||
18 | use yii\db\ActiveRecord; |
||
19 | use yii\db\Expression; |
||
20 | use yii\helpers\ArrayHelper; |
||
21 | use yii\helpers\Json; |
||
22 | |||
23 | /** |
||
24 | * This is the model class for table "import_settings". |
||
25 | * |
||
26 | * @property integer $id |
||
27 | * @property string $created |
||
28 | * @property string $updated |
||
29 | * @property string $name |
||
30 | * @property integer $ignored_lines |
||
31 | * @property string $email |
||
32 | * @property string $email_title_match |
||
33 | * @property string $csv_delimiter |
||
34 | * @property string $csv_enclosure |
||
35 | * @property string $import_files_source_id |
||
36 | * |
||
37 | * @property \execut\import\models\File[] $importFiles |
||
38 | * @property \execut\import\models\FilesSource $importFilesSource |
||
39 | * @property \execut\import\models\SettingsSheet[] $importSettingsSheets |
||
40 | */ |
||
41 | class Setting extends ActiveRecord |
||
42 | { |
||
43 | use ModelsHelperTrait, BehaviorStub; |
||
44 | const MODEL_NAME = '{n,plural,=0{Setting} =1{Setting} other{Settings}}'; |
||
45 | |||
46 | public function rules() |
||
47 | { |
||
48 | return $this->getBehavior('fields')->rules(); |
||
49 | } |
||
50 | |||
51 | public static function find() |
||
52 | { |
||
53 | return new queries\Setting(static::class); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | public static function tableName() |
||
60 | { |
||
61 | return 'import_settings'; |
||
62 | } |
||
63 | |||
64 | public function getSource() { |
||
65 | $adapter = $this->filesSource->getAdapterForSetting($this); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
66 | $source = new Source([ |
||
67 | 'adapter' => $adapter, |
||
68 | ]); |
||
69 | |||
70 | return $source; |
||
71 | } |
||
72 | |||
73 | public function behaviors() |
||
74 | { |
||
75 | return [ |
||
76 | 'relationsSaver' => [ |
||
77 | 'class' => SaveRelationsBehavior::class, |
||
78 | 'relations' => [ |
||
79 | 'settingsSheets' |
||
80 | ], |
||
81 | ], |
||
82 | 'fields' => [ |
||
83 | 'class' => Behavior::class, |
||
84 | 'module' => 'import', |
||
85 | 'fields' => $this->getStandardFields(['visible'], [ |
||
86 | 'ignored_lines' => [ |
||
87 | 'class' => NumberField::class, |
||
88 | 'attribute' => 'ignored_lines', |
||
89 | 'required' => true, |
||
90 | ], |
||
91 | 'is_check_mime_type' => [ |
||
92 | 'class' => Boolean::class, |
||
93 | 'attribute' => 'is_check_mime_type', |
||
94 | ], |
||
95 | 'import_files_source_id' => [ |
||
96 | 'class' => DropDown::class, |
||
97 | 'attribute' => 'import_files_source_id', |
||
98 | 'relation' => 'filesSource', |
||
99 | 'required' => true, |
||
100 | ], |
||
101 | 'csvGroup' => [ |
||
102 | 'class' => Group::class, |
||
103 | 'label'=>'Настройки Csv', |
||
104 | ], |
||
105 | 'csv_delimiter' => [ |
||
106 | 'attribute' => 'csv_delimiter', |
||
107 | ], |
||
108 | 'csv_enclosure' => [ |
||
109 | 'attribute' => 'csv_enclosure', |
||
110 | ], |
||
111 | 'emailGroup' => [ |
||
112 | 'class' => Group::class, |
||
113 | 'label'=>'Настройки Email', |
||
114 | ], |
||
115 | 'email' => [ |
||
116 | 'class' => Email::class, |
||
117 | 'attribute' => 'email', |
||
118 | ], |
||
119 | 'email_title_match' => [ |
||
120 | 'attribute'=> 'email_title_match', |
||
121 | ], |
||
122 | 'email_attachment_template' => [ |
||
123 | 'attribute' => 'email_attachment_template', |
||
124 | ], |
||
125 | 'import_files_encoding_id' => [ |
||
126 | 'class' => DropDown::class, |
||
127 | 'attribute' => 'import_files_encoding_id', |
||
128 | 'relation' => 'filesEncoding', |
||
129 | 'required' => true, |
||
130 | ], |
||
131 | 'ftpGroup' => [ |
||
132 | 'class' => Group::class, |
||
133 | 'label'=>'Настройки FTP', |
||
134 | ], |
||
135 | 'ftp_host' => [ |
||
136 | 'attribute' => 'ftp_host', |
||
137 | ], |
||
138 | 'ftp_ssl' => [ |
||
139 | 'class' => Boolean::class, |
||
140 | 'attribute' => 'ftp_ssl', |
||
141 | 'defaultValue' => false, |
||
142 | ], |
||
143 | 'ftp_port' => [ |
||
144 | 'attribute' => 'ftp_port', |
||
145 | ], |
||
146 | 'ftp_timeout' => [ |
||
147 | 'attribute' => 'ftp_timeout', |
||
148 | ], |
||
149 | 'ftp_login' => [ |
||
150 | 'attribute' => 'ftp_login', |
||
151 | ], |
||
152 | 'ftp_password' => [ |
||
153 | 'attribute' => 'ftp_password', |
||
154 | ], |
||
155 | 'ftp_dir' => [ |
||
156 | 'attribute' => 'ftp_dir', |
||
157 | ], |
||
158 | 'ftp_file_name' => [ |
||
159 | 'attribute' => 'ftp_file_name', |
||
160 | ], |
||
161 | 'siteSettingsGroup' => [ |
||
162 | 'class' => Group::class, |
||
163 | 'label'=>'Настройки Сайта', |
||
164 | ], |
||
165 | 'site_host' => [ |
||
166 | 'attribute' => 'site_host', |
||
167 | ], |
||
168 | 'site_auth_url' => [ |
||
169 | 'attribute' => 'site_auth_url', |
||
170 | ], |
||
171 | 'site_auth_method' => [ |
||
172 | 'attribute' => 'site_auth_method', |
||
173 | ], |
||
174 | 'site_login_field' => [ |
||
175 | 'attribute' => 'site_login_field', |
||
176 | ], |
||
177 | 'site_password_field' => [ |
||
178 | 'attribute' => 'site_password_field', |
||
179 | ], |
||
180 | 'site_other_fields' => [ |
||
181 | 'attribute' => 'site_other_fields', |
||
182 | ], |
||
183 | 'site_login' => [ |
||
184 | 'attribute' => 'site_login', |
||
185 | ], |
||
186 | 'site_password' => [ |
||
187 | 'attribute' => 'site_password', |
||
188 | ], |
||
189 | 'site_file_url' => [ |
||
190 | 'attribute' => 'site_file_url', |
||
191 | ], |
||
192 | 'sheetsGroup' => [ |
||
193 | 'class' => Group::class, |
||
194 | 'label' => 'Листы', |
||
195 | ], |
||
196 | 'settingsSheets' => [ |
||
197 | 'class' => HasManyMultipleInput::class, |
||
198 | 'attribute' => 'settingsSheets', |
||
199 | 'relation' => 'settingsSheets', |
||
200 | 'column' => false, |
||
201 | ], |
||
202 | ]), |
||
203 | 'plugins' => \yii::$app->getModule('import')->getSettingsCrudFieldsPlugins(), |
||
204 | ], |
||
205 | 'date' => [ |
||
206 | 'class' => TimestampBehavior::class, |
||
207 | 'createdAtAttribute' => 'created', |
||
208 | 'updatedAtAttribute' => 'updated', |
||
209 | 'value' => new Expression('NOW()'), |
||
210 | ], |
||
211 | ]; |
||
212 | } |
||
213 | |||
214 | public static function getFilesSourcesList() { |
||
215 | return ArrayHelper::map(FilesSource::find()->all(), 'id', 'name'); |
||
216 | } |
||
217 | |||
218 | public function getSiteOtherFields() { |
||
219 | if (!empty($this->site_other_fields)) { |
||
0 ignored issues
–
show
The property
site_other_fields does not exist on execut\import\models\Setting . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
220 | return Json::decode($this->site_other_fields); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | public function delete() |
||
225 | { |
||
226 | foreach ($this->importSettingsVsSchedulerEvents as $event) { |
||
0 ignored issues
–
show
The property
importSettingsVsSchedulerEvents does not exist on execut\import\models\Setting . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
227 | $event->delete(); |
||
228 | } |
||
229 | |||
230 | foreach ($this->settingsSheets as $sheet) { |
||
0 ignored issues
–
show
The property
settingsSheets does not exist on execut\import\models\Setting . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
231 | $sheet->delete(); |
||
232 | } |
||
233 | |||
234 | foreach ($this->files as $sheet) { |
||
0 ignored issues
–
show
The property
files does not exist on execut\import\models\Setting . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
235 | $sheet->delete(); |
||
236 | } |
||
237 | |||
238 | return parent::delete(); // TODO: Change the autogenerated stub |
||
239 | } |
||
240 | |||
241 | public function __toString() |
||
242 | { |
||
243 | return '#' . $this->id . ' ' . $this->name; |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @return \yii\db\ActiveQuery |
||
248 | */ |
||
249 | public function getFiles() |
||
250 | { |
||
251 | return $this->hasMany(\execut\import\models\File::class, ['import_setting_id' => 'id'])->inverseOf('importSetting'); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @return \yii\db\ActiveQuery |
||
256 | */ |
||
257 | public function getFilesEncoding() |
||
258 | { |
||
259 | return $this->hasOne(\execut\import\models\FilesEncoding::class, ['id' => 'import_files_encoding_id'])->inverseOf('settings'); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @return \yii\db\ActiveQuery |
||
264 | */ |
||
265 | public function getFilesSource() |
||
266 | { |
||
267 | return $this->hasOne(\execut\import\models\FilesSource::class, ['id' => 'import_files_source_id'])->inverseOf('settings'); |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * @return \yii\db\ActiveQuery |
||
272 | */ |
||
273 | public function getSettingsSheets() |
||
274 | { |
||
275 | return $this->hasMany(\execut\import\models\SettingsSheet::class, ['import_setting_id' => 'id'])->inverseOf('setting'); |
||
276 | } |
||
277 | } |
||
278 |