Jump to content
Juergen

Inputfield/Fieldtype OpeningHours

Recommended Posts

Hello @ all !

Today I want to share another new inputfield with the community!

It is called Fieldtype OpeningHours and it is designed to enter one or multiple times per day (especially for company opening times). I know that there is another great fieldtype in the repository (https://modules.processwire.com/modules/fieldtype-business-hours/), but I wanted to create my own with a different UI than the other one.

Here is a screencast of what it looks like in action:

A lot of things going on behind the scenes and I dont want to write it all down here, because you can find the whole information on my Github account (there you can also download this inputfield)

Download-link: https://github.com/juergenweb/FieldtypeOpeningHours

If you may find any bugs, have any ideas to improve this fieldtype please report it in my Github repository.

Greetings from Austria and have a nice day!

 

CHANGELOG:

21.7.20 Add new option to show (true) or hide (false) days with no opening hours on various methods (please be aware that setting options has been changed - it is recommended to deinstall old version and install this inputfield again) . Take a look at the READ.ME for further instructions.

1.1 Add multilang support for timeformat and add 2 additional Schema.org markup methods

 

 

  • Like 16

Share this post


Link to post
Share on other sites

He's on fire 😎💪😉

On 7/15/2020 at 6:02 PM, Juergen said:

If you may find any bugs, have any ideas to improve this fieldtype please report it in my Github repository.

Really not a big thing, but how would one remove this item? 🙂 

z6oDT0k.png

Business hours can be a pain... Have you thought about using a library? eg https://github.com/spatie/opening-hours

Maybe you have an idea for a good UI regarding exceptions (like holidays etc)?

Very nice UI btw! 🙂 

  • Thanks 1

Share this post


Link to post
Share on other sites

Hi @bernhard

Thanks for your feedback!

12 hours ago, bernhard said:

Really not a big thing, but how would one remove this item?

I will check this and and try to find a solution. 🙂

12 hours ago, bernhard said:

Have you thought about using a library? eg https://github.com/spatie/opening-hours

I have worked with this library in the past and it's really cool, but for the moment I have not planned to include a third party lib. The main purpose of this inputfield is to make entering of opening times simple for the user.

12 hours ago, bernhard said:

Maybe you have an idea for a good UI regarding exceptions (like holidays etc)?

Not really! Holidays are always hassle because they differ from country to country. For the moment you can enter only general opening times for all holidays. Exceptions can be really difficult and I guess there you will need to use Spatie to handle this.

Share this post


Link to post
Share on other sites
2 hours ago, bernhard said:

Really not a big thing, but how would one remove this item? 🙂 

Issue should be resolved and the file was updated on Github 🙂

  • Like 1

Share this post


Link to post
Share on other sites

Hello @ all

I have 2 new methods added which take care of days with same times. It often happens that different days have exactly the same opening times. To prevent writing the same times over and over again, you can combine these days with this 2 new methods.

1) First new method to output a multidim. array

print_r($page->fieldname->combinedDays());

You can use this array to create the markup by yourself.

2) Render method to output an unordered list of same opening times

echo $page->fieldname->renderCombinedDays();

This method outputs a rendered string like this one:

<ul class="uk-list">
  <li>Mo, Fr: 08:00 - 16:00</li>
  <li>Tu, Th: 08:00 - 16:00, 18:00 - 20:00</li>
  <li>We: 16:00 - 23:05</li>
  <li>Sa, Su, Ho: closed</li>
</ul>

As you can see days with same times are combined now. Changes are added to Github now, so please download the files again if you want the latest version.🙂

Best regards

  • Like 3

Share this post


Link to post
Share on other sites

New feature added:

I have updated the inputfield to support multilanguage timeformats on the frontend. You can set the timeformat of each language in the configuration of the inputfield in the backend (see screencast below). Supports strftime() and date() formats.

Version was bumped from 1.0 to 1.1 on Github.

Best regards Jürgen

  • Like 1

Share this post


Link to post
Share on other sites

2 new methods for Schema.org markup added:

print_r($page->fieldname->getjsonLDTimes());

returns an array like this:

Array ( [0] => Mo,Tu,We 08:00-12:00 [1] => Mo,Th 13:00-18:00 [2] => Th 08:00-11:00 )

Can be used to create the markup by yourself or

echo $page->fieldname->renderjsonLDTimes();

returns a string like this:

"Mo,Tu,We 08:00-12:00", "Mo,Th 13:00-18:00", "Th 08:00-11:00" 

You can use the second method in schema.org Local Business opening hours as followed:

.....
"openingHours": [
    "Mo,Th,Sa 11:00-14:30",
    "Mo,Th 17:00-21:30",
    "Fr,Sa 17:00-22:00"
  ],
.....

Best regards

  • Like 1

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...