public function loadModel($id) { if (($model = Series::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function actionSeries($alias) { $series = Series::model()->published()->with(array('collection', 'goods' => array('scopes' => 'published', 'order' => 'goods.sort ASC'), 'slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC'), 'images' => array('scopes' => 'published', 'order' => 'images.sort ASC')))->find('t.alias = :alias', array(':alias' => $alias)); if (!$series) { throw new CHttpException(404); } $this->currentCollection = $series->collection; $this->render('series', array('model' => $series)); }
public function actionIndex($alias = '') { //$this->processPageRequest('page'); // Список видов камней $seriesList = Series::model()->published()->findAll(); // Определяем, выбран или нет вид камня $series = null; if (!empty($alias)) { // Если выбран вид камня $series = Series::model()->published()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC')))->find('t.alias = :alias', array(':alias' => $alias)); if (!$series) { throw new CHttpException(404); } $page = $series; } else { // Загружаем страницу "Каталог камня" Yii::import("application.modules.page.models.Page"); $page = Page::model()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC')))->findByPath("catalog"); } // Список товаров $criteria = new CDbCriteria(); $criteria->with = array('images' => array('scopes' => 'published', 'order' => 'images.sort ASC')); $criteria->order = 't.series_id ASC, t.title ASC'; $model = new Stone('user_search'); $model->unsetAttributes(); if (isset($_GET['Stone'])) { $model->attributes = $_GET['Stone']; if ($model->title != '') { $criteria->condition = "(t.title LIKE :title OR t.title_rus LIKE :title)"; $criteria->params = array(':title' => $model->title . '%'); //$criteria->addSearchCondition('t.title', $model->title . '%', false, 'OR'); //$criteria->addSearchCondition('t.title_rus', $model->title . '%', false); } $criteria->addSearchCondition('t.color_id', $model->color_id); } // Если выбран вид камня if (!empty($series)) { $model = $model->series($series->id); } $dataProvider = new CActiveDataProvider($model->published(), array('criteria' => $criteria, 'pagination' => array('pageVar' => 'page'))); if (Yii::app()->request->isAjaxRequest) { // Обновление списка для бесконечной загрузки элементов if (isset($_GET['showMore'])) { $this->renderPartial('_list_ajax', array('dataProvider' => $dataProvider, 'pageNumber' => (int) Yii::app()->request->getParam('page', 1))); } else { $this->renderPartial('_list', array('dataProvider' => $dataProvider), false, true); } Yii::app()->end(); } else { // Вывод каталога $this->render('index', array('page' => $page, 'model' => $model, 'dataProvider' => $dataProvider, 'seriesList' => $seriesList, 'sizerVariants' => $sizerVariants)); } }
protected function beforeAction($action) { $actions = array('index', 'create'); if (in_array($action->id, $actions)) { $this->item_id = (int) Yii::app()->getRequest()->getParam('item_id'); if (!$this->item_id) { throw new CHttpException(400, 'Не установлен ID серии'); } if (($this->item = Series::model()->findByPk($this->item_id)) === null) { throw new CHttpException(404, 'Серия не найдена'); } } return parent::beforeAction($action); }
/** * Список серий: **/ public function getItemsList() { return CHtml::listData(Series::model()->findAll(), 'id', 'title'); }
<?php $this->widget('yupe\\widgets\\OGridView', array('id' => 'item-grid', 'type' => 'condensed', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'id', 'type' => 'raw', 'value' => 'CHtml::link($data->id, $data->url, array("target" => "_blank"))', 'htmlOptions' => array('style' => 'width:40px')), array('name' => 'image', 'type' => 'raw', 'value' => '$data->image ? CHtml::image($data->getImageUrl(220, 150), $data->title) : ""', 'filter' => false, 'sortable' => false, 'htmlOptions' => array('style' => 'width:220px')), array('name' => 'title', 'class' => 'yupe.widgets.CustomEditableColumn', 'editable' => array('placement' => 'right')), array('name' => 'alias', 'class' => 'yupe.widgets.CustomEditableColumn', 'editable' => array('placement' => 'right')), array('name' => 'search_material_id', 'type' => 'raw', 'value' => '$data->material', 'filter' => CHtml::listData(Series::model()->findAll(array('select' => 'id, title', 'order' => 'sort ASC')), 'id', 'title')), array('name' => 'category_id', 'value' => '$data->category->title', 'filter' => $model->categoryList), array('name' => 'color_id', 'value' => '$data->colorTitle', 'filter' => $model->colorList), array('name' => 'sort', 'class' => 'yupe.widgets.CustomEditableColumn', 'htmlOptions' => array('style' => 'width:80px'), 'editable' => array('placement' => 'right', 'success' => 'js: function(response, newValue) { $.fn.yiiGridView.update("item-grid"); }')), array('name' => 'status', 'type' => 'raw', 'value' => '$this->grid->returnBootstrapStatusHtml($data, "status", "Status", array("pencil", "ok-sign"))', 'filter' => $model->getStatusList(), 'sortable' => false), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{images}{update}{delete}', 'buttons' => array('images' => array('icon' => 'picture', 'label' => 'Изображения', 'url' => 'array("/interior/itemImageBackend/index", "item_id" => $data->id)')), 'htmlOptions' => array('style' => 'width: 80px; text-align: right;')))));
public function actionIndex() { exit; // prepare logger to dump logs every time one comes in Yii::getLogger()->autoFlush = 1; Yii::getLogger()->autoDump = true; function getNewFileName($fileName) { $ext = pathinfo($fileName, PATHINFO_EXTENSION); $oldName = pathinfo($fileName, PATHINFO_FILENAME); return md5(uniqid($fileName)) . '.' . $ext; } function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } function logParse($message) { Yii::log($message, CLogger::LEVEL_TRACE, 'parse'); Yii::getLogger()->flush(true); } logParse("Begin"); $begin = getmicrotime(); $regexpArray = array('p' => '~^p\\..+~iU', 'pl' => '~^pl\\..+~iU', 'plx' => '~^plx\\..+~iU'); $titlesArray = array('p' => '', 'pl' => 'Плитка из камня', 'plx' => 'Плитка из камня с подсветкой'); $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->uploadPath . DIRECTORY_SEPARATOR . 'parse_tile'; $seriesList = glob($parsePath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stones = array(); $imagesFiles = array(); // Обработка серий foreach ($seriesList as $skey => $seriesPath) { //if($skey > 1) break; $seriesAlias = basename($seriesPath); if ($seriesAlias == '.' || $seriesAlias == '..') { continue; } $series = Series::model()->findByAlias($seriesAlias); if (is_null($series)) { logParse("Серия " . $seriesAlias . " не найдена"); echo "Серия " . $seriesAlias . " не найдена<br />"; exit; } echo '<h1>' . $series->title . '</h1>'; logParse("Series " . $series->title); $stonesList = glob($seriesPath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stonesCounter = 0; $stoneImagesCounter = 0; $sort = 0; foreach ($stonesList as $stonePath) { $stoneTitle = basename($stonePath); if ($stoneTitle == '.' || $stoneTitle == '..') { continue; } //echo '<h3>' . $stoneTitle . '</h3>'; $stonesCounter++; $sort += 100; $stone = new Stone(); $stone->type_id = 2; $stone->series_id = $series->id; $stone->title = $stoneTitle; $stone->metatitle = $stone->keywords = $stone->description = $stone->title; // Генерация алиаса $alias = \yupe\helpers\YText::translit($stone->title) . '-tile'; if ($stone->findByAlias($alias) !== null) { $alias = $alias . '-' . mt_rand(10000, 99999); } $stone->alias = $alias; $stone->sort = $sort; $imagesList = array(); foreach ($regexpArray as $key => $regexp) { foreach (CFileHelper::findFiles($stonePath) as $file) { //echo $file . '<br />'; if (preg_match($regexp, basename($file))) { $imagesList[$key] = $file; } } } $stoneImages = array(); foreach ($imagesList as $key => $item) { $itemName = basename($item); $newName = getNewFileName($item); $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName); if (preg_match($regexpArray['p'], $itemName)) { $stone->image = $newName; //echo $itemName . '<br />'; } else { $image = new StoneImage(); $image->title = $titlesArray[$key]; $image->image = $newName; $stoneImages[] = $image; } //echo $itemName . '<br />'; $stoneImagesCounter++; } $stone->images = $stoneImages; $stones[] = $stone; } echo 'Камней: ' . $stonesCounter . '<br />'; echo 'Изображений: ' . $stoneImagesCounter . '<br />'; echo '<hr>'; } // Сохраняем камни и изображения в БД foreach ($stones as $stone) { logParse($stone->title); if ($stone->save(false)) { $imagesCounter = 0; foreach ($stone->images as $image) { $imagesCounter += 100; $image->item_id = $stone->id; $image->sort = $imagesCounter; if (!$image->save(false)) { logParse($image->image . ' - error'); echo $image->image . ' - error<br />'; } } logParse('success'); } else { logParse('error'); //echo $stone->title . ' - error<br />'; //var_dump($stone->getErrors()); } } // Копируем изображения foreach ($imagesFiles as $image) { copy($image['fullPath'], Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->getStonesUploadPath() . DIRECTORY_SEPARATOR . $image['newName']); } $end = getmicrotime(); $time = $end - $begin; echo "Время выполнения скрипта: " . $time . "с."; logParse("Время выполнения скрипта: " . $time . "с."); echo '<hr>'; }
public function actionGenerateFolders() { $path = Yii::app()->uploadManager->getBasePath() . '/' . Yii::app()->getModule('catalog')->uploadPath . '/stones'; // Генерируем каталоги серий $series = Series::model()->with(array('stones' => array('order' => 'stones.title ASC')))->findAll(array('order' => 't.sort ASC')); foreach ($series as $curSeries) { $folder = $path . '/' . iconv('utf-8', 'windows-1251', $curSeries->title); echo '<h1>' . $curSeries->title . '</h1>'; @mkdir($folder, 0755); foreach ($curSeries->stones as $key => $stone) { $counter = $key + 1; $stoneFolder = $folder . '/' . iconv('utf-8', 'windows-1251', $stone->title); echo $counter . '. ' . iconv('utf-8', 'windows-1251', $stone->title) . '<br />'; if (file_exists($stoneFolder)) { $stoneFolder .= '_' . $stone->id; } mkdir($stoneFolder, 0755); } } }
public function actionIndex() { // prepare logger to dump logs every time one comes in Yii::getLogger()->autoFlush = 1; Yii::getLogger()->autoDump = true; function getNewFileName($fileName) { $ext = pathinfo($fileName, PATHINFO_EXTENSION); $oldName = pathinfo($fileName, PATHINFO_FILENAME); return md5(uniqid($fileName)) . '.' . $ext; } function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; } function logParse($message) { Yii::log($message, CLogger::LEVEL_TRACE, 'parse'); Yii::getLogger()->flush(true); } logParse("Begin"); $begin = getmicrotime(); /* $regexpArray = array( 'mm' => '~^mm[^x]*\..+~iU', 'fr1' => '~^fr[\d]{0,2}[^x]*\..+~iU', 'sl' => '~^sl[\d]{0,2}[^x]*\..+~iU', 'b1' => '~^b1[^x]*\..+~iU', 'b2' => '~^b2[^x]*\..+~iU', 'frx' => '~^fr[\d]{0,2}x.*\..+~iU', 'slx' => '~^slx.*\..+~iU', 'b1x' => '~^b1x.*\..+~iU', 'b2x' => '~^b2x.*\..+~iU', ); * */ $regexpArray = array('mm' => '~^mm\\..+~iU', 'fr' => '~^fr\\..+~iU', 'fr2' => '~^fr2\\..+~iU', 'sl' => '~^sl\\..+~iU', 'b1' => '~^b1\\..+~iU', 'b2' => '~^b2\\..+~iU', 'frx' => '~^frx.*\\..+~iU', 'slx' => '~^slx.*\\..+~iU', 'b1x' => '~^b1x.*\\..+~iU', 'b2x' => '~^b2x.*\\..+~iU'); $titlesArray = array('mm' => '', 'fr' => 'Фрагмент', 'fr2' => 'Фрагмент 2', 'sl' => 'Слеб', 'b1' => 'Bookmatch 1', 'b2' => 'Bookmatch 2', 'frx' => 'Фрагмент с подсветкой', 'slx' => 'Слеб с подсветкой', 'b1x' => 'Bookmatch 1 с подсветкой', 'b2x' => 'Bookmatch 2 с подсветкой'); $parsePath = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->geParsePath(); $seriesList = glob($parsePath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stones = array(); $imagesFiles = array(); // Обработка серий foreach ($seriesList as $seriesPath) { $seriesAlias = basename($seriesPath); if ($seriesAlias == '.' || $seriesAlias == '..') { continue; } $series = Series::model()->findByAlias($seriesAlias); if (is_null($series)) { logParse("Серия " . $seriesAlias . " не найдена"); echo "Серия " . $seriesAlias . " не найдена<br />"; exit; } echo '<h1>' . $series->title . '</h1>'; logParse("Series " . $series->title); $stonesList = glob($seriesPath . DIRECTORY_SEPARATOR . '*', GLOB_BRACE | GLOB_ONLYDIR); $stonesCounter = 0; $stoneImagesCounter = 0; $sort = 0; foreach ($stonesList as $stonePath) { $stoneTitle = basename($stonePath); if ($stoneTitle == '.' || $stoneTitle == '..') { continue; } //echo '<h3>' . $stoneTitle . '</h3>'; $stonesCounter++; $sort += 100; $stone = new Stone(); $stone->series_id = $series->id; $stone->title = $stoneTitle; $stone->metatitle = $stone->keywords = $stone->description = $stone->title; $stone->generateAlias(); $stone->sort = $sort; $imagesList = array(); foreach ($regexpArray as $key => $regexp) { foreach (CFileHelper::findFiles($stonePath) as $file) { if (preg_match($regexp, basename($file))) { $imagesList[$key] = $file; } } } $stoneImages = array(); foreach ($imagesList as $key => $item) { $itemName = basename($item); $newName = getNewFileName($item); $imagesFiles[] = array('fullPath' => $item, 'name' => $itemName, 'newName' => $newName); if (preg_match($regexpArray['mm'], $itemName)) { $stone->image = $newName; //echo $itemName . '<br />'; } else { $image = new StoneImage(); $image->title = $titlesArray[$key]; $image->image = $newName; $stoneImages[] = $image; } //echo $itemName . '<br />'; $stoneImagesCounter++; } $stone->images = $stoneImages; $stones[] = $stone; } echo 'Камней: ' . $stonesCounter . '<br />'; echo 'Изображений: ' . $stoneImagesCounter . '<br />'; echo '<hr>'; } // Сохраняем камни и изображения в БД foreach ($stones as $stone) { logParse($stone->title); if ($stone->save(false)) { $imagesCounter = 0; foreach ($stone->images as $image) { $imagesCounter += 100; $image->item_id = $stone->id; $image->sort = $imagesCounter; if (!$image->save(false)) { logParse($image->image . ' - error'); echo $image->image . ' - error<br />'; } } logParse('success'); } else { logParse('error'); //echo $stone->title . ' - error<br />'; //var_dump($stone->getErrors()); } } // Копируем изображения foreach ($imagesFiles as $image) { copy($image['fullPath'], Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->module->getStonesUploadPath() . DIRECTORY_SEPARATOR . $image['newName']); } $end = getmicrotime(); $time = $end - $begin; echo "Время выполнения скрипта: " . $time . "с."; logParse("Время выполнения скрипта: " . $time . "с."); echo '<hr>'; }
public function actionSeoColorCountry() { // Цвета $colors = array(); $dictionaryGroup = DictionaryGroup::model()->findByCode('colors'); if ($dictionaryGroup != null) { $colors = $dictionaryGroup->getData(); } if (empty($colors)) { exit('Нет доступных цветов'); } // Страны $countries = array(); $dictionaryGroup = DictionaryGroup::model()->findByCode('country'); if ($dictionaryGroup != null) { $countries = $dictionaryGroup->getData(); } if (empty($countries)) { exit('Нет доступных стран'); } $seoArray = $this->_buildColorCountrySeoArray(); $typesList = ProductType::model()->findAll(array('order' => 't.sort ASC')); $seriesList = Series::model()->findAll(array('order' => 't.sort ASC')); $criteria = new CDbCriteria(); $criteria->select = new CDbExpression('MAX(sort) as sort'); $max = StoneSeoPage::model()->find($criteria); $sort = $max->sort; $counter = 0; foreach ($typesList as $type) { foreach ($seriesList as $series) { foreach ($countries as $country) { foreach ($colors as $color) { $seoKey = $type->id . '_' . $series->id . '_' . $color->id . '_' . $country->id; if (!in_array($seoKey, $seoArray)) { continue; } $counter++; $sort += 10; $seoPage = new StoneSeoPage(); $seoPage->type_id = $type->id; $seoPage->series_id = $series->id; $seoPage->country_id = $country->id; $seoPage->color_id = $color->id; $seoPage->sort = $sort; $countryCases = explode(';', $country->value); if ($type->id == ProductType::STONES_CATALOG_ID) { $seoTitle = $color->name . ' ' . mb_strtolower($series->title, 'UTF-8') . ' из ' . $countryCases[2]; // Страна } else { if (key_exists(2, $series->cases) && $series->cases[2] != '') { $seoTitle = $color->value . ' ' . mb_strtolower($series->cases[2], 'UTF-8') . ' ' . mb_strtolower($type->title_rus, 'UTF-8') . ' из ' . $countryCases[2]; // Страна } else { $seoTitle = $color->value . ' ' . mb_strtolower($type->title_rus, 'UTF-8') . ' из ' . $series->cases[1] . ' из ' . $countryCases[2]; // Страна } } $seoTitle = mb_strtoupper(mb_substr($seoTitle, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($seoTitle, 1, mb_strlen($seoTitle), 'UTF-8'); $seoPage->title = $seoTitle; //$seoPage->save(); echo $counter . '. ' . $seoPage->title . '<br />'; //echo $counter . '. ' . $type->getUrl($series->alias, $color->code, $country->code) . '<br />'; } } } } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Series the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Series::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionIndex($type = '', $series = '') { $type = trim($type); $type = $type == '' ? 'stone' : $type; $productType = ProductType::model()->published()->findByAlias($type); if (!$productType) { throw new CHttpException(404); } $page = $productType; //$this->processPageRequest('page'); $series = trim($series); $filter = array(); $seoFilter = array('series_id' => null, 'color_id' => null, 'country_id' => null); $seoFlag = false; // Список видов камней $seriesList = Series::model()->published()->findAll(array('order' => 't.sort ASC')); // Определяем, выбран или нет вид камня $currentSeries = null; $currentColor = null; $currentCountry = null; if (!empty($series)) { // Если выбран вид камня $currentSeries = Series::model()->published()->with(array('slides' => array('scopes' => 'published', 'order' => 'slides.sort ASC'), 'images' => array('scopes' => 'published', 'order' => 'images.sort ASC')))->find('t.alias = :alias', array(':alias' => $series)); if (!$currentSeries) { throw new CHttpException(404); } $filter['series_id'] = $currentSeries->id; $seoFilter['series_id'] = $currentSeries->id; $seoFlag = true; // Если выбран цвет или страна if (isset($_GET['colorCountry'])) { $code = trim($_GET['colorCountry']); $currentDictData = DictionaryData::model()->active()->with('group')->findByCode($code); if ($currentDictData !== null) { if ($currentDictData->group->code == 'colors') { $currentColor = $currentDictData; $seoFilter['color_id'] = $currentColor->id; } elseif ($currentDictData->group->code == 'country') { $currentCountry = $currentDictData; $seoFilter['country_id'] = $currentCountry->id; } } } // Если выбран только цвет if (isset($_GET['color'])) { $code = trim($_GET['color']); $currentColor = DictionaryData::model()->active()->findByCode($code); if ($currentColor !== null) { $seoFilter['color_id'] = $currentColor->id; } } // Если выбрана только страна if (isset($_GET['country'])) { $code = trim($_GET['country']); $currentCountry = DictionaryData::model()->active()->findByCode($code); if ($currentCountry !== null) { $seoFilter['country_id'] = $currentCountry->id; } } } if ($seoFlag) { $seoPage = StoneSeoPage::model()->published()->type($productType->id)->findByAttributes($seoFilter); $page = $seoPage !== null ? $seoPage : $page; } // Список товаров $model = new Stone('user_search'); $model->unsetAttributes(); $model->type_id = $productType->id; // Если выбран вид камня if (!empty($currentSeries)) { $model->series_id = $currentSeries->id; } // Если выбран цвет камня if (!empty($currentColor)) { $model->color_id = $currentColor->id; $filter['color_id'] = $currentColor->id; } // Если выбрана страна if (!empty($currentCountry)) { $model->country_id = $currentCountry->id; $filter['country_id'] = $currentCountry->id; } if (isset($_GET['Stone'])) { $model->attributes = $_GET['Stone']; if ($model->title != '') { $filter['title'] = $model->title; } if (!empty($model->color_id)) { $filter['color_id'] = $model->color_id; } if (!empty($model->country_id)) { $filter['country_id'] = $model->country_id; } } // Поиск товаров $dataProvider = $model->user_search(); // Сохраняем ссылку для возврата Yii::app()->user->setState('stoneCatalogReturnUrl', Yii::app()->request->requestUri); //var_dump(Yii::app()->user->getState('stoneCatalogReturnUrl')); // Сохраняем данные фильтра в сессии //$filter['page'] = (int) Yii::app()->request->getParam('page', 1); Yii::app()->user->setState('stoneCatalogFilter', $filter); if (Yii::app()->request->isAjaxRequest) { // Обновление списка для бесконечной загрузки элементов if (isset($_GET['showMore'])) { $this->renderPartial('_list_ajax', array('dataProvider' => $dataProvider, 'pageNumber' => (int) Yii::app()->request->getParam('page', 1))); } else { $this->renderPartial('_list', array('dataProvider' => $dataProvider, 'productType' => $productType), false, true); } Yii::app()->end(); } else { // Вывод каталога $this->render('index', array('page' => $page, 'model' => $model, 'dataProvider' => $dataProvider, 'seriesList' => $seriesList, 'series' => $currentSeries, 'productType' => $productType)); } }