Uname: Linux webm005.cluster107.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64
User: 6036 (villadal)
Group: 100 (users)
Disabled functions: NONE
Safe mode: On[ PHPinfo ]
//home/villadal/www/old/////booked/lib/Application/Admin      ( Reset | Go to )
File Name: ReservationFilter.php
Edit
<?php
/**
Copyright 2012-2014 Nick Korbel

This file is part of Booked SchedulerBooked SchedulereIt 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 versBooked SchedulerduleIt 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
alBooked SchedulercheduleIt.  If not, see <http://www.gnu.org/licenses/>.
 */

class ReservationFilter
{
    
/**
     * @var Date|null
     */
    
private $startDate null;

    
/**
     * @var Date|null
     */
    
private $endDate null;

    
/**
     * @var null|string
     */
    
private $referenceNumber null;

    
/**
     * @var int|null
     */
    
private $scheduleId null;

    
/**
     * @var int|null
     */
    
private $resourceId null;

    
/**
     * @var int|null
     */
    
private $userId null;

    
/**
     * @var int|null
     */
    
private $statusId null;

    
/**
     * @var int|null
     */
    
private $resourceStatusId null;

    
/**
     * @var int|null
     */
    
private $resourceStatusReasonId null;

    
/**
     * @var Attribute[]|null
     */
    
private $attributes null;

    
/**
     * @var array|ISqlFilter[]
     */
    
private $_and = array();

    
/**
     * @param Date $startDate
     * @param Date $endDate
     * @param string $referenceNumber
     * @param int $scheduleId
     * @param int $resourceId
     * @param int $userId
     * @param int $statusId
     * @param int $resourceStatusId
     * @param int $resourceStatusReasonId
     * @param Attribute[] $attributes
     */
    
public function __construct($startDate null,
                                
$endDate null,
                                
$referenceNumber null,
                                
$scheduleId null,
                                
$resourceId null,
                                
$userId null,
                                
$statusId null,
                                
$resourceStatusId null,
                                
$resourceStatusReasonId null,
                                
$attributes null)
    {
        
$this->startDate $startDate;
        
$this->endDate $endDate;
        
$this->referenceNumber $referenceNumber;
        
$this->scheduleId $scheduleId;
        
$this->resourceId $resourceId;
        
$this->userId $userId;
        
$this->statusId $statusId;
        
$this->resourceStatusId $resourceStatusId;
        
$this->resourceStatusReasonId $resourceStatusReasonId;
        
$this->attributes $attributes;
    }

    
/**
     * @param ISqlFilter $filter
     * @return ReservationFilter
     */
    
public function _And(ISqlFilter $filter)
    {
        
$this->_and[] = $filter;
        return 
$this;
    }

    public function 
GetFilter()
    {
        
$filter = new SqlFilterNull();

        if (!empty(
$this->startDate)) {
            
$filter->_And(new SqlFilterGreaterThan(ColumnNames::RESERVATION_START$this->startDate->ToDatabase(), true));
        }
        if (!empty(
$this->endDate)) {
            
$filter->_And(new SqlFilterLessThan(ColumnNames::RESERVATION_END$this->endDate->AddDays(1)->ToDatabase(), true));
        }
        if (!empty(
$this->referenceNumber)) {
            
$filter->_And(new SqlFilterEquals(ColumnNames::REFERENCE_NUMBER$this->referenceNumber));
        }
        if (!empty(
$this->scheduleId)) {
            
$filter->_And(new SqlFilterEquals(new SqlFilterColumn(TableNames::RESOURCESColumnNames::SCHEDULE_ID), $this->scheduleId));
        }
        if (!empty(
$this->resourceId)) {
            
$filter->_And(new SqlFilterEquals(new SqlFilterColumn(TableNames::RESOURCESColumnNames::RESOURCE_ID), $this->resourceId));
        }
        if (!empty(
$this->userId)) {
            
$filter->_And(new SqlFilterEquals(new SqlFilterColumn(TableNames::USERSColumnNames::USER_ID), $this->userId));
        }
        if (!empty(
$this->statusId)) {
            
$filter->_And(new SqlFilterEquals(new SqlFilterColumn(TableNames::RESERVATION_SERIES_ALIASColumnNames::RESERVATION_STATUS), $this->statusId));
        }
        if (!empty(
$this->resourceStatusId)) {
            
$filter->_And(new SqlFilterEquals(new SqlFilterColumn(TableNames::RESOURCESColumnNames::RESOURCE_STATUS_ID), $this->resourceStatusId));
        }
        if (!empty(
$this->resourceStatusReasonId)) {
            
$filter->_And(new SqlFilterEquals(new SqlFilterColumn(TableNames::RESOURCESColumnNames::RESOURCE_STATUS_REASON_ID), $this->resourceStatusReasonId));
        }
        if (!empty(
$this->attributes))
        {
            
$filteringAttributes false;

            
$f  = new SqlFilterFreeForm(TableNames::RESERVATION_SERIES_ALIAS '.' ColumnNames::SERIES_ID ' IN (SELECT a0.' ColumnNames::ATTRIBUTE_ENTITY_ID ' FROM ' TableNames::CUSTOM_ATTRIBUTE_VALUES ' a0 ');

            
$attributeFragment = new SqlFilterNull();

            
/** @var $attribute Attribute */
            
foreach ($this->attributes as $i => $attribute)
            {
                if (
$attribute->Value() == null || $attribute->Value() == '')
                {
                    continue;
                }
                
$id $attribute->Id();
                
$filteringAttributes true;
                
$attributeId = new SqlRepeatingFilterColumn("a$id"ColumnNames::CUSTOM_ATTRIBUTE_ID$id);
                
$attributeValue = new SqlRepeatingFilterColumn("a$id"ColumnNames::CUSTOM_ATTRIBUTE_VALUE$id);

                
$idEquals = new SqlFilterEquals($attributeId$attribute->Id());
                
$f->AppendSql('LEFT JOIN ' TableNames::CUSTOM_ATTRIBUTE_VALUES ' a' $id ' ON a0.entity_id = a' $id '.entity_id ');
                if (
$attribute->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX || $attribute->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX)
                {
                    
$attributeFragment->_And($idEquals->_And(new SqlFilterLike($attributeValue$attribute->Value())));
                }
                else
                {
                    
$attributeFragment->_And($idEquals->_And(new SqlFilterEquals($attributeValue$attribute->Value())));
                }
            }

            
$f->AppendSql("WHERE [attribute_list_token] )");
            
$f->Substitute('attribute_list_token'$attributeFragment);

            if (
$filteringAttributes)
            {
                
$filter->_And($f);
            }
        }

        foreach (
$this->_and as $and)
        {
            
$filter->_And($and);
        }

        return 
$filter;
    }
}

All system for education purposes only. For more tools: Telegram @jackleet

Mr.X Private Shell

Logo
-
New File | New Folder
Command
SQL