Esempio n. 1
0
 /**
  * Create default page cover
  * @param \MongoId $accountId
  * @throws ServerErrorHttpException
  */
 private function _createDefaultPageCover(\MongoId $accountId)
 {
     $page = new Page(['scenario' => 'createBasic']);
     $defaultCoverPage = Yii::$app->params['default_cover_page'];
     $page->load($defaultCoverPage, '');
     $page->_id = new \MongoId();
     $page->accountId = $accountId;
     $page->url = Yii::$app->request->hostinfo . '/msite/page/' . $page->_id;
     $shortUrl = Yii::$app->urlService->shortenUrl($page->url);
     $page->shortUrl = $shortUrl['Short'];
     if ($page->save()) {
         $pageComponent = new PageComponent(['scenario' => PageComponent::SCENARIO_CREATE]);
         $defaultCoverPageCompnent = Yii::$app->params['default_cover_pagecomponent'];
         $pageComponent->load($defaultCoverPageCompnent, '');
         $pageComponent->pageId = $page->_id;
         $pageComponent->parentId = $page->_id;
         $pageComponent->accountId = $accountId;
         $pageComponent->jsonConfig = Yii::$app->params['micrositeDefaultConfig'][$pageComponent->name];
         $pageComponent->save();
     } else {
         throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
     }
 }
Esempio n. 2
0
 /**
  * Render widget, query string 't' indicates the name of the widget
  */
 public function actionWidget($id = '')
 {
     $widgetType = \Yii::$app->request->get('t', '');
     $params = \Yii::$app->params;
     $color = $params['micrositeDefaultColor'];
     $data = null;
     if (empty($widgetType)) {
         $this->redirect(self::NOT_FOUND_PAGE_PATH);
     }
     if (!empty($id)) {
         $id = new \MongoId($id);
         $widget = PageComponent::findByPk($id);
         if (empty($widget)) {
             $this->redirect(self::NOT_FOUND_PAGE_PATH);
         }
         if (!empty($widget['color'])) {
             $color = $widget['color'];
         }
         $data = $widget['jsonConfig'];
     }
     if (empty($data)) {
         $data = $params['micrositeDefaultConfig'][$widgetType];
     }
     $params = ['type' => $widgetType, 'color' => $color];
     $this->view->params = $params;
     $this->view->params['pageRGBColor'] = join(',', StringUtil::hex2rgb($color));
     $this->layout = self::WIDGET_PATH;
     $this->registerWidgetResource($widgetType);
     return $this->render(self::WIDGET_PATH . '/' . $widgetType, $data);
 }
Esempio n. 3
0
 /**
  * View a page with statistics data
  * @param  string $id page id
  */
 public function actionPublish($id)
 {
     $pageId = new \MongoId($id);
     $page = Page::findByPk($pageId);
     if (empty($page)) {
         throw new ServerErrorHttpException(Yii::t('microSite', 'page_not_exist'));
     }
     $cpts = PageComponent::getAllComponents($pageId);
     $page->cpts = ArrayHelper::toArray($cpts);
     $page->isFinished = true;
     if ($page->validate()) {
         // all inputs are valid
         if ($page->save()) {
             return ['message' => 'ok'];
         } else {
             throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
         }
     } else {
         // valid fail, return errors
         return $page->errors;
     }
 }
 private function _createDefaultPageCover($accountId, $hostinfo)
 {
     $defaultCoverPage = ['title' => '默认首页', 'description' => '默认首页', 'type' => 'cover', 'isFinished' => true, 'deletable' => false];
     $defaultCoverPageCompnent = ['name' => 'cover1', 'color' => '#6AB3F7', 'order' => 0];
     $page = Page::findOne(array_merge($defaultCoverPage, ['accountId' => $accountId]));
     if (empty($page)) {
         $page = new Page(['scenario' => 'createBasic']);
         $page->load($defaultCoverPage, '');
         $page->_id = new MongoId();
         $page->accountId = $accountId;
         $page->url = $hostinfo . '/msite/page/' . $page->_id;
         $shortUrl = Yii::$app->urlService->shortenUrl($page->url);
         $page->shortUrl = $shortUrl['Short'];
         if ($page->save()) {
             $pageComponent = new PageComponent(['scenario' => PageComponent::SCENARIO_CREATE]);
             $pageComponent->load($defaultCoverPageCompnent, '');
             $pageComponent->pageId = $page->_id;
             $pageComponent->parentId = $page->_id;
             $pageComponent->accountId = $accountId;
             $pageComponent->jsonConfig = Yii::$app->params['micrositeDefaultConfig'][$pageComponent->name];
             $pageComponent->save();
         } else {
             echo $page->getErrors() . PHP_EOL;
             exit;
         }
     } else {
         echo $accountId . 'data is exists' . PHP_EOL;
     }
 }
Esempio n. 5
0
 /**
  * get all components with page id
  * @param  MongoId $pageId microsite page id
  */
 public static function getAllComponents($pageId)
 {
     $pageComponents = PageComponent::getByParentId($pageId);
     foreach ($pageComponents as $pageComponent) {
         if ($pageComponent->name == PageComponent::COMPONENT_TYPE_TAB) {
             $parentId = $pageComponent->_id;
             $componentTabs = $pageComponent->jsonConfig['tabs'];
             $tabIndex = 0;
             foreach ($componentTabs as &$componentTab) {
                 $tabs = PageComponent::getByParentId($parentId, $tabIndex);
                 $componentTab['cpts'] = $tabs;
                 $tabIndex++;
             }
             $pageComponent->jsonConfig = ['tabs' => $componentTabs];
         }
     }
     return $pageComponents;
 }
 private function _updateOrder($condition, $inc, $pageId, $tabId = null, $tabIndex = null)
 {
     if (empty($tabId)) {
         PageComponent::updateAll(['$inc' => ['order' => $inc]], array_merge($condition, ['parentId' => $pageId]));
     } else {
         PageComponent::updateAll(['$inc' => ['order' => $inc]], array_merge($condition, ['parentId' => new \MongoId($tabId), 'tabIndex' => $tabIndex]));
     }
 }