Egorka
7 years ago
7 changed files with 99 additions and 8 deletions
@ -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(), |
||||||
|
]); |
||||||
|
} |
||||||
|
} |
@ -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…
Reference in new issue