Browse Source

Blog save-preview fix

master
Egorka 6 years ago
parent
commit
37524a68a1
  1. 11
      common/modules/blog/controllers/PostController.php
  2. 2
      common/modules/blog/controllers/manage/PostController.php
  3. 2
      common/modules/blog/forms/BlogPostForm.php
  4. 8
      common/modules/blog/views/manage/post/_form.php
  5. 4
      common/modules/blog/views/post/post.php
  6. 42
      common/modules/blog/widgets/PostByTagsWidget.php
  7. 38
      common/modules/blog/widgets/views/slider-relative.php

11
common/modules/blog/controllers/PostController.php

@ -214,11 +214,12 @@ class PostController extends FrontendController
$post->image = $filename; $post->image = $filename;
} }
$path = $post->getUploadedFilePath('image'); if ($post->image && !is_string($post->image)) {
FileHelper::createDirectory(pathinfo($path, PATHINFO_DIRNAME), 0775, true); $path = $post->getUploadedFilePath( 'image' );
$post->image->saveAs($path); FileHelper::createDirectory( pathinfo( $path, PATHINFO_DIRNAME ), 0775, true );
$post->image->saveAs( $path );
$post->image = $post->getImageFileUrl('image'); $post->image = $post->getImageFileUrl( 'image' );
}
return $this->render('post', [ return $this->render('post', [
'post' => $post, 'post' => $post,

2
common/modules/blog/controllers/manage/PostController.php

@ -87,6 +87,7 @@ class PostController extends Controller
public function actionCreate() public function actionCreate()
{ {
$form = new BlogPostForm(); $form = new BlogPostForm();
$form->action = 'create';
$form->published_at = date('d.m.Y H:i:s'); $form->published_at = date('d.m.Y H:i:s');
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {
@ -112,6 +113,7 @@ class PostController extends Controller
{ {
$post = $this->findModel($id); $post = $this->findModel($id);
$form = new BlogPostForm($post); $form = new BlogPostForm($post);
$form->action = 'update';
$form->published_at = date('d.m.Y H:i:s', $form->published_at); $form->published_at = date('d.m.Y H:i:s', $form->published_at);
if ($form->load(Yii::$app->request->post()) && $form->validate()) { if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try { try {

2
common/modules/blog/forms/BlogPostForm.php

@ -17,6 +17,8 @@ use Yii;
*/ */
class BlogPostForm extends CompositeForm class BlogPostForm extends CompositeForm
{ {
public $action;
public $category_id; public $category_id;
public $title; public $title;
public $description; public $description;

8
common/modules/blog/views/manage/post/_form.php

@ -149,7 +149,13 @@ $this->registerJs($js2);
</div> </div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?> <?= Html::submitButton(Yii::t('buttons', 'Save'), [
'class' => 'btn btn-success',
'value'=>'save',
'name'=>'submit_save',
'formaction' => Yii::$app->request->getUrl(),
'formtarget' => '_self',
]) ?>
</div> </div>

4
common/modules/blog/views/post/post.php

@ -3,7 +3,7 @@
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $post \common\modules\blog\entities\BlogPost */ /* @var $post \common\modules\blog\entities\BlogPost */
use frontend\widgets\post\CommentsWidget; use common\modules\blog\widgets\CommentsWidget;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url; use yii\helpers\Url;
@ -98,7 +98,7 @@ $this->registerJs($js, $this::POS_READY);
</div> </div>
</div> </div>
<?= \frontend\widgets\post\PostByTagsWidget::widget([ <?= \common\modules\blog\widgets\PostByTagsWidget::widget([
'count' => 10, 'count' => 10,
'view' => 'slider-relative', 'view' => 'slider-relative',
'post' => $post, 'post' => $post,

42
common/modules/blog/widgets/PostByTagsWidget.php

@ -0,0 +1,42 @@
<?php
/**
* Created by Error202
* Date: 24.01.2018
*/
namespace common\modules\blog\widgets;
use common\modules\blog\entities\BlogTagAssignment;
use common\modules\blog\repositories\read\BlogPostReadRepository;
use yii\base\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
class PostByTagsWidget extends Widget
{
public $count;
public $view;
public $post;
public $posts;
public function __construct(BlogPostReadRepository $posts, $config = [])
{
parent::__construct($config);
$this->count = $this->count ? $this->count : 5;
$this->posts = $posts;
}
public function run(): string
{
$tag_ids = ArrayHelper::getColumn(BlogTagAssignment::find()->andWhere(['post_id' => $this->post->id])->all(), 'tag_id');
$posts = $this->posts->getByTagsId($this->post, $tag_ids, $this->count)->getModels();
return $this->render($this->view, [
'posts' => $posts,
'view' => $this->view,
'url' => Url::canonical(),
]);
}
}

38
common/modules/blog/widgets/views/slider-relative.php

@ -0,0 +1,38 @@
<?php
/**
* @var $this \yii\web\View
* @var $view string
* @var $posts \common\modules\blog\entities\BlogPost[]
*/
?>
<div class="row">
<div class="col-sm-12 owl-carousel-outer-navigation">
<!-- Heading Component-->
<article class="heading-component">
<div class="heading-component-inner">
<h5 class="heading-component-title"><?= Yii::t('post', 'Related') ?>
</h5>
<div class="owl-carousel-arrows-outline">
<div class="owl-nav">
<button class="owl-arrow owl-arrow-prev" id="relative-button-prev"></button>
<button class="owl-arrow owl-arrow-next" id="relative-button-next"></button>
</div>
</div>
</div>
</article>
<!-- Blog Carousel-->
<div id="relative_carousel" class="owl-carousel row">
<?php foreach ($posts as $post): ?>
<?= $this->render($view . '_item', [
'post' => $post
]) ?>
<?php endforeach; ?>
</div>
</div>
</div>
Loading…
Cancel
Save