-
Notifications
You must be signed in to change notification settings - Fork 2
/
PriceController.php
145 lines (128 loc) · 4.11 KB
/
PriceController.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
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* PriceController class for price module
*
* @author Sviatoslav Danylenko <Sviatoslav.Danylenko@udf.su>
* @package hamster.modules.price.controllers.PriceController
* @copyright Copyright © 2012 Sviatoslav Danylenko (http://hamstercms.com)
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
*/
class PriceController extends Controller
{
//TODO: нужно сохранять прайсы в защищенной дириктории и выдавать их по экшену только необходимым людям
public $layout='//layouts/column3';
/**
* @return array action filters
*/
/*public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}*/
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array();
/*return array(
array('allow',
'roles'=>array('price.access'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);*/
}
/**
* Отображает прайсы и фильтрует их позиции на основе информации из GET запроса
*
* @access public
* @return void
*/
public function actionIndex()
{
$config = HPrice::getConfig();
$chooseInvitation = $priceChoises[''] = 'Не важно';
// меню фильтрации по файлам прайсов
foreach($config as $price)
if(isset($price['id']))
{
$priceChoises[$price['id']] = $price['name'];
// добываем список категорий
foreach(array_keys($price['columns']['cat']) as $curCat)
{
if(!isset($cats[$curCat . '_id']))
{
if(isset($_GET['Price']['file_id']))
$catsData = PriceCat::model($curCat)->findAllByAttributes(array('file_id' => (int)$_GET['Price']['file_id']));
else
$catsData = PriceCat::model($curCat)->findAll();
$cats[$curCat . '_id'][''] = $chooseInvitation;
foreach($catsData as $cat)
$cats[$curCat . '_id'][$cat->primaryKey] = $cat->name;
}
}
}
$prod = new Price('search');
if($_GET['Price'])
$prod->attributes = $_GET['Price'];
$dataProvider = $prod->search();
$this->pushAside(array(
'block_filter',
'prod' => $prod,
'cats' => $cats,
),
array(
'title' => 'Фильтр',
'position' => 'top',
));
// колонки для таблицы
// TODO: перенести в модель всю инфу о колонках
$columns = array(
'code',
'name',
'price',
);
foreach(array_keys($cats) as $cat)
$columns[] = str_replace('_id', 'Name', $cat);
// TODO: названия колонок должны генерироваться в модели
if(is_array(($extra = $config['extraLabels'])))
foreach($extra as $attribute => $name)
$columns[] = array(
'name' => $name,
'header' => $name,
'value' => '$data->extra["' . $attribute . '"]',
);
$priceTable = $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>$columns,
'pager'=>array(
'cssFile'=>false,
'header'=>false,
'maxButtonCount' => 8,
),
'cssFile'=>false,
'summaryText' => false,
'enableHistory' => true,
), true);
$priceDownloadMenu = array();
// список прайсов
foreach( new DirectoryIterator(HPrice::getPricePath()) as $file) {
if( $file->isFile() === TRUE && substr($file->getBasename(), 0, 1) != '.')
$priceDownloadMenu[] = array(
'name' => $file->getBasename(),
'link' => HPrice::getPriceUrl() . '/' . $file->getBasename(),
);
}
$this->render('index', array(
'priceTable' => $priceTable,
'priceDownloadMenu' => array(
'elements' => $priceDownloadMenu,
),
));
}
}