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]);
 }
Exemple #2
0
 /**
  * @param Post $post
  * @param CmgFile $banner
  * @return Post
  */
 public static function create($post)
 {
     $post->type = CmsGlobal::TYPE_POST;
     if (!isset($post->order) || strlen($post->order) <= 0) {
         $post->order = 0;
     }
     // Create Post
     $post->save();
     return $post;
 }
Exemple #3
0
 public function getParent()
 {
     switch ($row['type']) {
         case self::TYPE_PAGE:
             return $this->hasOne(Page::className(), ['id' => 'parentId']);
         case self::TYPE_POST:
             return $this->hasOne(Post::className(), ['id' => 'parentId']);
     }
 }
Exemple #4
0
 public static function getPagination($config = [])
 {
     $postTable = CmsTables::TABLE_PAGE;
     $sort = new Sort(['attributes' => ['name' => ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'name'], 'slug' => ['asc' => ['slug' => SORT_ASC], 'desc' => ['slug' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'name'], 'visibility' => ['asc' => ['visibility' => SORT_ASC], 'desc' => ['visibility' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'visibility'], 'status' => ['asc' => ['status' => SORT_ASC], 'desc' => ['status' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'status'], 'template' => ['asc' => ['template' => SORT_ASC], 'desc' => ['template' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'template'], 'cdate' => ['asc' => ['createdAt' => SORT_ASC], 'desc' => ['createdAt' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'cdate'], 'pdate' => ['asc' => ['publishedAt' => SORT_ASC], 'desc' => ['publishedAt' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'pdate'], 'udate' => ['asc' => ['updatedAt' => SORT_ASC], 'desc' => ['updatedAt' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'udate']], 'defaultOrder' => ['pdate' => 'desc']]);
     if (!isset($config['conditions'])) {
         $config['conditions'] = [];
     }
     if (!isset($config['query'])) {
         $config['query'] = Post::findWithAuthor();
     }
     if (!isset($config['sort'])) {
         $config['sort'] = $sort;
     }
     if (!isset($config['search-col'])) {
         $config['search-col'] = 'name';
     }
     if (!isset($config['route'])) {
         $config['route'] = 'blog';
     }
     $config['conditions']["{$postTable}.status"] = Post::STATUS_PUBLISHED;
     $config['conditions']["{$postTable}.visibility"] = Post::VISIBILITY_PUBLIC;
     return self::getDataProvider(new Post(), $config);
 }