/** * Gets the account list from MstAccount model based on its status. * If the model is not found, return empty array. * @return MstAccount the loaded array */ public function getAccountList($index = null, $conditions = null, $count = null) { if (null != $count) { // to retrieve all *active* materials by their index and order them by their ID: $accounts = MstAccount::find()->where(['not', ['id' => Yii::$app->user->id]])->andWhere(ArrayHelper::merge($conditions, ['status' => Yii::$app->params['STATUS_ACTIVE']]))->indexBy($index)->count($count); } else { // to retrieve all *active* materials by their index and order them by their ID: $accounts = MstAccount::find()->where(['not', ['id' => Yii::$app->user->id]])->andWhere(ArrayHelper::merge($conditions, ['status' => Yii::$app->params['STATUS_ACTIVE']]))->orderBy('id')->indexBy($index)->all(); } return $accounts; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MstAccount::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->where(['status' => Yii::$app->params['STATUS_ACTIVE']]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'last_login_date' => $this->last_login_date, 'creator_id' => $this->creator_id, 'created_date' => $this->created_date, 'updater_id' => $this->updater_id, 'updated_date' => $this->updated_date]); $query->andFilterWhere(['like', 'account_type', $this->account_type])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'access_token', $this->access_token])->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'assignment', $this->assignment])->andFilterWhere(['like', 'status', $this->status]); // start date range filter if (isset($this->start_date) && $this->start_date != null) { $startDate = explode(' - ', $this->start_date); $startDateFrom = Yii::$app->dateFormatter->convert($startDate[0]); $startDateTo = Yii::$app->dateFormatter->convert($startDate[1]); $query->andFilterWhere(['between', 'start_date', $startDateFrom, $startDateTo]); } // end date range filter if (isset($this->end_date) && $this->end_date != null) { $endDate = explode(' - ', $this->end_date); $endDateFrom = Yii::$app->dateFormatter->convert($endDate[0]); $endDateTo = Yii::$app->dateFormatter->convert($endDate[1]); $query->andFilterWhere(['between', 'end_date', $endDateFrom, $endDateTo]); } // next start date range filter if (isset($this->next_start_date) && $this->next_start_date != null) { $nextStartDate = explode(' - ', $this->next_start_date); $nextStartDateFrom = Yii::$app->dateFormatter->convert($nextStartDate[0]); $nextStartDateTo = Yii::$app->dateFormatter->convert($nextStartDate[1]); $query->andFilterWhere(['between', 'next_start_date', $nextStartDateFrom, $nextStartDateTo]); } // next end date range filter if (isset($this->next_end_date) && $this->next_end_date != null) { $nextEndDate = explode(' - ', $this->next_end_date); $nextEndDateFrom = Yii::$app->dateFormatter->convert($nextEndDate[0]); $nextEndDateTo = Yii::$app->dateFormatter->convert($nextEndDate[1]); $query->andFilterWhere(['between', 'next_end_date', $nextEndDateFrom, $nextEndDateTo]); } return $dataProvider; }
/** * Find unique user by username * * @param string $username * @return static|null */ public static function findUniqueUsername($username, $accountId) { $account = MstAccount::find()->where(['username' => $username, 'status' => Yii::$app->params['STATUS_ACTIVE']])->andWhere(['not', ['id' => $accountId]])->one(); return $account; }