/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Subscriber::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, 'status' => $this->status]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'pwd', $this->pwd]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Subscriber::find(); $query->leftJoin('phone', 'phone.subscriber_id = subscriber.id'); $dataProvider = new ActiveDataProvider(['query' => $query]); /*echo "<pre>"; print_r($query); print_r($dataProvider); die;*/ $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->orFilterWhere(['user_id' => Yii::$app->user->getId(), 'birth_date' => $this->globalSearch]); $query->orFilterWhere(["phone.number" => $this->globalSearch]); $query->orFilterWhere(['like', 'name', $this->globalSearch])->orFilterWhere(['like', 'notes', $this->globalSearch]); return $dataProvider; }
public function get($id, $elequent) { $cacheKey = self::CACHE . $id; if ($elequent) { return Subscriber::find($id); } $cachedData = \Cache::has($cacheKey); if (empty($cachedData)) { $subscriber = Subscriber::find($id); if (!empty($subscriber)) { $subscriber = $subscriber->toArray(); $subscriber['updated_at'] = date('Y-m-d', strtotime($subscriber['updated_at'])); $subscriber['created_at_formatted'] = date('Y-m-d', strtotime($subscriber['created_at'])); $subscriber['updated_at_formatted'] = date('Y-m-d', strtotime($subscriber['updated_at'])); // Set data in cache \Cache::forever($cacheKey, $subscriber); return $subscriber; } else { return false; } } else { return \Cache::get($cacheKey); } }