fitness-web/common/modules/event/models/timetable/TimeTableMonthWeek.php

89 lines
2.1 KiB
PHP

<?php /** @noinspection ALL */
namespace common\modules\event\models\timetable;
use customerapi\models\available\EventInterval;
/** @noinspection PhpUnused */
/**
* Class TimeTableMonthWeek
* @property EventInterval $interval
* @property TimeTableMonthDay $monday
* @property TimeTableMonthDay $tuesday
* @property TimeTableMonthDay $wednesday
* @property TimeTableMonthDay $thursday
* @property TimeTableMonthDay $friday
* @property TimeTableMonthDay $saturday
* @property TimeTableMonthDay $sunday
* @property integer $weekNumber
*/
class TimeTableMonthWeek
{
public $monday;
public $tuesday;
public $wednesday;
public $thursday;
public $friday;
public $saturday;
public $sunday;
public $weekNumber;
/**Get the week day bay property name
* @param $weekDay
* @return mixed
*/
public function getWeekDay($weekDay)
{
$days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
$days = array_combine($days, $days);
$objectAttribute = $days[$weekDay];
/** @var TimeTableMonthDay $day */
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;
}
}