phpScheduleIt
May 25, 2013, 12:23:15 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: how to set up these limits  (Read 417 times)
fei
Newbie
*

Karma: 0
Posts: 2


« on: February 22, 2012, 10:05:34 AM »

Hi Nick,

We would like to do this:
For reservations less than 2 hour in length, users cannot reserve more than 2 weeks ahead;
For reservations more than 2 hours in length, users can reserve up to 3 months ahead.

for e.g., today is Feb 22, a user is trying to reserve 1 hour for March 30, can the system just pop up some message like "it is not allowed to reserve more than 2 weeks in advance"?
However, if a user is trying to reserve 48 hours for March 30, then there is no message and it can go through. But if a user is trying to reserve 48 hours for June 30, then it is not allowed and a message pops up too.

Thank you.
Logged
katherisy
Newbie
*

Karma: 0
Posts: 1


« Reply #1 on: February 24, 2012, 11:22:30 PM »

Hi Nick,

We would like to do this:
For reservations less than 2 hour in length, users cannot reserve more than 2 weeks ahead;
For reservations more than 2 hours in length, users can reserve up to 3 months ahead.

for e.g., today is Feb 22, a user is trying to reserve 1 hour for March 30, can the system just pop up some message like "it is not allowed to reserve more than 2 weeks in advance"?
However, if a user is trying to reserve 48 hours for March 30, then This is an excellent site I love  it
 there is no message and it can go through. But if a user is trying to reserve 48 hours for June 30, then it is not allowed and a message pops up too.

Thank you.





I have the same question.
« Last Edit: March 06, 2012, 11:38:55 PM by katherisy » Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5419


WWW
« Reply #2 on: February 27, 2012, 01:51:02 PM »

For these types of highly custom rules, I'd suggest writing a validation plugin.

Here's an example. You would need to drop this into plugins/PreReservation and change your config.php file to use this plugin.

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 PreReservationRuleExample 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;
        }

        if (
$this->PassesCustomRule($series))
        {
            return new 
ReservationValidationResult();
        }

        return new 
ReservationValidationResult(false"Custom validation failed");
    }

    
/**
     * @param ReservationSeries $series
     * @return bool
     */
    
private function PassesCustomRule($series)
    {
        
// make your custom checks here
        
return true;
    }
}
class 
PreReservationExample extends PreReservationFactory
{
    
/**
     * @var PreReservationFactory
     */
    
private $factoryToDecorate;

    public function 
__construct(PreReservationFactory $factoryToDecorate)
    {
        
$this->factoryToDecorate $factoryToDecorate;
    }

    public function 
CreatePreAddService(UserSession $userSession)
    {
        
$base $this->factoryToDecorate->CreatePreAddService($userSession);
        return new 
PreReservationRuleExample($base);
    }

    public function 
CreatePreUpdateService(UserSession $userSession)
    {
        
$base =  $this->factoryToDecorate->CreatePreUpdateService($userSession);
        return new 
PreReservationRuleExample($base);
    }

    public function 
CreatePreDeleteService(UserSession $userSession)
    {
        return 
$this->factoryToDecorate->CreatePreDeleteService($userSession);
    }

}

?>
Logged
Pages: [1]
  Print  
 
Jump to:  

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