Ejemplo n.º 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRes8Owner()
 {
     return $this->hasOne(Player::className(), ['id' => 'res8OwnerId'])->from(Player::tableName() . ' pro8');
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     if (empty($params)) {
         $query = Portal::find()->where(0);
     } else {
         $query = Portal::find()->joinWith('currOwner', true, 'INNER JOIN');
         if (Yii::$app->getUser()->identity !== null) {
             Yii::info('Поиск порталов пользователем ' . Yii::$app->getUser()->identity->email . ' по параметрам:' . var_export($params, true), 'user');
         }
     }
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50], 'sort' => ['defaultOrder' => ['timePassed' => SORT_DESC]]]);
     $dataProvider->sort->attributes['currOwner'] = ['asc' => [Player::tableName() . '.agentId' => SORT_ASC], 'desc' => [Player::tableName() . '.agentId' => SORT_DESC]];
     $dataProvider->sort->attributes['involved'] = ['asc' => [Player::tableName() . '.agentId' => SORT_ASC], 'desc' => [Player::tableName() . '.agentId' => SORT_DESC]];
     $dataProvider->sort->attributes['timePassed'] = ['asc' => ['dateCapture' => SORT_DESC], 'desc' => ['dateCapture' => SORT_ASC]];
     $dataProvider->sort->attributes['formattedDateCapture'] = ['asc' => ['dateCapture' => SORT_ASC], 'desc' => ['dateCapture' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'approved' => $this->approved, 'level' => $this->level, 'resCount' => $this->resCount, 'dateCapture' => $this->dateCapture, 'timeUpdated' => $this->timeUpdated]);
     $query->andFilterWhere(['like', 'guid', $this->guid])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['in', 'currOwnerId', $this->currOwnerId]);
     if (!empty($this->timePassed)) {
         if (mb_strpos($this->timePassed, '-') === false) {
             $this->timePassed = (int) $this->timePassed;
             $query->andFilterWhere(['<', 'dateCapture', time() - ($this->timePassed - 1) * 3600 * 24]);
             $query->andFilterWhere(['>', 'dateCapture', time() - $this->timePassed * 3600 * 24]);
         } else {
             $data = explode('-', $this->timePassed);
             foreach ($data as &$d) {
                 $d = (int) $d;
             }
             $query->andFilterWhere(['<', 'dateCapture', time() - $data[0] * 3600 * 24]);
             $query->andFilterWhere(['>', 'dateCapture', time() - $data[1] * 3600 * 24]);
             unset($data, $d);
         }
     }
     if (!empty($this->point1) && !empty($this->point2)) {
         if ($this->extractCoords($this->point1)[0] < $this->extractCoords($this->point2)[0]) {
             $query->andWhere(['between', 'lat', $this->extractCoords($this->point1)[0], $this->extractCoords($this->point2)[0]]);
         } else {
             $query->andWhere(['between', 'lat', $this->extractCoords($this->point2)[0], $this->extractCoords($this->point1)[0]]);
         }
         if ($this->extractCoords($this->point1)[1] < $this->extractCoords($this->point2)[1]) {
             $query->andWhere(['between', 'lng', $this->extractCoords($this->point1)[1], $this->extractCoords($this->point2)[1]]);
         } else {
             $query->andWhere(['between', 'lng', $this->extractCoords($this->point2)[1], $this->extractCoords($this->point1)[1]]);
         }
     }
     if (!empty($this->involved)) {
         $query->andWhere('
         [[currOwnerId]] IN (:inv) OR
         [[mod1OwnerId]] IN (:inv) OR
         [[mod2OwnerId]] IN (:inv) OR
         [[mod3OwnerId]] IN (:inv) OR
         [[mod4OwnerId]] IN (:inv) OR
         [[res1OwnerId]] IN (:inv) OR
         [[res2OwnerId]] IN (:inv) OR
         [[res3OwnerId]] IN (:inv) OR
         [[res4OwnerId]] IN (:inv) OR
         [[res5OwnerId]] IN (:inv) OR
         [[res6OwnerId]] IN (:inv) OR
         [[res7OwnerId]] IN (:inv) OR
         [[res8OwnerId]] IN (:inv)
         ', [':inv' => implode(',', $this->involved)]);
     }
     return $dataProvider;
 }