Calendar plugin - how to do reservation

Topics related to AppGini plugins/add-ons go here.
Post Reply
Jevgeni
Posts: 3
Joined: 2017-03-12 09:18

Calendar plugin - how to do reservation

Post by Jevgeni » 2021-01-29 08:02

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?

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Calendar plugin - how to do reservation

Post by onoehring » 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

Jevgeni
Posts: 3
Joined: 2017-03-12 09:18

Re: Calendar plugin - how to do reservation

Post by Jevgeni » 2021-01-31 10:22

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.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Calendar plugin - how to do reservation

Post by onoehring » 2021-02-01 09:14

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

Post Reply