/**
  * Creates data provider instance with search query applied
  *
  * @param array $params        	
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CmsMenuItem::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'cms_hierarchy_item_id' => $this->cms_hierarchy_item_id, 'language' => $this->language, 'page_content_id' => $this->page_content_id, 'document_id' => $this->document_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 /**
  * show the page for the given alias name
  * @menuLabel __HIDDEN__
  * @param String $menuItemAlias
  * @return View
  */
 public function actionAlias($menuItemAlias)
 {
     $menuItemAlias = preg_replace('/[^a-zA-Z0-9_\\-]/', '', $menuItemAlias);
     $menuItem = CmsMenuItem::find()->where(['alias' => $menuItemAlias])->with('pageContent')->with('cmsHierarchyItem')->one();
     return $this->renderPage($menuItem);
 }
 /**
  *
  * @return \yii\db\ActiveQuery
  */
 public function getCmsMenuItems()
 {
     return $this->hasMany(CmsMenuItem::className(), ['page_content_id' => 'id']);
 }
 /**
  * Create a new hierarchy item and return the result as json encoded object
  *
  * @menuLabel __HIDDEN__
  * @menuIcon <span class="glyphicon glyphicon-list-alt"></span>
  * @functionalRight cmsBackendWrite
  *
  * @param integer $parentHierarchyItemId
  *        	the parent item id to create the new element below
  * @param string $newMenuName
  *        	the language sepcific display name of the menu item
  * @param integer $position
  *        	the position (for specifiying the display order amongst all siblings) within the other siblings of the newly created item
  * @param integer $language
  *        	the language id of the menu to create
  * @see CmsHierarchyItem::DISPLAYSTATE_PUBLISHED_VISIBLE_IN_NAVIGATION
  * @see CmsHierarchyItem::DISPLAYSTATE_PUBLISHED_HIDDEN_IN_NAVIGATION
  * @see CmsHierarchyItem::DISPLAYSTATE_UNPUBLISHED
  * @return string
  */
 public function actionCreateHierarchyItemJson($parentHierarchyItemId = -1, $newMenuName = null, $position = -1, $language = -1, $jsonEncode = true)
 {
     $parentHierarchyItemId = intval($parentHierarchyItemId);
     $position = intval($position);
     $language = intval($language);
     $result = [];
     $result['message'] = '';
     $result['success'] = false;
     if ($parentHierarchyItemId < 0 || $newMenuName == '' || $position <= 0 || $language < 1) {
         $result['result'] = 'failed';
         $result['success'] = false;
         $result['message'] .= 'error, missing required parameters or invalid values given';
     } else {
         $newHierarchyItem = new CmsHierarchyItem();
         $newHierarchyItem->parent_id = $parentHierarchyItemId;
         $newHierarchyItem->display_state = CmsHierarchyItem::DISPLAYSTATE_UNPUBLISHED;
         $newHierarchyItem->position = $position;
         if ($newHierarchyItem->validate() && $newHierarchyItem->save()) {
             $result['message'] .= 'hierarchy item created, id is ' . $newHierarchyItem->id . " | ";
             $newMenuItem = new CmsMenuItem();
             $newMenuItem->created_datetime = new Expression('NOW()');
             $newMenuItem->createdby_userid = Yii::$app->user->id;
             $newMenuItem->cms_hierarchy_item_id = $newHierarchyItem->id;
             $newMenuItem->language = $language;
             $newMenuItem->name = $newMenuName;
             if ($newMenuItem->validate() && $newMenuItem->save()) {
                 $result['result'] = 'success';
                 $result['success'] = true;
                 $result['message'] .= 'new hierarchy item created';
                 $hierarchyItemDetailsArray = $newHierarchyItem->getAttributes();
                 $hierarchyItemDetailsArray['menu_item'] = $newMenuItem->getAttributes();
                 $hierarchyItemDetailsArray['children'] = [];
                 $hierarchyItemDetailsArray['available_menu_items_all_languages'] = ['language' => $newMenuItem];
                 $result['item'] = new SimpleHierarchyItem($hierarchyItemDetailsArray, true, 1);
             } else {
                 $result['result'] = 'failed';
                 $result['success'] = false;
                 $result['message'] .= 'error, hierarchy item created, but creation of language version for menu failed: ' . implode($newMenuItem->getFirstErrors());
             }
             $updateCounter = 0;
             $failedUpdateCounter = 0;
             $checkedItems = 0;
             SettingsAndMaintenanceController::fixItemPositionsForChildren($parentHierarchyItemId, $updateCounter, $failedUpdateCounter, $checkedItems, false);
         } else {
             $result['result'] = 'failed';
             $result['success'] = false;
             $result['message'] .= 'error while trying to validate and save the hierarchy item: ' . implode($newHierarchyItem->getFirstErrors());
         }
     }
     if ($jsonEncode) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
         $headers = Yii::$app->response->headers;
         $headers->add('Content-Type', 'application/json; charset=utf-8');
         Yii::$app->response->charset = 'UTF-8';
         return json_encode($result, JSON_PRETTY_PRINT);
     } else {
         return $result;
     }
 }
 /**
  * Finds the CmsMenuItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id        	
  * @return CmsMenuItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CmsMenuItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  *
  * @return \yii\db\ActiveQuery
  */
 public function getCmsMenus()
 {
     return $this->hasMany(CmsMenuItem::className(), ['cms_hierarchy_item_id' => 'id']);
 }