/** * 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->validate()) { $broker = new Broker(); $broker->user_id = 1; $broker->type_id = $this->type_id; $broker->name = $this->name; $broker->company = $this->company; $broker->phone = $this->phone; $broker->email = $this->email; $broker->address = $this->address; $broker->contact = $this->contact; $broker->recommend = $this->recommend; $broker->note_user = $this->note_user; $broker->sale_add = $this->sale_add; if ($broker->validate()) { $user->save(); $broker->user_id = $user->id; $broker->save(); return $user; } } } return null; }
public function actionBroker() { if (Yii::$app->user->isGuest) { return $this->goHome(); } $model = Broker::findOne(Yii::$app->user->identity->getId()); if ($model->load(Yii::$app->request->post())) { if ($model->validate() && $model->getDirtyAttributes()) { $mes = []; foreach ($model->getDirtyAttributes() as $k => $v) { if ($k == 'name' && $model->type_id == 1) { $mes[$k] = [Yii::t('app', 'Full name'), $model->name]; } else { $mes[$k] = [$model->getAttributeLabel($k), $model->{$k}]; } } $message = ""; foreach ($mes as $m) { $message .= "<p><b>" . $m[0] . ":</b> " . $m[1] . "</p>"; } $new = Broker::findOne($model->user_id); if ($message) { $new->edit = $message; Yii::$app->session->setFlash('success', Yii::t('app', 'Sent admin to verify.')); } else { $new->edit = ''; } $new->save(); return $this->redirect(Url::toRoute('personal/index')); } } return $this->render('broker', ['model' => $model]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Broker::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['user_id' => $this->user_id, 'type_id' => $this->type_id, 'sale_add' => $this->sale_add]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'company', $this->company])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'contact', $this->contact])->andFilterWhere(['like', 'recommend', $this->recommend])->andFilterWhere(['like', 'note_user', $this->note_user])->andFilterWhere(['like', 'note_admin', $this->note_admin]); return $dataProvider; }
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?> <div class="row"> <div class="col-md-4"> <?php echo $form->field($model, 'username'); ?> <?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'type_id')->dropDownList(Broker::getTypeList())->label(Yii::t('app', 'Who are you?')); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true])->label($model->type_id == 1 ? Yii::t('app', 'Enter your full name') : Yii::t('app', 'Enter company name')); ?> <?php echo $form->field($model, 'company')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'phone')->textInput(['maxlength' => true]); ?> <?php
public function getBroker() { return $this->hasOne(Broker::className(), ['user_id' => 'id']); }
use common\models\Group; use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel common\models\BrokerSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Agents'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="box"> <div class="box-body table-responsive"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'rowOptions' => function ($model, $index, $widget, $grid) { if ($model->edit != '' || $model->user->group_id == Group::GROUP_DEFAULT) { return ['class' => 'danger']; } else { return []; } }, 'columns' => [['attribute' => 'user_id', 'headerOptions' => ['width' => '50']], ['class' => SetColumn::className(), 'attribute' => 'type_id', 'filter' => Broker::getTypeList(), 'name' => 'typeName'], ['class' => SetColumn::className(), 'attribute' => 'user.group_id', 'filter' => Group::getList(), 'name' => 'user.group.groupName'], 'name', 'company', 'phone', 'email:email', 'address', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div> <div class="box-footer"> <?php echo Html::a(Yii::t('app', 'Add agent'), ['create', 'type_id' => 1], ['class' => 'btn btn-success']); ?> <?php echo Html::a(Yii::t('app', 'Add company'), ['create', 'type_id' => 2], ['class' => 'btn btn-success']); ?> </div> </div>
?> </div> </div> </div> <div class="col-md-8"> <div class="box"> <div class="box-header with-border"> <?php echo Yii::t('app', 'Information broker'); ?> </div> <div class="box-body"> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'type_id')->dropDownList(Broker::getTypeList()); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true])->label($model->type_id == 1 ? Yii::t('app', 'Full name') : Yii::t('app', 'Name')); ?> <?php if ($model->type_id == 1) { echo $form->field($model, 'company')->textInput(['maxlength' => true]); } ?> <?php echo $form->field($model, 'phone')->textInput(['maxlength' => true]); ?>
/** * Finds the Broker model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Broker the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Broker::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }