Business Hours Open / Closed.

sunnyjey

Active Member
I have repeatable table :

day | opening_time | closing_time
1 | 08:00:00 | 18:00:00
2 | 09:00:00 | 15:00:00

I want to echo whether Business in Open or Closed at this moment comparing with $currentTime using PHP in custom detail template. With limited PHP knowledge, I tried for hours but couldn't figure out, may be I need to use foreach for:
$currentTime
in_array($day) | in_array($opening_time) | in_array($closing_time)

Looking for some help. Thank you in advance.
 
Thank you for reply.

Yes. You are right. The in_array approach is incorrect.

I have F! Business listing, Say List A

mytableA_id | mytable_name
12 | Metro Business
22 | Mega Store

I have added repeatable Group which displays Working days like:
Screenshot 2019-11-11 at 9.34.34 PM.png
repeat_table_working_days
id | parent_id | day | starts_time | end_time
1 | 12 | 1 | 08:00:00 | 18:00:00
2 | 12 | 2 | 07:00:00 | 15:00:00
3 | 22 | 1 | 08:00:00 | 15:00:00
4 | 22 | 3 | 06:00:00 | 17:00:00

where day 1 = Monday; day 2 = Tuesday .....

I am not sure there are two approach :
1. To echo directly through custom detail page like:

Code:
    $myDb = FabrikWorker::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
   /// some code not sure what
$myDb->setQuery($myQuery);
$working_day = $myDb->loadList();

if $working_day = $current_day {
echo 'Open now';
}

This could slow down the site as I expect 100+ Primary table with 7 days of repeatable data.

2. Maybe using placeholders

I hope, I made it clear now.

I short, if current_day and current_time Wednesday is 7:00pm, it should show something like*:
open.png
** This is just for graphical representation.
 
I would probably do it with a PHP onLoad plugin, for list and/or form view (using list php_events and/or form php plugins), which updates an "open_now" field on the actual table data with a query as you load the page.

So on a details page, the query would be ...

Code:
$app = JFactory::getApplication();
$parentId = $app->input->getInt('rowid', 0);
if (!empty($parentId)) {
   $db = JFactory::getDbo();
   $query = "UPDATE  repeat_table_working_days SET open_now = CASE WHEN day = DAYOFWEEK(NOW()) AND NOW() BETWEEN start_time AND end_time THEN 1  ELSE 0 WHERE parent_id = $parentId";
   $db->setQuery($query);
   $db->execute();
}

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top