You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
922 B

<?php
/**
* Created by Error202
* Date: 31.07.2018
*/
namespace common\modules\banners\widgets;
use common\modules\banners\entities\Banner;
use common\modules\banners\entities\BannerPlace;
use yii\base\Widget;
class BannerWidget extends Widget
{
public $id;
public function run()
{
$place = BannerPlace::findOne($this->id);
if (!$place) {
return 'Place is not found';
}
$banners = Banner::find()
->active()
->showTime()
//->excludeFree()
->andWhere(['place_id' => $place->id])
->all();
if (!$banners || $place->isDraft()) {
return '';
}
/* @var $banner Banner */
$banner = $banners[array_rand($banners)];
return $this->render('banner', [
'banner' => $banner,
]);
}
}