/**
  * Creates data provider instance with search query applied
  *
  * @param array $params        	
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CmsDocument::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'language' => $this->language]);
     $query->andFilterWhere(['like', 'file_name', $this->file_name])->andFilterWhere(['like', 'file_path', $this->file_path])->andFilterWhere(['like', 'mime_type', $this->mime_type]);
     return $dataProvider;
 }
 /**
  * display the document in the chosen presentation style (Inline, Window or send as download response)
  * @menuLabel __HIDDEN__
  * @param unknown $documentId
  * @throws NotFoundHttpException
  * @return void|string
  */
 public function actionDocument($documentId)
 {
     $documentId = intval($documentId);
     $documentModel = CmsDocument::findOne($documentId);
     if ($documentModel == null) {
         throw new NotFoundHttpException('Document could not be found', 404);
     }
     $filePath = $documentModel->file_path . DIRECTORY_SEPARATOR . $documentModel->file_name;
     if (file_exists($filePath)) {
         switch ($documentModel->presentation_style) {
             case CmsDocument::PRESENTATION_STYLE_DOWNLOAD:
                 Yii::$app->response->sendFile($filePath, $documentModel->file_name, ['mimeType' => $documentModel->mime_type, 'inline' => false])->send();
                 return;
             case CmsDocument::PRESENTATION_STYLE_WINDOW:
                 Yii::$app->response->sendFile($filePath, $documentModel->file_name, ['mimeType' => $documentModel->mime_type, 'inline' => true])->send();
                 return;
             case CmsDocument::PRESENTATION_STYLE_EMBEDED:
                 return $this->render('document', ['documentModel' => $documentModel]);
                 break;
             default:
                 break;
         }
     } else {
         throw new NotFoundHttpException('Document could not be found, invalid path', 404);
     }
 }
 /**
  * @menuLabel __HIDDEN__
  * @menuIcon <span class="glyphicon glyphicon-list-alt"></span>
  */
 public function actionEditMenuLanguageVersion($menuItemId, $useget = false)
 {
     $menuItemId = intval($menuItemId);
     $model_menu = CmsMenuItem::find()->where(['id' => $menuItemId])->with('cmsHierarchyItem')->one();
     $hierarchyItem = $model_menu->cmsHierarchyItem;
     $languageCode = $this->module->getLanguageManager()->getMappingForIdResolveAlias($model_menu->language);
     $model_wrapperform = new MenuItemAndContentForm();
     if ($useget) {
         $model_wrapperform->load(Yii::$app->request->get());
     } else {
         $model_wrapperform->load(Yii::$app->request->post());
     }
     $model_content = null;
     $model_document = null;
     $message = null;
     $page_content_id_set = $model_menu->page_content_id != null;
     $contentType = $page_content_id_set ? MenuItemAndContentForm::CONTENT_TYPE_PAGE : intval($model_wrapperform->contentType);
     /**
      * **** PAGE CONTENT FORM ****************
      */
     if ($page_content_id_set || $contentType == intval(MenuItemAndContentForm::CONTENT_TYPE_PAGE)) {
         $model_content = new CmsPageContent();
         if ($page_content_id_set) {
             $model_content = CmsPageContent::findOne($model_menu->page_content_id);
         }
         $loadSuccess_content = $model_content->load(Yii::$app->request->post());
         // check if menu item needs to be saved
         $model_content->language = $model_menu->language;
         if ($loadSuccess_content) {
             if ($model_content->created_datetime == null) {
                 $model_content->created_datetime = new Expression('NOW()');
                 $model_content->createdby_userid = Yii::$app->user->id;
             }
             if ($model_content->validate() && $model_content->save()) {
                 // link new item to menu if needed
                 if (!$page_content_id_set) {
                     $model_menu->page_content_id = $model_content->id;
                     if ($model_menu->save()) {
                         $message .= '<span class="success">' . Yii::t('simplecms', 'Content linked to Menu language version') . '</span>';
                     } else {
                         $message .= '<span class="error">' . Yii::t('simplecms', 'Error: content saved, yet it could not be linked to the menu language version!') . implode($model_content->getFirstErrors(), ' ') . '</span>';
                     }
                 }
                 $message .= '<span class="success">' . Yii::t('simplecms', 'Content saved successfully') . '</span>';
             } else {
                 $message .= '<span class="error">' . Yii::t('simplecms', 'Error: saving content failed!') . implode($model_content->getFirstErrors(), ' ') . '</span>';
             }
         }
         // update menu item
         // $menu_item_new_name = new CmsMenuItem();
         if ($model_menu->load(Yii::$app->request->post())) {
             if ($model_menu->save()) {
                 $message .= '<span class="success">' . Yii::t('simplecms', 'Menu details saved successfully') . '</span>';
             } else {
                 $message .= '<span class="error">' . Yii::t('simplecms', 'Error: saving new menu name!') . '</span>';
             }
         }
         $model_wrapperform->contentType = MenuItemAndContentForm::CONTENT_TYPE_PAGE;
     } else {
         if ($model_menu->document_id != null || $contentType == MenuItemAndContentForm::CONTENT_TYPE_DOCUMENT) {
             /**
              * **** DOCUMENT FORM ****************
              */
             if ($model_menu->document_id != null) {
                 $model_document = CmsDocument::findOne($model_menu->document_id);
             } else {
                 $model_document = new CmsDocument();
                 $model_document->created_datetime = new Expression('NOW()');
                 $model_document->createdby_userid = Yii::$app->user->id;
             }
             $loadSuccess_document = $model_document->load(Yii::$app->request->post());
             // set fixed values
             $model_document->language = $model_menu->language;
             if ($loadSuccess_document) {
                 if ($model_document->save()) {
                     // link new item to menu if needed
                     if ($model_menu->document_id == null) {
                         $model_menu->document_id = $model_document->id;
                         $model_menu->save();
                     }
                     $message .= '<span class="success">' . Yii::t('simplecms', 'Document saved successfully') . '</span>';
                 } else {
                     $message .= '<span class="error">' . Yii::t('simplecms', 'Error: saving document failed!') . '</span>';
                 }
             }
             // check if menu item name has been altered
             if ($model_menu->load(Yii::$app->request->post())) {
                 if ($model_menu->save()) {
                     $message .= '<span class="success">' . Yii::t('simplecms', 'Menu details saved successfully') . '</span>';
                 } else {
                     $message .= '<span class="error">' . Yii::t('simplecms', 'Error: saving new menu name!') . '</span>';
                 }
             }
             $model_wrapperform->contentType = MenuItemAndContentForm::CONTENT_TYPE_DOCUMENT;
         } else {
             if ($model_menu->direct_url != null || $contentType == MenuItemAndContentForm::CONTENT_TYPE_URL) {
                 /**
                  * **** DIRECT URL FORM ****************
                  */
                 if ($model_menu->load(Yii::$app->request->post())) {
                     if ($model_menu->save()) {
                         $message .= '<span class="success">' . Yii::t('simplecms', 'Menu details saved successfully') . '</span>';
                     } else {
                         $message .= '<span class="error">' . Yii::t('simplecms', 'Error: saving new menu name!') . '</span>';
                     }
                 }
                 $model_wrapperform->contentType = MenuItemAndContentForm::CONTENT_TYPE_URL;
             } else {
                 // illegal state, no content found for item, menu might not have been created properly or not completed, display selector for new content type
                 $model_wrapperform->contentType = MenuItemAndContentForm::CONTENT_TYPE_UNDEFINED;
             }
         }
     }
     // get post parameters
     // TODO
     // set default values
     return $this->render('editMenuAndContent', ['model_wrapperform' => $model_wrapperform, 'model_content' => $model_content, 'hierarchy_item' => $hierarchyItem, 'languageCode' => $languageCode, 'model_document' => $model_document, 'model_menu' => $model_menu, 'message' => $message]);
 }
Esempio n. 4
0
 /**
  *
  * @return \yii\db\ActiveQuery
  */
 public function getDocument()
 {
     return $this->hasOne(CmsDocument::className(), ['id' => 'document_id']);
 }
 /**
  * Finds the CmsDocument model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id        	
  * @return CmsDocument the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CmsDocument::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }