Exemple #1
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = MstAccount::findByUsername($this->username);
     }
     return $this->_user;
 }
 /**
  * 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;
 }
Exemple #3
0
 /**
  * Validates username
  *
  * @param attribute
  * @param $params
  */
 public function validateUsername($attribute, $params)
 {
     $userName = MstAccount::findUniqueUsername($this->username, $this->id);
     if (!Yii::$app->request->post('hasEditable') && $userName) {
         $this->addError('username', 'Username is already taken.');
     }
 }
 /**
  * Creates a new MstAccount model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreateUser()
 {
     $model = new MstAccount();
     $date = date('Y-m-d H:i:s');
     // @TODO Use Yii dateformatter
     // set defaults
     // @TODO: transfer updating of status/created/updated details to model
     // set status, created and updated details
     $model->status = Yii::$app->params['STATUS_ACTIVE'];
     $model->creator_id = Yii::$app->user->id;
     $model->created_date = $date;
     $model->updater_id = Yii::$app->user->id;
     $model->updated_date = $date;
     // get plant list
     $plant_location_list = Yii::$app->modelFinder->getPlantList(null, ['status' => Yii::$app->params['STATUS_ACTIVE']], 'plant_location');
     $assignment_list = ArrayHelper::map($plant_location_list, 'plant_location', 'plant_location');
     if ($model->load(Yii::$app->request->post())) {
         $model->password = md5($model->password);
         // convert to correct date format
         $model->start_date = Yii::$app->dateFormatter->convert($model->start_date);
         $model->end_date = Yii::$app->dateFormatter->convert($model->end_date);
         if ($model->save()) {
             return $this->redirect(['view-user', 'id' => $model->id]);
         } else {
             return $this->render('create-user', ['model' => $model, 'assignment_list' => $assignment_list]);
         }
     } else {
         return $this->render('create-user', ['model' => $model, 'assignment_list' => $assignment_list]);
     }
 }
Exemple #5
0
 /**
  * Finds the MstAccount model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return MstAccount the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 public function findAccountModel($id)
 {
     if (($model = MstAccount::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }