108 lines
2.7 KiB
PHP
108 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace common\models;
|
|
|
|
use Yii;
|
|
use common\components\AccountAwareBehavior;
|
|
use common\components\UserAwareBehavior;
|
|
use yii\helpers\ArrayHelper;
|
|
use yii\behaviors\TimestampBehavior;
|
|
|
|
/**
|
|
* This is the model class for table "collection".
|
|
*
|
|
* @property integer $id_collection
|
|
* @property integer $id_user
|
|
* @property integer $created_by
|
|
* @property integer $id_account
|
|
* @property integer $money
|
|
* @property string $start
|
|
* @property string $end
|
|
* @property integer $type
|
|
* @property string $created_at
|
|
* @property string $updated_at
|
|
*/
|
|
class Collection extends \common\models\BaseFitnessActiveRecord
|
|
{
|
|
|
|
const TYPE_RECEPTION = 10;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static function tableName()
|
|
{
|
|
return 'collection';
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function behaviors()
|
|
{
|
|
return ArrayHelper::merge( [
|
|
[
|
|
'class' => TimestampBehavior::className(),
|
|
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
|
],
|
|
[
|
|
'class' => UserAwareBehavior::className(),
|
|
],
|
|
[
|
|
'class' => AccountAwareBehavior::className(),
|
|
],
|
|
], parent::behaviors());
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['id_user', 'created_by', 'id_account', 'money', 'type'], 'integer'],
|
|
[['money', 'type', 'created_at', 'updated_at'], 'required'],
|
|
[['start', 'end', 'created_at', 'updated_at'], 'safe']
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id_collection' => Yii::t('common/collection', 'Id Collection'),
|
|
'id_user' => Yii::t('common/collection', 'Id User'),
|
|
'created_by' => Yii::t('common/collection', 'Created By'),
|
|
'id_account' => Yii::t('common/collection', 'Id Account'),
|
|
'money' => Yii::t('common/collection', 'Money'),
|
|
'start' => Yii::t('common/collection', 'Start'),
|
|
'end' => Yii::t('common/collection', 'End'),
|
|
'type' => Yii::t('common/collection', 'Type'),
|
|
'created_at' => Yii::t('common/collection', 'Created At'),
|
|
'updated_at' => Yii::t('common/collection', 'Updated At'),
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
* @param \common\models\User $user the user
|
|
* */
|
|
public static function readLast($user,$types = [Collection::TYPE_RECEPTION]){
|
|
$result = null;
|
|
$query = Collection::find();
|
|
if ( isset($user)){
|
|
$query->andWhere(['id_user' =>$user->id]);
|
|
}
|
|
$query->andFilterWhere([ 'in', 'type' ,$types]);
|
|
|
|
$query->orderBy(['end' => SORT_DESC]);
|
|
|
|
$query->limit(1);
|
|
$result = $query->one();
|
|
|
|
return $result;
|
|
}
|
|
}
|