Ejemplo n.º 1
0
 /**
  * The first step of creating page
  * Use the createBasic scenario
  **/
 public function actionCreate()
 {
     $params = $this->getParams();
     $accesstoken = $this->getAccessToken();
     $token = Token::getToken($accesstoken);
     $page = new Page(['scenario' => 'createBasic']);
     $page->attributes = $params;
     $page->_id = new \MongoId();
     $page->accountId = $token->accountId;
     $userId = $token->userId;
     $user = User::findByPk($userId);
     $page->creator = ['id' => $userId, 'name' => $user->name];
     $page->url = Yii::$app->request->hostinfo . '/msite/page/' . $page->_id;
     $shortUrl = Yii::$app->urlService->shortenUrl($page->url);
     $page->shortUrl = $shortUrl['Short'];
     if ($page->validate()) {
         // all inputs are valid
         if ($page->save()) {
             return $page;
         } else {
             throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
         }
     } else {
         // valid fail, return errors
         $errors = array_keys($page->errors);
         throw new InvalidParameterException([$errors[0] => Yii::t("microSite", $errors[0] . '_field_not_empty')]);
     }
 }
Ejemplo n.º 2
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'));
     }
 }
Ejemplo n.º 3
0
 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;
     }
 }