Ejemplo n.º 1
0
 public function run()
 {
     if (Yii::app()->request->isAjaxRequest) {
         //Yii::app()->clientScript->registerCoreScript('jquery.ui');
         Yii::app()->clientScript->scriptMap = array('jquery.js' => false, 'jquery.ba-bbq.js' => false);
         $modelClass = $_POST['model'];
         $grid_id = $_POST['grid_id'];
         $mod = $_POST['module'];
         $upMod = ucfirst($mod);
         Yii::import("mod.{$mod}.models.{$modelClass}");
         Yii::import("mod.{$mod}.{$upMod}Module");
         if (isset($_POST['GridColumns'])) {
             GridColumns::model()->deleteAllByAttributes(array('grid_id' => $grid_id));
             foreach ($_POST['GridColumns']['check'] as $key => $post) {
                 $model = new GridColumns();
                 $model->grid_id = $grid_id;
                 // $model->name = $post;
                 $model->ordern = $_POST['GridColumns']['ordern'][$key];
                 $model->key = $key;
                 try {
                     $model->save(false, false, false);
                 } catch (CDbException $e) {
                     //error
                 }
             }
         }
         $data = array();
         $cr = new CDbCriteria();
         $cr->order = '`t`.`ordern` DESC';
         $cr->condition = '`t`.`grid_id`=:grid';
         $cr->params = array(':grid' => $grid_id);
         $model = GridColumns::model()->findAll($cr);
         $m = array();
         foreach ($model as $r) {
             $m[$r->key]['ordern'] = $r->ordern;
             $m[$r->key]['key'] = $r->key;
         }
         $columsArray = $modelClass::model()->getGridColumns();
         unset($columsArray['DEFAULT_COLUMNS'], $columsArray['DEFAULT_CONTROL']);
         foreach ($columsArray as $key => $column) {
             if (isset($column['header'])) {
                 $name = $column['header'];
             } else {
                 $name = $modelClass::model()->getAttributeLabel($column['name']);
             }
             if (isset($m[$key])) {
                 $isChecked = $m[$key]['key'] == $key ? true : false;
             } else {
                 $isChecked = false;
             }
             $data[] = array('checkbox' => Html::checkbox('GridColumns[check][' . $key . ']', $isChecked, array('value' => $name)), 'name' => $name, 'sort' => Html::textField('GridColumns[ordern][' . $key . ']', $m[$key]['ordern'], array('class' => 'form-control text-center')));
         }
         $provider = new CArrayDataProvider($data, array('pagination' => false));
         $this->controller->render('ext.adminList.views._EditGridColumns', array('modelClass' => $modelClass, 'provider' => $provider, 'grid_id' => $grid_id, 'module' => $mod));
     } else {
         throw new CHttpException(401);
     }
 }
Ejemplo n.º 2
0
 public function afterUninstall()
 {
     $db = Yii::app()->db;
     $tablesArray = array(ShopDiscount::model()->tableName(), $db->tablePrefix . 'shop_discount_category', $db->tablePrefix . 'shop_discount_manufacturer');
     foreach ($tablesArray as $table) {
         $db->createCommand()->dropTable($table);
     }
     GridColumns::model()->deleteAll("grid_id='shopdiscount-grid'");
     return parent::afterUninstall();
 }
Ejemplo n.º 3
0
 /**
  * Initializes the grid view.
  */
 public function init()
 {
     if (isset($this->dataProvider->model)) {
         if ($this->enableDragDropSorting === true && array_key_exists('ordern', $this->dataProvider->model->attributes)) {
             /* To use this widget, data provider must be an instance of CActiveDataProvider */
             if (!$this->dataProvider instanceof ActiveDataProvider) {
                 throw new CException(Yii::t('zii', 'Data provider must be an instance of ActiveDataProvider'));
             }
             if ($this->allItemsInOnePage === true) {
                 $this->dataProvider->pagination = false;
             }
             // $this->enableSorting = false;
             if ($this->descSort !== true) {
                 $sort_direction = 'DESC';
             } else {
                 $sort_direction = 'ASC';
             }
             $this->dataProvider->setSort(array('defaultOrder' => '`t`.`' . $this->orderField . '`' . $sort_direction));
         }
     }
     // Uhhhh! ugly copy-paste from CBaseListView::init()!
     if ($this->dataProvider === null) {
         throw new CException(Yii::t('zii', 'The "dataProvider" property cannot be empty.'));
     }
     // $this->dataProvider->getData();
     $this->htmlOptions['id'] = $this->getId();
     $this->htmlOptions['class'] = 'grid-view';
     if ($this->enableSorting && $this->dataProvider->getSort() === false) {
         $this->enableSorting = false;
     }
     if ($this->enablePagination && $this->dataProvider->getPagination() === false) {
         $this->enablePagination = false;
     }
     // End of ugly
     if ($this->baseScriptUrl === null) {
         $this->baseScriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.adminList.assets'), false, -1, YII_DEBUG);
     }
     if ($this->cssFile !== false) {
         if ($this->cssFile === null) {
             $this->cssFile = $this->baseScriptUrl . '/styles.css';
         }
         Yii::app()->getClientScript()->registerCssFile($this->cssFile);
     }
     $this->pager = array('class' => 'LinkPager', 'cssFile' => false, 'htmlOptions' => array('class' => 'pagination'), 'header' => Yii::app()->controller instanceof AdminController ? '' : null);
     if (isset($this->dataProvider->model) && $this->autoColumns) {
         //@remove isset($this->dataProvider->model->gridColumns) &&
         $cr = new CDbCriteria();
         $cr->order = '`t`.`ordern` ASC';
         $cr->condition = '`t`.`grid_id`=:grid';
         $cr->params = array('grid' => $this->id);
         $model = GridColumns::model()->findAll($cr);
         $colms = array();
         if (isset($model)) {
             foreach ($model as $k => $col) {
                 $colms[$col->key] = $col->key;
             }
         }
         $this->columns = $this->dataProvider->model->getColumnSearch($colms);
     }
     $this->initColumns();
 }