Esempio n. 1
0
 /**
  * Manages all models.
  */
 public function actionIndex()
 {
     $model = new BanersElements('search');
     $model->attachBehavior('dateComparator', array('class' => 'DateComparator'));
     $model->unsetAttributes();
     // clear any default values
     // set attributes from get
     if (isset($_GET['BanersElements'])) {
         $model->attributes = $_GET['BanersElements'];
     }
     $param = array();
     $data['sort'] = array('defaultOrder' => 'id DESC');
     $data['Pagination'] = array('PageSize' => 100);
     if ($settingsModel = SiteModuleSettings::model()->find('site_module_id = 15')) {
         $data['Pagination'] = array('PageSize' => (int) $settingsModel->elements_page_admin > 0 ? $settingsModel->elements_page_admin : 100);
     }
     $provider = new CActiveDataProvider('BanersElements', $data);
     $param = implode(" AND ", $param);
     $provider->criteria = $model->search($param);
     $root = BanersRubrics::getRoot(new BanersRubrics());
     $catalog = $root->descendants()->findAll($root->id);
     $this->render('list', array('model' => $model, 'provider' => $provider, 'root' => $root, 'catalog' => $catalog));
 }
Esempio n. 2
0
}, '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);
    return '
                    <a href="/admin/baners/banersrubrics/index?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)?false:true', 'url' => '"/admin/baners/banersrubrics/move?id=$data->id&move=1"', 'options' => array('class' => 'icon-arrow-up', 'data-original-title' => 'Переместить выше')), 'move_down' => array('label' => '', 'visible' => '(($row+1)==BanersRubrics::model()->count("level=$data->level"))?false:true', 'url' => '"/admin/baners/banersrubrics/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')))));
?>

Esempio n. 3
0
 /**
  * Получить количество элементов в узле
  */
 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;
 }