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

@@ -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;
}
}
/**