/** * Create a new menu item * * @param int $site_id */ public function actionCreateFromContent($target, $content) { if (\GO\Base\Util\Http::isPostRequest()) { $target = json_decode($target); $content = json_decode($content); $targetModelName = \GO\Site\SiteModule::getModelNameFromTreeNodeType($target->type); $contentModelName = \GO\Site\SiteModule::getModelNameFromTreeNodeType($content->type); $targetModel = $targetModelName::model()->findByPk($target->modelId); $contentModel = $contentModelName::model()->findByPk($content->modelId); if ($targetModel instanceof \GO\Site\Model\MenuItem) { $menuId = $targetModel->menu_id; } else { $menuId = $targetModel->id; } $model = $this->_loadModel($menuId); $model->parent_id = $targetModel->id; $model->content_id = $contentModel->id; $model->label = $contentModel->title; // * @property int $menu_id The menu_id of this menu // * @property int $id The id of this menu item // * @property int $parent_id Optional: The parent menuItem of this current item. // * @property int $content_id Optional: The content_id where this menu items links to // * @property String $label The label of the menu item // * @property String $url Optional: url field to create menu items that link to a page that you can fill in manually // * @property Boolean $display_children Only usable when content_id is set. When true this will load the child items of the current content_id. // * @property int $sort_order The sort order for the menu items at the same level // * @property String $target The target for the url in this menu item // // $model->setAttributes($_POST); $model->save(); } echo $this->renderJson(array('success' => true)); }
public static function setTreeSort($extractedParent, $sortOrder, $allowedTypes) { $sort = 0; foreach ($sortOrder as $sortItem) { $extrChild = \GO\Site\SiteModule::extractTreeNode($sortItem); if (in_array($extrChild['type'], $allowedTypes)) { $modelName = \GO\Site\SiteModule::getModelNameFromTreeNodeType($extrChild['type']); $model = $modelName::model()->findByPk($extrChild['modelId']); $model->parent_id = $extractedParent['modelId']; $model->sort_order = $sort; if ($model->save()) { $sort++; } } } return array("success" => true); }