From 45b110ac444c3df1f27ee295e6889cfecb3c4f62 Mon Sep 17 00:00:00 2001 From: iIronside Date: Tue, 8 Nov 2022 18:01:42 +0300 Subject: [PATCH] add document module --- backend/modules/document/Document.php | 24 ++++ .../controllers/DocumentController.php | 127 ++++++++++++++++++ .../DocumentTemplateController.php | 127 ++++++++++++++++++ backend/modules/document/models/Document.php | 8 ++ .../document/models/DocumentSearch.php | 69 ++++++++++ .../document/models/DocumentTemplate.php | 8 ++ .../models/DocumentTemplateSearch.php | 69 ++++++++++ .../views/document-template/_form.php | 25 ++++ .../views/document-template/_search.php | 31 +++++ .../views/document-template/create.php | 20 +++ .../views/document-template/index.php | 35 +++++ .../views/document-template/update.php | 21 +++ .../document/views/document-template/view.php | 38 ++++++ .../modules/document/views/document/_form.php | 29 ++++ .../document/views/document/_search.php | 35 +++++ .../document/views/document/create.php | 20 +++ .../modules/document/views/document/index.php | 37 +++++ .../document/views/document/update.php | 21 +++ .../modules/document/views/document/view.php | 40 ++++++ common/models/Document.php | 91 +++++++++++++ common/models/DocumentTemplate.php | 46 +++++++ ..._135514_create_document_template_table.php | 29 ++++ .../m221108_135939_create_document_table.php | 36 +++++ 23 files changed, 986 insertions(+) create mode 100644 backend/modules/document/Document.php create mode 100644 backend/modules/document/controllers/DocumentController.php create mode 100644 backend/modules/document/controllers/DocumentTemplateController.php create mode 100644 backend/modules/document/models/Document.php create mode 100644 backend/modules/document/models/DocumentSearch.php create mode 100644 backend/modules/document/models/DocumentTemplate.php create mode 100644 backend/modules/document/models/DocumentTemplateSearch.php create mode 100644 backend/modules/document/views/document-template/_form.php create mode 100644 backend/modules/document/views/document-template/_search.php create mode 100644 backend/modules/document/views/document-template/create.php create mode 100644 backend/modules/document/views/document-template/index.php create mode 100644 backend/modules/document/views/document-template/update.php create mode 100644 backend/modules/document/views/document-template/view.php create mode 100644 backend/modules/document/views/document/_form.php create mode 100644 backend/modules/document/views/document/_search.php create mode 100644 backend/modules/document/views/document/create.php create mode 100644 backend/modules/document/views/document/index.php create mode 100644 backend/modules/document/views/document/update.php create mode 100644 backend/modules/document/views/document/view.php create mode 100644 common/models/Document.php create mode 100644 common/models/DocumentTemplate.php create mode 100644 console/migrations/m221108_135514_create_document_template_table.php create mode 100644 console/migrations/m221108_135939_create_document_table.php diff --git a/backend/modules/document/Document.php b/backend/modules/document/Document.php new file mode 100644 index 0000000..5c22c96 --- /dev/null +++ b/backend/modules/document/Document.php @@ -0,0 +1,24 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Document models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new DocumentSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Document model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Document model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Document(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing Document model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing Document model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Document model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Document the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Document::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/document/controllers/DocumentTemplateController.php b/backend/modules/document/controllers/DocumentTemplateController.php new file mode 100644 index 0000000..412fc07 --- /dev/null +++ b/backend/modules/document/controllers/DocumentTemplateController.php @@ -0,0 +1,127 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all DocumentTemplate models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new DocumentTemplateSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single DocumentTemplate model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new DocumentTemplate model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new DocumentTemplate(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing DocumentTemplate model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing DocumentTemplate model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the DocumentTemplate model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return DocumentTemplate the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = DocumentTemplate::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/backend/modules/document/models/Document.php b/backend/modules/document/models/Document.php new file mode 100644 index 0000000..8f2dda1 --- /dev/null +++ b/backend/modules/document/models/Document.php @@ -0,0 +1,8 @@ + $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([ + 'id' => $this->id, + 'company_id' => $this->company_id, + 'contractor_company_id' => $this->contractor_company_id, + 'manager_id' => $this->manager_id, + 'contractor_manager_id' => $this->contractor_manager_id, + ]); + + return $dataProvider; + } +} diff --git a/backend/modules/document/models/DocumentTemplate.php b/backend/modules/document/models/DocumentTemplate.php new file mode 100644 index 0000000..e8469de --- /dev/null +++ b/backend/modules/document/models/DocumentTemplate.php @@ -0,0 +1,8 @@ + $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([ + 'id' => $this->id, + ]); + + $query->andFilterWhere(['like', 'title', $this->title]) + ->andFilterWhere(['like', 'template_body', $this->template_body]); + + return $dataProvider; + } +} diff --git a/backend/modules/document/views/document-template/_form.php b/backend/modules/document/views/document-template/_form.php new file mode 100644 index 0000000..2769e67 --- /dev/null +++ b/backend/modules/document/views/document-template/_form.php @@ -0,0 +1,25 @@ + + +
+ + + + field($model, 'title')->textInput(['maxlength' => true]) ?> + + field($model, 'template_body')->textarea(['rows' => 6]) ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/document/views/document-template/_search.php b/backend/modules/document/views/document-template/_search.php new file mode 100644 index 0000000..2944f95 --- /dev/null +++ b/backend/modules/document/views/document-template/_search.php @@ -0,0 +1,31 @@ + + + diff --git a/backend/modules/document/views/document-template/create.php b/backend/modules/document/views/document-template/create.php new file mode 100644 index 0000000..460ebd6 --- /dev/null +++ b/backend/modules/document/views/document-template/create.php @@ -0,0 +1,20 @@ +title = 'Create Document Template'; +$this->params['breadcrumbs'][] = ['label' => 'Document Templates', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/document/views/document-template/index.php b/backend/modules/document/views/document-template/index.php new file mode 100644 index 0000000..46abc2b --- /dev/null +++ b/backend/modules/document/views/document-template/index.php @@ -0,0 +1,35 @@ +title = 'Document Templates'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'title', + 'template_body:ntext', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/document/views/document-template/update.php b/backend/modules/document/views/document-template/update.php new file mode 100644 index 0000000..8eefff0 --- /dev/null +++ b/backend/modules/document/views/document-template/update.php @@ -0,0 +1,21 @@ +title = 'Update Document Template: ' . $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Document Templates', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/document/views/document-template/view.php b/backend/modules/document/views/document-template/view.php new file mode 100644 index 0000000..bee27b1 --- /dev/null +++ b/backend/modules/document/views/document-template/view.php @@ -0,0 +1,38 @@ +title = $model->title; +$this->params['breadcrumbs'][] = ['label' => 'Document Templates', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'title', + 'template_body:ntext', + ], + ]) ?> + +
diff --git a/backend/modules/document/views/document/_form.php b/backend/modules/document/views/document/_form.php new file mode 100644 index 0000000..68bd948 --- /dev/null +++ b/backend/modules/document/views/document/_form.php @@ -0,0 +1,29 @@ + + +
+ + + + field($model, 'company_id')->textInput() ?> + + field($model, 'contractor_company_id')->textInput() ?> + + field($model, 'manager_id')->textInput() ?> + + field($model, 'contractor_manager_id')->textInput() ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/backend/modules/document/views/document/_search.php b/backend/modules/document/views/document/_search.php new file mode 100644 index 0000000..1bfb645 --- /dev/null +++ b/backend/modules/document/views/document/_search.php @@ -0,0 +1,35 @@ + + + diff --git a/backend/modules/document/views/document/create.php b/backend/modules/document/views/document/create.php new file mode 100644 index 0000000..32b8a7e --- /dev/null +++ b/backend/modules/document/views/document/create.php @@ -0,0 +1,20 @@ +title = 'Create Document'; +$this->params['breadcrumbs'][] = ['label' => 'Documents', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/document/views/document/index.php b/backend/modules/document/views/document/index.php new file mode 100644 index 0000000..b3bdf3a --- /dev/null +++ b/backend/modules/document/views/document/index.php @@ -0,0 +1,37 @@ +title = 'Documents'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'company_id', + 'contractor_company_id', + 'manager_id', + 'contractor_manager_id', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/backend/modules/document/views/document/update.php b/backend/modules/document/views/document/update.php new file mode 100644 index 0000000..2207d50 --- /dev/null +++ b/backend/modules/document/views/document/update.php @@ -0,0 +1,21 @@ +title = 'Update Document: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Documents', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/modules/document/views/document/view.php b/backend/modules/document/views/document/view.php new file mode 100644 index 0000000..f5a24a4 --- /dev/null +++ b/backend/modules/document/views/document/view.php @@ -0,0 +1,40 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Documents', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'company_id', + 'contractor_company_id', + 'manager_id', + 'contractor_manager_id', + ], + ]) ?> + +
diff --git a/common/models/Document.php b/common/models/Document.php new file mode 100644 index 0000000..0d87cb2 --- /dev/null +++ b/common/models/Document.php @@ -0,0 +1,91 @@ + true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']], + [['contractor_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['contractor_company_id' => 'id']], + [['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']], + [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'company_id' => 'Company ID', + 'contractor_company_id' => 'Contractor Company ID', + 'manager_id' => 'Manager ID', + 'contractor_manager_id' => 'Contractor Manager ID', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCompany() + { + return $this->hasOne(Company::className(), ['id' => 'company_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getContractorCompany() + { + return $this->hasOne(Company::className(), ['id' => 'contractor_company_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getContractorManager() + { + return $this->hasOne(Manager::className(), ['id' => 'contractor_manager_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getManager() + { + return $this->hasOne(Manager::className(), ['id' => 'manager_id']); + } +} diff --git a/common/models/DocumentTemplate.php b/common/models/DocumentTemplate.php new file mode 100644 index 0000000..a2a301d --- /dev/null +++ b/common/models/DocumentTemplate.php @@ -0,0 +1,46 @@ + 255], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'title' => 'Title', + 'template_body' => 'Template Body', + ]; + } +} diff --git a/console/migrations/m221108_135514_create_document_template_table.php b/console/migrations/m221108_135514_create_document_template_table.php new file mode 100644 index 0000000..023fba8 --- /dev/null +++ b/console/migrations/m221108_135514_create_document_template_table.php @@ -0,0 +1,29 @@ +createTable('{{%document_template}}', [ + 'id' => $this->primaryKey(), + 'title' => $this->string(), + 'template_body' => $this->text() + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%document_template}}'); + } +} diff --git a/console/migrations/m221108_135939_create_document_table.php b/console/migrations/m221108_135939_create_document_table.php new file mode 100644 index 0000000..42ddfb7 --- /dev/null +++ b/console/migrations/m221108_135939_create_document_table.php @@ -0,0 +1,36 @@ +createTable('{{%document}}', [ + 'id' => $this->primaryKey(), + 'company_id' => $this->integer(11)->notNull(), + 'contractor_company_id' => $this->integer(11), + 'manager_id' => $this->integer(11)->notNull(), + 'contractor_manager_id' => $this->integer(11)->notNull(), + ]); + + $this->addForeignKey('company_document', 'document', 'company_id', 'company', 'id'); + $this->addForeignKey('contractor_company_document', 'document', 'contractor_company_id', 'company', 'id'); + $this->addForeignKey('manager_document', 'document', 'manager_id','manager', 'id'); + $this->addForeignKey('contractor_manager_document', 'document', 'contractor_manager_id','manager', 'id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%document}}'); + } +}