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

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

View File

@@ -0,0 +1,82 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\AccountState;
/**
* AccountStateSearch represents the model behind the search form about `common\models\AccountState`.
*/
class AccountStateSearch extends AccountState
{
public $type;
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
/**
* @inheritdoc
*/
public function rules()
{
return [
[[ 'id_account', 'type', 'id_user'], 'integer'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = AccountState::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => false,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
$query->where('0=1');
return $dataProvider;
}
$query->orderBy(['created_at' => SORT_DESC]);
$query->andFilterWhere([
'id_user' => $this->id_user,
'id_account' => $this->id_account,
'type' => $this->type,
]);
$query->andFilterWhere([ '>=', 'created_at', $this->timestampStart ] );
$query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] );
return $dataProvider;
}
}

View File

@@ -66,6 +66,7 @@ class TransferSearch extends Transfer
'query' => $query,
]);
// $query->distinct();
$selectObjectName = "";
$selectObjectName .= " case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end as object_name";

View File

@@ -8,6 +8,7 @@ class UserCreate extends User{
public $password_plain;
public $password_repeat;
public $selected_accounts = [];
/**
* @inheritdoc
@@ -16,11 +17,17 @@ class UserCreate extends User{
{
return [
[['username','email','password_plain','password_repeat'], 'required' ],
['selected_accounts',function ($attribute, $params) {
if (!is_array($this->$attribute)) {
$this->addError($attribute, 'Invalid array');
}
}
],
['email' ,'email' ],
['email' ,'unique' ],
['username' ,'unique' ],
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
[['password_repeat'] ,'validatePasswordRepeat' ]
[['password_repeat'] ,'validatePasswordRepeat' ],
];
}

View File

@@ -8,6 +8,7 @@ use common\models\User;
class UserUpdate extends User {
public $password_plain;
public $password_repeat;
public $selected_accounts = [];
/**
* @inheritdoc
@@ -21,9 +22,16 @@ class UserUpdate extends User {
['email' ,'unique' , 'targetClass' => User::className(), 'targetAttribute' => 'email'],
['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'],
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
[['password_repeat'] ,'validatePasswordRepeat' ]
[['password_repeat'] ,'validatePasswordRepeat' ],
['selected_accounts',function ($attribute, $params) {
if (!is_array($this->$attribute)) {
$this->addError($attribute, 'Invalid array');
}
}
]
];
}
/**
* @formatter:on
*/