-
-
Save pooza/813fc773e109f04f75eebd118c7f7880 to your computer and use it in GitHub Desktop.
Calendar.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Minc3; | |
use \Carrot3 as C; | |
class Calendar extends C\Calendar { | |
const ROW_SIZE = 31; | |
public function getWeeks () { | |
$weeks = C\Tuple::create(); | |
$date = clone $this->getStartDate(); | |
$date['day'] = '-' . ($date->format('N') - 1); | |
$end = clone $this->getEndDate(); | |
$end['day'] = '+' . (7 - $end->format('N')); | |
while ($date->getTimestamp() <= $end->getTimestamp()) { | |
if ($date->format('N') == 1) { | |
$week = C\Tuple::create(); | |
$weeks[] = $week; | |
} | |
if (C\StringUtils::isBlank($values = $this[$date->format('Y-m-d')])) { | |
$values = C\Tuple::create($date->format('Y-m-d')); | |
$values['disabled'] = true; | |
} | |
$week[] = $values; | |
$date['day'] = '+1'; | |
} | |
return $weeks; | |
} | |
public function getMonths (C\Tuple $hours) { | |
$date = clone $this->getStartDate(); | |
$end = clone $this->getEndDate(); | |
$months = C\Tuple::create(); | |
while ($date->getTimestamp() <= $end->getTimestamp()) { | |
$day = $this[$date->format('Y-m-d')]; | |
$times = C\Tuple::create($day['times']); | |
if (!$months[$date->format('Y-m')]) { | |
$months[$date->format('Y-m')] = C\Tuple::create([ | |
'name' => $date->format('n月'), | |
'times' => $hours, | |
'days' => [], | |
]); | |
} | |
$day['times'] = C\Tuple::create(); | |
foreach ($hours as $hour) { | |
$day['times'][$hour] = []; | |
} | |
$day['times']->setParameters($times); | |
$months[$date->format('Y-m')]['days'][$date->format('Y-m-d')] = $day; | |
$date['day'] = '+1'; | |
} | |
return $months; | |
} | |
public function getRows (C\Tuple $hours) { | |
$schedule = C\Tuple::create(); | |
$index = 0; | |
foreach ($this as $day) { | |
if (!($index % self::ROW_SIZE)) { | |
$schedule[] = $row = C\Tuple::create([ | |
'month' => [], | |
'day' => [], | |
'weekday' => [], | |
'details' => [], | |
]); | |
foreach ($hours as $hour) { | |
$row['details'][$hour] = C\Tuple::create(); | |
} | |
} | |
if (!($index % self::ROW_SIZE) || ($day['day'] == 1)) { | |
$row['month'][] = $monthCell = C\Tuple::create(['value' => $day['month']]); | |
} | |
$row['day'][] = $day['day']; | |
$row['weekday'][] = C\Tuple::create([ | |
'value' => $day['weekday_name'], | |
'is_holiday' => $day['holiday'], | |
]); | |
foreach ($hours as $hour) { | |
$row['details'][$hour][$day['date']] = C\Tuple::create([ | |
'status' => 'fullclose', | |
'date' => $day['date'], | |
]); | |
} | |
foreach ($day['times'] as $time) { | |
$row['details'][$time['time']][$day['date']] = $time; | |
} | |
$index ++; | |
$monthCell['colspan'] += 1; | |
} | |
return $schedule; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment