Item.php
2.78 KB
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
<?php
namespace backend\modules\map\models;
use Yii;
use ZipArchive;
/**
* Class Item
* @package backend\modules\map\models
* @author Alla Kuzmenko
* @copyright (c), Thread
*/
class Item extends \common\modules\map\models\Item
{
/**
* @param $params
* @return \yii\data\ActiveDataProvider
*/
public function search($params)
{
return (new search\Item())->search($params);
}
/**
* @param $params
* @return \yii\data\ActiveDataProvider
*/
public function trash($params)
{
return (new search\Item())->trash($params);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTypeItem()
{
return $this->hasOne(Type::class, ['id' => 'type_id']);
}
/**
* @return array
*/
public static function type_of_promoterKeyRange()
{
$l = Yii::$app->params['themes']['language'];
Yii::$app->params['themes']['language'] = Yii::$app->language;
$r = [
'Municipal project' => Yii::t('map', 'Municipal project'),
'Commercial project' => Yii::t('map', 'Commercial project'),
];
Yii::$app->params['themes']['language'] = $l;
return $r;
}
/**
* @return array
*/
public static function current_stage_of_project_developmentKeyRange()
{
$l = Yii::$app->params['themes']['language'];
Yii::$app->params['themes']['language'] = Yii::$app->language;
$r = [
// 'Idea' => Yii::t('map', 'Idea'),
'Under development' => Yii::t('map', 'Under development'),
'Ready to build' => Yii::t('map', 'Ready to build'),
// 'Turnkey' => Yii::t('map', 'Turnkey'),
'Operating' => Yii::t('map', 'Operating'),
'Expansion' => Yii::t('map', 'Expansion'),
];
Yii::$app->params['themes']['language'] = $l;
return $r;
}
public function afterSave($insert, $changedAttributes)
{
if (isset($changedAttributes['gallery_file'])) {
if (is_file($this->module->getItemUploadPath() . $this->getArchiveName())) {
unlink($this->module->getItemUploadPath() . $this->getArchiveName());
}
$files = $this->getGalleryFileLink();
if (!empty($files)) {
//собираем архив
$zip = new ZipArchive();
if ($zip->open('..' . $this->module->getItemUploadUrl() . $this->getArchiveName(), ZIPARCHIVE::CREATE)) {
foreach ($files as $file) {
$zip->addFile('..' . $file);
}
}
$zip->close(); //Завершаем работу с архивом
}
}
parent::afterSave($insert, $changedAttributes);
}
}