diff --git a/backend/web/js/option.js b/backend/web/js/option.js index 1786a9a..298e76e 100755 --- a/backend/web/js/option.js +++ b/backend/web/js/option.js @@ -17,6 +17,14 @@ function checkboxerInit() { $(value).trigger('change'); }); } +function accountRedraw() { + var type = $('input[name="User[type]"]:checked').val(); + if(type == 2) { + $('#form_definition').addClass('form_for_company'); + } else { + $('#form_definition').removeClass('form_for_company'); + } +} $(function() { var counter = 0; $(document).on('click', '.add_row', function() { @@ -137,4 +145,8 @@ $(function() { $(val).find('a[role=tab]').first().trigger('click'); }); checkboxerInit(); + accountRedraw(); + $(document).on('change', 'input[name="User[type]"]', function() { + accountRedraw(); + }); }); \ No newline at end of file diff --git a/common/models/CompanyInfo.php b/common/models/CompanyInfo.php new file mode 100644 index 0000000..e8f0b7b --- /dev/null +++ b/common/models/CompanyInfo.php @@ -0,0 +1,52 @@ + Yii::t('app', 'Company Info ID'), + 'name' => Yii::t('app', 'Name'), + 'staff' => Yii::t('app', 'Staff'), + 'street' => Yii::t('app', 'Street'), + 'house' => Yii::t('app', 'House'), + 'hide_mail' => Yii::t('app', 'Hide Mail'), + ]; + } +} diff --git a/common/models/CompanyInfoSearch.php b/common/models/CompanyInfoSearch.php new file mode 100644 index 0000000..4213d75 --- /dev/null +++ b/common/models/CompanyInfoSearch.php @@ -0,0 +1,70 @@ + $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([ + 'company_info_id' => $this->company_info_id, + 'staff' => $this->staff, + 'hide_mail' => $this->hide_mail, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'street', $this->street]) + ->andFilterWhere(['like', 'house', $this->house]); + + return $dataProvider; + } +} diff --git a/common/models/User.php b/common/models/User.php index b199db1..1aec640 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -31,6 +31,9 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface const STATUS_DELETED = 0; const STATUS_ACTIVE = 10; public $profile; + public $old_password; + public $new_password; + public $password_reply; /** * @inheritdoc @@ -58,6 +61,8 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface return [ ['status', 'default', 'value' => self::STATUS_ACTIVE], ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], + [['username', 'lastname', 'firstname', 'middlename'], 'string', 'max' => 255], + [['type'], 'in', 'range' => [1, 2]], ]; } @@ -263,4 +268,14 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface public function getUserInfo(){ return $this->hasOne(UserInfo::className(), ['user_id' => 'id']); } + + public function getIsPerformer() + { + return true; + } + + public function getIsCustomer() + { + return true; + } } diff --git a/common/models/UserInfo.php b/common/models/UserInfo.php index accd2d8..7e21add 100755 --- a/common/models/UserInfo.php +++ b/common/models/UserInfo.php @@ -25,9 +25,28 @@ use Yii; * @property integer $delivery * @property double $prepayment * @property string $about + * @property integer $type */ class UserInfo extends \yii\db\ActiveRecord { + // Константа обознащающая физическое лицо + const USER_TYPE_FIZ = 1; + + // Константа обозначающая компанию + const USER_TYPE_COMPANY = 2; + + // Константа обозначающая, что компания/физ.лицо свободно + const USER_STATUS_FREE = 1; + + // Константа обозначающая, что компания/физ.лицо занято + const USER_STATUS_BUSY = 2; + + // Константа обозначающая, что компания/физ.лицо хочет стать членом МФП + const USER_MEMBER_FALSE = 1; + + // Константа обозначающая, что компания/физ.лицо не хочет стать членом МФП + const USER_MEMBER_TRUE = 2; + /** * @inheritdoc */ @@ -44,10 +63,11 @@ class UserInfo extends \yii\db\ActiveRecord return [ [['user_id', 'view_count', 'contract', 'estimate', 'purchase', 'delivery'], 'integer'], [['date_visit'], 'safe'], - [['experience', 'soft', 'guarantee', 'about'], 'string'], + [['experience', 'soft', 'guarantee', 'about', 'city', 'country'], 'string'], [['prepayment'], 'number'], - [['busy', 'rank', 'location'], 'string', 'max' => 50], - [['salary', 'job'], 'string', 'max' => 255] + [['rank', 'location'], 'string', 'max' => 50], + [['salary', 'job'], 'string', 'max' => 255], + [['busy', 'member'], 'boolean'], ]; } diff --git a/console/migrations/m160202_090343_user_add_fields.php b/console/migrations/m160202_090343_user_add_fields.php new file mode 100644 index 0000000..6a37820 --- /dev/null +++ b/console/migrations/m160202_090343_user_add_fields.php @@ -0,0 +1,34 @@ +addColumn('user', 'type', $this->smallInteger()); + $this->addColumn('user_info', 'image', $this->integer()); + $this->addColumn('user_info', 'poster', $this->integer()); + $this->addColumn('user_info', 'member', $this->smallInteger()); + + $this->createTable('{{%company_info}}', [ + 'company_info_id' => $this->primaryKey(), + 'name' => $this->string(255)->notNull(), + 'staff' => $this->integer(), + 'street' => $this->string(255), + 'house' => $this->string(255), + 'hide_mail' => $this->smallInteger(), + 'user_id' => $this->integer(), + ], null); + } + + public function down() + { + $this->dropColumn('user', 'type'); + $this->dropColumn('user_info', 'image'); + $this->dropColumn('user_info', 'poster'); + $this->dropColumn('user_info', 'member'); + $this->dropTable('company_info'); + } +} diff --git a/console/migrations/m160202_094943_user_info_country_city.php b/console/migrations/m160202_094943_user_info_country_city.php new file mode 100644 index 0000000..5603f81 --- /dev/null +++ b/console/migrations/m160202_094943_user_info_country_city.php @@ -0,0 +1,30 @@ +addColumn('user_info', 'country', $this->string(255)); + $this->addColumn('user_info', 'city', $this->string(255)); + } + + public function down() + { + $this->dropColumn('user_info', 'country'); + $this->dropColumn('user_info', 'city'); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index d62641b..80d629c 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -1,6 +1,7 @@ AccessControl::className(), 'rules' => [ [ - 'actions' => ['cabinet','change-password', 'bookmarks'], + //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'], 'allow' => true, 'roles' => ['@'], ], @@ -75,6 +76,111 @@ class AccountsController extends Controller return $this->render('bookmarks'); } + public function actionGeneral() + { + $user_info = UserInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one(); + $company_info = CompanyInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one(); + $user = \Yii::$app->user->identity; + if(empty($user_info)) + { + $user_info = new UserInfo(['user_id' => \Yii::$app->user->getId()]); + } + if(empty($company_info)) + { + $company_info = new CompanyInfo(['user_id' => \Yii::$app->user->getId()]); + } + $post = \Yii::$app->request->post(); + if(!empty($post)) + { + $user_info->load($post); + $company_info->load($post); + $user->load($post); + if($user_info->save() && $user->save() && $company_info->save()) + { + \Yii::$app->session->setFlash('userinfoupdate', 'Информация успешно обновлена'); + } else { + \Yii::$app->session->setFlash('userinfoupdate', 'Ошибка обновления. Проверьте форму'); + } + } + return $this->render('general', ['user_info' => $user_info, 'user' => $user, 'company_info' => $company_info]); + } + + public function actionPortfolio() + { + + } + + /** + * $user User + */ + public function actionSetting() + { + $user = \Yii::$app->user->identity; + $post = \Yii::$app->request->post('User'); + if(!empty($post)) { + if(empty($post['new_password'])) { + $user->addError('new_password', 'Введите новый пароль'); + } else { + $user->new_password = $post['new_password']; + } + if(empty($post['old_password'])) { + $user->addError('old_password', 'Введите новый пароль'); + } else { + $user->old_password = $post['old_password']; + } + if(empty($post['password_reply']) || $post['password_reply'] !== $post['new_password']) { + $user->addError('password_reply', 'Неправильный повтор пароля'); + } else { + $user->password_reply = $post['password_reply']; + } + if(!$user->hasErrors()) { + if($user->validatePassword($user->old_password)) { + $user->setPassword($user->new_password); + $user->generateAuthKey(); + if($user->save()) { + \Yii::$app->session->setFlash('passwordupdate', 'Пароль успешно обновлен'); + } + } else { + $user->addError('old_password', 'Неправильный старый пароль'); + } + } + } + return $this->render('setting', ['user' => $user]); + } + + public function actionContacts() + { + $user_info = UserInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one(); + if(empty($user_info)) { + $user_info = new UserInfo(['user_id' => \Yii::$app->user->getId()]); + } + return $this->render('contacts', ['user_info' => $user_info]); + } + + public function actionService() + { + return $this->render('service'); + } + + public function actionAddSkills() + { + + } + + public function actionEmployment() + { + + } + + public function actionProjects() + { + return $this->render('projects'); + } + + public function actionGallery() + { + + } /** * @param $id diff --git a/frontend/controllers/CompanyInfoController.php b/frontend/controllers/CompanyInfoController.php new file mode 100644 index 0000000..3bf053a --- /dev/null +++ b/frontend/controllers/CompanyInfoController.php @@ -0,0 +1,121 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all CompanyInfo models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CompanyInfoSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single CompanyInfo model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new CompanyInfo model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new CompanyInfo(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->company_info_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing CompanyInfo model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->company_info_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing CompanyInfo model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the CompanyInfo model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return CompanyInfo the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = CompanyInfo::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/frontend/views/accounts/add-skills.php b/frontend/views/accounts/add-skills.php new file mode 100644 index 0000000..162a954 --- /dev/null +++ b/frontend/views/accounts/add-skills.php @@ -0,0 +1,26 @@ +title = 'Мой профиль'; + $this->params['breadcrumbs'][] = $this->title; +?> + +
= \Yii::$app->session->getFlash ('passwordupdate') ?>
+Сменить пароль:
"; + echo $form->field ($user, 'old_password', ['template' => "{input}{label}\n{hint}\n{error}"]) + ->label ('Старый пароль') + ->passwordInput (['value' => '']); + echo $form->field ($user, 'new_password', ['template' => "{input}{label}\n{hint}\n{error}"]) + ->label ('Новый пароль') + ->passwordInput (['value' => '']); + echo $form->field ($user, 'password_reply', ['template' => "{input}{label}\n{hint}\n{error}"]) + ->label ('Повторите пароль') + ->passwordInput (['value' => '']); + echo Html::submitButton ('Обновить', ['class' => 'btn btn-primary']); + $form->end (); +?> + + diff --git a/frontend/views/chat/list.php b/frontend/views/chat/list.php index 48dabf4..9387e0e 100644 --- a/frontend/views/chat/list.php +++ b/frontend/views/chat/list.php @@ -1,10 +1,10 @@ title = 'Мой профиль'; $this->params['breadcrumbs'][] = $this->title; ?> -+ = Html::a(Yii::t('app', 'Create Company Info'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'company_info_id', + 'name', + 'staff', + 'street', + 'house', + // 'hide_mail', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + ++ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->company_info_id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->company_info_id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'company_info_id', + 'name', + 'staff', + 'street', + 'house', + 'hide_mail', + ], + ]) ?> + +