<legend><?php echo Yii::t("Bootstrap", "LIST.BanersRubrics"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = BanersRubrics::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'faq-group-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/baners/rubrics/admin-' . $dataProvider->id . '.' . $dataProvider->image)) { $url_img = '/../uploads/filestorage/baners/rubrics/admin-' . $dataProvider->id . '.' . $dataProvider->image; } return '<img src="' . $url_img . '" style="width:80px" />'; }, 'filter' => ''), array('header' => $labels["name"], 'type' => 'raw', 'value' => function ($data) { $count = BanersRubrics::getCountTree($data->left_key, $data->right_key); return ' <a href="/admin/baners/baners/index?BanersElements[parent_id]=' . $data->id . '">' . $data->name . '</a> '; }, 'filter' => ''), array('header' => 'url', 'name' => "url", 'type' => 'raw', 'value' => function ($data) { return $data->url; /* return ' <a href="'.$data->url.'" target="_blank"> '.$data->url.' </a> '; */ }, 'filter' => ''), array('header' => 'Позиций', 'type' => 'raw', 'value' => function ($data) { $count = BanersRubrics::getCountTree($data->left_key, $data->right_key);
/** * Получить количество элементов в узле */ public static function getCountTree($left_key, $right_key) { $model = Yii::app()->db->createCommand()->select('count(id) as count')->from(BanersRubrics::model()->tableName())->where('left_key>=' . (int) $left_key . ' AND right_key<=' . (int) $right_key . '')->queryRow(); $result = current($model) - 1; //вычитае из резуьтата сам узел return $result; }
/** * 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 = BanersRubrics::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }