diff --git a/common/models/Job.php b/common/models/Job.php new file mode 100644 index 0000000..8fbff20 --- /dev/null +++ b/common/models/Job.php @@ -0,0 +1,62 @@ + 255] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'job_id' => Yii::t('app', 'Job ID'), + 'name' => Yii::t('app', 'Name'), + 'link' => Yii::t('app', 'Link'), + 'date_start' => Yii::t('app', 'Date Start'), + 'date_end' => Yii::t('app', 'Date End'), + 'position' => Yii::t('app', 'Position'), + 'user_id' => Yii::t('app', 'User ID'), + 'total_count' => Yii::t('app', 'Total Count'), + 'complete_count' => Yii::t('app', 'Complete Count'), + 'current' => Yii::t('app', 'Current'), + ]; + } +} diff --git a/common/models/JobSearch.php b/common/models/JobSearch.php new file mode 100644 index 0000000..4e0c062 --- /dev/null +++ b/common/models/JobSearch.php @@ -0,0 +1,74 @@ + $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([ + 'job_id' => $this->job_id, + 'date_start' => $this->date_start, + 'date_end' => $this->date_end, + 'user_id' => $this->user_id, + 'total_count' => $this->total_count, + 'complete_count' => $this->complete_count, + 'current' => $this->current, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'link', $this->link]) + ->andFilterWhere(['like', 'position', $this->position]); + + return $dataProvider; + } +} diff --git a/console/migrations/m160203_082111_jobs.php b/console/migrations/m160203_082111_jobs.php index 1f7ba8e..8ff295c 100644 --- a/console/migrations/m160203_082111_jobs.php +++ b/console/migrations/m160203_082111_jobs.php @@ -18,6 +18,7 @@ class m160203_082111_jobs extends Migration 'user_id' => $this->integer(), 'total_count' => $this->integer(), 'complete_count' => $this->integer(), + 'current' => $this->smallInteger(), ], $tableOptions); } diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 80d629c..b3b1772 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -3,6 +3,7 @@ namespace frontend\controllers; use common\models\CompanyInfo; use common\models\Fields; +use common\models\Job; use common\models\Language; use Yii; use common\models\User; @@ -169,7 +170,18 @@ class AccountsController extends Controller public function actionEmployment() { - + $job = Job::find()->where(['user_id' => \Yii::$app->user->getId()])->orderBy(['current' => SORT_DESC])->all(); + if(empty($job)) { + $job[] = new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 0]); + } + if(!$job[0]->current) { + array_unshift($job, new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 1])); + } + if(!empty(\Yii::$app->request->post())) { + var_dump(\Yii::$app->request->post()); + die(); + } + return $this->render('employment', ['job' => $job]); } public function actionProjects() @@ -182,6 +194,11 @@ class AccountsController extends Controller } + public function actionGetForm($lastindex) + { + return $this->renderAjax('_job_form', ['index' => $lastindex+1]); + } + /** * @param $id * @return User diff --git a/frontend/controllers/JobController.php b/frontend/controllers/JobController.php new file mode 100644 index 0000000..1c88a22 --- /dev/null +++ b/frontend/controllers/JobController.php @@ -0,0 +1,121 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Job models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new JobSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Job model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Job model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Job(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->job_id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Job 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->job_id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Job 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 Job model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Job the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Job::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/frontend/views/accounts/_job_form.php b/frontend/views/accounts/_job_form.php new file mode 100644 index 0000000..7e26125 --- /dev/null +++ b/frontend/views/accounts/_job_form.php @@ -0,0 +1,35 @@ + \Yii::$app->user->getId (), 'current' => 0]); + $form = ActiveForm::begin (); + echo "
Текущее место работы:
+Предыдущие места работы
+ $job_model) + { + echo "+ = Html::a(Yii::t('app', 'Create Job'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'job_id', + 'name', + 'link', + 'date_start', + 'date_end', + // 'position', + // 'user_id', + // 'total_count', + // 'complete_count', + // 'current', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + ++ = Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->job_id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->job_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' => [ + 'job_id', + 'name', + 'link', + 'date_start', + 'date_end', + 'position', + 'user_id', + 'total_count', + 'complete_count', + 'current', + ], + ]) ?> + +