Jump to content

Simple bookings calendar system?


alan
 Share

Recommended Posts

Has anyone any experience making a dynamic calendar:

  • person visits site and can see a calendar with some days marked as taken and others as free
  • person clicks a day and is allowed to fill a form to book the whole day
  • next person visiting sees that previously free day is now booked and so can't book that one
I am actually using the Form Builder to collect bookings but that only gets the data in to PW for me, what I don't know how to do is:

  • have recorded entries show as booked days in a calendar
  • have logic to stop people booking already booked days

Any comments most appreciated, cheers!


 


PS: there is a thread for this in the Form Builder forum, but as it looks like what I want to do is not specific to Forms and more to do with generic PW code/use, I am posting here.

Link to comment
Share on other sites

How are you saving each booking?  Does each booking have it's own page in PW?  If each booking has a date field (that defines the day that is booked), I would think it's rather straightforward.

When you display the calendar, you'd just want to grab all the bookings that fall within that month.  You'd loop through each of the days in that calendar month and if a booking exists for that day, you wouldn't provide a link to the booking form.

Of course, I am making assumptions here about the entire process.

  • Like 1
Link to comment
Share on other sites

Thanks Hani, I am SO rusty on PW that even that simple but very helpful suggestion has made me want to go and start writing some code (shame I am off doing chores instead shortly :()

I am saving each booking as a page (or will be) via the Forms Module which allows for pages to be created (never used it before and so I've no direct knowledge of this yet but I saw the option, so I will go experiment).

Thanks again!

Link to comment
Share on other sites

No problem!  Happy to help.  :)

I know excactly how you feel - the more you work with ProcessWire, the more enjoyable it gets.

Yup - so when you save the booking as a page, the booking date can be used as a selector.  So would be a quick example: (untested, written in browser)

$m = date('n'); 
$bookings = $pages->find('template=booking, booking_date>=mktime(1,1,1,$m,0,date('Y')), booking_date<=mktime(1,1,1,$m,0,date('Y'))');
 

You'd probably want to be a little more specific with the selector (defining the parent page).  Gotta rush out the door...

  • Like 1
Link to comment
Share on other sites

I know excactly how you feel - the more you work with ProcessWire, the more enjoyable it gets.

Exactly!

Thanks SO much for the sample code, browser-written or fully tested, always helpful for a PHP weakling ;) Cheers!

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

I would like some suggestion for the same but with hourly or user selected slot which can be 30mins or 45mins or 1hour, etc. What would be the best way to store those info? If I store as pages as each appointment (which can be 1hour, 30mins, etc) then for one day of bookings could be more than 6 entries and that would end up over 150 entries of pages in a month (if I use as 25days with 6 entries per day calculation).

Please let me know your thoughts/input. Thank you!

Link to comment
Share on other sites

fmgujju I am using form entries to store booked days (whole booked days).

I created a field in the form for the booking date and then the calendar when displaying month N looks for calendar entries for any days in month N and those it finds it shows as taken.

I think the same approach could be used for time slots. The trouble is that, as you say, there are a lot more going on when it's time slots. But although I've not needed to try to solve that need yet, so far I think I would step-repeat this approach and use the submitted form entries as the means of storing booked slots.

Good luck with your project :)

Link to comment
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
 Share

×
×
  • Create New...