fitness-web/frontend/models/MoneyMovementSearch.php
2015-10-30 09:28:58 +01:00

83 lines
2.1 KiB
PHP

<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\MoneyMovement;
use yii\helpers\ArrayHelper;
/**
* MoneyMovementSearch represents the model behind the search form about `common\models\MoneyMovement`.
*/
class MoneyMovementSearch extends MoneyMovement
{
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
/**
* @inheritdoc
*/
public function rules()
{
return [
[[ 'start', ], 'date', 'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
];
}
/**
* @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 = MoneyMovement::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$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->andFilterWhere([ '>=', 'money_movement.created_at', $this->timestampStart ] );
$query->andFilterWhere([ '<', 'money_movement.created_at', $this->timestampEnd ] );
return $dataProvider;
}
public function attributeLabels( ) {
return ArrayHelper::merge(parent::attributeLabels(),
[
'start' => Yii::t('frontend/money-movement', 'Start'),
'end' => Yii::t('frontend/money-movement', 'End'),
]
);
}
}