Ejemplo n.º 1
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);
 }
 /**
  * Delete page component
  *
  * <b>Request Type: </b>DELETE<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/microsite/page-component/{id}
  * <b>Summary: </b>This api is for delete page component
  *
  * <b>Response Example: </b>
  * <pre>
  *  {'message' : 'OK'}
  * </pre>
  */
 public function actionDelete($id)
 {
     $pageComponentId = new \MongoId($id);
     $pageComponent = PageComponent::findByPk($pageComponentId);
     if (empty($pageComponent)) {
         throw new ServerErrorHttpException(\Yii::t('common', 'data_error'));
     }
     $result = PageComponent::deleteAll(['$or' => [['_id' => $pageComponentId], ['parentId' => $pageComponentId]]]);
     if ($result) {
         $tabId = $pageComponent->pageId === $pageComponent->parentId ? null : $pageComponent->parentId;
         $inc = -1;
         $condition = ['order' => ['$gt' => $pageComponent->order]];
         $this->_updateOrder($condition, $inc, $pageComponent->pageId, $tabId, $pageComponent->tabIndex);
     } else {
         throw new ServerErrorHttpException(\Yii::t('common', 'delete_fail'));
     }
     return ['message' => 'OK'];
 }