Exemplo n.º 1
0
 public function actionCreate()
 {
     $model = new ObjectData();
     $model->siteId = Yii::$app->cmgCore->siteId;
     $model->type = CmsGlobal::TYPE_MENU;
     $model->data = "{ \"links\": {} }";
     $pages = PageService::getIdNameList();
     $model->setScenario('create');
     // Menu Pages
     $pageLinks = [];
     for ($i = 0, $j = count($pages); $i < $j; $i++) {
         $pageLinks[] = new PageLink();
     }
     // Menu Links
     $links = [];
     for ($i = 0; $i < 4; $i++) {
         $links[] = new Link();
     }
     if ($model->load(Yii::$app->request->post(), 'ObjectData') && Link::loadMultiple($links, Yii::$app->request->post(), 'Link') && PageLink::loadMultiple($pageLinks, Yii::$app->request->post(), 'PageLink') && $model->validate() && Link::validateMultiple($links) && PageLink::validateMultiple($pageLinks)) {
         $menu = MenuService::create($model);
         if ($menu) {
             MenuService::updateLinks($menu, $links, $pageLinks);
             $this->redirect(['all']);
         }
     }
     return $this->render('create', ['model' => $model, 'pages' => $pages, 'links' => $links, 'pageLinks' => $pageLinks]);
 }
Exemplo n.º 2
0
 public function actionCreate()
 {
     $model = new ObjectData();
     $model->siteId = Yii::$app->cmgCore->siteId;
     $model->type = CmsGlobal::TYPE_WIDGET;
     $meta = new WidgetForm();
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post(), 'ObjectData') && $meta->load(Yii::$app->request->post(), 'WidgetForm') && $model->validate()) {
         if (WidgetService::create($model, $meta)) {
             return $this->redirect(['all']);
         }
     }
     $templatesMap = TemplateService::getIdNameMap(['conditions' => ['type' => CmsGlobal::TYPE_WIDGET], 'prepend' => [['name' => '0', 'value' => 'Choose Template']]]);
     return $this->render('create', ['model' => $model, 'meta' => $meta, 'templatesMap' => $templatesMap]);
 }
Exemplo n.º 3
0
 public function actionCreate()
 {
     $model = new ObjectData();
     $model->siteId = Yii::$app->cmgCore->siteId;
     $model->type = CmsGlobal::TYPE_SIDEBAR;
     $model->data = "{ \"widgets\": {} }";
     $widgets = WidgetService::getIdNameList();
     $model->setScenario('create');
     // Sidebar Widgets
     $sidebarWidgets = [];
     for ($i = 0, $j = count($widgets); $i < $j; $i++) {
         $sidebarWidgets[] = new SidebarWidget();
     }
     if ($model->load(Yii::$app->request->post(), 'ObjectData') && SidebarWidget::loadMultiple($sidebarWidgets, Yii::$app->request->post(), 'SidebarWidget') && $model->validate() && SidebarWidget::validateMultiple($sidebarWidgets)) {
         $sidebar = SidebarService::create($model);
         if ($sidebar) {
             SidebarService::updateWidgets($sidebar, $sidebarWidgets);
             $this->redirect(['all']);
         }
     }
     return $this->render('create', ['model' => $model, 'widgets' => $widgets, 'sidebarWidgets' => $sidebarWidgets]);
 }
Exemplo n.º 4
0
 /**
  * @param string $slug
  * @param string $type
  * @return ObjectData
  */
 public static function findBySlugType($slug, $type)
 {
     return ObjectData::findBySlugType($slug, $type);
 }