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 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + +
+ isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/modules/lrm/views/person-state/create.php b/modules/lrm/views/person-state/create.php new file mode 100644 index 0000000..67000cc --- /dev/null +++ b/modules/lrm/views/person-state/create.php @@ -0,0 +1,21 @@ +title = 'Create Person State'; +$this->params['breadcrumbs'][] = ['label' => 'Person States', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/modules/lrm/views/person-state/index.php b/modules/lrm/views/person-state/index.php new file mode 100644 index 0000000..bc5b04c --- /dev/null +++ b/modules/lrm/views/person-state/index.php @@ -0,0 +1,30 @@ +title = 'Person States'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

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

+ $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/modules/lrm/views/person-state/update.php b/modules/lrm/views/person-state/update.php new file mode 100644 index 0000000..3de1eeb --- /dev/null +++ b/modules/lrm/views/person-state/update.php @@ -0,0 +1,21 @@ +title = 'Update Person State: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Person States', '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-state/view.php b/modules/lrm/views/person-state/view.php new file mode 100644 index 0000000..4dbbf46 --- /dev/null +++ b/modules/lrm/views/person-state/view.php @@ -0,0 +1,36 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Person States', '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', + ], + ]) ?> + +
diff --git a/modules/lrm/views/person/_form.php b/modules/lrm/views/person/_form.php index 8421e2e..2870afc 100755 --- a/modules/lrm/views/person/_form.php +++ b/modules/lrm/views/person/_form.php @@ -33,6 +33,10 @@ field($model, 'gender')->dropDownList(['f' => 'female', 'm' => 'male']) ?> + field($model, 'stateId')->dropDownList(\app\modules\lrm\models\PersonState::find()->select('name')->indexBy('id')->column(), [ + 'prompt' => '-', + ]) ?> +
isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/modules/lrm/views/person/index.php b/modules/lrm/views/person/index.php index 6a082e8..3cd02c1 100755 --- a/modules/lrm/views/person/index.php +++ b/modules/lrm/views/person/index.php @@ -28,6 +28,10 @@ 'name', 'birthdate', 'gender', + [ + 'attribute' => 'state.name', + 'label' => 'State', + ], // 'createdAt', // 'updatedAt', diff --git a/views/layouts/main.php b/views/layouts/main.php index 7dc2d10..0b05ffb 100644 --- a/views/layouts/main.php +++ b/views/layouts/main.php @@ -45,6 +45,7 @@ ['label' => 'Relationships', 'items' => [ ['label' => 'Persons', 'url' => ['/lrm/person']], ['label' => 'Log', 'url' => ['/lrm/interaction-note']], + ['label' => 'States', 'url' => ['/lrm/person-state']], ]], ['label' => 'Settings', 'items' => [ ['label' => 'Tags', 'url' => ['/tags']],