public function evaluateSchedule($prepFile = false)
    {
        if (!$this->scheduleStart && !$this->test) {
            $rate   = max(1, (int) $this->settings['rate']);
            $endDay = 30;
            $this->scheduleModel
                ->reset()
                ->setContactClient($this->contactClient)
                ->setTimezone();

            $openings = $this->scheduleModel->findOpening(0, $endDay, $rate);
            if (!$openings) {
                throw new ContactClientException(
                    'Could not find an open time slot to send in the next '.$endDay.' days',
                    0,
                    null,
                    Stat::TYPE_SCHEDULE,
                    false
                );
            }

            $opening           = reset($openings);
            list($start, $end) = $opening;

            // More stringent schedule check to discern if now is a good time to prepare a file for build/send.
            if ($prepFile) {
                $now       = new \DateTime();
                $prepStart = clone $start;
                $prepEnd   = clone $end;
                $prepStart->modify('-'.self::FILE_PREP_BEFORE_TIME);
                $prepEnd->modify('+'.self::FILE_PREP_AFTER_TIME);
                if ($now < $prepStart || $now > $prepEnd) {
                    throw new ContactClientException(
                        'It is not yet time to prepare the next file for this client.',
                        0,
                        null,
                        Stat::TYPE_SCHEDULE,
                        false
                    );
                }
            }
            $this->scheduleStart = $start;
        }

        return $this->scheduleStart;
    }
public function evaluateSchedule($prepFile = false)
    {
        if (!$this->scheduleStart && !$this->test) {
            $rate   = max(1, (int) $this->settings['rate']);
            $endDay = 30;
            $this->scheduleModel
                ->reset()
                ->setContactClient($this->contactClient)
                ->setTimezone();

            $openings = $this->scheduleModel->findOpening(0, $endDay, $rate);
            if (!$openings) {
                throw new ContactClientException(
                    'Could not find an open time slot to send in the next '.$endDay.' days',
                    0,
                    null,
                    Stat::TYPE_SCHEDULE,
                    false
                );
            }

            $opening           = reset($openings);
            list($start, $end) = $opening;

            // More stringent schedule check to discern if now is a good time to prepare a file for build/send.
            if ($prepFile) {
                $now       = new \DateTime();
                $prepStart = clone $start;
                $prepEnd   = clone $end;
                $prepStart->modify('-'.self::FILE_PREP_BEFORE_TIME);
                $prepEnd->modify('+'.self::FILE_PREP_AFTER_TIME);
                if ($now < $prepStart || $now > $prepEnd) {
                    throw new ContactClientException(
                        'It is not yet time to prepare the next file for this client.',
                        0,
                        null,
                        Stat::TYPE_SCHEDULE,
                        false
                    );
                }
            }
            $this->scheduleStart = $start;
        }

        return $this->scheduleStart;
    }
public function evaluateSchedule ( $ prepFile = false ) { if ( ! $ this -> scheduleStart && ! $ this -> test ) { $ rate = max ( 1 , ( int ) $ this -> settings [ 'rate' ] ) ; $ endDay = 30 ; $ this -> scheduleModel -> reset ( ) -> setContactClient ( $ this -> contactClient ) -> setTimezone ( ) ; $ openings = $ this -> scheduleModel -> findOpening ( 0 , $ endDay , $ rate ) ; if ( ! $ openings ) { throw new ContactClientException ( 'Could not find an open time slot to send in the next ' . $ endDay . ' days' , 0 , null , Stat :: TYPE_SCHEDULE , false ) ; } $ opening = reset ( $ openings ) ; list ( $ start , $ end ) = $ opening ; // More stringent schedule check to discern if now is a good time to prepare a file for build/send. if ( $ prepFile ) { $ now = new \ DateTime ( ) ; $ prepStart = clone $ start ; $ prepEnd = clone $ end ; $ prepStart -> modify ( '-' . self :: FILE_PREP_BEFORE_TIME ) ; $ prepEnd -> modify ( '+' . self :: FILE_PREP_AFTER_TIME ) ; if ( $ now < $ prepStart || $ now > $ prepEnd ) { throw new ContactClientException ( 'It is not yet time to prepare the next file for this client.' , 0 , null , Stat :: TYPE_SCHEDULE , false ) ; } } $ this -> scheduleStart = $ start ; } return $ this -> scheduleStart ; }
Assuming we have a file entity ready to go
Throws an exception if an open slot is not available.

@param bool $prepFile

@return \DateTime|null

@throws ContactClientException
Assuming we have a file entity ready to go Throws an exception if an open slot is not available .