• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

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