thuijzer Posted January 18, 2018 Share Posted January 18, 2018 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'); 14 2 Link to comment Share on other sites More sharing options...
louisstephens Posted January 18, 2018 Share Posted January 18, 2018 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. 1 Link to comment Share on other sites More sharing options...
bernhard Posted January 18, 2018 Share Posted January 18, 2018 hi thuijzer, would you mind adding a screenshot to get an instant first impression of how it looks like? 5 Link to comment Share on other sites More sharing options...
thuijzer Posted January 19, 2018 Author Share Posted January 19, 2018 @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. Link to comment Share on other sites More sharing options...
Juergen Posted January 19, 2018 Share Posted January 19, 2018 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 Link to comment Share on other sites More sharing options...
thuijzer Posted January 19, 2018 Author Share Posted January 19, 2018 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. 1 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 28, 2018 Share Posted January 28, 2018 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 1 Link to comment Share on other sites More sharing options...
thuijzer Posted January 28, 2018 Author Share Posted January 28, 2018 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. 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 29, 2018 Share Posted January 29, 2018 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) Link to comment Share on other sites More sharing options...
thuijzer Posted January 29, 2018 Author Share Posted January 29, 2018 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 Link to comment Share on other sites More sharing options...
kongondo Posted January 29, 2018 Share Posted January 29, 2018 4 minutes ago, thuijzer said: Looks like the license makes this possible. Yeah. MIT license is pretty permissive. Link to comment Share on other sites More sharing options...
Juergen Posted January 29, 2018 Share Posted January 29, 2018 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) 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. Link to comment Share on other sites More sharing options...
Juergen Posted January 29, 2018 Share Posted January 29, 2018 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 2 Link to comment Share on other sites More sharing options...
Kiwi Chris Posted February 22, 2018 Share Posted February 22, 2018 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. 1 Link to comment Share on other sites More sharing options...
kongondo Posted February 23, 2018 Share Posted February 23, 2018 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. Link to comment Share on other sites More sharing options...
guenter55 Posted July 2, 2018 Share Posted July 2, 2018 Hi, I have PHP 5.4.45 and PW 3.0.106 and get this error: Fehler: Class 'DateTimeImmutable' not found (Zeile 51 in /home/wwwapow/public_html/cms/site/modules/_FieldtypeBusinessHours/FieldtypeBusinessHours.module) How can I solve this error? Thanks for help! Link to comment Share on other sites More sharing options...
netcarver Posted July 2, 2018 Share Posted July 2, 2018 You need to upgrade your PHP installation - that class was only added in version 5.5.0 (ref: PHP page for the class) Link to comment Share on other sites More sharing options...
guenter55 Posted July 2, 2018 Share Posted July 2, 2018 1 minute ago, netcarver said: You need to upgrade your PHP installation - that class was only added in version 5.5.0 (ref: PHP page for the class) Thanks for your quick reply! Is there no way to rewrite the code for earlier PHP version? Link to comment Share on other sites More sharing options...
adrian Posted July 2, 2018 Share Posted July 2, 2018 5 minutes ago, guenter55 said: Thanks for your quick reply! Is there no way to rewrite the code for earlier PHP version? This might do the trick: https://gist.github.com/Grummfy/6d4f07a86121a1477cdc 1 Link to comment Share on other sites More sharing options...
netcarver Posted July 2, 2018 Share Posted July 2, 2018 @guenter55 I've no idea, about rewriting to remove this, I'm not familiar with the code. However, if on a linux system (or mac) it's probably much easier to upgrade the installed version of PHP than it is to rewrite the code to remove its use of that class. You are also well behind the curve in terms of supported (and potentially more secure) versions of PHP. Edited to add: Or wait until @adrian finds a shim ? @thuijzer sounds like you need to add a 'requires' =>'php>=5.5.0' line to your module config. 1 Link to comment Share on other sites More sharing options...
guenter55 Posted July 2, 2018 Share Posted July 2, 2018 11 minutes ago, adrian said: This might do the trick: https://gist.github.com/Grummfy/6d4f07a86121a1477cdc @adrian Where should I implement this class? I tried it in FieldtypeBusinessHours.module without effect. Link to comment Share on other sites More sharing options...
adrian Posted July 2, 2018 Share Posted July 2, 2018 4 minutes ago, guenter55 said: @adrian Where should I implement this class? I tried it in FieldtypeBusinessHours.module without effect. I would think that including it in the __construct() method would work. Make sure the path is correct and it is actually being included. Note that I haven't ever used this. Link to comment Share on other sites More sharing options...
guenter55 Posted July 2, 2018 Share Posted July 2, 2018 12 minutes ago, adrian said: I would think that including it in the __construct() method would work. Make sure the path is correct and it is actually being included. Thanks for the help @adrian but that seems to exceed my php knowledge. I see the __construct() functions in the modul-files, but I don´t know what exactly to do. Link to comment Share on other sites More sharing options...
adrian Posted July 2, 2018 Share Posted July 2, 2018 I would try this line: include_once(__DIR__ . '/DateTimeImmutable_php5.4.php'); before: include_once(__DIR__ . '/BusinessHours.php'); making sure that you have saved the contents of that new class into the BusinessHours module folder. Link to comment Share on other sites More sharing options...
guenter55 Posted July 2, 2018 Share Posted July 2, 2018 7 minutes ago, adrian said: I would try this line: include_once(__DIR__ . '/DateTimeImmutable_php5.4.php'); You are Great adrian!! No more error in admin, I´ll try it in template tomorrow - it´s time to catch some hours sleep ? Greetings from Austria! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now