Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CmsMenu::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['menu_id' => $this->menu_id, 'page_id' => $this->page_id, 'parent_menu_id' => $this->parent_menu_id, 'area_id' => $this->area_id, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsMenus()
 {
     return $this->hasMany(CmsMenu::className(), ['parent_menu_id' => 'menu_id']);
 }
Пример #3
0
 public function actionSavemenu()
 {
     if (Yii::$app->request->isAjax) {
         $data = Yii::$app->request->post();
         $area_id = $data['area_id'];
         $menu_items = BaseJson::decode($data['menu_json']);
         if (count($menu_items) > 0) {
             // Delete Existing Menu's Before Adding New
             CmsMenu::deleteAll('area_id = ' . $area_id);
             // Insert New Set Of Menu's
             $p = $c = $sc = $sc1 = $sc2 = 1;
             foreach ($menu_items as $parent) {
                 $model = new CmsMenu();
                 $model->page_id = $parent['pageid'];
                 $model->sort_order = $p;
                 $model->area_id = $area_id;
                 $model->created_by = Yii::$app->user->id;
                 $model->save();
                 $new_parent_id = $model->menu_id;
                 //Children
                 if ($new_parent_id > 0 && isset($parent['children'])) {
                     foreach ($parent['children'] as $children) {
                         $model = new CmsMenu();
                         $model->page_id = $children['pageid'];
                         $model->sort_order = $c;
                         $model->area_id = $area_id;
                         $model->parent_menu_id = $new_parent_id;
                         $model->created_by = Yii::$app->user->id;
                         $model->save();
                         $new_child_id = $model->menu_id;
                         // Sub Child
                         if ($new_child_id > 0 && isset($children['children'])) {
                             foreach ($children['children'] as $sub_children) {
                                 $model = new CmsMenu();
                                 $model->page_id = $sub_children['pageid'];
                                 $model->sort_order = $sc;
                                 $model->area_id = $area_id;
                                 $model->parent_menu_id = $new_child_id;
                                 $model->created_by = Yii::$app->user->id;
                                 $model->save();
                                 $new_sub_child_id = $model->menu_id;
                                 // Sub Child 1
                                 if ($new_sub_child_id > 0 && isset($sub_children['children'])) {
                                     foreach ($sub_children['children'] as $sub_children1) {
                                         $model = new CmsMenu();
                                         $model->page_id = $sub_children1['pageid'];
                                         $model->sort_order = $sc1;
                                         $model->area_id = $area_id;
                                         $model->parent_menu_id = $new_sub_child_id;
                                         $model->created_by = Yii::$app->user->id;
                                         $model->save();
                                         $new_sub_child_id1 = $model->menu_id;
                                         // Sub Child 2
                                         if ($new_sub_child_id1 > 0 && isset($sub_children1['children'])) {
                                             foreach ($sub_children1['children'] as $sub_children2) {
                                                 $model = new CmsMenu();
                                                 $model->page_id = $sub_children2['pageid'];
                                                 $model->sort_order = $sc2;
                                                 $model->area_id = $area_id;
                                                 $model->parent_menu_id = $new_sub_child_id1;
                                                 $model->created_by = Yii::$app->user->id;
                                                 $model->save();
                                                 $sc2++;
                                             }
                                         }
                                         $sc1++;
                                     }
                                 }
                                 $sc++;
                             }
                         }
                         $c++;
                     }
                 }
                 $p++;
             }
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ['status' => 'success', 'message' => '<strong>Success !! </strong>Menu Item/s Succesfully Added / Updated', 'array' => $new_sub_child_id];
         } else {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ['status' => 'failed', 'message' => '<strong>Failed !! </strong> Menu Item is empty. Kindly add atleast one menu to a area'];
         }
     } else {
         $this->redirect(['selectarea']);
     }
 }
Пример #4
0
 /**
  * Retrieve all child menu's given area and parent
  * @param integer $area_id, integer $parent_id
  * @return Array $cmenu
  */
 public function getChildMenus($area_id, $parent_id)
 {
     if (empty($parent_id)) {
         return null;
     } else {
         $child_menus = CmsMenu::find()->where(['area_id' => $area_id, 'parent_menu_id' => $parent_id])->asArray()->all();
         $cmenu = null;
         if (count($child_menus) > 0) {
             foreach ($child_menus as $child_menu) {
                 $menu_model = $this->findModel($child_menu['menu_id']);
                 if ($menu_model->page->status == 1) {
                     $cmenu[] = array('menu_id' => $child_menu['menu_id'], 'menu_title' => $menu_model->page->menu_title, 'menu_status' => $menu_model->page->status, 'parent_menu_id' => $child_menu['parent_menu_id'], 'page_id' => $child_menu['page_id'], 'sort_order' => $child_menu['sort_order'], 'sub_children' => $this->getChildMenus($child_menu['area_id'], $child_menu['menu_id']));
                 }
             }
         }
         return $cmenu;
     }
 }
Пример #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsMenus()
 {
     return $this->hasMany(CmsMenu::className(), ['area_id' => 'area_id']);
 }