/** * Find a day which is available for booking based on * user requested set of days. * * @access private * @param string $date * @return string | false */ private function _findAvailableDay($date) { $datetime = new DateTime($date); $attempt = 0; // Finds day when customer is available $customer_available_days = $this->_userData->getAvailableDays(); while (!in_array($datetime->format('w') + 1, $customer_available_days)) { $datetime->modify('+1 day'); if (++$attempt >= 7) { return false; } } return $datetime->format('Y-m-d'); }