diff --git a/modules/lrm/controllers/PersonController.php b/modules/lrm/controllers/PersonController.php index 875f415..76f85fa 100755 --- a/modules/lrm/controllers/PersonController.php +++ b/modules/lrm/controllers/PersonController.php @@ -76,7 +76,7 @@ public function actionCreate() $model = new Person(); if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); + return $this->redirect(['index']); } else { return $this->render('create', [ 'model' => $model, @@ -95,7 +95,7 @@ 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->redirect(['index']); } else { return $this->render('update', [ 'model' => $model, diff --git a/modules/lrm/controllers/PersonStateController.php b/modules/lrm/controllers/PersonStateController.php new file mode 100644 index 0000000..5adbc24 --- /dev/null +++ b/modules/lrm/controllers/PersonStateController.php @@ -0,0 +1,124 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all PersonState models. + * @return mixed + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => PersonState::find(), + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single PersonState model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new PersonState model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new PersonState(); + + 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 PersonState 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 PersonState 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 PersonState model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return PersonState the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = PersonState::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 index 59babe4..0970da4 100755 --- a/modules/lrm/migrations/m170711_171718_createPerson.php +++ b/modules/lrm/migrations/m170711_171718_createPerson.php @@ -22,6 +22,7 @@ public function up() public function down() { + return false; 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 index c34dc62..10ffd4d 100755 --- a/modules/lrm/migrations/m170711_173037_note.php +++ b/modules/lrm/migrations/m170711_173037_note.php @@ -28,6 +28,7 @@ public function up() public function down() { + return false; echo self::TABLE . ' reverted'; $this->dropTable(self::TABLE); } diff --git a/modules/lrm/migrations/m170712_181655_leadPerson.php b/modules/lrm/migrations/m170712_181655_leadPerson.php new file mode 100644 index 0000000..ca037f4 --- /dev/null +++ b/modules/lrm/migrations/m170712_181655_leadPerson.php @@ -0,0 +1,47 @@ +tableFk;//m170711_171718_createPerson::TABLE; + + $this->addColumn($table, 'stateId', $this->integer()->null()); + + $this->createTable(self::TABLE, [ + 'id' => $this->primaryKey(), + 'name' => $this->string(), + ]); + + $this->addForeignKey( + self::FK, + $table, 'stateId', + self::TABLE, 'id' + ); + + } + + public function down() + { + $this->dropForeignKey(self::FK, $this->tableFk); + $this->dropColumn($this->tableFk, 'stateId'); + $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/Person.php b/modules/lrm/models/Person.php index f67f084..5d0027b 100755 --- a/modules/lrm/models/Person.php +++ b/modules/lrm/models/Person.php @@ -15,6 +15,7 @@ * @property string $birthdate * @property string $description * @property string $gender + * @property int $stateId * @property integer $createdAt * @property integer $updatedAt * @@ -39,6 +40,7 @@ public function rules() [['birthdate'], 'date', 'format' => 'php:Y-m-d'], [['name', 'fullName', 'description'], 'string', 'max' => 255], [['gender'], 'in', 'range' => ['m', 'f']], + [['stateId'], 'exist', 'targetClass' => PersonState::class, 'targetAttribute' => 'id'], ]; } @@ -54,6 +56,7 @@ public function attributeLabels() 'birthdate' => 'Birthdate', 'description' => 'Description', 'gender' => 'Gender', + 'stateId' => 'State', 'createdAt' => 'Created At', 'updatedAt' => 'Updated At', ]; @@ -82,4 +85,9 @@ public function getInteractionNotes() { return $this->hasMany(InteractionNote::className(), ['personId' => 'id']); } + + public function getState() + { + return $this->hasOne(PersonState::class, ['id' => 'stateId']); + } } diff --git a/modules/lrm/models/PersonState.php b/modules/lrm/models/PersonState.php new file mode 100644 index 0000000..8168f5a --- /dev/null +++ b/modules/lrm/models/PersonState.php @@ -0,0 +1,54 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getPeople() + { + return $this->hasMany(Person::className(), ['stateId' => 'id']); + } +} diff --git a/modules/lrm/views/person-state/_form.php b/modules/lrm/views/person-state/_form.php new file mode 100644 index 0000000..0f83785 --- /dev/null +++ b/modules/lrm/views/person-state/_form.php @@ -0,0 +1,23 @@ + + +
+ = Html::a('Create Person State', ['create'], ['class' => 'btn btn-success']) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> ++ = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Delete', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + 'name', + ], + ]) ?> + +