diff --git a/common/config/main.php b/common/config/main.php index c3b3ecb..1be91dc 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -40,7 +40,7 @@ return [ ], 'bootstrap' => [ - 'options' + 'options', ], 'components' => [ 'cache' => [ diff --git a/common/models/Country.php b/common/models/Country.php new file mode 100644 index 0000000..c12a721 --- /dev/null +++ b/common/models/Country.php @@ -0,0 +1,48 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'country_id' => Yii::t('app', 'Country ID'), + 'oid' => Yii::t('app', 'Oid'), + 'country_name' => Yii::t('app', 'Country Name'), + 'country_name_en' => Yii::t('app', 'Country Name En'), + ]; + } +} diff --git a/common/models/Department.php b/common/models/Department.php new file mode 100644 index 0000000..8e16441 --- /dev/null +++ b/common/models/Department.php @@ -0,0 +1,53 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'department_id' => Yii::t('app', 'Department ID'), + 'name' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTeams() + { + return $this->hasMany(Team::className(), ['department_id' => 'department_id']); + } +} diff --git a/common/models/Employment.php b/common/models/Employment.php new file mode 100644 index 0000000..1deee91 --- /dev/null +++ b/common/models/Employment.php @@ -0,0 +1,53 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'employment_id' => Yii::t('app', 'Employment ID'), + 'name' => Yii::t('app', 'Name'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getVacancyEmployments() + { + return $this->hasMany(VacancyEmployment::className(), ['employment_id' => 'employment_id']); + } +} diff --git a/common/models/Team.php b/common/models/Team.php new file mode 100644 index 0000000..9e8bb58 --- /dev/null +++ b/common/models/Team.php @@ -0,0 +1,127 @@ + BlameableBehavior::className(), + 'createdByAttribute' => 'user_id', + 'updatedByAttribute' => false, + ], + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'date_add', + 'updatedAtAttribute' => false, + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'firstname', + 'lastname', + 'position', + 'country_id', + ], + 'required', + ], + [ + [ + 'department_id', + ], + 'integer', + ], + [ + [ + 'experience_from', + ], + 'safe', + ], + [ + [ + 'firstname', + 'lastname', + 'midlename', + 'link', + 'position', + 'photo', + 'country_id', + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'team_id' => Yii::t('app', 'Team ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'firstname' => Yii::t('app', 'Имя'), + 'lastname' => Yii::t('app', 'Фамилия'), + 'midlename' => Yii::t('app', 'Отчество'), + 'link' => Yii::t('app', 'Ссылка на профиль МФП'), + 'position' => Yii::t('app', 'Должность'), + 'department_id' => Yii::t('app', 'Отдел компании'), + 'experience_from' => Yii::t('app', 'Опыт'), + 'date_add' => Yii::t('app', 'дата добавления'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'photo' => Yii::t('app', 'Фото'), + 'country_id' => Yii::t('app', 'Страна'), + ]; + } + + public function getDepartment() + { + return $this->hasOne(Department::className(), [ 'department_id' => 'department_id' ]); + } + + } diff --git a/common/models/Vacancy.php b/common/models/Vacancy.php new file mode 100644 index 0000000..a66da69 --- /dev/null +++ b/common/models/Vacancy.php @@ -0,0 +1,133 @@ + BlameableBehavior::className(), + 'createdByAttribute' => 'user_id', + 'updatedByAttribute' => false, + ], + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'date_add', + 'updatedAtAttribute' => false, + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'name' ], + 'required', + ], + [ + [ 'description' ], + 'string', + ], + [ + ['employmentInput'], + 'safe', + ], + [ + [ + 'name', + 'link', + 'user_name', + 'city', + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'vacancy_id' => Yii::t('app', 'Vacancy ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Название'), + 'link' => Yii::t('app', 'URL'), + 'date_add' => Yii::t('app', 'Дата добавления'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'view_count' => Yii::t('app', 'Количество просмотров'), + 'user_name' => Yii::t('app', 'Контактное лицо'), + 'city' => Yii::t('app', 'Город'), + 'description' => Yii::t('app', 'Описание'), + 'employmentInput' => Yii::t('app', 'Вид занятости'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getVacancyEmployments() + { + return $this->hasMany(VacancyEmployment::className(), [ 'vacancy_id' => 'vacancy_id' ]); + } + + public function getEmployments() + { + return $this->hasMany(Employment::className(), [ 'employment_id' => 'employment_id' ]) + ->viaTable('vacancy_employment', [ 'vacancy_id' => 'vacancy_id' ]); + } + + public function getEmploymentInput() + { + return $this->getEmployments() + ->asArray() + ->column(); + } + + public function setEmploymentInput($value) + { + $this->employmentInput = $value; + } + + } diff --git a/common/models/VacancyEmployment.php b/common/models/VacancyEmployment.php new file mode 100644 index 0000000..1fa7cfe --- /dev/null +++ b/common/models/VacancyEmployment.php @@ -0,0 +1,66 @@ + true, 'targetClass' => Employment::className(), 'targetAttribute' => ['employment_id' => 'employment_id']], + [['vacancy_id'], 'exist', 'skipOnError' => true, 'targetClass' => Vacancy::className(), 'targetAttribute' => ['vacancy_id' => 'vacancy_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'vacancy_employment' => Yii::t('app', 'Vacancy Employment'), + 'vacancy_id' => Yii::t('app', 'Vacancy ID'), + 'employment_id' => Yii::t('app', 'Employment ID'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getEmployment() + { + return $this->hasOne(Employment::className(), ['employment_id' => 'employment_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getVacancy() + { + return $this->hasOne(Vacancy::className(), ['vacancy_id' => 'vacancy_id']); + } +} diff --git a/console/migrations/m160208_101449_team.php b/console/migrations/m160208_101449_team.php index 5bb93ec..d6cc451 100644 --- a/console/migrations/m160208_101449_team.php +++ b/console/migrations/m160208_101449_team.php @@ -13,7 +13,7 @@ class m160208_101449_team extends Migration 'user_id' => $this->integer()->notNull(), 'firstname' => $this->string(255)->notNull(), 'lastname' => $this->string(255)->notNull(), - 'midlename' => $this->string(255), + 'middlename' => $this->string(255), 'link' => $this->string(255), 'position' => $this->string(255)->notNull(), 'department_id' => $this->integer()->notNull(), diff --git a/console/migrations/m160209_151553_employment_data.php b/console/migrations/m160209_151553_employment_data.php new file mode 100644 index 0000000..850c1b5 --- /dev/null +++ b/console/migrations/m160209_151553_employment_data.php @@ -0,0 +1,33 @@ +batchInsert('{{%employment}}', [ 'name' ], [ + [ 'Проектная' ], + [ 'Полная' ], + [ 'Не полная' ], + [ 'Удаленная' ], + ]); + } + + public function down() + { + $this->delete('employment'); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ + } diff --git a/console/migrations/m160210_085744_department.php b/console/migrations/m160210_085744_department.php new file mode 100644 index 0000000..5e0c398 --- /dev/null +++ b/console/migrations/m160210_085744_department.php @@ -0,0 +1,19 @@ +createTable('{{%department}}', ['department_id' => $this->primaryKey(), 'name' => $this->string()]); + $this->addForeignKey('team_department_key', '{{%team}}', 'department_id', '{{%department}}', 'department_id'); + } + + public function down() + { + $this->dropForeignKey('team_department_key', '{{%team}}'); + $this->dropTable('{{%department}}'); + } + +} diff --git a/console/migrations/m160210_101931_country.php b/console/migrations/m160210_101931_country.php new file mode 100644 index 0000000..e7708b9 --- /dev/null +++ b/console/migrations/m160210_101931_country.php @@ -0,0 +1,22 @@ +createTable('{{%country}}', [ + 'country_id' => $this->primaryKey(), + 'oid' => $this->integer(), + 'country_name' => $this->string(), + 'country_name_en' => $this->string(), + ]); + } + + public function down() + { + $this->dropTable('{{%country}}'); + } + +} diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index e5ea2c1..3a1bd40 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -3,6 +3,8 @@ use common\models\Blog; use common\models\CompanyInfo; + use common\models\Country; + use common\models\Department; use common\models\Employment; use common\models\Fields; use common\models\Gallery; @@ -13,6 +15,7 @@ use common\models\PortfolioSpecialization; use common\models\Project; use common\models\Specialization; + use common\models\Team; use common\models\UserPayment; use common\models\UserSpecialization; use common\models\Vacancy; @@ -531,7 +534,7 @@ $user = \Yii::$app->user->identity; $post = \Yii::$app->request->post(); if($gallery->load($post) && $gallery->save()) { - Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); + Fields::saveFieldData(Yii::$app->request->post('Fields'), $gallery->gallery_id, Gallery::className(), 'ru'); return $this->redirect([ 'gallery-update', 'id' => $gallery->gallery_id, @@ -563,6 +566,73 @@ } } + public function actionTeam() + { + return $this->render('team'); + } + + public function actionTeamCreate() + { + $team = new Team(); + $department = Department::find() + ->select([ + 'name', + 'department_id', + ]) + ->indexBy('department_id') + ->asArray() + ->column(); + $country = Country::find() + ->select([ 'country_name' ]) + ->indexBy('country_name') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if($team->load($post) && $team->save()) { + return $this->redirect([ + 'team-update', + 'id' => $team->team_id, + ]); + } else { + return $this->render('_team_form', [ + 'team' => $team, + 'department' => $department, + 'country' => $country, + ]); + } + } + + public function actionTeamUpdate($id) + { + $team = Team::findOne($id); + $department = Department::find() + ->select([ + 'name', + 'department_id', + ]) + ->indexBy('department_id') + ->asArray() + ->column(); + $country = Country::find() + ->select([ 'country_name' ]) + ->indexBy('country_name') + ->asArray() + ->column(); + $post = \Yii::$app->request->post(); + if($team->load($post) && $team->save()) { + return $this->redirect([ + 'team-update', + 'id' => $team->team_id, + ]); + } else { + return $this->render('_team_form', [ + 'team' => $team, + 'department' => $department, + 'country' => $country, + ]); + } + } + public function actionVacancy() { $this->render('vacancy'); @@ -580,7 +650,7 @@ ->asArray() ->column(); $post = \Yii::$app->request->post(); - if(!empty($post)) { + if(!empty( $post )) { $vacancy->load($post); $vacancy->validate(); if(!$vacancy->hasErrors()) { @@ -590,11 +660,14 @@ foreach($vacancy->employmentInput as $one_employment) { $vacancy->link('employments', Employment::findOne($one_employment)); } - return $this->redirect(['vacancy-update', 'id' => $vacancy->vacancy_id]); + return $this->redirect([ + 'vacancy-update', + 'id' => $vacancy->vacancy_id, + ]); } } return $this->render('_vacancy_form', [ - 'vacancy' => $vacancy, + 'vacancy' => $vacancy, 'employment' => $employment, ]); } @@ -611,7 +684,7 @@ ->asArray() ->column(); $post = \Yii::$app->request->post(); - if(!empty($post)) { + if(!empty( $post )) { $vacancy->load($post); $vacancy->validate(); if(!$vacancy->hasErrors()) { @@ -621,11 +694,14 @@ foreach($vacancy->employmentInput as $one_employment) { $vacancy->link('employments', Employment::findOne($one_employment)); } - return $this->redirect(['vacancy-update', 'id' => $vacancy->vacancy_id]); + return $this->redirect([ + 'vacancy-update', + 'id' => $vacancy->vacancy_id, + ]); } } return $this->render('_vacancy_form', [ - 'vacancy' => $vacancy, + 'vacancy' => $vacancy, 'employment' => $employment, ]); } diff --git a/frontend/views/accounts/_gallery_form.php b/frontend/views/accounts/_gallery_form.php index d8f8730..228a621 100644 --- a/frontend/views/accounts/_gallery_form.php +++ b/frontend/views/accounts/_gallery_form.php @@ -53,7 +53,7 @@ = FieldEditor::widget ( [ - 'template' => 'youtube', 'item_id' => $user->id, 'model' => 'common\models\User', 'language' => 'ru', + 'template' => 'youtube', 'item_id' => $gallery->gallery_id, 'model' => 'common\models\Gallery', 'language' => 'ru', ] ); ?> diff --git a/frontend/views/accounts/_team_form.php b/frontend/views/accounts/_team_form.php new file mode 100644 index 0000000..74c178b --- /dev/null +++ b/frontend/views/accounts/_team_form.php @@ -0,0 +1,61 @@ +title = 'Мой профиль'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +