Blame view

common/models/OptionHelper.php 1.25 KB
b0f143c3   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
  <?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;
27f8af79   Yarik   test
13
  
b0f143c3   Yarik   first commit
14
      const OPTION_ARRAY = 2;
27f8af79   Yarik   test
15
  
b0f143c3   Yarik   first commit
16
      const OPTION_VALUE = 3;
27f8af79   Yarik   test
17
  
b0f143c3   Yarik   first commit
18
19
      public function getRule($return = 3)
      {
cdb04594   Yarik   test
20
          $result = Option::find()->where(['name' => 'rules'])->with('value');
b0f143c3   Yarik   first commit
21
22
23
24
25
26
27
28
29
30
          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'));
          }
      }
27f8af79   Yarik   test
31
32
33
34
35
36
37
38
  
      public function createOptions($user_id)
      {
          if($rows_delete = \Yii::$app->db->createCommand()->delete('option', ['model' => 'common\models\User', 'model_id' => $user_id])->execute()) {
              Yii::trace( $rows_delete . " rows has been deleted.");
          } else {
              Yii::trace( "No rows has been deleted" );
          }
317dd52a   Yarik   test
39
          //Yii::$app->db->createCommand()->batchInsert('option', ['model', 'model_id', 'name', 'template', 'option_pid'], [['common\models\User', $user_id, 'about', '']])
27f8af79   Yarik   test
40
41
      }
  
b0f143c3   Yarik   first commit
42
  }