public function run() { $moduleModel = SiteModule::model()->findByPk(4); if (!empty($moduleModel)) { $root = CatalogRubrics::getRoot(); $categories = $root->descendants()->findAll($root->id); $tree = ''; $level = 0; foreach ($categories as $n => $category) { if ($category->status == 1) { if ($category->level == $level) { $tree .= CHtml::closeTag('li') . "\r\n"; } else { if ($category->level > $level) { $tree .= CHtml::openTag('ul') . "\r\n"; } else { $tree .= CHtml::closeTag('li') . "\r\n"; for ($i = $level - $category->level; $i; $i--) { $tree .= CHtml::closeTag('ul') . "\r\n"; $tree .= CHtml::closeTag('li') . "\r\n"; } } } $tree .= CHtml::openTag('li'); $tree .= CHtml::link($category->name, Yii::app()->urlManager->createUrl($moduleModel->url_to_controller . '/element', array('param' => $category->url))); $level = $category->level; } } $tree .= CHtml::closeTag('li') . "\r\n"; $tree .= CHtml::closeTag('ul') . "\r\n"; $data['tree'] = $tree; $this->render('view_Categories', $data); } }
public function actionIndex($model = null) { if (SiteModuleSettings::model()->find('site_module_id = 4 AND `status`=0')) { throw new CHttpException(404, 'The page can not be found.'); } $data = array(); $filters = ''; $data['base_url'] = Pages::getBaseUrl(4); if (empty($model)) { $model = CatalogRubrics::getRoot(); } //Титл и SEO $this->setSEOData($model); $criteria = new CDbCriteria(); $criteria->condition = "parent_id = :parent_id AND status = 1"; $criteria->params = array(":parent_id" => $model->id); $criteria->order = "order_id, id"; $count = CatalogElements::model()->count($criteria); $pages = new CPagination($count); $pages->pageSize = 12; $pages->applyLimit($criteria); $data['elements'] = CatalogElements::model()->findAll($criteria); $data['pages'] = $pages; $data['catalogs'] = $this->getChaildCategory($model, 1); $data['model'] = $model; $this->render('index', $data); }
public function actionSharechars($type_parent = 3) { $this->breadcrumbs = array('Группы товаров' => array('/catalog/catalog/listgroup'), 'Настройки' => array('/catalog/catalog/settings'), 'Список предопределенных характеристик' => array('/catalog/catalog/sharechars')); $model = new CatalogChars('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['CatalogChars'])) { $model->attributes = $_GET['CatalogChars']; } if (isset($_POST['CatalogChars'])) { //Добавляем новую предопределенную характеристику $model->attributes = $_POST['CatalogChars']; $model->type_parent = $type_parent; if ($model->save()) { //Если указано наследование - создаем это свойство для остальных элементов в этом объекте if ($model->inherits == 1) { CatalogChars::model()->addInherits($model, $_POST['CatalogChars']); } else { //Иначе - создаем только для указаного каталога это свойство $model = new CatalogChars(); $model->attributes = $_POST['CatalogChars']; $model->type_parent = 1; $model->save(); } } $model = new CatalogChars('search'); $model->unsetAttributes(); // clear any default values } $param = null; $param[] = 'type_parent = ' . $type_parent; $param[] = 'is_deleted = 0'; $data['sort'] = array('defaultOrder' => 'id DESC'); $data['Pagination'] = array('PageSize' => 100); $provider = new CActiveDataProvider('CatalogChars', $data); $param = implode(" AND ", $param); $provider->criteria = $model->search($param); $root = CatalogRubrics::getRoot(); $catalog = CMap::mergeArray(array($root->id => $root->name), $root->getFormattedDescendants($root->id)); $this->render('sharechars', array('model' => $model, 'provider' => $provider, 'catalog' => $catalog, 'root' => $root)); }