I am trying to say that I use the Date module to keep appointments for a doctor.
When he selects a date, and start and end hours, is there a way, so if he already has entered an appointment for that time, to be informed that he cannot add a new date for that period??

Comments

I have not used any of these and have no idea if/how they work, but you could investigate:

http://drupal.org/project/resource_conflict
http://drupal.org/project/availability_calendars
http://drupal.org/project/bookingsapi/
http://drupal.org/project/publicbookings
http://drupal.org/project/eventbookings

Since there are other modules that are trying to provide this kind of functionality, it's probably a low priority to add it directly to Date. But I'll leave this open as a feature request because this comes up all the time and perhaps there would be a reason to revisit this.

Thank you, but nothing of them seems to be the solution I'm searching...
:(

None of these seem like they would work along with the Calendar module. Instead they seem to be alternatives to it. Am I missing something?

I thought it might not be too difficult to have an alert message displayed when an event overlaps an existing one since there is logic in place to handle a different display in that case. I apologize if I'm ignorant of the complexity.

I would like to add my voice to being able to avoid a conflict in a calendar because I had started to develop an item booking calendar with the Calendar + Date modules and then discovered that there seems to be no way to avoid two users booking the same item at the same time.
Can we reject the SAVE if there is an existing conflict?

Since someone has emailed me about how to avoid a conflict I would like to share my solution. I ended up writing a module ( my first one )
The function below works on a node type called "booking"
and uses form_set_error if the booking node being saved is bad
a) Because the length of the booking is > some limit
b) The length of time specified is less than some limit ( fixed at 30 minutes )
c) There is a booking conflict with one that already exists.
There is another type called "bookable_item" which has the max limit it. As I write this I suppose I could have another field for the minimum.

If any one sees a bug in my function or sees some way to be more efficient or better code I would appreciate the comments.

Bill

<?php
function bszk_node_validate($node, $form, &$form_state) {
  if (!isset(
$uid)) {
   
$uid = $GLOBALS['user']->uid;
  }
 
$nid = $node->nid;
  if(
"booking" == $node->type ) {
   
$bnid="";
    if (isset(  
$node->field_item['und'][0]['nid'] )) { // fetch the node bookable item being booked
     
$bnid = $node->field_item['und'][0]['nid'];
     
$bnode = node_load($bnid);
     
$t=$bnode->field_max_booktime_hours;
     
$maxhours=$t['und'][0]['value'];
     
$maxsecs=$maxhours*60*60;
    }
   
$stat = $node->status;
   
$query = new EntityFieldQuery();
   
$query->entityCondition('entity_type', 'node')
      ->
entityCondition('bundle', 'booking')
      ->
propertyCondition('status', 1)
      ->
fieldCondition('field_item', 'nid', $bnid, '=')
      ->
addMetaData('account', user_load(1)); // Run the query as user 1.
   
$result = $query->execute();
   
$nbookings=0;
   
$items=array();
    if (isset(
$result['node'])) {
     
$nids = array_keys($result['node']);
     
$items = entity_load('node', $nids);
    }
   
$timenow = new DateTime("now");
   
$no = $timenow->format("Y-m-d H:i:s");
   
$tz = new DateTimeZone('America/Toronto');
   
$offset = $tz->getOffset($timenow);
   
$v=$node;
   
$t=$v->field_booking_time;
   
$st = $t['und'][0]['value']; // start time
   
$stt = strtotime($st) + $offset;
   
$newstts = date("Y-m-d H:i:s", $stt);
   
$et = $t['und'][0]['value2']; // end time
   
$ett = strtotime($et) + $offset;
   
$newetts = date("Y-m-d H:i:s", $ett);
   
$blength=$ett-$stt;
    if (
$blength < 1800 ) { // 1800 secs = 30 minutes
     
form_set_error('time', t('You must book for at least half an hour'));
      exit;
    }
    if(
$maxsecs>0 and ($blength > $maxsecs) ) {
     
form_set_error('time', t('You may not book this item for more than ' . $maxhours . ' hours'));
      exit;
    }
   
$bad=false;
   
// Here I am comparing the booking being created
    // to all of the ones in the database
    // looking for a conflict
   
foreach ($items as $v) {
      if(
$nid != $v->nid) {
   
$t=$v->field_booking_time;
   
$st = $t['und'][0]['value'];
   
$stt = strtotime($st) + $offset;
   
$stts = date("Y-m-d H:i:s", $stt);
   
$et = $t['und'][0]['value2'];
   
$ett = strtotime($et) + $offset;
   
$etts = date("Y-m-d H:i:s", $ett);
    if((
$newstts $stts) and $newstts $etts ){ $bad=true; $r="1";}
    if((
$newetts $etts) and $newetts $stts ){ $bad=true; $r="2";}
    if((
$newstts $stts) and $newetts $etts ){ $bad=true; $r="3";}
      }
    }
    if (
$bad ) {
     
form_set_error('time', t('Booking conflict'));
    }
  }
}
?>