Booked Scheduler Community Support
September 22, 2017, 06:10:23 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Booked is proud to recommend Shift Capsule in the employee shift scheduling space www.ShiftCapsule.com
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Minimum Cancellation Plugin Version 2 (Includes Updates)  (Read 7825 times)
Alecardo
Jr. Member
**

Karma: 0
Posts: 81


« on: August 12, 2013, 07:04:38 PM »

This is a new version of the Minimum Cancellation Plugin I posted earlier. This one will also stop people from updating when they are certain number of days away from their reservation. You also don't need to add anything to the core code to make this work, nor do you need to input the correct attribute Id into this plugin. Inside the preReservation Plugins folder make a folder called MinimumCancellation2. Then save this document into the folder as MinimumCancellation2
Code:
<?php
/**
Copyright 2012 Nick Korbel

This file is part of phpScheduleIt.

phpScheduleIt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

phpScheduleIt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with phpScheduleIt.  If not, see <http://www.gnu.org/licenses/>.
 */

class MinimumCancellation2 extends PreReservationFactory
{
    private 
$factoryToDecorate;
    
    public function 
__construct(PreReservationFactory $factoryToDecorate){
    
    
$this->factoryToDecorate $factoryToDecorate;    
    
//require_once(dirname(__FILE__) . '/MinimumCancellation.config.php');
 
    //Configuration::Instance()->Register(dirname(__FILE__) . '/MinimumCancellation.config.php','MinimumCancellation');
    
}
    public function 
CreatePreAddService(UserSession $userSession)
    {
        return 
$this->factoryToDecorate->CreatePreAddService($userSession);
        
        
    }

    public function 
CreatePreUpdateService(UserSession $userSession)
    {
        
Log::Debug('Hey Alec we are getting to the CreatePreUpdateService');
        
$base $this->factoryToDecorate->CreatePreUpdateService($userSession);
        
         if (
$userSession->IsAdmin) {
         return 
$this->factoryToDecorate->CreatePreUpdateService($userSession);  
        }
        
        return new 
MinimumUpdateStop($base);
    }
        
    
    public function 
CreatePreDeleteService(UserSession $userSession){
        
Log::Debug('Hey Alec we are getting to the CreatePreDeleteSErvice');
        
$base $this->factoryToDecorate->CreatePreDeleteService($userSession);
        
        if (
$userSession->IsAdmin) {
         return 
$this->factoryToDecorate->CreatePreDeleteService($userSession);  
       }
        
        return new 
MinimumCancellationValidation($base);
    }
}
    class 
MinimumCancellationSave implements IReservationValidationService //I want to get rid of this save function
{
/**
 * @var IReservationValidationService
 */
private $serviceToDecorate;
        public 
$minimumCancellationTime;
public function __construct(IReservationValidationService $serviceToDecorate)
{
$this->serviceToDecorate $serviceToDecorate;
}

/**
 * @param ReservationSeries|ExistingReservationSeries $series
 * @return IReservationValidationResult
 */

/**
 * @param ReservationSeries $series
 * @return bool
 */

        public function 
Validate($series)
{
$result $this->serviceToDecorate->Validate($series);

// don't bother validating this rule if others have failed
if (!$result->CanBeSaved())
{
return $result;
}
                
return $this->EvaluateCustomRule($series);
}
        
        private function 
EvaluateCustomRule($series)
{       $customAttributeId 7;
                
$resource $series->Resource();
$minimumCancellationTime $resource->GetAttributeValue2($customAttributeId);
                
$attributeValue $series->AddAttributeValue($minimumCancellationTime);

                return new 
ReservationValidationResult();


}

}
    class 
