From 91dfeabcdfa1827950df5c9dde4606475129e789 Mon Sep 17 00:00:00 2001 From: boryashkin Date: Wed, 12 Jul 2017 00:22:41 +0500 Subject: [PATCH] LRM: love relationship management --- modules/lrm/Module.php | 11 ++ .../controllers/InteractionNoteController.php | 134 ++++++++++++++++++ modules/lrm/controllers/PersonController.php | 134 ++++++++++++++++++ .../m170711_171718_createPerson.php | 28 ++++ .../lrm/migrations/m170711_173037_note.php | 45 ++++++ modules/lrm/models/InteractionNote.php | 85 +++++++++++ modules/lrm/models/Person.php | 85 +++++++++++ .../models/search/InteractionNoteSearch.php | 74 ++++++++++ modules/lrm/models/search/PersonSearch.php | 75 ++++++++++ modules/lrm/views/interaction-note/_form.php | 41 ++++++ .../lrm/views/interaction-note/_search.php | 39 +++++ modules/lrm/views/interaction-note/create.php | 21 +++ modules/lrm/views/interaction-note/index.php | 38 +++++ modules/lrm/views/interaction-note/update.php | 21 +++ modules/lrm/views/interaction-note/view.php | 41 ++++++ modules/lrm/views/person/_form.php | 42 ++++++ modules/lrm/views/person/_search.php | 41 ++++++ modules/lrm/views/person/create.php | 21 +++ modules/lrm/views/person/index.php | 37 +++++ modules/lrm/views/person/update.php | 21 +++ modules/lrm/views/person/view.php | 42 ++++++ 21 files changed, 1076 insertions(+) create mode 100755 modules/lrm/Module.php create mode 100755 modules/lrm/controllers/InteractionNoteController.php create mode 100755 modules/lrm/controllers/PersonController.php create mode 100755 modules/lrm/migrations/m170711_171718_createPerson.php create mode 100755 modules/lrm/migrations/m170711_173037_note.php create mode 100755 modules/lrm/models/InteractionNote.php create mode 100755 modules/lrm/models/Person.php create mode 100755 modules/lrm/models/search/InteractionNoteSearch.php create mode 100755 modules/lrm/models/search/PersonSearch.php create mode 100755 modules/lrm/views/interaction-note/_form.php create mode 100755 modules/lrm/views/interaction-note/_search.php create mode 100755 modules/lrm/views/interaction-note/create.php create mode 100755 modules/lrm/views/interaction-note/index.php create mode 100755 modules/lrm/views/interaction-note/update.php create mode 100755 modules/lrm/views/interaction-note/view.php create mode 100755 modules/lrm/views/person/_form.php create mode 100755 modules/lrm/views/person/_search.php create mode 100755 modules/lrm/views/person/create.php create mode 100755 modules/lrm/views/person/index.php create mode 100755 modules/lrm/views/person/update.php create mode 100755 modules/lrm/views/person/view.php diff --git a/modules/lrm/Module.php b/modules/lrm/Module.php new file mode 100755 index 0000000..c99f0db --- /dev/null +++ b/modules/lrm/Module.php @@ -0,0 +1,11 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => ['@'], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all InteractionNote models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new InteractionNoteSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single InteractionNote model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new InteractionNote model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new InteractionNote(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing InteractionNote 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->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing InteractionNote 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 InteractionNote model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return InteractionNote the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = InteractionNote::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/modules/lrm/controllers/PersonController.php b/modules/lrm/controllers/PersonController.php new file mode 100755 index 0000000..875f415 --- /dev/null +++ b/modules/lrm/controllers/PersonController.php @@ -0,0 +1,134 @@ + [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => ['@'], + ], + ], + ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Person models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new PersonSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Person model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Person model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Person(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Person 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->id]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Person 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 Person model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Person the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Person::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/modules/lrm/migrations/m170711_171718_createPerson.php b/modules/lrm/migrations/m170711_171718_createPerson.php new file mode 100755 index 0000000..59babe4 --- /dev/null +++ b/modules/lrm/migrations/m170711_171718_createPerson.php @@ -0,0 +1,28 @@ +createTable(self::TABLE, [ + 'id' => $this->primaryKey(), + 'name' => $this->string(), + 'fullName' => $this->string(), + 'birthdate' => $this->date(), + 'description' => $this->string(), + 'gender' => $this->string(1),// f/m + 'createdAt' => $this->integer()->notNull(), + 'updatedAt' => $this->integer()->notNull(), + ]); + } + + public function down() + { + echo self::TABLE . ' reverted'; + $this->dropTable(self::TABLE); + } +} diff --git a/modules/lrm/migrations/m170711_173037_note.php b/modules/lrm/migrations/m170711_173037_note.php new file mode 100755 index 0000000..c34dc62 --- /dev/null +++ b/modules/lrm/migrations/m170711_173037_note.php @@ -0,0 +1,45 @@ +createTable(self::TABLE, [ + 'id' => $this->primaryKey(), + 'personId' => $this->integer()->notNull(), + 'text' => $this->text()->notNull(), + 'appraisal' => $this->smallInteger(1)->notNull(),// 0 - 9 + 'date' => $this->date(), + 'createdAt' => $this->integer()->notNull(), + 'updatedAt' => $this->integer()->notNull(), + ]); + + $personTable = m170711_171718_createPerson::TABLE; + $this->addForeignKey( + 'fk-inter-person', + '{{%' . self::TABLE . '}}', 'personId', + "{{%{$personTable}}}", 'id' + ); + } + + public function down() + { + echo self::TABLE . ' reverted'; + $this->dropTable(self::TABLE); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/modules/lrm/models/InteractionNote.php b/modules/lrm/models/InteractionNote.php new file mode 100755 index 0000000..d1cac34 --- /dev/null +++ b/modules/lrm/models/InteractionNote.php @@ -0,0 +1,85 @@ + true, 'targetClass' => Person::className(), 'targetAttribute' => ['personId' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'personId' => 'Person ID', + 'text' => 'Text', + 'appraisal' => 'Appraisal', + 'date' => 'Date', + 'createdAt' => 'Created At', + 'updatedAt' => 'Updated At', + ]; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'attributes' => [ + ActiveRecord::EVENT_BEFORE_INSERT => ['createdAt', 'updatedAt'], + ActiveRecord::EVENT_BEFORE_UPDATE => ['updatedAt'], + ], + ], + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getPerson() + { + return $this->hasOne(Person::className(), ['id' => 'personId']); + } +} diff --git a/modules/lrm/models/Person.php b/modules/lrm/models/Person.php new file mode 100755 index 0000000..f67f084 --- /dev/null +++ b/modules/lrm/models/Person.php @@ -0,0 +1,85 @@ + 'php:Y-m-d'], + [['name', 'fullName', 'description'], 'string', 'max' => 255], + [['gender'], 'in', 'range' => ['m', 'f']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + 'fullName' => 'Full Name', + 'birthdate' => 'Birthdate', + 'description' => 'Description', + 'gender' => 'Gender', + 'createdAt' => 'Created At', + 'updatedAt' => 'Updated At', + ]; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::className(), + 'attributes' => [ + ActiveRecord::EVENT_BEFORE_INSERT => ['createdAt', 'updatedAt'], + ActiveRecord::EVENT_BEFORE_UPDATE => ['updatedAt'], + ], + ], + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getInteractionNotes() + { + return $this->hasMany(InteractionNote::className(), ['personId' => 'id']); + } +} diff --git a/modules/lrm/models/search/InteractionNoteSearch.php b/modules/lrm/models/search/InteractionNoteSearch.php new file mode 100755 index 0000000..907117a --- /dev/null +++ b/modules/lrm/models/search/InteractionNoteSearch.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; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'personId' => $this->personId, + 'appraisal' => $this->appraisal, + 'date' => $this->date, + 'createdAt' => $this->createdAt, + 'updatedAt' => $this->updatedAt, + ]); + + $query->andFilterWhere(['like', 'text', $this->text]); + + return $dataProvider; + } +} diff --git a/modules/lrm/models/search/PersonSearch.php b/modules/lrm/models/search/PersonSearch.php new file mode 100755 index 0000000..00caa0d --- /dev/null +++ b/modules/lrm/models/search/PersonSearch.php @@ -0,0 +1,75 @@ + $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, + 'birthdate' => $this->birthdate, + 'createdAt' => $this->createdAt, + 'updatedAt' => $this->updatedAt, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'fullName', $this->fullName]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'gender', $this->gender]); + + return $dataProvider; + } +} diff --git a/modules/lrm/views/interaction-note/_form.php b/modules/lrm/views/interaction-note/_form.php new file mode 100755 index 0000000..50f3041 --- /dev/null +++ b/modules/lrm/views/interaction-note/_form.php @@ -0,0 +1,41 @@ + + +
+ + + + field($model, 'personId')->dropDownList(Person::find()->select('fullName')->indexBy('id')->column()) ?> + + field($model, 'text')->textarea(['rows' => 6]) ?> + + field($model, 'appraisal')->dropDownList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) ?> + + field($model, 'date')->widget(DateTimePicker::class, [ + 'options' => [ + 'class' => 'form-control input-sm', + ], + 'pluginOptions' => [ + 'autoclose'=>true, + 'format' => 'yyyy-mm-dd', + 'maxView' => 2, + 'minView' => 3, + ] + ]) ?> + +
+ isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/modules/lrm/views/interaction-note/_search.php b/modules/lrm/views/interaction-note/_search.php new file mode 100755 index 0000000..b9bc58f --- /dev/null +++ b/modules/lrm/views/interaction-note/_search.php @@ -0,0 +1,39 @@ + + + diff --git a/modules/lrm/views/interaction-note/create.php b/modules/lrm/views/interaction-note/create.php new file mode 100755 index 0000000..b2993f1 --- /dev/null +++ b/modules/lrm/views/interaction-note/create.php @@ -0,0 +1,21 @@ +title = 'Create Interaction Note'; +$this->params['breadcrumbs'][] = ['label' => 'Interaction Notes', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/modules/lrm/views/interaction-note/index.php b/modules/lrm/views/interaction-note/index.php new file mode 100755 index 0000000..28b832a --- /dev/null +++ b/modules/lrm/views/interaction-note/index.php @@ -0,0 +1,38 @@ +title = 'Interaction Notes'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

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

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'personId', + 'text:ntext', + 'appraisal', + 'date', + // 'createdAt', + // 'updatedAt', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/modules/lrm/views/interaction-note/update.php b/modules/lrm/views/interaction-note/update.php new file mode 100755 index 0000000..e9b406d --- /dev/null +++ b/modules/lrm/views/interaction-note/update.php @@ -0,0 +1,21 @@ +title = 'Update Interaction Note: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Interaction Notes', '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/modules/lrm/views/interaction-note/view.php b/modules/lrm/views/interaction-note/view.php new file mode 100755 index 0000000..dab3450 --- /dev/null +++ b/modules/lrm/views/interaction-note/view.php @@ -0,0 +1,41 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Interaction Notes', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

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', + 'personId', + 'text:ntext', + 'appraisal', + 'date', + 'createdAt', + 'updatedAt', + ], + ]) ?> + +
diff --git a/modules/lrm/views/person/_form.php b/modules/lrm/views/person/_form.php new file mode 100755 index 0000000..8421e2e --- /dev/null +++ b/modules/lrm/views/person/_form.php @@ -0,0 +1,42 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'fullName')->textInput(['maxlength' => true]) ?> + + field($model, 'birthdate')->widget(DateTimePicker::class, [ + 'options' => [ + 'class' => 'form-control input-sm', + ], + 'pluginOptions' => [ + 'autoclose'=>true, + 'format' => 'yyyy-mm-dd', + 'maxView' => 4, + 'minView' => 3, + ] + ]) ?> + + field($model, 'description')->textInput(['maxlength' => true]) ?> + + field($model, 'gender')->dropDownList(['f' => 'female', 'm' => 'male']) ?> + +
+ isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/modules/lrm/views/person/_search.php b/modules/lrm/views/person/_search.php new file mode 100755 index 0000000..2278636 --- /dev/null +++ b/modules/lrm/views/person/_search.php @@ -0,0 +1,41 @@ + + + diff --git a/modules/lrm/views/person/create.php b/modules/lrm/views/person/create.php new file mode 100755 index 0000000..17d86cb --- /dev/null +++ b/modules/lrm/views/person/create.php @@ -0,0 +1,21 @@ +title = 'Create Person'; +$this->params['breadcrumbs'][] = ['label' => 'People', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/modules/lrm/views/person/index.php b/modules/lrm/views/person/index.php new file mode 100755 index 0000000..6a082e8 --- /dev/null +++ b/modules/lrm/views/person/index.php @@ -0,0 +1,37 @@ +title = 'People'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

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

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + 'birthdate', + 'gender', + // 'createdAt', + // 'updatedAt', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/modules/lrm/views/person/update.php b/modules/lrm/views/person/update.php new file mode 100755 index 0000000..def2798 --- /dev/null +++ b/modules/lrm/views/person/update.php @@ -0,0 +1,21 @@ +title = 'Update Person: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'People', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/modules/lrm/views/person/view.php b/modules/lrm/views/person/view.php new file mode 100755 index 0000000..fe4fe33 --- /dev/null +++ b/modules/lrm/views/person/view.php @@ -0,0 +1,42 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'People', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

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', + 'name', + 'fullName', + 'birthdate', + 'description', + 'gender', + 'createdAt', + 'updatedAt', + ], + ]) ?> + +