Source of file ScheduleRangeDay.php
Size: 2,053 Bytes - Last Modified: 2020-10-12T11:05:02+00:00
/var/www/docs.ssmods.com/process/src/src/Model/ScheduleRange/ScheduleRangeDay.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php namespace Sunnysideup\Schedulizer\Model\ScheduleRange; use DateInterval; use SilverStripe\Forms\CheckboxSetField; use Sunnysideup\Schedulizer\Model\ScheduleRange; /** * A date range class that can hold: * - specific date range (e.g 01/01/2015 to 29/01/2015 * - specific day range (e.g Mon to Friday) * - specific day type range (e.g Weekday or Weekend) * * @author Stephen McMahon <stephen@symbiote.com.au> */ class ScheduleRangeDay extends ScheduleRange { private static $table_name = 'ScheduleRangeDay'; public const WEEK_DAYS = [ 'Mon' => 'Monday', 'Tue' => 'Tuesday', 'Wed' => 'Wednesday', 'Thu' => 'Thursday', 'Fri' => 'Friday', 'Sat' => 'Saturday', 'Sun' => 'Sunday', ]; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab( 'Root.Main', CheckboxSetField::create( 'ApplicableDays', 'Schedule Days', self::WEEK_DAYS ) ); return $fields; } /** * Determines the next valid time and date for this schedule to execute * * @return DateTime|null */ public function getNextDateTime() : ?DateTime { $nextRunDateTime = $this->getScheduleDateTime(); if ($nextRunDateTime) { $i = 0; //In case getDays is corrupt exit after 7 tries. while (! in_array($nextRunDateTime->format('d'), $this->getDays(), true) && $i < 7) { $nextRunDateTime->add(new DateInterval('P1D')); //Reset the start time list($h, $m, $s) = explode(':', $this->StartTime); $nextRunDateTime->setTime($h, $m, $s); $i++; } } return $nextRunDateTime; } /** * Uses the ApplicableDays list to create a weeks worth of valid start/end dates */ protected function getDays() { return explode(',', $this->ApplicableDays); } } |