MinimumCancellationValidation  implements IReservationValidationService
{
/**
 * @var IReservationValidationService
 */
private $serviceToDecorate;

public function __construct(IReservationValidationService $serviceToDecorate)
{
$this->serviceToDecorate $serviceToDecorate;
}

/**
 * @param ReservationSeries|ExistingReservationSeries $series
 * @return IReservationValidationResult
 */
public function Validate($series)
{
$result $this->serviceToDecorate->Validate($series);

// don't bother validating this rule if others have failed
if (!$result->CanBeSaved())
{
return $result;
}

return $this->EvaluateCustomRule($series);
}

/**
 * @param ReservationSeries $series
 * @return bool
 */
public function EvaluateCustomRule($series) {
                
$customAttributeId;
                
$resource $series->Resource();
                
$attributeRepository = new AttributeRepository();
                
//$attributes = $attributeRepository->LoadById($customAttributeId);
                
$attributes $attributeRepository->GetEntityValues(4,$resource->GetId());
                
$attributesByCategory $attributeRepository->GetByCategory(4);
                foreach(
$attributesByCategory as $attributeByCategory){
                    if(
$attributeByCategory->Label() == "Minimum Cancel"){ //Cange Minimum Cancel to whatever you want to call the label
                        
                        
$customAttributeId $attributeByCategory->Id();
                    }
                }
                
                foreach(
$attributes as $attribute){
                 if(
$customAttributeId == $attribute->AttributeId){
                   
$minimumCancellationTime $attribute->Value;   
                 }
                } 

$currentInstance $series->CurrentInstance();
                
$isValid $currentInstance->StartDate()->GreaterThan(Date::Now()->AddDays($minimumCancellationTime));
if ($isValid)
{
return new ReservationValidationResult();
}

return new ReservationValidationResult(false"you must cancel $minimumCancellationTime days before your reservation");
}

}
 class 
MinimumUpdateStop extends MinimumCancellationSave implements IReservationValidationService
{
/**
 * @var IReservationValidationService
 */
private $serviceToDecorate;

public function __construct(IReservationValidationService $serviceToDecorate)
{
$this->serviceToDecorate $serviceToDecorate;
}

/**
 * @param ReservationSeries|ExistingReservationSeries $series
 * @return IReservationValidationResult
 */
public function Validate($series)
{
$result $this->serviceToDecorate->Validate($series);

// don't bother validating this rule if others have failed
if (!$result->CanBeSaved())
{
return $result;
}

return $this->EvaluateCustomRule($series);
}

/**
 * @param ReservationSeries $series
 * @return bool
 */
public function EvaluateCustomRule($series) {
                
$customAttributeId
                
$resource $series->Resource();

                
$reservationRepository = new ReservationRepository();
                
$InterestedInstance $reservationRepository->LoadById($series->SeriesId());
                
$instances $InterestedInstance->Instances();
                foreach(
$instances as $instance){
                if(
$instance)
                    
//This is almost working, but I need to find out a way to take care of it if there are different resources. I thinking this is a good stopping point on this. of the resources. Ugh, this is frustrating. 
                
                
$attributeRepository = new AttributeRepository();
                
$attributes $attributeRepository->GetEntityValues(4,$resource->GetId());
                
$attributesByCategory $attributeRepository->GetByCategory(4);
                foreach(
$attributesByCategory as $attributeByCategory){
                    if(
$attributeByCategory->Label() == "Minimum Cancel"){ //Cange Minimum Cancel to whatever you want to call the label
                        
                        
$customAttributeId $attributeByCategory->Id();
                    }
                }
                foreach(
$attributes as $attribute){
                if(
$customAttributeId == $attribute->AttributeId){
                   
$minimumCancellationTime $attribute->Value;   
                 }
                }
                
$isValid $instance->StartDate()->GreaterThan(Date::Now()->AddDays($minimumCancellationTime)); 
                
                }
                
               
if ($isValid)
{   

return new ReservationValidationResult();
}
                
                

return new ReservationValidationResult(false"you must update $minimumCancellationTime days before your reservation");
}

}


?>
Then make sure that the label you are using on your custom attribute is the same name as in the if statment on lines 151 and 221. By Default it is set at Minimum Cancel.

If you are having any problems please post them here and I will do my best to address them.
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 6396


WWW
« Reply #1 on: August 17, 2013, 06:08:11 PM »

Thank you!
Logged
DanielTurner
Newbie
*

Karma: 0
Posts: 1


« Reply #2 on: March 07, 2014, 09:37:31 PM »

I am having a problem with the message that is presented to the user.

the button has an "?" in the text and the message is not formatted properly.  Any suggestions?
Logged
pvdemael
Newbie
*

Karma: 1
Posts: 28


« Reply #3 on: March 27, 2014, 04:19:39 PM »

I ran the plugin before successfully, but now I get some errors:

When I click the Delete button, no matter if the Minimum Cancel time was exceeded or not,  get the following error message: There was a critical error saving your reservation. If this continues, contact your system administrator.

