thuijzer

Fieldtype Business Hours

Recommended Posts

https://github.com/thuijzer/processwire-FieldtypeBusinessHours

Fieldtype Business Hours

ProcessWire Fieldtype for entering business hours (opening hours)

 

Input format

Leave a day empty when closed on that day

Times are in 24 hour format.

9:00-12:00
9:00-12:00, 13:00-17:30
16:00-2:00

 

Usage in templates

Days are from 1 to 7 where 1 is Monday and 7 is Sunday (ISO-8601)

echo $page->field_name->isNowOpen() ? 'Now open' : 'Now closed';
if($page->field_name[1] == null) { echo 'Closed on Monday'; }
if($page->field_name[2]->inRange('11:00')) { echo 'Tuesday at 11:00 open'; }
echo $page->field_name[1];
echo $page->field_name[1]->getEntries()->getFrom()->format('H:i');

 

  • Like 14
  • Thanks 2

Share this post


Link to post
Share on other sites

Thanks for the module! I will have to give it a try this week. In the past I have just use the Pro Fields: Textarea module to create "fields" for each day, which was quite convenient. However, this looks promising and quite straight forward. 

 

** Just in case, I added a screenshot of the layout using dummy times.

Screen Shot 2018-01-18 at 2.48.24 PM.png

  • Like 1

Share this post


Link to post
Share on other sites

hi thuijzer,

would you mind adding a screenshot to get an instant first impression of how it looks like?

  • Like 5

Share this post


Link to post
Share on other sites

@louisstephens Thank you for the screenshot! Note that a 24 hour input is used. So on Saturday you will be open from 3:00-6:00AM and 10:30-12:00AM.

Share this post


Link to post
Share on other sites

Hello thuijzer, I always get this error message after calling

echo $page->field_name[1]->entries[0]->getFrom()->format('H:i');

in template:

Cannot access private property ProcessWire\BusinessHoursDay::$entries

Best regards

Share this post


Link to post
Share on other sites
On 19-1-2018 at 8:57 PM, Juergen said:

Hello thuijzer, I always get this error message after calling


echo $page->field_name[1]->entries[0]->getFrom()->format('H:i');

in template:

Cannot access private property ProcessWire\BusinessHoursDay::$entries

Best regards

My bad. The documentation is wrong.

I like to use immutable objects so I created a getter function for the enries: getEntries()

The readme is now updated.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Hello @thuijzer,

I dont know if others agree with me, but I would find it useful if an extra input field for public holidays will be added after Sunday. Fe in the gastronomy there is often the scenario that the business is open on public holidays. Here in Austria most of the time restaurants are closed on Monday, but if it falls on a public holiday they are open. So an extra field will take care of this. If the field will be left blank business is closed on a public holiday.

Best regards

  • Like 1

Share this post


Link to post
Share on other sites
17 minutes ago, Juergen said:

Hello @thuijzer,

I dont know if others agree with me, but I would find it useful if an extra input field for public holidays will be added after Sunday. Fe in the gastronomy there is often the scenario that the business is open on public holidays. Here in Austria most of the time restaurants are closed on Monday, but if it falls on a public holiday they are open. So an extra field will take care of this. If the field will be left blank business is closed on a public holiday.

Best regards

That sounds like a great idea. I will think about a way to enter dates that override opening hours.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, Juergen said:

Most of the time I use this library for business hours. You can take a look at it: https://github.com/spatie/opening-hours

This will take care of exceptions (like public holidays)

 

 

I've never seen that library. That is looking very good. Maybe I will just use this library and create a fieldtype that creates the right settings for this lib. Looks like the license makes this possible.

Edit: looks like it needs PHP 7. I think a lot of ProcessWire users are still on 5.6 or even lower, so maybe that's not an option.
But I can always take a look at the source ;)

Share this post


Link to post
Share on other sites
4 minutes ago, thuijzer said:

Looks like the license makes this possible.

Yeah. MIT license is pretty permissive.

Share this post


