add ticket type model + crud ( bérlet típus)

This commit is contained in:
2015-09-22 11:59:58 +02:00
parent ab885b13e9
commit db8fca5630
9 changed files with 242 additions and 106 deletions

View File

@@ -20,37 +20,74 @@ use Yii;
* @property string $created_at
* @property string $updated_at
*/
class TicketType extends \common\models\BaseFitnessActiveRecord
{
class TicketType extends \common\models\BaseFitnessActiveRecord {
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
CONST TIME_UNIT_DAY = 10;
CONST TIME_UNIT_MONTH = 20;
CONST TIME_UNIT_MONTH_REFERENCE = 30;
CONST TIME_UNIT_DAY = 10;//nap
CONST TIME_UNIT_MONTH = 20;//hónap
CONST TIME_UNIT_MONTH_REFERENCE = 30; //tárgy hónap
const TYPE_NORMAL = 10;
const TYPE_DEFAULT = self::TYPE_NORMAL;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'ticket_type';
}
/**
const FLAG_STUDENT_OFF = 0;
const FLAG_STUDENT_ON = 1;
/**
* @inheritdoc
*/
public static function tableName() {
return 'ticket_type';
}
/**
* @formatter:off
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'id_account'], 'required'],
[['type', 'max_usage_count', 'time_unit_type', 'time_unit_count', 'price_brutto', 'id_account', 'flag_student', 'status'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 64]
[['name', 'id_account','time_unit_count','type' ,'time_unit_type' ,'max_usage_count','price_brutto'], 'required'],
////////////////
//price brutto
////////////////
[[ 'price_brutto', ], 'integer'],
////////////////
//time_unit_type
////////////////
[['time_unit_type',], 'integer'],
[['time_unit_type',], 'in', 'range' => [ self::TIME_UNIT_DAY,self::TIME_UNIT_MONTH,self::TIME_UNIT_MONTH_REFERENCE] ],
////////////////
//time_unit_count
////////////////
[['time_unit_count',], 'integer','min' => 1 , 'max' => 100],
////////////////
//max_usage_count
////////////////
[['max_usage_count',], 'integer','min' => 0 , 'max' => 10000],
////////////////
//flag_student
////////////////
[['flag_student',], 'integer'],
[['flag_student',], 'in', 'range' => [ self::FLAG_STUDENT_OFF, self::FLAG_STUDENT_ON ]],
////////////////
//status
////////////////
[['status',], 'integer'],
[['status',], 'in', 'range' => [ self::STATUS_ACTIVE, self::STATUS_DELETED ]],
////////////////
//type
////////////////
[['type',], 'integer'],
[['type',], 'in', 'range' => [ self::TYPE_NORMAL ]],
////////////////
//name
////////////////
[['name'], 'string', 'max' => 64],
////////////////
//id_account
////////////////
[['id_account',], 'integer'],
[['id_account',], 'validateIdAccount'],
];
}
@@ -75,58 +112,86 @@ class TicketType extends \common\models\BaseFitnessActiveRecord
];
}
static function statuses() {
return [
self::STATUS_ACTIVE => Yii::t('common/ticket_type', 'Active'),
self::STATUS_DELETED => Yii::t('common/ticket_type', 'Inactive'),
];
}
public function getStatusHuman(){
$result = null;
$s = self::statuses($this->status);
if ( array_key_exists($this->status, $s)){
$result = $s[$this->status];
}
return $result;
}
static function timeUnitTypes() {
return [
self::TIME_UNIT_DAY => Yii::t('common/ticket_type', 'Nap'),
self::TIME_UNIT_MONTH => Yii::t('common/ticket_type', 'Hónap'),
self::TIME_UNIT_MONTH_REFERENCE => Yii::t('common/ticket_type', 'Tárgyhónap'),
];
}
public function getTimeUnitHuman(){
$result = null;
$s = self::timeUnitTypes($this->time_unit_type);
if ( array_key_exists($this->time_unit_type, $s)){
$result = $s[$this->time_unit_type];
}
return $result;
}
static function ticketTypes() {
return [
self::TYPE_NORMAL => Yii::t('common/ticket_type', 'Normal'),
];
}
public function getTypeHuman(){
$result = null;
$s = self::ticketTypes( );
if ( array_key_exists($this->type, $s)){
$result = $s[$this->type];
}
return $result;
}
public function getAccount(){
return $this->hasOne(Account::className(), [ 'id_account' => 'id_account' ]);
}
/**
* @formatter:on
*/
static function statuses() {
return [
self::STATUS_ACTIVE => Yii::t ( 'common/ticket_type', 'Active' ),
self::STATUS_DELETED => Yii::t ( 'common/ticket_type', 'Inactive' )
];
}
public function getStatusHuman() {
$result = null;
$s = self::statuses ( $this->status );
if (array_key_exists ( $this->status, $s )) {
$result = $s [$this->status];
}
return $result;
}
static function timeUnitTypes() {
return [
self::TIME_UNIT_DAY => Yii::t ( 'common/ticket_type', 'Day' ),
self::TIME_UNIT_MONTH => Yii::t ( 'common/ticket_type', 'Month' ),
self::TIME_UNIT_MONTH_REFERENCE => Yii::t ( 'common/ticket_type', 'Reference month' )
];
}
public function getTimeUnitHuman() {
$result = null;
$s = self::timeUnitTypes ( $this->time_unit_type );
if (array_key_exists ( $this->time_unit_type, $s )) {
$result = $s [$this->time_unit_type];
}
return $result;
}
static function ticketTypes() {
return [
self::TYPE_NORMAL => Yii::t ( 'common/ticket_type', 'Normal' )
];
}
public function getTypeHuman() {
$result = null;
$s = self::ticketTypes ();
if (array_key_exists ( $this->type, $s )) {
$result = $s [$this->type];
}
return $result;
}
public function getAccount() {
return $this->hasOne ( Account::className (), [
'id_account' => 'id_account'
] );
}
public function getAccountName() {
return $this->account->name;
}
public function isStudent(){
return $this->flag_student == ( self::FLAG_STUDENT_ON);
}
public function validateIdAccount($attribute,$params){
$account = null;
if ( !$this->hasErrors("id_account")){
$account = Account::findOne($this->$attribute);
if ( !isset($account)){
$this->addError($attribute,Yii::t('common/ticket_type','Invalid account!'));
}else{
//on update
if ( !$this->isNewRecord ){
//if selected account is inactive ...
if ( $account->isInactive() ){
//... and changed
if ( $this->isAttributeChanged('id_account')){
$this->addError($attribute,Yii::t('common/ticket_type','Invalid account (inactive)!'));
}
}
}
}
}
}
}