Skip to content

Commit

Permalink
LRM: person statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
boryashkin committed Jul 12, 2017
1 parent 91dfeab commit f915124
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/lrm/controllers/PersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
124 changes: 124 additions & 0 deletions modules/lrm/controllers/PersonStateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace app\modules\lrm\controllers;

use Yii;
use app\modules\lrm\models\PersonState;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
* PersonStateController implements the CRUD actions for PersonState model.
*/
class PersonStateController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'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.');
}
}
}
1 change: 1 addition & 0 deletions modules/lrm/migrations/m170711_171718_createPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function up()

public function down()
{
return false;
echo self::TABLE . ' reverted';
$this->dropTable(self::TABLE);
}
Expand Down
1 change: 1 addition & 0 deletions modules/lrm/migrations/m170711_173037_note.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function up()

public function down()
{
return false;
echo self::TABLE . ' reverted';
$this->dropTable(self::TABLE);
}
Expand Down
47 changes: 47 additions & 0 deletions modules/lrm/migrations/m170712_181655_leadPerson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use yii\db\Migration;

class m170712_181655_leadPerson extends Migration
{
const TABLE = 'personState';
const FK = 'fk-pers-persState';
public $tableFk = 'person';

public function up()
{
$table = $this->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()
{
}
*/
}
8 changes: 8 additions & 0 deletions modules/lrm/models/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @property string $birthdate
* @property string $description
* @property string $gender
* @property int $stateId
* @property integer $createdAt
* @property integer $updatedAt
*
Expand All @@ -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'],
];
}

Expand All @@ -54,6 +56,7 @@ public function attributeLabels()
'birthdate' => 'Birthdate',
'description' => 'Description',
'gender' => 'Gender',
'stateId' => 'State',
'createdAt' => 'Created At',
'updatedAt' => 'Updated At',
];
Expand Down Expand Up @@ -82,4 +85,9 @@ public function getInteractionNotes()
{
return $this->hasMany(InteractionNote::className(), ['personId' => 'id']);
}

public function getState()
{
return $this->hasOne(PersonState::class, ['id' => 'stateId']);
}
}
54 changes: 54 additions & 0 deletions modules/lrm/models/PersonState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace app\modules\lrm\models;

use Yii;

/**
* //todo: order property for sorting
* This is the model class for table "{{%personState}}".
*
* @property integer $id
* @property string $name
*
* @property Person[] $people
*/
class PersonState extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%personState}}';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'string', 'max' => 255],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getPeople()
{
return $this->hasMany(Person::className(), ['stateId' => 'id']);
}
}
23 changes: 23 additions & 0 deletions modules/lrm/views/person-state/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\modules\lrm\models\PersonState */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="person-state-form">

<?php $form = ActiveForm::begin(); ?>

<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>

</div>
21 changes: 21 additions & 0 deletions modules/lrm/views/person-state/create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use yii\helpers\Html;


/* @var $this yii\web\View */
/* @var $model app\modules\lrm\models\PersonState */

$this->title = 'Create Person State';
$this->params['breadcrumbs'][] = ['label' => 'Person States', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="person-state-create">

<h1><?= Html::encode($this->title) ?></h1>

<?= $this->render('_form', [
'model' => $model,
]) ?>

</div>
30 changes: 30 additions & 0 deletions modules/lrm/views/person-state/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Person States';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="person-state-index">

<h1><?= Html::encode($this->title) ?></h1>

<p>
<?= Html::a('Create Person State', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
'name',

['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
21 changes: 21 additions & 0 deletions modules/lrm/views/person-state/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $model app\modules\lrm\models\PersonState */

$this->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';
?>
<div class="person-state-update">

<h1><?= Html::encode($this->title) ?></h1>

<?= $this->render('_form', [
'model' => $model,
]) ?>

</div>
Loading

0 comments on commit f915124

Please sign in to comment.