fix clear and copy week
This commit is contained in:
parent
9c0e2a56ee
commit
2c5db234ce
@ -11,7 +11,7 @@ use common\models\Ticket;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use yii\base\Object;
|
||||
use yii\base\BaseObject;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\db\Query;
|
||||
use yii\web\BadRequestHttpException;
|
||||
@ -24,7 +24,7 @@ use yii\web\ServerErrorHttpException;
|
||||
* Date: 2018.12.17.
|
||||
* Time: 6:12
|
||||
*/
|
||||
class EventRegistrationManager extends Object
|
||||
class EventRegistrationManager extends BaseObject
|
||||
{
|
||||
const CARD_NOT_FOUND = 1;
|
||||
const CUSTOMER_NOT_FOUND = 2;
|
||||
@ -189,21 +189,25 @@ class EventRegistrationManager extends Object
|
||||
|
||||
/**
|
||||
* @param EventRegistration $registration
|
||||
* @throws ServerErrorHttpException
|
||||
* @return bool
|
||||
* @throws \yii\base\Exception
|
||||
*/
|
||||
public function deleteRegistration($registration)
|
||||
{
|
||||
if (isset($registration->deleted_at)) {
|
||||
throw new ServerErrorHttpException('The reservation is already deleted');
|
||||
return false;
|
||||
}
|
||||
|
||||
$ticket = Ticket::findOne(['id_ticket' => $registration->id_ticket]);
|
||||
if( !isset($ticket ) ) {
|
||||
throw new \yii\base\Exception('Ticket not found: ' . $registration->id_ticket);
|
||||
}
|
||||
|
||||
$ticket->restoreReservationCount(1);
|
||||
$ticket->save(false);
|
||||
|
||||
$registration->deleted_at = date('Y-m-d H:i:s');
|
||||
$registration->save(false);
|
||||
return $registration->save(false);
|
||||
|
||||
}
|
||||
|
||||
@ -221,12 +225,16 @@ class EventRegistrationManager extends Object
|
||||
|
||||
$registrations = $event->getEventRegistrations()->all();
|
||||
// ////////////////////////////////
|
||||
// if even has no registrations
|
||||
// if event has no registrations
|
||||
// we can simply delete it from db
|
||||
// ////////////////////////////////
|
||||
if ( count($registrations) === 0 ) {
|
||||
$event->delete();
|
||||
} else {
|
||||
// /////////////////////////////
|
||||
// otherwise we mark the event deleted
|
||||
// and we have to delete the registrations
|
||||
// /////////////////////////////
|
||||
$event->deleted_at = date('Y-m-d H:i:s');
|
||||
$event->save(false);
|
||||
foreach ($registrations as $registration) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -457,15 +457,15 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
public function consumeReservationCount($count){
|
||||
$newReservationCount = $this->reservation_count + $count;
|
||||
if ( $newReservationCount > $this->max_reservation_count ){
|
||||
throw new HttpException(406,"Max ticket seat count exceeded",EventRegistrationManager::MAX_SEAT_COUNT_EXCEEDED);
|
||||
throw new HttpException(406, 'Max ticket seat count exceeded',EventRegistrationManager::MAX_SEAT_COUNT_EXCEEDED);
|
||||
}
|
||||
$this->reservation_count = $newReservationCount;
|
||||
}
|
||||
|
||||
public function restoreReservationCount($usagesToRestore){
|
||||
$this->reservation_count = $this->reservation_count - $usagesToRestore;
|
||||
if ( $this->usage_count < 0 ){
|
||||
$this->usage_count = 0;
|
||||
$this->reservation_count -= $usagesToRestore;
|
||||
if ( $this->reservation_count < 0 ){
|
||||
$this->reservation_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ namespace common\modules\event\controllers;
|
||||
use common\manager\EventRegistrationManager;
|
||||
use common\models\CardEventRegistrationForm;
|
||||
use common\modules\event\EventModule;
|
||||
use common\modules\event\models\copy\ClearWeekForm;
|
||||
use common\modules\event\models\copy\CopyWeekSearch;
|
||||
use common\modules\event\models\EventPermissions;
|
||||
use common\modules\event\models\timetable\TimeTableSearch;
|
||||
@ -42,7 +43,7 @@ class EventController extends Controller
|
||||
|
||||
$module = EventModule::getInstance();
|
||||
assert(isset($module), 'event module not set');
|
||||
$allowedActions = ['index', 'view', 'reserve-card', 'cancel-registration', 'delete-registration', 'timetable','copy-week'];
|
||||
$allowedActions = ['index', 'view', 'reserve-card', 'cancel-registration', 'delete-registration', 'timetable', 'copy-week','clear-week'];
|
||||
if ($module->mode === 'backend') {
|
||||
$allowedActions[] = 'create';
|
||||
$allowedActions[] = 'update';
|
||||
@ -259,10 +260,39 @@ class EventController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
public function actionCopyWeek(){
|
||||
/** @noinspection PhpUnused */
|
||||
/**
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionCopyWeek()
|
||||
{
|
||||
$model = new CopyWeekSearch();
|
||||
$model->search(\Yii::$app->request->get());
|
||||
return $this->render('copy_week',['model' => $model]);
|
||||
$model->sourceDateString = date('Y.m.d');
|
||||
$model->targetDateString = date('Y.m.d', strtotime('+1 week'));
|
||||
if (Yii::$app->request->isPost) {
|
||||
$model->search(Yii::$app->request->post());
|
||||
if (count($model->getErrors()) === 0) {
|
||||
$model->save();
|
||||
$this->redirect(['copy-week', $model->formName() . '[sourceDateString]'=> $model->sourceDateString, $model->formName() . '[targetDateString]' =>$model->targetDateString ]);
|
||||
}
|
||||
} else {
|
||||
$model->search(Yii::$app->request->get());
|
||||
}
|
||||
return $this->render('copy_week', ['model' => $model]);
|
||||
|
||||
|
||||
}/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* @return Response
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function actionClearWeek(){
|
||||
|
||||
$clearWeekForm = new ClearWeekForm();
|
||||
$clearWeekForm->clear(Yii::$app->request->get());
|
||||
return $this->redirect(['timetable', []]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -9,9 +9,34 @@ use common\modules\event\models\timetable\TimeTableMonthWeek;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use yii\db\Query;
|
||||
use yii\db\StaleObjectException;
|
||||
|
||||
class EventManager
|
||||
{
|
||||
/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* Delete or mark deleted an event
|
||||
* @param $id
|
||||
* @throws Throwable
|
||||
* @throws \yii\base\Exception on any error
|
||||
* @throws StaleObjectException
|
||||
*/
|
||||
public function deleteEvent($id){
|
||||
$event = Event::findOne($id);
|
||||
if ( !isset($event)){
|
||||
throw new \yii\base\Exception("Event $id not found");
|
||||
}
|
||||
$registrations = $event->eventRegistrations;
|
||||
if ( !isset($registrations) || count($registrations) === 0 ){
|
||||
$event->delete();
|
||||
} else {
|
||||
$event->deleted_at = time();
|
||||
$event->save(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -49,35 +74,22 @@ class EventManager
|
||||
$timeTable->weeks[$weekNumber]->$weekDayName = $timeTableMonthDay;
|
||||
}
|
||||
|
||||
$dateTimeFrom = $interval->firstActiveDate;
|
||||
$dateTimeTo = (clone $interval->lastActiveDate)->modify('+1 day');
|
||||
// get events between active dates
|
||||
$query = Event::find();
|
||||
$query = $query->select(
|
||||
[
|
||||
'{{event}}.*',
|
||||
// 'COUNT({{event_registration}}.id) AS reservationCount'
|
||||
]);
|
||||
|
||||
$events = $query
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrations')
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
|
||||
->andWhere(['event.active' => '1'])
|
||||
->orderBy([
|
||||
'event.start' => SORT_ASC
|
||||
])
|
||||
->all();
|
||||
$events =$this->getEvents($dateTimeFrom,$dateTimeTo);
|
||||
|
||||
// set events per day
|
||||
/** @var Event $event */
|
||||
foreach ($events as $event) {
|
||||
$eventDay = new DateTime();
|
||||
$eventDay->setTimestamp($event->start);
|
||||
$eventDay->setTime(0, 0);
|
||||
|
||||
foreach ($timeTable->days as $date) {
|
||||
$eventDay = new DateTime();
|
||||
$eventDay->setTimestamp($event->start);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$eventDay->setTimezone($date->date->getTimezone());
|
||||
$eventDay->setTime(0, 0);
|
||||
if ($date->date == $eventDay) {
|
||||
$date->events[] = $event;
|
||||
break;
|
||||
@ -87,4 +99,58 @@ class EventManager
|
||||
return $timeTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active events between the to dates
|
||||
* @param DateTime $fromInc from date inclusive (>=)
|
||||
* @param DateTime $toExcl to date exclusive (<)
|
||||
* @return Event[]
|
||||
*/
|
||||
public function getEvents($fromInc, $toExcl)
|
||||
{
|
||||
$query = Event::find();
|
||||
|
||||
$query = $query
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrations')
|
||||
->andWhere(['>=', 'event.start', $fromInc->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', $toExcl->getTimestamp()])
|
||||
->orderBy([
|
||||
'event.start' => SORT_ASC
|
||||
]);
|
||||
$query = $this->withEventConditions($query);
|
||||
return $query
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get conditions to retrieve all valid active events
|
||||
* @param Query $query
|
||||
* @return Query
|
||||
*/
|
||||
public function withEventConditions($query)
|
||||
{
|
||||
$query = $query->andWhere(['event.active' => '1'])
|
||||
->andWhere(['event.deleted_at' => null]);
|
||||
return $query;
|
||||
}/** @noinspection PhpUnused */
|
||||
|
||||
/**
|
||||
* @param DateTime $date
|
||||
* @return Event[]
|
||||
*/
|
||||
public function getEventsForDay($date)
|
||||
{
|
||||
$start = clone $date;
|
||||
$start->setTime(0,0);
|
||||
|
||||
$to = clone $start;
|
||||
$to->modify('+1 day');
|
||||
|
||||
return $this->getEvents($start,$to);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
74
common/modules/event/models/copy/ClearWeekForm.php
Normal file
74
common/modules/event/models/copy/ClearWeekForm.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace common\modules\event\models\copy;
|
||||
|
||||
use common\manager\EventRegistrationManager;
|
||||
use common\modules\event\manager\EventManager;
|
||||
use common\modules\event\models\timetable\TimeTableMonth;
|
||||
use common\modules\event\models\timetable\TimeTableMonthWeek;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use DateTime;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* @property string $sourceDateString
|
||||
* @property string $targetDateString
|
||||
* @property integer $timestampSource
|
||||
* @property integer $timestampTarget
|
||||
* @property EventInterval $sourceInterval
|
||||
* @property EventInterval $targetInterval
|
||||
* @property TimeTableMonth $sourceTimeTable
|
||||
* @property TimeTableMonth $targetTimeTable
|
||||
*/
|
||||
class ClearWeekForm extends Model
|
||||
{
|
||||
|
||||
public /** @noinspection PhpUnused */
|
||||
$targetDateString;
|
||||
public $timestampTarget;
|
||||
|
||||
|
||||
public $targetInterval;
|
||||
public $targetTimeTable;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['targetDateString',], 'date', 'format' => Yii::$app->formatter->dateFormat, 'timestampAttribute' => 'timestampTarget', 'timeZone' => 'UTC'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function clear($params){
|
||||
$this->load($params);
|
||||
$this->validate();
|
||||
|
||||
$targetDate = new DateTime('@'.$this->timestampTarget );
|
||||
$targetDate->modify('this week');
|
||||
|
||||
$this->targetInterval = EventInterval::createInterval($targetDate,7,7);
|
||||
|
||||
// load the time table objects for source and target interval
|
||||
$eventManager = new EventManager();
|
||||
$this->targetTimeTable = $eventManager->loadTimeTable($this->targetInterval);
|
||||
|
||||
/** @var TimeTableMonthWeek $targetWeek */
|
||||
$targetWeek = $this->targetTimeTable->getWeekByIndex(0);
|
||||
|
||||
$events = $targetWeek->getAllEvents();
|
||||
|
||||
$eventRegisterManager = new EventRegistrationManager();
|
||||
foreach ($events as $event){
|
||||
$eventRegisterManager->deleteEvent($event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
132
common/modules/event/models/copy/CopyWeekForm.php
Normal file
132
common/modules/event/models/copy/CopyWeekForm.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace common\modules\event\models\copy;
|
||||
|
||||
use common\models\Event;
|
||||
use common\modules\event\manager\EventManager;
|
||||
use common\modules\event\models\timetable\TimeTableMonth;
|
||||
use common\modules\event\models\timetable\TimeTableMonthDay;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* @property string $sourceDateString
|
||||
* @property string $targetDateString
|
||||
* @property integer $timestampSource
|
||||
* @property integer $timestampTarget
|
||||
* @property EventInterval $sourceInterval
|
||||
* @property EventInterval $targetInterval
|
||||
* @property TimeTableMonth $sourceTimeTable
|
||||
* @property TimeTableMonth $targetTimeTable
|
||||
*/
|
||||
class CopyWeekForm extends Model
|
||||
{
|
||||
|
||||
|
||||
public /** @noinspection PhpUnused */
|
||||
$sourceDateString;
|
||||
public $timestampSource;
|
||||
|
||||
public /** @noinspection PhpUnused */
|
||||
$targetDateString;
|
||||
public $timestampTarget;
|
||||
|
||||
public $sourceInterval;
|
||||
public $targetInterval;
|
||||
|
||||
public $sourceTimeTable;
|
||||
public $targetTimeTable;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['sourceDateString',], 'date', 'format' => Yii::$app->formatter->dateFormat, 'timestampAttribute' => 'timestampSource', 'timeZone' => 'UTC'],
|
||||
[['targetDateString',], 'date', 'format' => Yii::$app->formatter->dateFormat, 'timestampAttribute' => 'timestampTarget', 'timeZone' => 'UTC'],
|
||||
[['targetDateString',], 'validateTargetWeekHasNoEvents'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save(){
|
||||
|
||||
$sourceDate = new DateTime();
|
||||
$sourceDate->setTimestamp($this->timestampSource);
|
||||
$sourceDate->modify('this week');
|
||||
|
||||
$targetDate = new DateTime();
|
||||
$targetDate->setTimestamp($this->timestampTarget);
|
||||
$targetDate->modify('this week');
|
||||
|
||||
$this->sourceInterval = EventInterval::createInterval($sourceDate,7,7);
|
||||
$this->targetInterval = EventInterval::createInterval($targetDate,7,7);
|
||||
|
||||
// load the time table objects for source and target interval
|
||||
$eventManager = new EventManager();
|
||||
$this->sourceTimeTable = $eventManager->loadTimeTable($this->sourceInterval);
|
||||
$this->targetTimeTable = $eventManager->loadTimeTable($this->targetInterval);
|
||||
|
||||
$sourceWeek = $this->sourceTimeTable->weeks[0];
|
||||
$targetWeek = $this->targetTimeTable->weeks[0];
|
||||
|
||||
// Iterate over all the week days: monday, tuesday, ...
|
||||
foreach (EventInterval::weekdays as $weekday ){
|
||||
// this is very ugly
|
||||
// it returns eg.: $sourceWeek->monday , $sourceWeek->tuesday...
|
||||
/** @var TimeTableMonthDay $sourceDay */
|
||||
$sourceDay = $sourceWeek->$weekday;
|
||||
/** @var TimeTableMonthDay $targetDay */
|
||||
$targetDay = $targetWeek->$weekday;
|
||||
|
||||
$sourceEvents = $sourceDay->events;
|
||||
|
||||
/** @var Event $sourceEvent */
|
||||
foreach ($sourceEvents as $sourceEvent ){
|
||||
$event = new Event();
|
||||
$event->start = $sourceEvent->start;
|
||||
$event->id_room = $sourceEvent->id_room;
|
||||
$event->id_event_type = $sourceEvent->id_event_type;
|
||||
$event->id_trainer = $sourceEvent->id_trainer;
|
||||
$event->seat_count = $sourceEvent->seat_count;
|
||||
$event->active = $sourceEvent->active;
|
||||
$event->deleted_at = $sourceEvent->deleted_at;
|
||||
|
||||
$start = $this->createDateTime(new DateTime('@'.$targetDay->date),new DateTime('@'.$event->start));
|
||||
$event->start = $start->getTimestamp();
|
||||
|
||||
// end date is start date + duration
|
||||
$eventDuration = $sourceEvent->end - $sourceEvent->start;
|
||||
$event->end = $start->getTimestamp() + $eventDuration;
|
||||
|
||||
$event->save(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DateTime object from 2 input DateTimes.
|
||||
* The first input will be used to set the date part.
|
||||
* The second input will be used to set the time part.
|
||||
*
|
||||
* @param DateTime $date the date part of the new date will set to the values of this object
|
||||
* @param DateTime $time the time part of the new date will set to the values of this object
|
||||
* @return DateTime
|
||||
* @throws Exception
|
||||
*/
|
||||
private function createDateTime($date,$time){
|
||||
$result = new DateTime();
|
||||
$result->setDate($date->format('Y'),$date->format('m'),$date->format('d'));
|
||||
$result->setTime($time->format('H'),$time->format('i'));
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@ -2,16 +2,15 @@
|
||||
|
||||
namespace common\modules\event\models\copy;
|
||||
|
||||
use common\components\DateUtil;
|
||||
use common\modules\event\manager\EventManager;
|
||||
use common\modules\event\models\timetable\TimeTableMonth;
|
||||
use common\modules\event\models\timetable\TimeTableMonthDay;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use common\models\Event;
|
||||
use yii\base\Model;
|
||||
use yii\data\ArrayDataProvider;
|
||||
|
||||
/**
|
||||
* @property string $sourceDateString
|
||||
@ -39,7 +38,6 @@ class CopyWeekSearch extends Model
|
||||
public $sourceTimeTable;
|
||||
public $targetTimeTable;
|
||||
|
||||
public $tableHeaders;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -47,6 +45,7 @@ class CopyWeekSearch extends Model
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['sourceDateString','targetDateString'], 'required'],
|
||||
[['sourceDateString',], 'date', 'format' => Yii::$app->formatter->dateFormat, 'timestampAttribute' => 'timestampSource', 'timeZone' => 'UTC'],
|
||||
[['targetDateString',], 'date', 'format' => Yii::$app->formatter->dateFormat, 'timestampAttribute' => 'timestampTarget', 'timeZone' => 'UTC'],
|
||||
];
|
||||
@ -60,12 +59,9 @@ class CopyWeekSearch extends Model
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function search($params)
|
||||
@ -89,4 +85,84 @@ class CopyWeekSearch extends Model
|
||||
$this->sourceTimeTable = $eventManager->loadTimeTable($this->sourceInterval);
|
||||
$this->targetTimeTable = $eventManager->loadTimeTable($this->targetInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save(){
|
||||
|
||||
$sourceDate = new DateTime();
|
||||
$sourceDate->setTimestamp($this->timestampSource);
|
||||
$sourceDate->modify('this week');
|
||||
|
||||
$targetDate = new DateTime();
|
||||
$targetDate->setTimestamp($this->timestampTarget);
|
||||
$targetDate->modify('this week');
|
||||
|
||||
$this->sourceInterval = EventInterval::createInterval($sourceDate,7,7);
|
||||
$this->targetInterval = EventInterval::createInterval($targetDate,7,7);
|
||||
|
||||
// load the time table objects for source and target interval
|
||||
$eventManager = new EventManager();
|
||||
$this->sourceTimeTable = $eventManager->loadTimeTable($this->sourceInterval);
|
||||
$this->targetTimeTable = $eventManager->loadTimeTable($this->targetInterval);
|
||||
|
||||
$sourceWeek = array_values( $this->sourceTimeTable->weeks)[0];
|
||||
$targetWeek = array_values($this->targetTimeTable->weeks)[0];
|
||||
|
||||
// Iterate over all the week days: monday, tuesday, ...
|
||||
foreach (EventInterval::weekdays as $weekday ){
|
||||
// this is very ugly
|
||||
// it returns eg.: $sourceWeek->monday , $sourceWeek->tuesday...
|
||||
/** @var TimeTableMonthDay $sourceDay */
|
||||
$sourceDay = $sourceWeek->$weekday;
|
||||
/** @var TimeTableMonthDay $targetDay */
|
||||
$targetDay = $targetWeek->$weekday;
|
||||
|
||||
$sourceEvents = $sourceDay->events;
|
||||
|
||||
/** @var Event $sourceEvent */
|
||||
foreach ($sourceEvents as $sourceEvent ){
|
||||
$event = new Event();
|
||||
$event->start = $sourceEvent->start;
|
||||
$event->id_room = $sourceEvent->id_room;
|
||||
$event->id_event_type = $sourceEvent->id_event_type;
|
||||
$event->id_trainer = $sourceEvent->id_trainer;
|
||||
$event->seat_count = $sourceEvent->seat_count;
|
||||
$event->active = $sourceEvent->active;
|
||||
$event->deleted_at = $sourceEvent->deleted_at;
|
||||
|
||||
$start = $this->createDateTime( clone $targetDay->date , new DateTime( '@'. $event->start ) );
|
||||
$event->start = $start->getTimestamp();
|
||||
|
||||
// end date is start date + duration
|
||||
$eventDuration = $sourceEvent->end - $sourceEvent->start;
|
||||
$event->end = $start->getTimestamp() + $eventDuration;
|
||||
|
||||
$event->save(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a DateTime object from 2 input DateTimes.
|
||||
* The first input will be used to set the date part.
|
||||
* The second input will be used to set the time part.
|
||||
*
|
||||
* @param DateTime $date the date part of the new date will set to the values of this object
|
||||
* @param DateTime $time the time part of the new date will set to the values of this object
|
||||
* @return DateTime
|
||||
* @throws Exception
|
||||
*/
|
||||
private function createDateTime($date,$time){
|
||||
$result = new DateTime();
|
||||
$result->setDate($date->format('Y'),$date->format('m'),$date->format('d'));
|
||||
$result->setTimezone($time->getTimezone());
|
||||
$result->setTime($time->format('H'),$time->format('i'));
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,4 +29,16 @@ class TimeTableMonth
|
||||
]);
|
||||
}
|
||||
|
||||
public function getAllEvents(){
|
||||
$events = [];
|
||||
foreach ($this->days as $day){
|
||||
$events = array_merge($events,$day->events);
|
||||
}
|
||||
return $events;
|
||||
}
|
||||
|
||||
public function getWeekByIndex($index) {
|
||||
return array_values($this->weeks)[$index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ use customerapi\models\available\EventInterval;
|
||||
class TimeTableMonthWeek
|
||||
{
|
||||
|
||||
|
||||
public $monday;
|
||||
public $tuesday;
|
||||
public $wednesday;
|
||||
@ -47,4 +46,43 @@ class TimeTableMonthWeek
|
||||
return $this->$objectAttribute;
|
||||
}
|
||||
|
||||
public function getAllDays(){
|
||||
$result = [];
|
||||
foreach (EventInterval::weekdays as $weekday ){
|
||||
$result[] = $this->$weekday;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getWeekStart()
|
||||
{
|
||||
$firstDayOfWeek = clone $this->monday->date ;
|
||||
$firstDayOfWeek->modify('this week');
|
||||
$firstDayOfWeek->setTime(0,0);
|
||||
return $firstDayOfWeek;
|
||||
}
|
||||
|
||||
public function getWeekNumber(){
|
||||
return $this->getWeekStart()->format('W');
|
||||
}
|
||||
|
||||
public function getWeekYear(){
|
||||
return $this->getWeekStart()->format('Y');
|
||||
}
|
||||
|
||||
public function getWeekString(){
|
||||
return $this->getWeekYear() . " - " . $this->getWeekNumber();
|
||||
}
|
||||
|
||||
public function getAllEvents(){
|
||||
$events = [];
|
||||
foreach ($this->getAllDays() as $day){
|
||||
$events = array_merge($events,$day->events);
|
||||
}
|
||||
return $events;
|
||||
}
|
||||
}
|
||||
|
||||
33
common/modules/event/views/event/_copy_week_form.php
Normal file
33
common/modules/event/views/event/_copy_week_form.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php /** @noinspection PhpUnhandledExceptionInspection */
|
||||
|
||||
use common\modules\event\models\copy\CopyWeekSearch;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $model CopyWeekSearch */
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Másolás</div>
|
||||
<div class="panel-body">
|
||||
|
||||
<?php $form = ActiveForm::begin(['options' =>['class' => 'form-inline' ]]); ?>
|
||||
<?= $form->field($model, 'sourceDateString')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'targetDateString')->hiddenInput()->label(false) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="inpSourceEvent">Forrás hét: </label>
|
||||
|
||||
<input type="text" id="inpSourceEvent" disabled class="form-control" value="<?=$model->sourceTimeTable->getWeekByIndex(0)->getWeekString()?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inpTargetEvent">Cél hét:</label>
|
||||
<input type="text" id="inpTargetEvent" disabled class="form-control" value="<?=$model->targetTimeTable->getWeekByIndex(0)->getWeekString()?>">
|
||||
</div>
|
||||
<?= Html::submitButton( 'Másol', ['class' => 'btn btn-success' ]) ?>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
||||
@ -27,7 +27,8 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'sourceDateString')->widget(DatePicker::class, [
|
||||
'pluginOptions' => [
|
||||
'autoclose' => true,
|
||||
'format' => 'yyyy.mm.dd'
|
||||
'format' => 'yyyy.mm.dd',
|
||||
'calendarWeeks'=> true
|
||||
],
|
||||
'options' => [
|
||||
'autocomplete' => 'off'
|
||||
@ -38,7 +39,8 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'targetDateString')->widget(DatePicker::class, [
|
||||
'pluginOptions' => [
|
||||
'autoclose' => true,
|
||||
'format' => 'yyyy.mm.dd'
|
||||
'format' => 'yyyy.mm.dd',
|
||||
'calendarWeeks'=> true
|
||||
],
|
||||
'options' => [
|
||||
'autocomplete' => 'off'
|
||||
|
||||
@ -24,7 +24,8 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'startDateString')->widget(DatePicker::class, [
|
||||
'pluginOptions' => [
|
||||
'autoclose' => true,
|
||||
'format' => 'yyyy.mm.dd'
|
||||
'format' => 'yyyy.mm.dd',
|
||||
'calendarWeeks'=> true
|
||||
],
|
||||
'options' => [
|
||||
'autocomplete' => 'off'
|
||||
|
||||
@ -12,7 +12,10 @@ use common\modules\event\widgets\timetable\TimeTableMonthView;
|
||||
<?php
|
||||
|
||||
echo $this->render('_copy_week_search', ['model' => $model]);
|
||||
echo $this->render('_copy_week_form', ['model' => $model]);
|
||||
?>
|
||||
|
||||
|
||||
<h2>Forrás hét</h2>
|
||||
<?= TimeTableMonthView::widget(['timeTable' => $model->sourceTimeTable]) ?>
|
||||
<h2>Cél hét</h2>
|
||||
|
||||
@ -7,13 +7,13 @@ use common\modules\event\models\timetable\TimeTableSearch;
|
||||
/* @var $model TimeTableSearch */
|
||||
/* @var $tableModel TimeTableModel */
|
||||
|
||||
|
||||
$tableModel = $model->tableModel;
|
||||
$timeTable = $model->tableModel->timeTableMonth;
|
||||
|
||||
|
||||
use common\modules\event\models\timetable\TimeTableModel;
|
||||
use common\modules\event\widgets\timetable\TimeTableMonthView;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
|
||||
?>
|
||||
<h1>Órarend</h1>
|
||||
@ -23,5 +23,36 @@ use common\modules\event\widgets\timetable\TimeTableMonthView;
|
||||
-
|
||||
<?= $timeTable->interval->firstActiveDate->format('m') ?>
|
||||
</h2>
|
||||
<?= TimeTableMonthView::widget(['timeTable' => $timeTable]) ?>
|
||||
<?= TimeTableMonthView::widget([
|
||||
'timeTable' => $timeTable,
|
||||
'actionsColumn' => ['class' => \yii\grid\ActionColumn::class,
|
||||
'template' =>'{delete}',
|
||||
'buttons' => [
|
||||
'delete' => static function ($url) { return Html::a( '<span class="glyphicon glyphicon-trash"> </span>', $url,
|
||||
[
|
||||
'title' => 'Események törlése',
|
||||
'data-confirm' => Yii::t('yii', 'Biztosan törölni szeretné a heti eseményeket?'),
|
||||
'data-method' => 'post',
|
||||
]
|
||||
); }
|
||||
],
|
||||
|
||||
'urlCreator' => /**
|
||||
* @param $action
|
||||
* @param common\modules\event\models\timetable\TimeTableMonthWeek $model
|
||||
* @param $key
|
||||
* @param $index
|
||||
* @return string|null
|
||||
*/ static function($action, $model, $key, $index){
|
||||
if ( $action === 'delete' ){
|
||||
|
||||
/** @var DateTime $start */
|
||||
$start = $model->getWeekStart();
|
||||
|
||||
return Url::toRoute( [ 'event/clear-week' , 'ClearWeekForm[targetDateString]' => $start->format('Y.m.d') ] );
|
||||
}
|
||||
return null;
|
||||
},
|
||||
]
|
||||
]) ?>
|
||||
|
||||
|
||||
@ -14,10 +14,14 @@ use yii\bootstrap\Widget;
|
||||
class TimeTableMonthView extends Widget
|
||||
{
|
||||
public $timeTable;
|
||||
public $actionsColumn;
|
||||
|
||||
|
||||
public function run() {
|
||||
return $this->render('_timetable', [ 'timeTable' => $this->timeTable]);
|
||||
return $this->render('_timetable', [
|
||||
'timeTable' => $this->timeTable,
|
||||
'actionsColumn' => ( isset($this->actionsColumn) ? $this->actionsColumn : null)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +32,9 @@ class TimeTableMonthView extends Widget
|
||||
* @return string
|
||||
*/
|
||||
return static function ($week) use ($weekDay) {
|
||||
return TimeTableMonthDayView::widget(['day' => $week->getWeekDay($weekDay)]);
|
||||
return TimeTableMonthDayView::widget([
|
||||
'day' => $week->getWeekDay($weekDay),
|
||||
]);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -11,64 +11,67 @@ use common\modules\event\widgets\timetable\TimeTableMonthView;
|
||||
use yii\grid\ActionColumn;
|
||||
use yii\grid\GridView;
|
||||
|
||||
|
||||
$columns = [
|
||||
[
|
||||
'attribute' => 'weekNumber',
|
||||
'label' => '',
|
||||
'value' => static function ($model,$key){
|
||||
return $model->weekNumber;
|
||||
}
|
||||
],
|
||||
[
|
||||
'attribute' => 'monday',
|
||||
'label' => 'Hétfő',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('monday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'tuesday',
|
||||
'label' => 'Kedd',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('tuesday')
|
||||
],
|
||||
|
||||
[
|
||||
'attribute' => 'wednesday',
|
||||
'label' => 'Szerda',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('wednesday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'thursday',
|
||||
'label' => 'Csütörtök',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('thursday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'friday',
|
||||
'label' => 'Péntek',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('friday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'saturday',
|
||||
'format' => 'raw',
|
||||
'label' => 'Szombat',
|
||||
'value' => TimeTableMonthView::renderDay('saturday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'Sunday',
|
||||
'label' => 'Vasárnap',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('sunday')
|
||||
],
|
||||
];
|
||||
|
||||
if ( isset($actionsColumn)){
|
||||
$columns[] = $actionsColumn;
|
||||
}
|
||||
|
||||
?>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $timeTable->getWeeksArrayDataProvider(),
|
||||
'layout' => '{items}',
|
||||
'columns' => [
|
||||
[
|
||||
'attribute' => 'weekNumber',
|
||||
'label' => '',
|
||||
'value' => static function ($model,$key){
|
||||
return $model->weekNumber;
|
||||
}
|
||||
],
|
||||
[
|
||||
'attribute' => 'monday',
|
||||
'label' => 'Hétfő',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('monday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'tuesday',
|
||||
'label' => 'Kedd',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('tuesday')
|
||||
],
|
||||
|
||||
[
|
||||
'attribute' => 'wednesday',
|
||||
'label' => 'Szerda',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('wednesday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'thursday',
|
||||
'label' => 'Csütörtök',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('thursday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'friday',
|
||||
'label' => 'Péntek',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('friday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'saturday',
|
||||
'format' => 'raw',
|
||||
'label' => 'Szombat',
|
||||
'value' => TimeTableMonthView::renderDay('saturday')
|
||||
],
|
||||
[
|
||||
'attribute' => 'Sunday',
|
||||
'label' => 'Vasárnap',
|
||||
'format' => 'raw',
|
||||
'value' => TimeTableMonthView::renderDay('sunday')
|
||||
],
|
||||
[
|
||||
'class' => ActionColumn::class,
|
||||
'template' => '{view} {update}',
|
||||
],
|
||||
],
|
||||
'columns' => $columns,
|
||||
]) ?>
|
||||
|
||||
@ -34,7 +34,8 @@
|
||||
"iisns/yii2-assets-compress": "*",
|
||||
"yiisoft/yii2-composer": "2.0.4",
|
||||
"sizeg/yii2-jwt": "^2.0",
|
||||
"fxp/composer-asset-plugin": "dev-master"
|
||||
"fxp/composer-asset-plugin": "dev-master",
|
||||
"ext-http": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-codeception": "*",
|
||||
|
||||
@ -5,18 +5,30 @@ namespace customerapi\models\available;
|
||||
|
||||
|
||||
use DateTime;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class DateIntervalHelper
|
||||
* @package customerapi\models\available
|
||||
* @property \DateTime $firstActiveDate
|
||||
* @property \DateTime $lastActiveDate
|
||||
* @property \DateTime $firstDisplayDate
|
||||
* @property \DateTime $lastDisplayDate
|
||||
* @property DateTime $firstActiveDate
|
||||
* @property DateTime $lastActiveDate
|
||||
* @property DateTime $firstDisplayDate
|
||||
* @property DateTime $lastDisplayDate
|
||||
*/
|
||||
class EventInterval
|
||||
{
|
||||
|
||||
const monday = 'monday';
|
||||
const tuesday = 'tuesday';
|
||||
const wednesday = 'wednesday';
|
||||
const thursday = 'thursday';
|
||||
const friday = 'friday';
|
||||
const saturday = 'saturday';
|
||||
const sunday = 'sunday';
|
||||
|
||||
const weekdays = [EventInterval::monday, EventInterval::tuesday, EventInterval::wednesday, EventInterval::thursday, EventInterval::friday, EventInterval::saturday, EventInterval::sunday];
|
||||
|
||||
|
||||
public $year;
|
||||
public $month;
|
||||
|
||||
@ -29,13 +41,20 @@ class EventInterval
|
||||
public $firstDisplayDate;
|
||||
public $lastDisplayDate;
|
||||
|
||||
private function __construct($today = null, $countOfActiveDays = 14,$daysToDisplay = 21)
|
||||
/**
|
||||
* EventInterval constructor.
|
||||
* @param DateTime $today
|
||||
* @param int $countOfActiveDays count of active days from today
|
||||
* @param int $daysToDisplay the count of visible days from the first weekday of week, which is calculated by today
|
||||
* @throws Exception on any error
|
||||
*/
|
||||
private function __construct($today = null, $countOfActiveDays = 14, $daysToDisplay = 21)
|
||||
{
|
||||
|
||||
$this->countOfActiveDays = $countOfActiveDays;
|
||||
$this->daysToDisplay = $daysToDisplay;
|
||||
|
||||
if ( !isset($today)){
|
||||
if (!isset($today)) {
|
||||
$today = new DateTime();
|
||||
}
|
||||
$today->setTime(0, 0);
|
||||
@ -61,13 +80,20 @@ class EventInterval
|
||||
|
||||
}
|
||||
|
||||
public static function createInterval($today = null,$countOfActiveDays = 14,$daysToDisplay = 21)
|
||||
/**
|
||||
* @param null $today
|
||||
* @param int $countOfActiveDays
|
||||
* @param int $daysToDisplay
|
||||
* @return EventInterval
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createInterval($today = null, $countOfActiveDays = 14, $daysToDisplay = 21)
|
||||
{
|
||||
return new EventInterval($today,$countOfActiveDays,$daysToDisplay);
|
||||
return new EventInterval($today, $countOfActiveDays, $daysToDisplay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $day
|
||||
* @param DateTime $day
|
||||
* @return bool true if active, otherwise false
|
||||
*/
|
||||
public function isActive($day)
|
||||
@ -75,7 +101,7 @@ class EventInterval
|
||||
$afterFirstActiveDay = $this->firstActiveDate < $day || $this->firstActiveDate == $day;
|
||||
$beforeLastActiveDay = $this->lastActiveDate > $day || $this->lastActiveDate == $day;
|
||||
|
||||
return ($afterFirstActiveDay && $beforeLastActiveDay);
|
||||
return ($afterFirstActiveDay && $beforeLastActiveDay);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,5 +119,4 @@ class EventInterval
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user