public function testFieldSelectionBasicInjector() { $block = new Block(); $injector = new ActiveQueryCheckboxInjector(['query' => NavItem::find()->select(['title']), 'varName' => 'test', 'varLabel' => 'test label', 'context' => $block]); $injector->setup(); $vars = $block->getConfigVarsExport(); $v = $vars[0]; $this->assertSame('test', $v['var']); $this->assertSame('test label', $v['label']); $items = $v['options']['items']; $this->assertNotEmpty(count($items)); $item1 = $v['options']['items'][0]; $this->assertSame('Homepage', $item1['label']); }
public function actionVersions() { if (Config::has('luya_cmsadmin_updater_versions')) { return $this->outputError("You already have run the version updater, so your system should be up-to-date already."); } echo $this->outputInfo("Starting VERSIONS updater"); foreach (NavItem::find()->all() as $item) { if ($item->nav_item_type !== NavItem::TYPE_PAGE) { echo $this->output('- Skip "' . $item->title . '" as its not a page type (module or redirect)'); continue; } $typeModel = $item->getType(); $typeModel->updateAttributes(['nav_item_id' => $item->id, 'timestamp_create' => $item->timestamp_create, 'create_user_id' => $item->create_user_id, 'version_alias' => Module::VERSION_INIT_LABEL]); $this->outputSuccess('- updated: ' . $item->title); } Config::set('luya_cmsadmin_updater_versions', time()); return $this->outputSuccess('We have successfully updated your version index.'); }
/** * Render the NavItem content and set several view specific data. * * @param integer $navItemId * @param string $appendix * @param boolean|integer $setNavItemTypeId To get the content of a version this parameter will change the database value from the nav item Model * to this provided value * * @throws NotFoundHttpException * @throws MethodNotAllowedHttpException */ public function renderItem($navItemId, $appendix = null, $setNavItemTypeId = false) { $model = NavItem::find()->where(['id' => $navItemId])->with('nav')->one(); if (!$model) { throw new NotFoundHttpException('The requested nav item could not found.'); } Yii::$app->urlManager->contextNavItemId = $navItemId; Yii::$app->set('page', ['class' => 'luya\\cms\\frontend\\components\\Page', 'model' => $model]); $currentMenu = Yii::$app->menu->current; $event = new BeforeRenderEvent(); $event->menu = $currentMenu; foreach ($model->nav->getProperties() as $property) { $object = $property->getObject(); $object->trigger($object::EVENT_BEFORE_RENDER, $event); if (!$event->isValid) { throw new MethodNotAllowedHttpException('Your are not allowed to see this page.'); return Yii::$app->end(); } } if ($setNavItemTypeId !== false && !empty($setNavItemTypeId)) { $model->nav_item_type_id = $setNavItemTypeId; } $typeModel = $model->getType(); if (!$typeModel) { throw new NotFoundHttpException("The requestd nav item could not be found with the paired type, maybe this version does not exists for this Type."); } $typeModel->setOptions(['navItemId' => $navItemId, 'restString' => $appendix]); $content = $typeModel->getContent(); if ($content instanceof Response) { return Yii::$app->end(0, $content); } // it seems to be a json response as it is an array if (is_array($content)) { return $content; } // https://github.com/luyadev/luya/issues/863 - if context controller is not false and the layout variable is not empty, the layout file will be displayed // as its already renderd by the module controller itself. if ($typeModel->controller !== false && !empty($typeModel->controller->layout)) { $this->layout = false; } if ($this->view->title === null) { if (empty($model->title_tag)) { $this->view->title = $model->title; } else { $this->view->title = $model->title_tag; } } $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], 'fbTitle'); $this->view->registerMetaTag(['name' => 'og:type', 'content' => 'website'], 'ogType'); if (!empty($model->description)) { $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], 'metaDescription'); $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], 'fbDescription'); } if (!empty($model->keywords)) { $this->view->registerMetaTag(['name' => 'keywords', 'content' => implode(", ", $currentMenu->keywords)], 'metyKeywords'); } if ($this->module->enableTagParsing) { $content = TagParser::convert($content); } if (Yii::$app->has('adminuser') && !Yii::$app->adminuser->isGuest && $this->module->overlayToolbar === true) { $this->view->registerCssFile('https://fonts.googleapis.com/icon?family=Material+Icons'); $this->getView()->on(View::EVENT_BEGIN_BODY, [$this, 'renderToolbar'], ['content' => $content]); } return $content; }
public function actionDelete($navId) { $model = Nav::find()->where(['id' => $navId])->one(); if ($model) { Yii::$app->menu->flushCache(); // check for internal redirects $redirectResult = false; $redirects = NavItemRedirect::find()->where(['value' => $navId])->asArray()->all(); foreach ($redirects as $redirect) { $navItem = NavItem::find()->where(['nav_item_type' => 3, 'nav_item_type_id' => $redirect['id']])->one(); $redirectResult = empty(Nav::find()->where(['id' => $navItem->nav_id, 'is_deleted' => 0])->one()) ? $redirectResult : true; } if ($redirectResult) { Yii::$app->response->statusCode = 417; return; } $model->is_deleted = 1; foreach (NavItem::find()->where(['nav_id' => $navId])->all() as $navItem) { $navItem->setAttribute('alias', date('Y-m-d-H-i') . '-' . $navItem->alias); $navItem->update(false); } return $model->update(false); } }
/** * * Create a new nav item with a specific language, title and alias based on a given nav item id. * All content of the source nav item will be copied dependent on the nav item type (page content, module link, redirect informations). * * @param $navItemId source nav item * @param $langId (new) target language * @param $title title of nav item * @param $alias alias of nav item * @return bool */ public function createItemLanguageCopy($navItemId, $langId, $title, $alias) { $sourceNavItem = NavItem::findOne($navItemId); if (!$sourceNavItem) { return false; } if (NavItem::find()->where(['nav_id' => $sourceNavItem->nav_id, 'lang_id' => $langId])->one()) { return false; } $navItem = new NavItem(); $navItem->attributes = $sourceNavItem->toArray(); $navItem->title = $title; $navItem->alias = $alias; $navItem->lang_id = $langId; $navItem->setParentFromModel(); if (!$navItem->save()) { return false; } // we have created the copy, but its seems like no version existis for the original to copy page, // so we can not copy any content, lets return true and skip copy process. if (empty($sourceNavItem->nav_item_type_id)) { return true; } return $sourceNavItem->copyTypeContent($navItem); }
/** * Get full constructed of a nav item. * * @param $navId * @return string Path */ public function actionGetNavItemPath($navId) { $data = ""; $node = NavItem::find()->where(['nav_id' => $navId])->one(); if ($node) { $data .= $node->title; $parentNavId = $navId; while ($parentNavId != 0) { $parentNavId = Nav::findOne($parentNavId)->parent_nav_id; if ($parentNavId != 0) { $node = NavItem::find()->where(['nav_id' => $parentNavId])->one(); if ($parentNavId) { $data = $node->title . '/' . $data; } } } } return $data; }