Пример #1
0
 public function getType()
 {
     switch ($this->nav_item_type) {
         case self::TYPE_PAGE:
             return \cmsadmin\models\NavItemPage::findOne($this->nav_item_type_id);
             break;
         case self::TYPE_MODULE:
             return \cmsadmin\models\NavItemModule::findOne($this->nav_item_type_id);
             break;
     }
 }
Пример #2
0
 public function getType()
 {
     switch ($this->nav_item_type) {
         case self::TYPE_PAGE:
             $object = NavItemPage::findOne($this->nav_item_type_id);
             break;
         case self::TYPE_MODULE:
             $object = NavItemModule::findOne($this->nav_item_type_id);
             break;
         case self::TYPE_REDIRECT:
             $object = NavItemRedirect::findOne($this->nav_item_type_id);
             break;
     }
     // assign the current context for an item type object.
     $object->setNavItem($this);
     return $object;
 }
Пример #3
0
 /**
  * check old entries - delete if obsolete (changed type) and add new entry to the appropriate cms_nav_item_(page/module/redirect).
  *
  * @param $navItemId
  * @param $navItemType
  * @param $navItemTypeId
  * @param $title
  * @param $alias
  *
  * @return array|bool
  */
 public function actionUpdatePageItem($navItemId, $navItemType, $navItemTypeId)
 {
     $model = NavItem::find()->where(['id' => $navItemId])->one();
     if (!$model) {
         throw new Exception('Unable to find item id ' . $navItemId);
     }
     $model->setParentFromModel();
     // save old id
     $oldNavItemType = $model->nav_item_type;
     $oldNavItemTypeId = $model->nav_item_type_id;
     $oldTitle = $model->title;
     $oldAlias = $model->alias;
     $model->nav_item_type = $navItemType;
     $model->title = Yii::$app->request->post('title', false);
     $model->alias = Yii::$app->request->post('alias', false);
     $model->description = Yii::$app->request->post('description', null);
     if (!$model->validate() || !$model->save()) {
         return $this->sendModelError($model);
     }
     $itemModel = null;
     if ($oldNavItemType == $model->nav_item_type) {
         switch ($navItemType) {
             case 1:
                 $itemModel = NavItemPage::find()->where(['id' => $navItemTypeId])->one();
                 break;
             case 2:
                 $itemModel = NavItemModule::find()->where(['id' => $navItemTypeId])->one();
                 break;
             case 3:
                 $itemModel = NavItemRedirect::find()->where(['id' => $navItemTypeId])->one();
                 break;
         }
     } else {
         switch ($navItemType) {
             case 1:
                 $itemModel = new NavItemPage();
                 break;
             case 2:
                 $itemModel = new NavItemModule();
                 break;
             case 3:
                 $itemModel = new NavItemRedirect();
                 break;
         }
     }
     switch ($navItemType) {
         case 1:
             $this->setPostAttribute($itemModel, 'layout_id');
             break;
         case 2:
             $this->setPostAttribute($itemModel, 'module_name');
             break;
         case 3:
             $this->setPostAttribute($itemModel, 'type');
             $this->setPostAttribute($itemModel, 'value');
             break;
     }
     if (!$itemModel->validate() || !$itemModel->save()) {
         // error: reverse changes in nav item
         $model->nav_item_type = $oldNavItemType;
         $model->nav_item_type_id = $oldNavItemTypeId;
         $model->alias = $oldAlias;
         $model->title = $oldTitle;
         $model->update(false);
         return $this->sendModelError($itemModel);
     }
     if ($oldNavItemType != $model->nav_item_type) {
         $this->deleteItem($oldNavItemType, $oldNavItemTypeId);
     }
     // save new type id
     $model->nav_item_type_id = $itemModel->id;
     $model->update(false);
     return true;
 }
Пример #4
0
 /**
  * If the type of the item is equals 2 we can detect the module name and returns
  * this information.
  * 
  * @return boolean|string The name of the module or false if not found or wrong type
  * @since 1.0.0-beta5
  */
 public function getModuleName()
 {
     if ($this->getType() === 2) {
         $module = NavItemModule::find()->select(['module_name'])->where(['id' => $this->itemArray['nav_item_type_id']])->asArray()->one();
         if ($module) {
             return $module['module_name'];
         }
     }
     return false;
 }
Пример #5
0
 /**
  *
  * 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();
 }