Link to post
Share on other sites

Here is another library that I use to get public holidays for each country, but dont make it too complicated.

https://github.com/azuyalabs/yasumi

Its only a possibility to get holidays of each country without entering them inside an textarea input.

The big problem of holidays is that they can change from year to year (fe. Eastern)

So my thought is to include only an additional input field for the opening times on a public holiday (like the other days of the week).

Everyone can include the libraries I have mentioned if there is a need (like I have done with your input field). The new inputfield can be used to output the opening times for holidays like the other days of the week. Include a hint that holiday times will be not included in your output functions  like this

On 18.1.2018 at 2:46 PM, thuijzer said:

echo $page->field_name->isNowOpen() ? 'Now open' : 'Now closed';

Keep it as simple as possible.:)

Here is a screenshot of how I did it. The values of the opening times come from your field. If it is open today or not, comes from the Spatie library, so it will be no problem for developers to include it .

In addition a hint will be shown, when the business is open the next time (comes also from Spatie library)

Screenshot(2).thumb.png.81f3b067d8801e1ce72b707ea2c6e83f.png

In my case I only use your input field for entering the business hours. Everything on the frontend side (output) comes from the Spatie library.

Share this post


Link to post
Share on other sites

Just to clearify:

I think the first aim of this inputfield should be a clean UI for entering business hours in an easy way (and in this case you made a great job).:)

The next step is to provide the API calls to get the opening times for each day (like you have also done).:) So every opening time of each day can be indivdually outputted, formatted, styled or used for further PHP operations.

Offering some nice additional API-calls for getting some additional information (whether it is open or not) is great, but can be achived with other libraries or PHP coding too and should only be an addon (not really necessary).;)

So an additional input field for opening times on natural holidays is enough. We can use the value to make further operations (fe to check if this day is a nat. holiday or not by using fe. the Yasumi library) -> thats up to us as site developers and should not be an issue you have to deal with. Not everyone needs this feature.

Best regards

 

  • Like 2

Share this post


Link to post
Share on other sites

On PW 3.0.92 on my production server with Maria DB 10.2.12 I get the following error when trying to save a page with the fieldtype, even though all the fields have been filled out.

 Error saving field "businessHours" - SQLSTATE[HY000]: General error: 1364 Field 'data' doesn't have a default value

On my WAMP setup with mySQL 5.7.14 it does work.

I managed to create a workaround by manually editing the table design in phpMyAdmin and setting a default value for the data field to 0.

 

Share this post


Link to post
Share on other sites
1 hour ago, Kiwi Chris said:

On PW 3.0.92 on my production server with Maria DB 10.2.12 I get the following error when trying to save a page with the fieldtype, even though all the fields have been filled out.

 Error saving field "businessHours" - SQLSTATE[HY000]: General error: 1364 Field 'data' doesn't have a default value

Just wondering. All Fieldtypes need to have a column 'data' in their database table. This is defined in their getDatabaseSchema(). If you look at this method in the parent field type class, wire/core/Fieldtype.php, it has this comment each Fieldtype should override this in particular (with respect to the data column). I notice that this module does not define data in its schema but I would have thought that shouldn't be a problem since it first calls  the parent's parent::getDatabaseSchema() (which has data defined) and builds on that.

