Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Domain::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // Important: here is how we set up the sorting
     // The key is the attribute name on our "TourSearch" instance
     $dataProvider->sort->attributes['search_date_created'] = ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC]];
     // Important: here is how we set up the sorting
     // The key is the attribute name on our "TourSearch" instance
     $dataProvider->sort->attributes['search_date_updated'] = ['asc' => ['updated_at' => SORT_ASC], 'desc' => ['updated_at' => 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;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'locale_group_id' => $this->locale_group_id, 'dealer_id' => $this->dealer_id]);
     if ($this->search_date_created != '') {
         $this->data_begin_created = strtotime($this->search_date_created);
         $this->data_end_created = strtotime($this->search_date_created) + 24 * 60 * 60;
     }
     if ($this->search_date_updated != '') {
         $this->data_begin_updated = strtotime($this->search_date_updated);
         $this->data_end_updated = strtotime($this->search_date_updated) + 24 * 60 * 60;
     }
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['between', 'created_at', $this->data_begin_created, $this->data_end_created])->andFilterWhere(['between', 'updated_at', $this->data_begin_updated, $this->data_end_updated])->andFilterWhere(['like', 'locale', $this->locale]);
     return $dataProvider;
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $domain = preg_split("/\r\n/isU", trim($this->domain_txt));
     $site_id = $this->getPrimaryKey();
     $domains = Domain::find()->where(['site_id' => $site_id])->all();
     foreach ($domain as $key => $dm) {
         $dm = trim($dm);
         if (empty($dm)) {
             continue;
         }
         $domain_model = $this->findModelByDomain($domains, $dm);
         if (!isset($domain_model)) {
             $domain_model = new Domain();
         }
         if ($key === 0) {
             $domain_model->main = 1;
         } else {
             $domain_model->main = 0;
         }
         $domain_model->domain = $dm;
         $domain_model->site_id = $this->id;
         $domain_model->save();
     }
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Domain::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status, 'locale_group_id' => $this->locale_group_id, 'dealer_id' => $this->dealer_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'locale', $this->locale]);
     return $dataProvider;
 }
Example #4
0
 private function _getDomainsArray()
 {
     $domainsArray = ArrayHelper::map(Domain::find()->active()->all(), 'id', 'title');
     $domainsArray['0'] = '';
     ksort($domainsArray);
     return $domainsArray;
 }