fix clear and copy week
This commit is contained in:
@@ -2,8 +2,13 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
@@ -19,12 +24,13 @@ use yii\helpers\ArrayHelper;
|
||||
* @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
|
||||
* @property \common\models\EventRegistration[] $eventRegistrations
|
||||
* @property integer $active
|
||||
* @property EventType $eventType
|
||||
* @property Trainer $trainer
|
||||
* @property Room $room
|
||||
* @property EventRegistration[] $eventRegistrations
|
||||
*/
|
||||
class Event extends \yii\db\ActiveRecord
|
||||
class Event extends ActiveRecord
|
||||
{
|
||||
|
||||
public $startDateString;
|
||||
@@ -85,15 +91,15 @@ class Event extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function afterFind()
|
||||
{
|
||||
parent::afterFind(); // TODO: Change the autogenerated stub
|
||||
$format = "Y.m.d H:i";
|
||||
$date = new \DateTime();
|
||||
$format = 'Y.m.d H:i';
|
||||
$date = new DateTime();
|
||||
$date->setTimestamp($this->start);
|
||||
$date->setTimezone(new \DateTimeZone('UTC'));
|
||||
$date->setTimezone(new DateTimeZone('UTC'));
|
||||
$this->startDateString = $date->format($format);
|
||||
$date->setTimestamp($this->end);
|
||||
$this->endDateString = $date->format($format);
|
||||
@@ -103,48 +109,50 @@ class Event extends \yii\db\ActiveRecord
|
||||
{
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
||||
'class' => TimestampBehavior::class,
|
||||
'value' => static function(){ return date('Y-m-d H:i:s' ); }
|
||||
]
|
||||
],
|
||||
parent::behaviors());
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
public function getEventType(){
|
||||
return $this->hasOne($this->getEventTypeClass(),['id' => 'id_event_type']);
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
public function getTrainer(){
|
||||
return $this->hasOne($this->getTrainerClass(),['id' => 'id_trainer']);
|
||||
}
|
||||
}/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* @return Room|\yii\db\ActiveQuery
|
||||
* @return Room|ActiveQuery
|
||||
*/
|
||||
public function getRoom() {
|
||||
return $this->hasOne($this->getRoomClass(),['id' => 'id_room']);
|
||||
}
|
||||
}/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* @return Card|\yii\db\ActiveQuery
|
||||
* @return Card|ActiveQuery
|
||||
*/
|
||||
public function getCard() {
|
||||
return $this->hasOne(Card::className(),['id_card' => 'id_card']);
|
||||
return $this->hasOne(Card::class,['id_card' => 'id_card']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
|
||||
* @return EventRegistration[]|ActiveQuery
|
||||
*/
|
||||
public function getEventRegistrations(){
|
||||
return $this->hasMany(EventRegistration::className(),['id_event' => 'id']);
|
||||
return $this->hasMany(EventRegistration::class,['id_event' => 'id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
|
||||
* @return EventRegistration[]|ActiveQuery
|
||||
*/
|
||||
public function getActiveEventRegistrations(){
|
||||
return $this->hasMany(EventRegistration::className(),['id_event' => 'id'])->andWhere(
|
||||
return $this->hasMany(EventRegistration::class,['id_event' => 'id'])->andWhere(
|
||||
[
|
||||
'event_registration.canceled_at' => null,
|
||||
'event_registration.deleted_at' => null,
|
||||
@@ -153,21 +161,22 @@ class Event extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \common\models\EventRegistration[]|\yii\db\ActiveQuery
|
||||
* @return EventRegistration[]|ActiveQuery
|
||||
*/
|
||||
public function getEventRegistrationCount(){
|
||||
return sizeof($this->getActiveEventRegistrations()->all());
|
||||
return count($this->getActiveEventRegistrations()->all());
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
public function getOpenSeatCount(){
|
||||
return $this->seat_count - $this->getEventRegistrationCount();
|
||||
}
|
||||
|
||||
public function hasFreeSeats(){
|
||||
$registrationCount = sizeof($this->eventRegistrations) ;
|
||||
$registrationCount = count($this->eventRegistrations) ;
|
||||
|
||||
$seatCount = $this->seat_count;
|
||||
if ( !isset($seatCount ) || $seatCount == 0){
|
||||
if ( !isset($seatCount ) || $seatCount === 0){
|
||||
$seatCount = PHP_INT_MAX;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user