Just thinking out loud.

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.

  • Similar Content

    • By Robin S
      Checkbox Reversed
      Modifies InputfieldCheckbox so that it shows the reverse of its true value. The checkbox will be unchecked when the field value is 1 and checked when the field value is not 1.
      Background
      The core FieldtypeCheckbox does not have a setting that allows a checkbox to be checked by default. One reason for this is that only a checked field saves a value to the database. An unchecked field does not save "0" to the database, but rather does not save any value for the field at all. Therefore there is no way to distinguish between a new field that has not yet been saved (and therefore could potentially get a default checked state) and a field that has deliberately been saved as unchecked.
      Because of this you sometimes have to use a checkbox in the opposite way than you would like. Suppose your client has requested a checkbox labelled "Bootylicious" that will be checked by default. This isn't possible with FieldtypeCheckbox so instead you have to convince them that a checkbox labelled "Not bootylicious" that is unchecked by default is just as good. This alternative will achieve the same thing, but it's not ideal.
      A solution
      This module doesn't change the limitations of the core checkbox field, but it provides a workaround that allows you to show the checkbox with the desired default state and label. So in the example above you would still name the field "not_bootylicious" (otherwise it could get confusing in your template files) but you can label the field "Bootylicious" and the checkbox will appear checked when its true value is actually unchecked, and vice versa. This allows new pages to show the checkbox checked by default. Clear as mud?
      Usage
      Install the Checkbox Reversed module.
      For any Checkbox field where you want the inputfield to show the reverse of its true value, activate the "Reverse the checked state of this inputfield?" option in the field settings.

       
      https://github.com/Toutouwai/CheckboxReversed
      http://modules.processwire.com/modules/checkbox-reversed/
    • By louisstephens
      I have been following @bernhard's great tutorial on creating a Dashboard and everything has very easy to understand so far. However, I need to add a select field that a template is using (so users can create a new page from the dashboard), but I am really at a complete lost on how to achieve this. I have been googling, but can't really find anything on the matter.
      $field = $this->modules->get('InputfieldSelect'); $field->name = "Select Manufacturer"; $field->findPagesSelector = "template=basic-page"; //not needed for select field $field->labelFieldName = "title"; $field->name = "Manufacturer Select"; $field->columnWidth = 34; $fieldset->add($field); I have the above code, which was originally an InputfieldPage, but since this is an options field, I have changed it. Has anyone actually gotten a select from a template (and its' values) in a module?
    • By Lex Sanchez
      Video or Social Post Embed
      Based on the TextformatterVideoEmbed module developed by Ryan Cramer, we have added the possibility to embed publications of the main social networks Facebook, Twitter and Instagram.
      ProcessWire Textformatter module that enables translation of YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu URLs to full embed codes, resulting in a viewable video or social post in textarea fields you apply it to.
      How to install
      Download or Clone from Github: https://github.com/lexsanchez/VideoOrSocialPostEmbed
      Copy the VideoOrSocialPostEmbed.module file to your /site/modules/ directory (or place it in /site/modules/VideoOrSocialPostEmbed/).
      Click check for new modules in ProcessWire Admin Modules screen. Click install for the module labeled: "Video or Social Post Embed".
      Now you will be on the module config screen. Please make note of the config options and set as you see fit.
      How to use
      Edit your body field in Setup > Fields (or whatever field(s) you will be placing videos in). On the details tab, find the Text Formatters field and select "Video or Social Post Embed". Save.
      Edit a page using the field you edited and paste in YouTube, Vimeo, Facebook, Twitter, Instagram and/or Issuu URLs each on their own paragraph.
      Example
      How it might look in your editor (like TinyMCE):
      How it works
      This module uses YouTube, Vimeo, Instagram, Facebook, Twitter and Issuu oEmbed services to generate the embed codes populated in your content. After these services are queried the first time, the embed code is cached so that it doesn't need to be pulled again.
      Configuration
      You may want to update the max width and max height settings on the module's configuration screen. You should make these consistent with what is supported by your site design.
      If you change these max width / max height settings you may also want to check the box to clear cache, so that YouTube/Vimeo/Facebook/Twitter/Instagram/Issuu oembed services will generate new embed codes for you.
      Using with Markdown, Textile or other LML
      This text formatter is looking for a YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu video URL surrounded by paragraph tags. As a result, if you are using Markdown or Textile (or something else like it) you want that text formatter to run before this one. That ensures that the expected paragraph tags will be present when VideoOrSocialPostEmbed runs. You can control the order that text formatters are run in by drag/drop sorting in the field editor.
      Copyright 2018 by Ryan Cramer / Updated by Lex Sanchez
    • By kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt