public function actionIndex() { //Общий список категорий вопросов $root = FaqRubrics::getRoot(new FaqRubrics()); //Титл и SEO $this->setSEO(Yii::app()->request->requestUri, 'Вопрос-ответ', $root); $model['rubrics'] = $root->descendants(1)->findAll($root->id); $model['elements'] = FaqElements::model()->findAll('parent_id = ' . $root->id); $this->render('index', array('root' => $root, 'model' => $model)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'update' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $root = FaqRubrics::getRoot(new FaqRubrics()); $catalog = $root->descendants()->findAll($root->id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // set attributes from get if (isset($_GET['FaqElements'])) { $model->attributes = $_GET['FaqElements']; } if (isset($_POST['FaqElements'])) { $model->attributes = $_POST['FaqElements']; if ($model->save()) { $url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id); $this->redirect($url); } } $this->render('update', array('model' => $model, 'root' => $root, 'catalog' => $catalog)); }
/** * Manages all models. */ public function actionIndex($id = null) { $this->breadcrumbs = array('Вопрос-ответ' => array('/faq/faqrubrics/index')); set_time_limit(0); //получаем URL $base_patch = SITE_NAME_FULL . '/question'; if (!empty($id)) { $model = FaqRubrics::model()->findByPk((int) $id); if ($model) { $i = (int) $id; $array = array(); do { $model = FaqRubrics::model()->findByPk((int) $i); if (isset($model->id)) { $array[] = $model->id; } $i = (int) $model->parent_id; } while ($i != 0); $array = array_reverse($array); unset($array[0]); foreach ($array as $value) { $base_patch .= '/' . FaqRubrics::model()->findByPk((int) $value)->url; } } } if (!empty($id)) { $model = FaqRubrics::model()->findByPk((int) $id); $root = FaqRubrics::getRoot($model); $category = FaqRubrics::model()->findByPk((int) $id); //Получаем нужный узел $descendants = $category->descendants(1)->findAll(); $param[] = 'left_key > ' . $model->left_key . ' AND right_key < ' . $model->right_key; } else { $model = new FaqRubrics(); $category = FaqRubrics::getRoot($model); $category = FaqRubrics::model()->findByPk($category->id); $descendants = $category->descendants(1)->findAll(); $root = ""; $param[] = 'level=2'; } $model = new FaqRubrics(); $param = implode(" AND ", $param); $data = array('criteria' => array('condition' => $param)); if ($settingsModel = SiteModuleSettings::model()->find('site_module_id = 7')) { $data['Pagination'] = array('PageSize' => (int) $settingsModel->elements_page_admin > 0 ? $settingsModel->elements_page_admin : 100); } $data['sort'] = array('defaultOrder' => 'left_key ASC'); $provider = new CActiveDataProvider('FaqRubrics', $data); $provider->criteria = $model->search($param); $this->render('list', array('model' => $model, 'provider' => $provider, 'root' => $root, 'categories' => $descendants, 'base_patch' => $base_patch)); }