diff --git a/.initialCss/price/style.css b/.initialCss/price/style.css
index 02564b0..5fa859b 100644
--- a/.initialCss/price/style.css
+++ b/.initialCss/price/style.css
@@ -14,7 +14,7 @@
}
.priceDownload a {
- display:block;
+ display:inline-block;
line-height: 28px;
font-size: 15px;
background:url('../images/icon_excel.png') no-repeat;
diff --git a/protected/modules/price/admin/AdminAction.php b/protected/modules/price/admin/AdminAction.php
index 23c40f5..71626c4 100644
--- a/protected/modules/price/admin/AdminAction.php
+++ b/protected/modules/price/admin/AdminAction.php
@@ -149,12 +149,12 @@ public function actionIndex()
. CHtml::endForm();
?>
- Очистить БД от всех прайсов - полностью очищает базу данных от содержимого прайсов. (использовать, когда нужно обновить прайсы в базе данных)
diff --git a/protected/modules/price/components/HPriceBase.php b/protected/modules/price/components/HPriceBase.php
index 719db66..52f78f1 100644
--- a/protected/modules/price/components/HPriceBase.php
+++ b/protected/modules/price/components/HPriceBase.php
@@ -436,11 +436,11 @@ protected function queryArray(array $array)
}
$connection->createCommand($catsSql)->execute();
- // получаем категории
+ // получаем id категорий для вставки в основную таблицу прайсов
foreach(array_keys($cats) as $catId)
{
// переключаем модель на нужную нам таблицу
- $allCats = PriceCat::model('price_' . $catId)->findAll();
+ $allCats = PriceCat::model($catId)->findAll();
foreach($allCats as $cat)
{
$catTockens['{' . $catId . $cat->name . '}'] = $cat->primaryKey;
diff --git a/protected/modules/price/controllers/PriceController.php b/protected/modules/price/controllers/PriceController.php
index 764d2c0..f5ea01d 100644
--- a/protected/modules/price/controllers/PriceController.php
+++ b/protected/modules/price/controllers/PriceController.php
@@ -9,7 +9,7 @@
*/
class PriceController extends Controller
{
- //TODO: можно сохранять прайсы в защищенной дириктории и выдавать их по экшену только необходимым людям
+ //TODO: нужно сохранять прайсы в защищенной дириктории и выдавать их по экшену только необходимым людям
public $layout='//layouts/column3';
/**
* @return array action filters
@@ -49,7 +49,7 @@ public function actionIndex()
{
$config = HPrice::getConfig();
- $choseInvitation = $priceChoises[''] = 'Не важно';
+ $chooseInvitation = $priceChoises[''] = 'Не важно';
// меню фильтрации по файлам прайсов
foreach($config as $price)
if(isset($price['id']))
@@ -61,38 +61,85 @@ public function actionIndex()
{
if(!isset($cats[$curCat . '_id']))
{
- $catsData = PriceCat::model($curCat)->findAllByAttributes(array('file_id' => (int)$_GET['Price']['file_id']));
- $label = isset($config['attributeLabels'][$curCat])
- ? $config['attributeLabels'][$curCat]
- : 'Категория';
- $cats[$curCat . '_id'][''] = $choseInvitation;
+ 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;
}
}
}
-
- $priceDownloadMenu = array();
- // список файлов в директории
- foreach( new DirectoryIterator(HPrice::getPricePath()) as $file) {
- if( $file->isFile() === TRUE && substr($file->getBasename(), 0, 1) != '.')
- $priceDownloadMenu[HPrice::getPriceUrl() . '/' . $file->getBasename()] = $file->getBasename();
- }
$prod = new Price('search');
if($_GET['Price'])
$prod->attributes = $_GET['Price'];
$dataProvider = $prod->search();
-
- $this->render('index', array(
- 'brands' => $brands,
- 'cats' => $cats,
+
+
+ $this->pushAside(array(
+ 'block_filter',
'prod' => $prod,
- 'config' => $config,
- 'priceChoises' => $priceChoises,
- 'dataProvider' => $dataProvider,
- 'priceDownloadMenu' => $priceDownloadMenu,
+ '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,
+ ),
));
}
}
diff --git a/protected/modules/price/models/Price.php b/protected/modules/price/models/Price.php
index 5de98fa..761a6d3 100644
--- a/protected/modules/price/models/Price.php
+++ b/protected/modules/price/models/Price.php
@@ -113,7 +113,6 @@ public function attributeLabels()
return array_merge(array(
'code' => 'Код',
- 'cat_id' => 'Категория',
'name' => 'Наименование товара',
'price' => 'Цена, грн.',
'min' => 'От',
@@ -188,17 +187,30 @@ public function __get($name)
{
$tableId = $matches[1];
if(!isset(self::$catNames[$tableId]))
- {
// в методе {@link PriceCat::findAll()} сразу после выборки
// будет заполнен необходимый нам массив {@link Price::$catNames}
- $models = PriceCat::model($tableId)->findAll();
- }
+ PriceCat::model($tableId)->findAll();
return self::$catNames[$tableId][$this->{$tableId . '_id'}];
}
return parent::__get($name);
}
+ /**
+ * Добавляет функционал необходимый для переопределенного геттера
+ *
+ * @param mixed $att
+ * @access public
+ * @return void
+ */
+ public function __isset($att)
+ {
+ if(preg_match('/^(\w+)Name$/', $att))
+ return true;
+
+ return parent::__isset($att);
+ }
+
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
diff --git a/protected/modules/price/models/PriceCat.php b/protected/modules/price/models/PriceCat.php
index cbccde7..6b46843 100644
--- a/protected/modules/price/models/PriceCat.php
+++ b/protected/modules/price/models/PriceCat.php
@@ -19,7 +19,7 @@ class PriceCat extends CActiveRecord
* @property string $tableName таблица для которой инициализируется модель по умолчанию,
* если при вызове метода {@link PriceCat::model()} не задать другую
*/
- private $tableName = 'price_cat';
+ private $_tableName = 'price_cat';
/**
* @property array $_models используется аналогичным образом как и такая же переменная в родительском классе
@@ -52,7 +52,7 @@ public static function model($tableName = false, $className=__CLASS__)
else
{
$model=self::$_models[$tableName.$className]=new $className(null);
- $model->tableName = $tableName;
+ $model->_tableName = $tableName;
$model->_md=new CActiveRecordMetaData($model);
$model->attachBehaviors($model->behaviors());
return $model;
@@ -64,7 +64,7 @@ public static function model($tableName = false, $className=__CLASS__)
*/
public function tableName()
{
- return $this->tableName;
+ return $this->_tableName;
}
/**
@@ -126,6 +126,8 @@ public function attributeLabels()
public function findAll($condition='',$params=array())
{
$models = parent::findAll($condition,$params);
+
+ // кешируем названия категорий
if(!isset(Price::$catNames[$tableId]))
{
$tableId = str_replace('price_','', $this->tableName());
@@ -134,4 +136,16 @@ public function findAll($condition='',$params=array())
}
return $models;
}
+
+ /**
+ * Returns the meta-data for this AR
+ * @return CActiveRecordMetaData the meta for this AR class.
+ */
+ public function getMetaData()
+ {
+ if($this->_md!==null)
+ return $this->_md;
+ else
+ return $this->_md=self::model($this->tableName())->_md;
+ }
}
diff --git a/protected/modules/price/views/price/block_filter.php b/protected/modules/price/views/price/block_filter.php
new file mode 100644
index 0000000..89e9a6d
--- /dev/null
+++ b/protected/modules/price/views/price/block_filter.php
@@ -0,0 +1,34 @@
+';
+ $action = preg_replace('/\?[^\?]*$/','',$_SERVER["REQUEST_URI"]);
+ $form = $this->beginWidget('CActiveForm', array(
+ 'id'=>'priceFilterForm',
+ 'method'=>'get',
+ 'action'=>$action,
+ 'enableAjaxValidation'=>false,
+ 'enableClientValidation'=>false,
+ ));
+
+ echo '' . $form->labelEx($prod, 'name') . $form->textField($prod, 'name') . '
';
+ // FIXME: убрано до лучших времен. нужно либо сделать настроку отображения фильтрации
+ // по файлам в админке, либо отказаться от этого функционала
+ // echo '' . $form->labelEx($prod, 'file_id') . $form->dropDownList($prod, 'file_id', $priceChoises) . '
';
+ foreach($cats as $columnId => $cat)
+ echo '' . $form->labelEx($prod, $columnId) . $form->dropDownList($prod, $columnId, $cat) . '
';
+
+ $this->widget('ext.jui.HFilterRangeSlider', array(
+ 'model'=>$prod,
+ 'attribute'=>'min',
+ 'maxAttribute'=>'max',
+ // additional javascript options for the slider plugin
+ 'options'=>array(
+ 'range'=>true,
+ 'min'=>$prod->minValue,
+ 'max'=>$prod->maxValue,
+ ),
+ ));
+ echo '
' . CHtml::submitButton('Поиск') . '
';
+
+ $this->endWidget();
+
+ echo '';
diff --git a/protected/modules/price/views/price/index.mustache b/protected/modules/price/views/price/index.mustache
new file mode 100644
index 0000000..4636c03
--- /dev/null
+++ b/protected/modules/price/views/price/index.mustache
@@ -0,0 +1,32 @@
+{{# hamster }}
+ {{# title }}Прайсы{{/ title }}
+ {{!$this->breadcrumbs = array($this->pageTitle);}}
+
+{{ title }}
+{{/ hamster }}
+
+{{# priceDownloadMenu }}
+
+{{/ priceDownloadMenu }}
+
+{{# hamster.js }}
+ {{! скрипт для анимации и отображения прайсов }}
+ $(function() {
+ $('#priceDownloadLink').click(function() {
+ $(this).next().show('normal');
+ $(this).remove();
+
+ return false;
+ });
+ });
+{{/ hamster.js }}
+
+{{! выводим таблицу с прайсами }}
+{{{ priceTable }}}
\ No newline at end of file
diff --git a/protected/modules/price/views/price/index.php b/protected/modules/price/views/price/index.php
deleted file mode 100644
index 345f73f..0000000
--- a/protected/modules/price/views/price/index.php
+++ /dev/null
@@ -1,107 +0,0 @@
-pageTitle = 'Прайсы';
-$this->breadcrumbs = array($this->pageTitle);
-
-echo '' . $this->pageTitle . '
';
-$this->beginAside('', array(
- 'title' => 'Фильтр',
- 'position' => 'top',
-));
-echo '';
-$action = preg_replace('/\?[^\?]*$/','',$_SERVER["REQUEST_URI"]);
-$form = $this->beginWidget(array(
- 'id'=>'priceFilterForm',
- 'method'=>'get',
- 'action'=>$action,
- 'enableAjaxValidation'=>false,
- 'enableClientValidation'=>false,
-));
-
-echo '
' . $form->labelEx($prod, 'name') . $form->textField($prod, 'name') . '
';
-// FIXME: убрано до лучших времен. нужно либо сделать настроку отображения фильтрации
-// по файлам в админке, либо отказаться от этого функционала
-// echo '
' . $form->labelEx($prod, 'file_id') . $form->dropDownList($prod, 'file_id', $priceChoises) . '
';
-foreach($cats as $columnId => $cat)
- echo '
' . $form->labelEx($prod, $columnId) . $form->dropDownList($prod, $columnId, $cat) . '
';
-
-$this->widget('ext.jui.HFilterRangeSlider', array(
- 'model'=>$prod,
- 'attribute'=>'min',
- 'maxAttribute'=>'max',
- // additional javascript options for the slider plugin
- 'options'=>array(
- 'range'=>true,
- 'min'=>$prod->minValue,
- 'max'=>$prod->maxValue,
- ),
-));
-echo '
' . CHtml::submitButton('Поиск') . '
';
-
-$this->endWidget();
-
-echo '
';
-$this->endAside();
-?>
-
-
-
-Скачать прайсы
-
- $name)
- {
- echo '- ' . CHtml::link($name, $link) . '
';
- }
-?>
-
-
-
-$(function() {
- $('#priceDownloadLink').click(function() {
- $(this).next().show('normal');
- $(this).remove();
-
- return false;
- });
-});
-clientScript->registerScript(__CLASS__, ob_get_clean(), CClientScript::POS_END);
-
-$columns = array(
- 'code',
- 'name',
- 'price',
-);
-
-foreach(array_keys($cats) as $cat)
- $columns[] = str_replace('_id', '', $cat) . 'Name';
-
-if(is_array(($extra = $config['extraLabels'])))
- foreach($extra as $attribute => $name)
- $columns[] = array(
- 'name' => $name,
- 'header' => $name,
- 'value' => '$data->extra["' . $attribute . '"]',
- );
-
-$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,
-));
diff --git a/protected/views/page/index.php b/protected/views/page/index.php
deleted file mode 100644
index d239b24..0000000
--- a/protected/views/page/index.php
+++ /dev/null
@@ -1,18 +0,0 @@
-breadcrumbs=array(
- $model->title
-);
-
-$this->pageTitle = $model->title;
-?>
-
-
-beginWidget('application.widgets.lightbox.HLightBox');
-
-echo $model->content;
-
-$this->endWidget('application.widgets.lightbox.HLightBox');
-?>
-
-