Blame view

common/models/OptionHelper.php 757 Bytes
b0f143c3   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <?php
  
  namespace common\models;
  
  use frontend\models\Options;
  use Yii;
  use yii\base\InvalidParamException;
  use yii\base\Model;
  
  class OptionHelper extends Model
  {
      const OPTION_OBJECT = 1;
      const OPTION_ARRAY = 2;
      const OPTION_VALUE = 3;
      public function getRule($return = 3)
      {
cdb04594   Yarik   test
17
          $result = Option::find()->where(['name' => 'rules'])->with('value');
b0f143c3   Yarik   first commit
18
19
20
21
22
23
24
25
26
27
28
          if($return == self::OPTION_OBJECT) {
              return $result->one();
          } elseif($return == self::OPTION_ARRAY) {
              return $result->asArray()->one();
          } elseif($return == self::OPTION_VALUE) {
              return $result->one()->value->value;
          } else {
              throw new InvalidParamException(Yii::t('app', 'Must be 1-3'));
          }
      }
  }