1717use dmstr \modules \pages \models \Tree ;
1818use dmstr \modules \pages \Module ;
1919use dmstr \modules \pages \traits \RequestParamActionTrait ;
20+ use kartik \tree \TreeView ;
2021use pheme \settings \components \Settings ;
2122use Yii ;
2223use yii \base \Event ;
2324use yii \helpers \ArrayHelper ;
2425use yii \helpers \Html ;
26+ use yii \helpers \Inflector ;
2527use yii \helpers \Json ;
2628use yii \helpers \Url ;
2729use yii \web \Controller ;
@@ -61,9 +63,9 @@ protected function refPageActionParamPageId()
6163 {
6264
6365 $ rootIds = [Tree::ROOT_NODE_PREFIX ];
64- /** @var Settings \ Yii::$app->settings */
66+ /** @var Settings Yii::$app->settings */
6567 if (Module::checkSettingsInstalled () && Yii::$ app ->settings ->get ('refPageRootIds ' , 'pages ' , null )) {
66- $ tmp = explode ("\n" , \ Yii::$ app ->settings ->get ('pages.refPageRootIds ' ));
68+ $ tmp = explode ("\n" , Yii::$ app ->settings ->get ('pages.refPageRootIds ' ));
6769 $ tmp = array_filter (array_map ('trim ' , $ tmp ));
6870 $ rootIds = $ tmp ?? $ rootIds ;
6971 }
@@ -106,8 +108,8 @@ protected function refPageActionParamPageId()
106108 */
107109 public function init ()
108110 {
109- if (\ Yii::$ app ->user ->can ('pages ' , ['route ' => true ])) {
110- \ Yii::$ app ->trigger ('registerMenuItems ' , new Event (['sender ' => $ this ]));
111+ if (Yii::$ app ->user ->can ('pages ' , ['route ' => true ])) {
112+ Yii::$ app ->trigger ('registerMenuItems ' , new Event (['sender ' => $ this ]));
111113 }
112114
113115 parent ::init ();
@@ -118,58 +120,84 @@ public function init()
118120 */
119121 public function actionIndex ($ pageId = null )
120122 {
121- $ localicedRootNode = $ this ->module ->getLocalizedRootNode ();
122- if (!$ localicedRootNode ) {
123- $ language = mb_strtolower (\Yii::$ app ->language );
124- $ rootNodePrefix = Tree::ROOT_NODE_PREFIX ;
125-
126- $ msg = <<<HTML
127- <b>Localized root-node missing</b>
128- <p>
129- Please create a new root-node for the current language.
130- </p>
131- <p>
132- <a onclick="$('#tree-domain_id').val(' {$ rootNodePrefix }');$('#tree-name').val(' {$ rootNodePrefix }_ {$ language }');$('.kv-detail-container button[type=submit]').click()"
133- class="btn btn-warning">Create root-node for <b> {$ language }</b></a>
134- </p>
123+
124+ // do rbac permission check if page is readable. The active record permssion check does not show the page if it does not exist
125+ if (!empty ($ pageId ) && empty (Tree::findOne ($ pageId ))) {
126+ throw new NotFoundHttpException (Yii::t ('pages ' , 'The requested page does not exist. ' ));
127+ }
128+
129+ $ query = Tree::getAccessibleItemsQuery ();
130+
131+ $ headerTemplate = <<< HTML
132+ <div class="row">
133+ <div class="col-sm-6" id="dmstr-pages-detail-heading">
134+ {heading}
135+ </div>
136+ <div class="col-sm-6" id="dmstr-pages-detail-search">
137+ {search}
138+ </div>
139+ </div>
135140HTML ;
136141
137- $ js = <<<'JS'
138- $(".kv-create-root").click();
139- JS;
142+ $ toolbar = [];
140143
141- $ this ->getView ()->registerJs ($ js , View::POS_LOAD );
142- \Yii::$ app ->session ->addFlash ('warning ' , $ msg );
143- } else {
144- if (!empty ($ pageId )) {
145- Yii::$ app ->session ->set ('kvNodeId ' , $ pageId );
144+ // check settings component and module existence
145+ if (Yii::$ app ->has ('settings ' ) && Yii::$ app ->hasModule ('settings ' )) {
146+
147+ // check module permissions
148+ $ settingPermission = false ;
149+ if (Yii::$ app ->getModule ('settings ' )->accessRoles === null ) {
150+ $ settingPermission = true ;
151+ } else {
152+ foreach (Yii::$ app ->getModule ('settings ' )->accessRoles as $ role ) {
153+ $ settingPermission = Yii::$ app ->user ->can ($ role );
154+ }
155+ }
156+
157+ if ($ settingPermission ) {
158+ $ settings = [
159+ 'icon ' => 'cogs ' ,
160+ 'url ' => ['/settings ' , 'SettingSearch ' => ['section ' => 'pages ' ]],
161+ 'options ' => [
162+ 'title ' => Yii::t ('pages ' , 'Settings ' ),
163+ 'class ' => 'btn btn-info '
164+ ]
165+ ];
166+ $ toolbar [] = TreeView::BTN_SEPARATOR ;
167+ $ toolbar ['settings ' ] = $ settings ;
146168 }
147169 }
148170
149- /**
150- * Register the pages asset bundle
151- */
152- PagesBackendAsset::register ($ this ->view );
171+ $ mainTemplate = <<< HTML
172+ <div class="row">
173+ <div class="col-md-5" id="dmstr-pages-detail-wrapper">
174+ <div class="box box-solid">
175+ {wrapper}
176+ </div>
177+ </div>
178+ <div class="col-md-7" id="dmstr-pages-detail-panel">
179+ {detail}
180+ </div>
181+ </div>
182+ HTML ;
153183
154- /** @var Tree $queryTree */
155- $ queryTree = Tree::find ()
156- ->andWhere (
157- [
158- Tree::ATTR_ACCESS_DOMAIN => [
159- \Yii::$ app ->language ,
160- Tree::GLOBAL_ACCESS_DOMAIN
161- ]
162- ]
163- )
164- ->orderBy ('root, lft ' );
165184
166- return $ this ->render ('index ' , ['queryTree ' => $ queryTree ]);
185+ PagesBackendAsset::register ($ this ->view );
186+ $ this ->view ->title = Yii::t ('pages ' , 'Pages ' );
187+
188+ return $ this ->render ('index ' , [
189+ 'query ' => $ query ,
190+ 'headerTemplate ' => $ headerTemplate ,
191+ 'toolbar ' => $ toolbar ,
192+ 'mainTemplate ' => $ mainTemplate ,
193+ 'pageId ' => $ pageId
194+ ]);
167195 }
168196
169197 /**
170- * @return \yii \web\Response
198+ * @return Yii \web\Response
171199 * @throws MethodNotAllowedHttpException
172- * @throws \yii \base\InvalidConfigException
200+ * @throws Yii \base\InvalidConfigException
173201 */
174202 public function actionResolveRouteToSchema ()
175203 {
@@ -214,7 +242,7 @@ public function actionRefPage($pageId)
214242 public function actionPage ($ pageId )
215243 {
216244 Url::remember ();
217- \ Yii::$ app ->session ->set ('__crudReturnUrl ' , null );
245+ Yii::$ app ->session ->set ('__crudReturnUrl ' , null );
218246
219247 // Set layout
220248 $ this ->layout = $ this ->module ->defaultPageLayout ;
@@ -232,15 +260,15 @@ public function actionPage($pageId)
232260 );
233261
234262 if ($ this ->module ->pageCheckAccessDomain ) {
235- $ pageQuery ->andWhere (['access_domain ' => [\ Yii::$ app ->language , Tree::$ _all ]]);
263+ $ pageQuery ->andWhere (['access_domain ' => [Yii::$ app ->language , Tree::$ _all ]]);
236264 }
237265
238266 // get page
239267 /** @var $page Tree */
240268 $ page = $ pageQuery ->one ();
241269
242270 // Show disabled pages for admins
243- if ($ page !== null && $ page ->isDisabled () && !\ Yii::$ app ->user ->can ('pages ' )) {
271+ if ($ page !== null && $ page ->isDisabled () && !Yii::$ app ->user ->can ('pages ' )) {
244272 $ page = null ;
245273 }
246274
@@ -257,13 +285,13 @@ public function actionPage($pageId)
257285 Tree::$ activeAccessTrait = true ;
258286 // check if page has access_read permissions set, if yes check if user is allowed
259287 if (!empty ($ page ->access_read ) && $ page ->access_read !== '* ' ) {
260- if (!\ Yii::$ app ->user ->can ($ page ->access_read )) {
288+ if (!Yii::$ app ->user ->can ($ page ->access_read )) {
261289 # if userIsGuest, redirect to login page
262- if (!\ Yii::$ app ->user ->isGuest ) {
263- throw new HttpException (403 , \ Yii::t ('pages ' , 'Forbidden ' ));
290+ if (!Yii::$ app ->user ->isGuest ) {
291+ throw new HttpException (403 , Yii::t ('pages ' , 'Forbidden ' ));
264292 }
265293
266- return $ this ->redirect (\ Yii::$ app ->user ->loginUrl );
294+ return $ this ->redirect (Yii::$ app ->user ->loginUrl );
267295 }
268296 }
269297
@@ -282,24 +310,24 @@ public function actionPage($pageId)
282310
283311 // Render view
284312 if (empty ($ page ->view )) {
285- throw new HttpException (404 , \ Yii::t ('pages ' , 'Page not found. ' ) . ' [ID: ' . $ pageId . '] ' );
313+ throw new HttpException (404 , Yii::t ('pages ' , 'Page not found. ' ) . ' [ID: ' . $ pageId . '] ' );
286314 }
287315 return $ this ->render ($ page ->view , ['page ' => $ page ]);
288316 } else {
289317 if ($ fallbackPage = $ this ->resolveFallbackPage ($ pageId )) {
290- \ Yii::trace ('Resolved fallback URL for ' . $ fallbackPage ->id , __METHOD__ );
318+ Yii::trace ('Resolved fallback URL for ' . $ fallbackPage ->id , __METHOD__ );
291319 return $ this ->redirect ($ fallbackPage ->createUrl (['language ' => $ fallbackPage ->access_domain ]));
292320 } else {
293- throw new HttpException (404 , \ Yii::t ('pages ' , 'Page not found. ' ) . ' [ID: ' . $ pageId . '] ' );
321+ throw new HttpException (404 , Yii::t ('pages ' , 'Page not found. ' ) . ' [ID: ' . $ pageId . '] ' );
294322 }
295323 }
296324
297325 if ($ fallbackPage = $ this ->resolveFallbackPage ($ pageId )) {
298- \ Yii::trace ('Resolved fallback URL for ' . $ fallbackPage ->id , __METHOD__ );
326+ Yii::trace ('Resolved fallback URL for ' . $ fallbackPage ->id , __METHOD__ );
299327 return $ this ->redirect ($ fallbackPage ->createUrl (['language ' => $ fallbackPage ->access_domain ]));
300328 }
301329
302- throw new HttpException (404 , \ Yii::t ('pages ' , 'Page not found. ' ) . ' [ID: ' . $ pageId . '] ' );
330+ throw new HttpException (404 , Yii::t ('pages ' , 'Page not found. ' ) . ' [ID: ' . $ pageId . '] ' );
303331 }
304332
305333
0 commit comments