/**
  * 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));
 }
Ejemplo n.º 2
0
 public function actionElement($param)
 {
     $paramArr = explode("/", $param);
     $paramArr = array_pop($paramArr);
     $paramArr = strtolower($paramArr);
     if (is_numeric($paramArr)) {
         $modelElements = NewsElements::model()->findByPk($paramArr);
         $model = NewsRubrics::model()->findByPk($modelElements->parent_id);
         if (!$modelElements) {
             throw new CHttpException(404, 'The page can not be found.');
         }
         $this->setSEOData($modelElements);
         $pageArray = array();
         $i = 0;
         foreach ($model->ancestors()->findAll() as $data) {
             if ($data->level == 1) {
                 continue;
             }
             $pageArray[$i]['url'] = $data->url;
             $pageArray[$i]['name'] = $data->name;
             ++$i;
         }
         $pageArray[$i]['url'] = $model->url;
         $pageArray[$i]['name'] = $model->name;
         if (count($pageArray) > 1) {
             rsort($pageArray);
         }
         $model = $model->descendants(1)->findAll($model->id);
         $render = 'view';
     } else {
         if ($modelPage = Pages::model()->find('url LIKE "' . $param . '"')) {
             if ($modelTabs = PagesTabs::model()->find('pages_id=' . $modelPage->id)) {
                 $module_id = array_diff(explode("|", $modelTabs->site_module_value), array(''));
                 if ($tmpParam = NewsRubrics::model()->find('id in (' . current($module_id) . ') AND `status` = 1')) {
                     $paramArr = $tmpParam->url;
                 }
             }
         }
         $model = NewsRubrics::model()->find('url LIKE "' . $paramArr . '"');
         if (!$model) {
             throw new CHttpException(404, 'The page can not be found.');
         }
         $this->setSEO(Yii::app()->request->requestUri, 'Статьи', $model);
         $pageArray = array();
         $pageArray[0]['name'] = ' / ' . $model->name;
         $pageArray[0]['url'] = null;
         $i = 1;
         foreach ($model->ancestors()->findAll('level>1') as $data) {
             $pageArray[$i]['name'] = ' / ' . $data->name;
             $pageArray[$i]['url'] = 'news/' . $data->url;
             ++$i;
         }
         rsort($pageArray);
         if (count($pageArray) > 1) {
             rsort($pageArray);
         }
         $modelElements = NewsElements::model()->findAll('parent_id = ' . $model->id . ' AND `status`=1 ORDER BY `primary` DESC');
         $model = $model->descendants(1)->findAll($model->id);
         $render = 'index';
     }
     $this->render($render, array('model' => $model, 'modelElements' => $modelElements, 'pageArray' => $pageArray));
 }
Ejemplo n.º 3
0
        $url_img = '/../uploads/filestorage/news/rubrics/admin-' . $dataProvider->id . '.' . $dataProvider->image;
    }
    return '<img src="' . $url_img . '" style="width:80px" />';
}, 'filter' => ''), array('header' => $labels["name"], 'type' => 'raw', 'value' => function ($data) {
    $return = '';
    //Если это level = 2 - вывожу выделеным черным шрифтом
    if ($data->level == 2) {
        $return = '<b>' . $data->name . '</b>';
    } else {
        //подчиненная категория - вывожу со смещением относительно родительской
        $repeat_prefix = $data->level == 3 ? $data->level : $data->level + 1;
        $return = str_repeat('&nbsp&nbsp', $repeat_prefix) . $data->name;
    }
    return $return;
}, 'filter' => ''), array('header' => 'Элементов', 'type' => 'raw', 'value' => function ($data) {
    $count = NewsRubrics::getCountElement($data->id);
    return '
                    <a href="/admin/news/newselements/index?NewsElements[parent_id]=' . $data->id . '">
                        <b>' . $count . '</b>
                    </a>
                ';
}, 'filter' => ''), array('header' => 'Статус', 'name' => "status", 'type' => 'raw', 'value' => function ($data) {
    return '
                    <a href="#" class="on-off-product" data-id="' . $data->id . '" data-status="' . $data->status . '">
                        <div style="margin-left:20px; width: 13px; height: 13px; border-radius: 3px; background:' . ($data->status == 1 ? 'green' : 'red') . '"></div>
                    </a>
                ';
}, 'filter' => ''), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{move_up}  {move_down}  {update}  {delete}', 'buttons' => array('move_up' => array('label' => '', 'visible' => '($row==0 || !$data->prev()->find() )?false:true', 'url' => '"/admin/' . Yii::app()->controller->module->id . '/' . Yii::app()->controller->id . '/move?id=$data->id&move=1"', 'options' => array('class' => 'icon-arrow-up', 'data-original-title' => 'Переместить выше')), 'move_down' => array('label' => '', 'visible' => '(($row+2)==NewsRubrics::model()->count() || !$data->next()->find())?false:true', 'url' => '"/admin/' . Yii::app()->controller->module->id . '/' . Yii::app()->controller->id . '/move?id=$data->id&move=2"', 'options' => array('class' => 'icon-arrow-down', 'data-original-title' => 'Переместить ниже')), 'update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap')))));
?>
<div class="buttons">
    <a class="btn btn-primary" href="/admin/<?php 
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = NewsRubrics::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 5
0
 /**
  * Получить количество элементов в узле
  */
 public static function getCountTree($left_key, $right_key)
 {
     $model = Yii::app()->db->createCommand()->select('count(id) as count')->from(NewsRubrics::model()->tableName())->where('left_key>=' . (int) $left_key . ' AND right_key<=' . (int) $right_key . '')->queryRow();
     $result = current($model) - 1;
     //вычитае из резуьтата сам узел
     return $result;
 }