Jump to content
n00bster

howto - show business_hours indicator elsewhere (open, closed)

Recommended Posts

with Alejandro's help and a patched "custom_fields.php" file you can display the "open or closed" indicator from the business hours where ever you want (at this time only on the detail views).

 

sample screenshot: post-20291-0-98434700-1468436947_thumb.png

 

setup:

1) upload the attached "business_hours_indicator" file in the "fields_phpformat" folder in your overrides.

https://docs.jreviews.com/?title=FormBuilder_Custom_Field#Using_a_theme_file

 

edit the line 16 in this file, you have to link to your field with your "business_hours".

 

2) include the "business_hours_indicator.thtml" in one of your detail views of your choice and have fun ;)

 

3) include this code on your position of your choice in your "detail view" override file.

<?php /* LISTING Business Hours INDICATOR */ ?>
<?php echo $this->renderControllerView('fields_phpformat','business_hours_indicator');?>

When someone finds a solution to display the indicators also on listing views, that would be great B)

business_hours_indicators.thtml

Edited by n00bster

Share this post


Link to post

Thank you for your reply.

 

I tried to follow your tips, but it displays the text of the business_hours_indicator.thtml file, instead of the "open or closed" indicator.

 

Probably I did something wrong ? ;)

post-22434-0-37828400-1470555553_thumb.jpg

Share this post


Link to post

It seems to me like your  business_hours_indicator.thtml  file may be corrupted. Open it to see if it has a php opening tag right at the beginning. You should also be aware that the file was written for the Schema that doesn't have the timezone improvement and won't work with new one.

Share this post


Link to post

The file doesn't exist, so it's not an override per se, but a customization provided by another client and may not work as is. Joomla overrides would go in /templates/jreviews_overrides/views/themes/yourcustomtheme/fields_phpformat

Share this post


Link to post

 

 

3) include this code on your position of your choice in your "detail view" override file.

<?php /* LISTING Business Hours INDICATOR */ ?>
<?php echo $this->renderControllerView('fields_phpformat','business_hours_indicator');?>
Which file is exactly meant and in which path is it located?
 
thank you
Bodo

Share this post


Link to post

 

 

 

3) include this code on your position of your choice in your "detail view" override file.

<?php /* LISTING Business Hours INDICATOR */ ?>
<?php echo $this->renderControllerView('fields_phpformat','business_hours_indicator');?>
Which file is exactly meant and in which path is it located?
 

 

This is the path to the "detail view" page theme file:

/com_jreviews/jreviews/views/themes/default/listings/detail.thtml

 

If you are new to JReviews theme customizations, read the articles on this page:

https://docs.jreviews.com/?title=JReviews:Theme_Customization

Share this post


Link to post

My Solution to Show OpeningHours Status in Litspages.

 

1. include the Code above "EDIT HTML BELOW THIS LINE"

