add collections to backend

This commit is contained in:
2015-11-04 15:39:02 +01:00
parent 48a00e4bdc
commit 4303409fe2
22 changed files with 212 additions and 266 deletions

View File

@@ -8,6 +8,9 @@ use backend\models\CollectionSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Account;
use common\models\Transfer;
use common\models\User;
/**
* CollectionController implements the CRUD actions for Collection model.
@@ -15,6 +18,25 @@ use yii\filters\VerbFilter;
class CollectionController extends \backend\controllers\BackendController
{
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
// allow authenticated users
[
'actions' => [ 'index','view' ],
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/**
* Lists all Collection models.
* @return mixed
@@ -22,7 +44,13 @@ class CollectionController extends \backend\controllers\BackendController
public function actionIndex()
{
$searchModel = new CollectionSearch();
$searchModel->accounts = Account::read();
$searchModel->accountMap = Account::toAccaountMap($searchModel->accounts);
$searchModel->users = User::find()->all( );
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$searchModel->searchTotal();
return $this->render('index', [
'searchModel' => $searchModel,
@@ -37,61 +65,20 @@ class CollectionController extends \backend\controllers\BackendController
*/
public function actionView($id)
{
$model = $this->findModel($id);
$accounts = Account::read();
$accountMap = Account::toAccaountMap($accounts);
$totals = Transfer::mkTotals($model->start, $model->end, $model->id_user, null, $model->id_account, $accounts, $accountMap);
return $this->render('view', [
'model' => $this->findModel($id),
'model' => $model,
'totals' => $totals,
]);
}
/**
* Creates a new Collection model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Collection();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_collection]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Collection 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_collection]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Collection 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 Collection model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.

View File

@@ -1,5 +1,4 @@
<?php
namespace backend\controllers;
use Yii;
@@ -45,11 +44,10 @@ class TransferController extends \backend\controllers\BackendController
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$accounts = Account::readAccounts();
$users = User::read();
$searchModel->totals(Yii::$app->request->queryParams);
$searchModel->totalsTransfers();
$users = User::read();
return $this->render('index', [
'searchModel' => $searchModel,