Exemplo n.º 1
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));
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
<style>
    #NewsRubrics_id{  width: 30px; }
</style>

<legend><?php 
echo Yii::t("Bootstrap", "LIST.NewsRubrics");
?>
</legend>

<?php 
$assetsDir = Yii::app()->basePath;
$labels = NewsRubrics::model()->attributeLabels();
$this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'pages-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $provider, 'filter' => $model, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => 'Картинка раздела', 'name' => "image", 'type' => 'raw', 'value' => function ($dataProvider) {
    $url_img = '/images/nophoto_100_100.jpg';
    if (file_exists(YiiBase::getPathOfAlias('webroot') . '/../uploads/filestorage/news/rubrics/admin-' . $dataProvider->id . '.' . $dataProvider->image)) {
        $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);
Exemplo n.º 4
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;
 }