/** * * @param unknown $navId * @param unknown $langId * @param unknown $title * @param unknown $alias * @param unknown $moduleName * @param unknown $description * @return boolean */ public function createModuleItem($navId, $langId, $title, $alias, $moduleName, $description) { $_errors = []; $navItem = new NavItem(); $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id; $navItemModule = new NavItemModule(); $navItem->attributes = ['nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 2]; $navItemModule->attributes = ['module_name' => $moduleName]; if (!$navItem->validate()) { $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors); } if (!$navItemModule->validate()) { $_errors = ArrayHelper::merge($navItemModule->getErrors(), $_errors); } if (!empty($_errors)) { return $_errors; } $navItemModule->save(); $navItem->nav_item_type_id = $navItemModule->id; $navItemId = $navItem->save(); return $navItemId; }
/** * Return all nav item modules to request data later in items * * @return array An array with all modules index by the id */ public function getModulesMap() { if ($this->_modulesMap === null) { $this->_modulesMap = NavItemModule::find()->select(['module_name', 'id'])->indexBy('id')->asArray()->all(); } return $this->_modulesMap; }
/** * * Copy content of type cms_nav_item_module to a target nav item. This will create a new entry in cms_nav_item_module. * * @param $targetNavItem * @return bool */ public function copyModuleItem($targetNavItem) { if ($this->nav_item_type !== 2) { return false; } $sourceModuleItem = NavItemModule::findOne($this->nav_item_type_id); if (!$sourceModuleItem) { return false; } $moduleItem = new NavItemModule(); $moduleItem->attributes = $sourceModuleItem->toArray(); if (!$moduleItem->save()) { return false; } $targetNavItem->nav_item_type_id = $moduleItem->id; return $targetNavItem->save(); }