Ejemplo n.º 1
0
 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]);
     }
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTree()
 {
     return $this->hasOne(Tree::className(), ['id' => 'tree_id']);
 }
Ejemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getElement()
 {
     return $this->hasOne(Tree::className(), ['id' => 'element_id']);
 }