Page 1 of 1

Calendar plugin - how to do reservation

Posted: 2021-01-29 08:02
by Jevgeni
Hi all.

Calendar plugin is really very nice.
But i dont know, how i can to do reservation time.
For default i can to do many same periods, but i want restrict reservation time, if same time in same day was reserved some time ago.
It is possible?

Re: Calendar plugin - how to do reservation

Posted: 2021-01-31 08:41
by onoehring
Hi,

I do have the plugin, but I have not used it yet.
As the calendar is simply a way of displaying data, I would think you probably need to make the checks you want in advance.
You can check in the /hooks/tablename.php -> _before_update (and before_insert) function if that condition is met and if it is return FALSE from the function. The update/insert will not take place. You can take a look on my custom error messages (in my footer) which would allow you to inform the user why saving was canceled

The code you could use looks probably like this (pseudo code!) in _before_update and before_insert:

Code: Select all

$myReturnValue = TRUE;
$sql = "select count(primarykey) as c from calendartable WHERE yourDATEField=`" . $data['yourDate'] . "` and yourTimeField = `" . $data['yourTime'] .  "`;" ;
$result = sqlValue($sql);
if ($result > 0){
    $myReturnValue = FALSE;
}
return $myReturnValue;
Or, not so elegant, set a constraint UNIQUE on both fields date and time in your database.

Olaf

Re: Calendar plugin - how to do reservation

Posted: 2021-01-31 10:22
by Jevgeni
I thou
onoehring wrote:
2021-01-31 08:41
Hi,

I do have the plugin, but I have not used it yet.
As the calendar is simply a way of displaying data, I would think you probably need to make the checks you want in advance.
You can check in the /hooks/tablename.php -> _before_update (and before_insert) function if that condition is met and if it is return FALSE from the function. The update/insert will not take place. You can take a look on my custom error messages (in my footer) which would allow you to inform the user why saving was canceled

The code you could use looks probably like this (pseudo code!) in _before_update and before_insert:

Code: Select all

$myReturnValue = TRUE;
$sql = "select count(primarykey) as c from calendartable WHERE yourDATEField=`" . $data['yourDate'] . "` and yourTimeField = `" . $data['yourTime'] . "`;" ;
$result = sqlValue($sql);
if ($result > 0){
 $myReturnValue = FALSE;
}
return $myReturnValue;
Or, not so elegant, set a constraint UNIQUE on both fields date and time in your database.

Olaf
I thought about it, but thats soultions have problems.
Example:

1-st people put in calendar event 15.02.2021 from 10.00 - 11.00
2-nd people put in calendar event 15.02.2021 from 10.30 - 11.15
Thats events time not unique, but time from 10.30 - 11.00 is same :(...
Code for this solutions should be harder. My PHP skills is not so good.

Re: Calendar plugin - how to do reservation

Posted: 2021-02-01 09:14
by onoehring
Hi,

I am not trying to give you ready-to-implement-code but an idea how to do it.
A:
1-st people put in calendar event 15.02.2021 from 10.00 - 11.00
B:
2-nd people put in calendar event 15.02.2021 from 10.30 - 11.15
Code should test:
There is an overlap in time (which you want to prevent) if:

Code: Select all

(starttimeB > starttimeA AND starttimeB < endtimeA)
OR 
(endtimeB > starttimeA AND endtimeB < endttimeA) 
OR
(starttimeB > starttimeA AND endtimeB < endtimeA) 
OR
(starttimeA > starttimeB AND endtimeA < endtimeB) 
 
I am not sure, if these are all possibilities ... make yourself a drawing - this helps.

Olaf