/** * @return string */ public function run() { $modelSeacrhClass = $this->modelSearchClassName; if (!$modelSeacrhClass) { $search = new Search($this->controller->modelClassName); $dataProvider = $search->search(\Yii::$app->request->queryParams); $searchModel = $search->loadedModel; } else { $searchModel = new $modelSeacrhClass(); $dataProvider = $searchModel->search(\Yii::$app->request->queryParams); } //Дополнительная обработка Дата провайдера if ($this->dataProviderCallback && is_callable($this->dataProviderCallback)) { $dataProviderCallback = $this->dataProviderCallback; $dataProviderCallback($dataProvider); } //Дополнительная обработка Дата провайдера if ($this->filter && is_callable($this->filter)) { $filter = $this->filter; $filter($dataProvider, \Yii::$app->request->queryParams); } $gridConfig = ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'adminController' => $this->controller, 'columns' => $this->columns]; $gridConfig = ArrayHelper::merge($gridConfig, $this->gridConfig); $this->viewParams = ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'controller' => $this->controller, 'columns' => $this->columns, 'gridConfig' => $gridConfig]; return parent::run(); }
public function actionNewChildren() { /** * @var Tree $parent */ $parent = $this->model; if (\Yii::$app->request->isPost) { $post = \Yii::$app->request->post(); $childTree = new Tree(); $parent = Tree::find()->where(['id' => $post["pid"]])->one(); $childTree->load($post); if (!$childTree->priority) { $childTree->priority = Tree::PRIORITY_STEP; //Элемент с большим приоритетом if ($treeChildrens = $parent->getChildren()->orderBy(['priority' => SORT_DESC])->one()) { $childTree->priority = $treeChildrens->priority + Tree::PRIORITY_STEP; } } $response = ['success' => false]; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; try { if ($parent && $parent->processAddNode($childTree)) { $response['success'] = true; } } catch (\Exception $e) { $response['success'] = false; $response['message'] = $e->getMessage(); } if (!$post["no_redirect"]) { $this->redirect(Url::to(["new-children", "id" => $parent->primaryKey])); } else { return $response; } } else { $tree = new Tree(); $search = new Search(Tree::className()); $dataProvider = $search->search(\Yii::$app->request->queryParams); $searchModel = $search->getLoadedModel(); $dataProvider->query->andWhere(['pid' => $parent->primaryKey]); $controller = \Yii::$app->cms->moduleCms->createControllerByID("admin-tree"); return $this->render('new-children', ['model' => new Tree(), 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'controller' => $controller]); } }
public function initDataProvider() { $this->search = new Search(CmsContentElement::className()); $this->dataProvider = $this->search->getDataProvider(); if ($this->enabledPaging == Cms::BOOL_Y) { $this->dataProvider->getPagination()->defaultPageSize = $this->pageSize; $this->dataProvider->getPagination()->pageParam = $this->pageParamName; $this->dataProvider->getPagination()->pageSizeLimit = [(int) $this->pageSizeLimitMin, (int) $this->pageSizeLimitMax]; } else { $this->dataProvider->pagination = false; } if ($this->orderBy) { $this->dataProvider->getSort()->defaultOrder = [$this->orderBy => (int) $this->order]; } return $this; }