/**
  * 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 = NewsRubrics::getRoot(new NewsRubrics());
     $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['NewsElements'])) {
         $model->attributes = $_GET['NewsElements'];
     }
     if (isset($_POST['NewsElements'])) {
         $model->attributes = $_POST['NewsElements'];
         $model->imagefile = CUploadedFile::getInstance($model, 'imagefile');
         if (isset($model->imagefile)) {
             $ext = pathinfo($model->imagefile);
             $model->image = $ext['extension'];
         }
         if ($model->save()) {
             if (isset($model->imagefile) && ($modelSettings = SiteModuleSettings::model()->find('site_module_id = 1'))) {
                 //site_module_id = - должен указывать на id модуля в tbl_site_module
                 $filename = $model->id . '.' . $model->image;
                 $filepatch = '/../uploads/filestorage/news/elements/';
                 $model->imagefile->saveAs(YiiBase::getPathOfAlias('webroot') . $filepatch . $filename);
                 //Обработка изображения
                 SiteModuleSettings::model()->chgImgModel($modelSettings, 'GD', 2, $model->id);
             }
             $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));
 }
예제 #2
0
 public function actionIndex()
 {
     $root = NewsRubrics::getRoot(new NewsRubrics());
     $model = $root->descendants(1)->findAll($root->id);
     $modelElements = NewsElements::model()->findAll('parent_id = ' . $root->id . ' AND `status` != 0');
     $this->setSEOData();
     $this->render('index', array('model' => $model, 'modelElements' => $modelElements));
 }
 /**
  * Manages all models.
  */
 public function actionIndex()
 {
     $this->breadcrumbs = array('Новости' => array('/news/newsrubrics/index'));
     set_time_limit(0);
     $model = new NewsRubrics();
     $category = NewsRubrics::getRoot($model);
     $category = NewsRubrics::model()->findByPk($category->id);
     $descendants = $category->descendants(1)->findAll();
     $root = "";
     $param = array();
     $param[] = 'level > 1';
     $param = implode(" AND ", $param);
     $data = array('criteria' => array('condition' => $param));
     $data['sort'] = array('defaultOrder' => 'left_key ASC');
     if ($settingsModel = SiteModuleSettings::model()->find('site_module_id = 6')) {
         $data['Pagination'] = array('PageSize' => (int) $settingsModel->elements_page_admin > 0 ? $settingsModel->elements_page_admin : 100);
     }
     $provider = new CActiveDataProvider('NewsRubrics', $data);
     $provider->criteria = $model->search($param);
     $this->render('list', array('model' => $model, 'provider' => $provider, 'root' => $root, 'categories' => $descendants));
 }