In the calendar view bookings can be viewed. When booking is possible a link 'book now' is shown. On unavailable dates or booked slots 'already booked' is shown. So far so good, but when making a new booking, time can be changed and the node is added, also when there is already a booking at the same time. Is it possible to validate if the timeslot is available before the node is saved ?

Comments

kenorb’s picture

Yes, it's possible.
I think it should be done soon in hook_validate()

aeeckhau’s picture

Thanks, I am looking forward to it.
I tried it myself and used hook_nodeapi() in my custom module. Here is the code which is only valid for my particular case:

case 'validate':
  if ($node->type=='afspraaktb'){
    $result = db_query("select field_tijdstip_tb_value from {content_type_afspraaktb} where field_tijdstip_tb_value like '".substr($node->field_tijdstip_tb[0]['value'],0,13)."%' and field_tb_value='".$node->field_tb[0]['value']."'");
    if ($resultaat = db_fetch_object($result)) {
      form_set_error('afspraaktb_node_form','Er is al een afspraak gepland op dit moment met de '.$node->field_tb[0]['value']);
    }
  }
  break;
kenorb’s picture

Thank you for suggestion.
It's already done partially so after testing probably it will be available next week.

aeeckhau’s picture

Great, you are really fast !

kenorb’s picture

Status: Active » Needs review

Commited.
http://drupal.org/cvs?commit=234586

Please test it.

peakk’s picture

I just tested it and when submitting a booking, system tells: "Sorry, this slot is unavailable". This happens everytime, even if the dates are available (valid).

I tried it many times (used update.php and cleared cache) and it didn't work.

I'm using D 6.12.

btw. previous version worked well :)

peakk’s picture

Just downloaded and tested latest dev (2009-Jul-14).

Now it accepts every single date (like there wouldn't be any kind of validation). So it doesn't work for me :/

kenorb’s picture

Status: Needs review » Needs work

new working version should be available probably tomorrow

kenorb’s picture

Status: Needs work » Needs review

Try the latest version:
http://drupal.org/cvs?commit=237256

kenorb’s picture

validation and access improvements:
http://drupal.org/cvs?commit=237320

peakk’s picture

I'm sorry. It still doesn't work.

For example: if someone has booked a timeslot "09:00 - 10:00" - some other user can unfortunately book "08:00 - 11:00". And I have only one available slot / hour.

I tested lots of different ways of booking, but I couldn't see a single sign about validation.

(Now I've began to suspect, that have I completely missunderstood the validation functionality)

kenorb’s picture

#11
UPDATE:
Probably I know what you mean.
Unfortunately if you have configuration set to 1h length, you can't book a party for 3h: 08:00 - 11:00
It's not supported right now.
If it's set to 1h, it checking conflicts with all events as they have 1h.

You should not give to users 'edit timeslot settings' permission, because they can mess with times, and to checking conflicts is a lot complicated, because you don't know if you want to check the length of slots from your configuration or the real length of the event. So basically it's not designed to change the hour times when you already selected the right slot, so tt's another feature request.

kenorb’s picture

What has been done:
- added support for customized timing
Read more: http://drupal.org/node/498600#comment-1800424
- added conflict validation of events calculated by fixed length of events which is set in configuration.
user with 'edit timeslot settings' permission should not change manually the length of the event (they can change the date - it's automatically updated via javascript, but not the hour)
It could be done by checking the real length of event, but it will be not done soon.
- fixed issue in #6, so conflicts are not overlapped with current edit event
- detection of gaps where user can't book a slot if there is no enough time space to do it, those slots are automatically 'Not available'

peakk’s picture

#12
That is exactly what I meant.

I was asking help for a function which didn't even exist.

I made some changes and now users can book only 1 (1 hour) slot at a time and it works very well. It's not very user friendly (booking lengths differ in reality) but I can live with that :)
(maybe the future brings us an advanced feature ;)

I'm sorry that I wasted your time with this and thank you very much sir for your support.

kenorb’s picture

#14 peakk
Not a problem at all.
You haven't wasted any time, I'm happy to improve functionality of this module, but everything takes time and it difficult from technical perspective to make something new without breaking existing functionality. So each requested feature have to be very clear.
I understand that in some cases even could have different lengths, but module was designed that slots length are fixed.
Here is similar feature request: #465830: Support for different timeslot lengths for content types

But I've created new feature request special for this purpose:
#519890: Check for conflicts when user choose the length of the event manually by Date To
So it'll be separate issue to finish.
I'll try to make it soon.

aeeckhau:
Can you review changes in #13?

kenorb’s picture

Component: Code » booking_timeslots
Status: Needs review » Fixed

Supposing it worked.
Feel free to re-open if the problem still persist.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.