add changes to account state

This commit is contained in:
2015-10-19 07:48:46 +02:00
parent b04cbda645
commit 9145f21371
50 changed files with 2139 additions and 27 deletions

View File

@@ -0,0 +1,130 @@
<?php
namespace backend\controllers;
use Yii;
use common\models\AccountState;
use backend\models\AccountStateSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Account;
use common\models\User;
/**
* AccountStateController implements the CRUD actions for AccountState model.
*/
class AccountStateController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all AccountState models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new AccountStateSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$accounts = Account::read();
$users = User::read();
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'accounts' => $accounts,
'users' => $users,
]);
}
/**
* Displays a single AccountState model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new AccountState model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new AccountState();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_account_state]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing AccountState 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_account_state]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing AccountState 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 AccountState model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return AccountState the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = AccountState::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@@ -11,12 +11,15 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\base\Object;
use backend\models\UserUpdate;
use common\models\Account;
use common\models\UserAccountAssignment;
/**
* UserController implements the CRUD actions for User model.
*/
class UserController extends Controller
{
public function behaviors()
{
return [
@@ -37,6 +40,8 @@ class UserController extends Controller
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
@@ -64,14 +69,35 @@ class UserController extends Controller
public function actionCreate()
{
$model = new UserCreate();
$accounts = Account::readAccounts();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
$this->updateAccountAssignments($model);
// return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
'accounts' => $accounts,
]);
}
}
public function updateAccountAssignments($model){
echo "saving accounts";
UserAccountAssignment::deleteAll(['id_user' => $model->id]);
foreach ( $model->selected_accounts as $id_account ){
echo "saving account";
$uaa = new UserAccountAssignment();
$uaa->id_user = $model->id;
$uaa->id_account = $id_account;
$uaa->save();
}
}
/**
@@ -87,14 +113,29 @@ class UserController extends Controller
if ( $model == null ){
throw new NotFoundHttpException('The requested page does not exist.');
}
$accounts = Account::readAccounts();
$this->applyAccounts($model);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->updateAccountAssignments($model);
return $this->redirect(['view', 'id' => $model->id]);
} else {
}
return $this->render('update', [
'model' => $model,
'accounts' => $accounts,
]);
}
}
private function applyAccounts($model ){
$assignedAccounts = $model->userAccountAssignments;
foreach ($assignedAccounts as $acc ){
$model->selected_accounts[] = $acc->id_account;
}
}
/**