/**
  * Set the display state of the hierarchy item with the given id to the given displayState value.
  * The result is returned as a json encoded object.
  *
  * @menuLabel __HIDDEN__
  * @menuIcon <span class="glyphicon glyphicon-list-alt"></span>
  * @functionalRight cmsBackendWrite
  *
  * @param $hierarchyItemId integer        	
  * @param $displayState integer        	
  * @return string
  */
 public function actionSetDisplayStateJson($hierarchyItemId = -1, $displayState = -1)
 {
     $result = [];
     if ($hierarchyItemId == -1 || $displayState == -1) {
         $result['result'] = 'failed';
         $result['message'] = 'missing required parameters for action';
     } else {
         $displayState = intval($displayState);
         if ($displayState <= CmsHierarchyItem::DISPLAYSTATE_MAX_VALUE && $displayState >= CmsHierarchyItem::DISPLAYSTATE_MIN_VALUE) {
             $cmsHierarchyItem = CmsHierarchyItem::findOne($hierarchyItemId);
             if ($cmsHierarchyItem) {
                 if ($cmsHierarchyItem->id == DefaultController::$ROOT_HIERARCHY_ITEM_ID) {
                     $result['result'] = 'failed';
                     $result['message'] = 'the display state of the root node cannot be changed';
                 } else {
                     $cmsHierarchyItem->display_state = $displayState;
                     if ($cmsHierarchyItem->save()) {
                         $result['result'] = 'success';
                         $result['newDisplayState'] = $displayState;
                         $result['hierarchyItemId'] = $cmsHierarchyItem->id;
                     } else {
                         $result['result'] = 'failed';
                         $result['message'] = 'error while trying to update hierarchy node';
                     }
                 }
             } else {
                 $result['result'] = 'failed';
                 $result['message'] = 'unknown hierarchy node id given. Update failed';
             }
         } else {
             $result['result'] = 'failed';
             $result['message'] = 'invalid value for display_state given. Not within valid range';
         }
     }
     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);
 }
 /**
  * Finds the CmsHierarchyItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id        	
  * @return CmsHierarchyItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CmsHierarchyItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }