Inventory_Presser_Shortcode_Hours_Today::create_sentence( array $days )

create_sentence


Description Description

Examines the array of $days and generates the sentence, the core feature of this shortcode.


Top ↑

Parameters Parameters

$days

(array) (Required) An array of Inventory_Presser_Business_Day objects


Top ↑

Return Return

(string) A string like "Open today until 5:00pm" or "Closed until 9:00am on Monday"


Top ↑

Source Source

File: includes/class-shortcode-hours-today.php

	function create_sentence( $days )
	{
		if( null == $days || 0 == sizeof( $days ) ) { return ''; }

		//find today
		$today = null;
		$today_weekday = date('w', current_time( 'timestamp' )); //0 if today is Sunday
		foreach( $days as $day )
		{
			if ( $today_weekday == $day->weekday )
			{
				$today = $day;
				break;
			}
		}

		//are we open right now?
		if( null != $today && $today->open_right_now() )
		{
			//currently open
			return __( 'Open today until ', 'inventory-presser' ) . $today->close_string();
		}
		elseif( null != $today && $today->open_later_today() )
		{
			//not yet open today
			$open_string = $today->open_string();
			if( '' == $open_string ) { return ''; }
			return __( 'Opening at ', 'inventory-presser' ) . $open_string . __( ' today', 'inventory-presser' );
		}

		//find the next day we are open
		$next_open_day = self::find_next_open_day( $days );
		if( null == $next_open_day )
		{
			return '';
		}

		//closed today, tell them about the next time we are open
		$str = __( 'Closed until ', 'inventory-presser' ) . $next_open_day->open_string();

		//If $next_open_day is tomorrow, output "tomorrow" instead of "on Tuesday"
		if( $next_open_day->is_tomorrow() )
		{
			$str .= __( ' tomorrow', 'inventory-presser' );
		}
		else
		{
			$str .= __( ' on ', 'inventory-presser' ) . jddayofweek( $next_open_day->weekday-1, 1 );
		}
		return $str;
	}