Blame view

common/modules/comment/models/CommentProjectSearch.php 2.46 KB
377b29c7   Yarik   Yarik comment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  <?php
      namespace common\modules\comment\models;
  
      use common\models\Currency;
      use common\models\File;
      use common\models\User;
      use yii\data\ActiveDataProvider;
      use yii\db\ActiveQuery;
      use yii\db\ActiveRecord;
      use yii\web\UploadedFile;
  
      /**
       * Class Comment
       * @property bool     $guestComment
       * @property integer  $comment_id
       * @property string   $text
       * @property int      $user_id
       * @property int      $status
       * @property string   $date_add
       * @property string   $date_update
       * @property string   $date_delete
       * @property string   $model
       * @property int      $model_id
       * @property string   $files
       * @property float    $budget_from
       * @property float    $budget_to
       * @property int      $term_from
       * @property int      $term_to
       * @property int      $state
       * @property Currency $currency
       * @package common\modules\comment\models
       */
      class CommentProjectSearch extends CommentProject
      {
  
          const SCENARIO_SEARCH = 'search';
  
          public function rules()
          {
              return [
                  [
                      [
                          'state',
                      ],
                      'integer',
                      'max' => 5,
                      'min' => 1,
                  ],
                  [
                      [
                          'state',
                      ],
                      'default',
                      'value' => self::STATE_NEW,
                  ],
              ];
          }
  
          public function scenarios()
          {
              return array_merge(parent::scenarios(), [
                  self::SCENARIO_SEARCH => [
                      'state',
                  ],
              ]);
          }
  
          public function search($params)
          {
              $query = CommentProject::find()
                                     ->with('project')
                                     ->with('project.budgetCurrency')
                                     ->with('project.comments')
                                     ->where([ 'user_id' => \Yii::$app->user->getId() ]);
  
              $dataProvider = new ActiveDataProvider([
                  'query' => $query,
              ]);
  
              $this->load($params);
  
              if(!$this->validate()) {
                  $query->andWhere('0=1');
                  return $dataProvider;
              }
  
              $query->andWhere([ 'state' => $this->state ]);
  
              return $dataProvider;
          }
  
      }