/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { $profile = new Profile(); $profile->loadDefaultValues(); $profile->first_name = $this->first_name; $profile->last_name = $this->last_name; $profile->dob = $this->dob; $profile->address = $this->address; $profile->address2 = $this->address2; $profile->district = $this->district; $profile->state = $this->state; $profile->mobile = $this->mobile; $profile->ic = $this->ic; $profile->postcode = $this->postcode; $profile->name = $this->name; $profile->link('user', $user); if ($this->role == 'ENT') { $ent = new Entrepreneur(); $ent->plkn = $this->plkn; $ent->link('user', $user); } elseif ($this->role == 'MNT') { $mnt = new Mentor(); $mnt->link('user', $user); } Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($user->email)->setSubject('SALEXES Registration')->setTextBody('Congratulations you have been succesfully registered with us !!!')->setHtmlBody('<b>Please contact admin@9teraju.com to make payment for account activation.</b>')->send(); return $user; } } return null; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Mentor::find(); $query->joinWith(['user', 'profile']); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['username'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]]; $dataProvider->sort->attributes['email'] = ['asc' => ['user.email' => SORT_ASC], 'desc' => ['user.email' => SORT_DESC]]; $dataProvider->sort->attributes['name'] = ['asc' => ['profile.name' => SORT_ASC], 'desc' => ['profile.name' => 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(['like', 'user.username', $this->username])->andFilterWhere(['like', 'profile.name', $this->name])->andFilterWhere(['like', 'user.email', $this->email]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getMentors() { return $this->hasMany(Mentor::className(), ['id' => 'mentor_id'])->viaTable('{{%mentor_entrepreneur}}', ['entrepreneur_id' => 'id']); }
/** * Finds the Mentor model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Mentor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Mentor::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getMentor() { return $this->hasOne(Mentor::className(), ['id' => 'mentor_id']); }