1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Business Hours Open / Closed.

Discussion in 'Community' started by sunnyjey, Nov 5, 2019 at 4:38 PM.

  1. sunnyjey

    sunnyjey Active Member

    Level: Community
    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.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Well, first issue is your use of in_array() is wrong, it takes two arguments - the 'needle' (the thing you are searching for) and the 'haystack' (the array you are searching in):

    https://www.php.net/manual/en/function.in-array.php

    And without knowing how you assign any of those variables, it's hard to give you any more advice.

    -- hugh
     
  3. sunnyjey

    sunnyjey Active Member

    Level: Community
    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 (Text):
        $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.
     

Share This Page