When I try to update a reservation, I see the spinning wheel running perpetually.

Any idea?
Logged
aguwisefe
Newbie
*

Karma: 0
Posts: 20


« Reply #4 on: November 13, 2014, 12:29:35 PM »

Can someone add some screenshots, to show how the plugin works? Just to be sure its doing what I'm searching for.
Logged
ringner
Newbie
*

Karma: 0
Posts: 24


« Reply #5 on: November 17, 2014, 07:20:56 AM »

Can someone add some screenshots, to show how the plugin works? Just to be sure its doing what I'm searching for.

It's a bit hard to provide screenshots since this plugin works almost exclusively in the background.

What it actually does is checking if a booking is cancelled or, indeed, edited before or after the number of days input in the custom attribute "Minimum cancellation". If edit/cancel is allowed, this is performed, otherwise an error message is presented to the user.

So, basically, the only thing visible to a user is the error message "you must cancel xxx days before your reservation" when a user tries to cancel/edit a reservation when it is too late.

In your backend, the only thing you need to do is to create the custom attribute "Minimum cancellation" and input the number of days for each of your resources. Piece of cake more or less. :-)
Logged
aguwisefe
Newbie
*

Karma: 0
Posts: 20


« Reply #6 on: November 17, 2014, 08:26:31 AM »

Where to set the custom attribute "Minimum cancellation"? Thats something I didn't get. But I'm not so used to of booked.
Logged
drkitty
Newbie
*

Karma: 0
Posts: 16


« Reply #7 on: March 03, 2015, 09:51:27 PM »

Could you say where the custom attribute "minimum cancel" should be created? Is it the custom attribute for resource?

UPDATE:  I created an attribute for resource "Minimum Cancel" under "Application Management >Customization >Attributes >Resource"  -  Wasn't sure what the value was, but the plugin seems to count in days, so I  put "1" as the attribute value since I wanted restrictions on updates to 1 day.  Was that right?
« Last Edit: March 03, 2015, 10:42:12 PM by drkitty » Logged
adam.shearman
Newbie
*

Karma: 0
Posts: 1


« Reply #8 on: February 25, 2016, 04:19:44 PM »

Bit of a late one but did anyone get this working?

Currently running V2.5.13 and after testing it I have the following issues:
Normal user
Within 24 hours
- unable to delete, but click button is a question mark rather than "cancel" or something to that matter
- unable to update but warning message not showing value from $minimumCancellationTime

More than 24 hours
- delete works as expected
- unable to update booking, shows warning message saying it's within *blank* days

Admin works as expected.

Soooo i'm assuming deleting (cancelling) bookings is working fine, but when doing the update function it's unable to pull a value for the number of days on a resource....

So yeah, anyone got it working? heh
Logged
ringner
Newbie
*

Karma: 0
Posts: 24


« Reply #9 on: February 18, 2017, 07:08:50 PM »

Hi!

I've just upgraded to 2.6.5, and this plugin stopped working:

Quote
Fatal error: Declaration of MinimumCancellationValidation::Validate() must be compatible with IReservationValidationService::Validate($series, $retryParameters = NULL) in /public_html/plugins/PreReservation/MinimumCancellation2/MinimumCancellation2.php on line 118

Anyone has a solution? Or at least a clue?

/Anders
Logged
deadcow
Newbie
*

Karma: 0
Posts: 3


« Reply #10 on: April 11, 2017, 08:40:32 AM »

Hi
I modified the script for v.2.6.5 and later.
Get it here:  GitHub

There is also a branch for this plugin to deny cancellation in hours instead in days.
« Last Edit: April 11, 2017, 01:14:51 PM by deadcow » Logged
mleij
Newbie
*

Karma: 0
Posts: 2


« Reply #11 on: April 16, 2017, 03:26:43 PM »

I have implemented the latest version from GitHub and are working with Booked v2.6.6. When I click the Delete button, no matter if the Minimum Cancel time was exceeded or not, I also get the following error message: There was a critical error saving your reservation. If this continues, contact your system administrator.

When I try to enter a reservation, I see the spinning wheel running perpetually.

What am I doing wrong?

Cheers
Logged
deadcow
Newbie
*

Karma: 0
Posts: 3


« Reply #12 on: April 19, 2017, 09:07:00 AM »

Strange.
When you deactivate the plugin, does it work again?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!