$daysArray = array(1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu', 5 => 'Fri', 6 => 'Sat', 7 => 'Sun');

$hoursArray = array(
   "0.0" => "12:00 am", "0.5" => "12:30 am", "1.0" => "1:00 am", "1.5" => "1:30 am", "2.0" => "2:00 am", "2.5" => "2:30 am",
   "3.0" => "3:00 am", "3.5" => "3:30 am", "4.0" => "4:00 am", "4.5" => "4:30 am", "5.0" => "5:00 am", "5.5" => "5:30 am",
   "6.0" => "6:00 am", "6.5" => "6:30 am", "7.0" => "7:00 am", "7.5" => "7:30 am", "8.0" => "8:00 am", "8.5" => "8:30 am",
   "9.0" => "9:00 am", "9.5" => "9:30 am", "10.0" => "10:00 am", "10.5" => "10:30 am", "11.0" => "11:00 am", "11.5" => "11:30 am",
   "12.0" => "12:00 pm", "12.5" => "12:30 pm", "13.0" => "1:00 pm", "13.5" => "1:30 pm", "14.0" => "2:00 pm", "14.5" => "2:30 pm",
   "15.0" => "3:00 pm", "15.5" => "3:30 pm", "16.0" => "4:00 pm", "16.5" => "4:30 pm", "17.0" => "5:00 pm", "17.5" => "5:30 pm",
   "18.0" => "6:00 pm", "18.5" => "6:30 pm", "19.0" => "7:00 pm", "19.5" => "7:30 pm", "20.0" => "8:00 pm", "20.5" => "8:30 pm",
   "21.0" => "9:00 pm", "21.5" => "9:30 pm", "22.0" => "10:00 pm", "22.5" => "10:30 pm", "23.0" => "11:00 pm", "23.5" => "11:30 pm"
); 

2. Include this Code above  "SET CONFIG OVERRIDES FOR EACH LISTING" and replace the jr_yourfieldname with the name of your OpeningHours Field.

<?php /* START LISTING Business Hours INDICATOR */ 
 
// $text = json_decode($text, true);
$text = json_decode($CustomFields->fieldValue('jr_yourfieldname', $listing), true);
// prx($text);
// Check if Field is Empty and Set Status to empty
if (empty($text)) {
	$status = 'empty';
	}
	else {
	$status = 'closed';
	}

// Sort the results on day, then start hour
$sort = array();

foreach ($text AS $key => $hour) {
	$sort['day'][$key] = $hour['day'];
	$sort['hours-start'][$key] = $hour['hours-start'];
	}

	array_multisort($sort['day'], SORT_ASC, $sort['hours-start'], SORT_ASC, $text);

	$days = array();

	$timestamp = time();

	$timezone = (new DateTime('NOW'))->getTimezone();
	// $timezone = new DateTimeZone('Europe/London');
	$dateTime = new DateTime('NOW', $timezone);

	$weekDay = $dateTime->format('N');

	$currentTime = $dateTime->format('G') + $dateTime->format('i')/60;

	foreach ($text AS $hour) {
	// If it's already past midnight we revert to the previous day if the opening hours extend past midnight
	$startTime = $hour['hours-start'];
		$endTime = $hour['hours-end'];
		if ($weekDay == $hour['day']+1
		&& $endTime < $startTime
		&& (!($startTime <= $currentTime) && ($currentTime <= $endTime))) {
			$weekDay -= 1;
			}
		}

	foreach ($text AS $period) {
		$days[$period['day']][] = $hoursArray[$period['hours-start']] . ' - ' . $hoursArray[$period['hours-end']];

		if ($period['day'] == $weekDay && $status == 'closed') {
			$startTime = $period['hours-start'];
			$endTime   = $period['hours-end'] == 0 ? 24 : $period['hours-end'];
				if ($endTime < $startTime) {
					$currentTime +=24;
					$endTime += 24;
				}
			// prx($currentTime, $startTime, $endTime);
				if (($startTime <= $currentTime) && ($currentTime <= $endTime)) {
					$status = 'open';
				}
			}
		}
/* END LISTING Business Hours INDICATOR */?>

3. Include this Code at any Position in your template file where you want

<?php /* LISTING Business Hours INDICATOR */ ?>					
<div class="jrBusinessHours">
	<?php foreach ($daysArray AS $key => $dayName):?>

	<?php if ($weekDay == $key):?>
	<span class="jrBusinessHoursStatus jrBusiness-<?php echo $status;?>">
		<?php //Output Status Open/Closed or nothing ?>
		<?php if ($status == 'open'):?>* zurzeit geöffnet<?php elseif ($status == 'empty'):?><?php else:?>* zurzeit geschlossen<?php endif;?>
	</span>
<?php endif;?>

<?php endforeach;?>
</div>

Share this post


Link to post

For the next update will are planning to include a new (optional) theme for the business hours output so it can automatically display the full schedule on the detail page and only the current day schedule and status on other views (list, module, etc). To use it you would edit the field and in the php output theme you would change it from business_hours to business_hours_multiview.

Share this post


Link to post

For the next update will are planning to include a new (optional) theme for the business hours output so it can automatically display the full schedule on the detail page and only the current day schedule and status on other views (list, module, etc). To use it you would edit the field and in the php output theme you would change it from business_hours to business_hours_multiview.

... what a great news :)

btw. how is it going with your recovery Alejandro?

Share this post


Link to post

@n00bster

 

I´ve got it work in Listpages. You can see it live on https://dev.trealop.com/essen-trinken

 

I will cleanup my Code and post the solution later.

cool that you have set up a solution, i checked your site right now but could not see a indicator on the listings view ???

... i will wait for the core implementation from Alejandro. the indicator for the list views was the last bit why i have not setup the business_hours til today. sometimes it is good to wait ;)

Edited by n00bster

Share this post


Link to post

Hi, great work!

 

I've just one question. How did you manage to display the time in the format 13:00 instead of 1pm? 

 

In the field selection I can choose 13:00 and in the form schema it is also configured in the right way (see code)

 

 {
                            "value": "13.0",
                            "title": "13:00"
                        },

But on the frontpage it appears as 1 pm.

 

Are there any ideas?

 

BR 

Werner

 

 

Share this post


Link to post

There's no need to change anything, except the output theme which has a variable to enable the 24h format.

/components/com_jreviews/jreviews/views/themes/default/fields_phpformat/business_hours.thtml

There you would change:

 

$twentyfourHourFormat = false;
to:
$twentyfourHourFormat = true;

And of course you can put this file in overrides.

Share this post


Link to post

Do you have any embedded modules on the page or any other types of customizations? That may affect JReviews' ability to determine if it's a detail page.

it works when use business_hours.thtml ,

only geomaps are active but thats also not showing  correct

post-25782-0-56446000-1501089100_thumb.png

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.