SlugAction::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace zacksleo\yii2\ad\actions;
4
5
use yii\base\Action;
6
use zacksleo\yii2\ad\models\Ad;
7
use zacksleo\yii2\ad\models\AdPosition;
8
9
class SlugAction extends Action
10
{
11
    public $slug;
12
13
    public function run()
14
    {
15
        if (($position = AdPosition::findOne(['slug' => $this->slug, 'status' => AdPosition::STATUS_ACTIVE])) == null) {
16
            return [];
17
        }
18
        return Ad::find()->orderBy('order')
19
            ->where(
20
                [
21
                    'position_id' => $position->id,
22
                    'status' => Ad::STATUS_ACTIVE
23
                ]
24
            )->andWhere(['<=', 'available_from', time()])
25
            ->andWhere(['>', 'available_to', time()])
26
            ->all();
27
    }
28
}
29