Пример #1
0
 /**
  * @param ModelContent $content
  * @param CmgFile $banner
  * @return Page
  */
 public static function create($parent, $parentType, $content, $publish = false, $banner = null, $video = null)
 {
     // template
     if (isset($content->templateId) && $content->templateId <= 0) {
         unset($content->templateId);
     }
     // publish
     if ($publish && !isset($content->publishedAt)) {
         $date = DateUtil::getDateTime();
         $content->publishedAt = $date;
     }
     // parent
     $content->parentId = $parent->id;
     $content->parentType = $parentType;
     // banner, video
     if (isset($banner)) {
         FileService::saveImage($banner, ['model' => $content, 'attribute' => 'bannerId']);
     }
     if (isset($video)) {
         FileService::saveImage($video, ['model' => $content, 'attribute' => 'videoId']);
     }
     // Create Content
     $content->save();
     return $content;
 }
Пример #2
0
 public function actionCreate()
 {
     $model = new Post();
     $model->siteId = Yii::$app->cmgCore->siteId;
     $content = new ModelContent();
     $banner = CmgFile::loadFile(null, 'File');
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post(), 'Post') && $content->load(Yii::$app->request->post(), 'ModelContent') && $model->validate() && $content->validate()) {
         $post = PostService::create($model);
         if (isset($post)) {
             // Create Content
             ModelContentService::create($post, CmsGlobal::TYPE_POST, $content, $post->isPublished(), $banner);
             // Bind Categories
             $binder = new Binder();
             $binder->binderId = $model->id;
             $binder->load(Yii::$app->request->post(), 'Binder');
             PostService::bindCategories($binder);
             $this->redirect(['all']);
         }
     }
     $categories = CategoryService::getIdNameListByType(CmsGlobal::TYPE_POST);
     $visibilityMap = Page::$visibilityMap;
     $statusMap = Page::$statusMap;
     $templatesMap = TemplateService::getIdNameMapByType(CmsGlobal::TYPE_POST);
     $templatesMap = ArrayHelper::merge(['0' => 'Choose Template'], $templatesMap);
     return $this->render('create', ['model' => $model, 'content' => $content, 'banner' => $banner, 'categories' => $categories, 'visibilityMap' => $visibilityMap, 'statusMap' => $statusMap, 'templatesMap' => $templatesMap]);
 }
Пример #3
0
 /**
  * @return ModelContent associated with parent.
  */
 public function getContent()
 {
     $parentType = $this->contentType;
     return $this->hasOne(ModelContent::className(), ['parentId' => 'id'])->where("parentType='{$parentType}'");
 }