Skip to content

Commit

Permalink
LRM: love relationship management
Browse files Browse the repository at this point in the history
  • Loading branch information
boryashkin committed Jul 11, 2017
1 parent 27830b5 commit 91dfeab
Show file tree
Hide file tree
Showing 21 changed files with 1,076 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/lrm/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace app\modules\lrm;

/**
* Love Relationship Management
*/
class Module extends \yii\base\Module
{
public $defaultRoute = 'person';
}
134 changes: 134 additions & 0 deletions modules/lrm/controllers/InteractionNoteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace app\modules\lrm\controllers;

use Yii;
use app\modules\lrm\models\InteractionNote;
use app\modules\lrm\models\search\InteractionNoteSearch;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
* InteractionNoteController implements the CRUD actions for InteractionNote model.
*/
class InteractionNoteController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'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.');
}
}
}
134 changes: 134 additions & 0 deletions modules/lrm/controllers/PersonController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace app\modules\lrm\controllers;

use Yii;
use app\modules\lrm\models\Person;
use app\modules\lrm\models\search\PersonSearch;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
* PersonController implements the CRUD actions for Person model.
*/
class PersonController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'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.');
}
}
}
28 changes: 28 additions & 0 deletions modules/lrm/migrations/m170711_171718_createPerson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use yii\db\Migration;

class m170711_171718_createPerson extends Migration
{
const TABLE = 'person';

public function up()
{
$this->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);
}
}
45 changes: 45 additions & 0 deletions modules/lrm/migrations/m170711_173037_note.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use yii\db\Migration;

class m170711_173037_note extends Migration
{
const TABLE = 'interactionNote';

public function up()
{
$this->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()
{
}
*/
}
Loading

0 comments on commit 91dfeab

Please sign in to comment.