Improve Event management
This commit is contained in:
@@ -18,6 +18,7 @@ use yii\helpers\ArrayHelper;
|
||||
* @property integer $seat_count
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property string $deleted_at
|
||||
* @property \common\models\EventType $eventType
|
||||
* @property \common\models\Trainer $trainer
|
||||
* @property \common\models\Room $room
|
||||
@@ -67,6 +68,7 @@ class Event extends \yii\db\ActiveRecord
|
||||
'id_event_type' => Yii::t('event', 'Id Event Type'),
|
||||
'created_at' => Yii::t('event', 'Created At'),
|
||||
'updated_at' => Yii::t('event', 'Updated At'),
|
||||
'deleted_at' => Yii::t('event', 'Deleted At'),
|
||||
'trainerName' => Yii::t('event', 'Trainer Name'),
|
||||
'roomName' => Yii::t('event', 'Room Name'),
|
||||
'eventTypeName' => Yii::t('event', 'Típus'),
|
||||
@@ -77,6 +79,8 @@ class Event extends \yii\db\ActiveRecord
|
||||
'endDateString' => Yii::t('event', 'End'),
|
||||
'status' => Yii::t('event', 'Status'),
|
||||
'seat_count' => Yii::t('event', 'Seat Count'),
|
||||
'eventRegistrationCount' => Yii::t('event', 'Event Registration Count'),
|
||||
'openSeatCount' => Yii::t('event', 'Open Seat Count'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -132,7 +136,16 @@ class Event extends \yii\db\ActiveRecord
|
||||
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
|
||||
*/
|
||||
public function getEventRegistrationCount(){
|
||||
return sizeof($this->eventRegistrations);
|
||||
return sizeof($this->getEventRegistrations()
|
||||
->andWhere( [
|
||||
'canceled_at' => null,
|
||||
'deleted_at' => null,
|
||||
])
|
||||
->all());
|
||||
}
|
||||
|
||||
public function getOpenSeatCount(){
|
||||
return $this->seat_count - $this->getEventRegistrationCount();
|
||||
}
|
||||
|
||||
public function hasFreeSeats(){
|
||||
@@ -146,4 +159,21 @@ class Event extends \yii\db\ActiveRecord
|
||||
return $registrationCount < $seatCount ;
|
||||
}
|
||||
|
||||
public function canReserve(){
|
||||
if ( isset($this->deleted_at)){
|
||||
return false;
|
||||
}
|
||||
if ( !$this->hasFreeSeats()){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canDelete(){
|
||||
if ( isset($this->deleted_at)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ use yii\helpers\ArrayHelper;
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property string $canceled_at
|
||||
* @property string $deleted_at
|
||||
*/
|
||||
class EventRegistration extends \yii\db\ActiveRecord
|
||||
{
|
||||
@@ -50,6 +51,7 @@ class EventRegistration extends \yii\db\ActiveRecord
|
||||
'created_at' => Yii::t('event-registration', 'Created At'),
|
||||
'updated_at' => Yii::t('event-registration', 'Updated At'),
|
||||
'canceled_at' => Yii::t('event-registration', 'Canceled At'),
|
||||
'deleted_at' => Yii::t('event-registration', 'Deleted At'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user