<?php
namespace TourOperatorProBlock\block_tour_destination;
use TourOperatorPro\Factory as FactoryAlias;
use TourOperatorPro\Utilities\Utility as UtilityAlias;
use TourOperatorProFrontend\app\helpers\DestinationHelper;
class block_tour_destination_helper{
    public static function get_tour_by_destination_id($tour_destination_id=0){
       $destination_key=DestinationHelper::getDestinationKey();
        $db= FactoryAlias::getDBO();
        $query=$db->getQuery(true);
        $query->select('tour.*')
            ->from(UtilityAlias::getTableName('tour').' AS tour ')
            ->leftJoin(UtilityAlias::getTableName('tourproperty'). ' AS tourproperty ON tourproperty.tour_id = tour.id')
            ->where('tour.published=1')
        ;
            if($tour_destination_id!=0){
                $query->where('type ='.$query->quote($destination_key))
                    ->where('object_id='.(int)$tour_destination_id);
            }
            $query->group('tour.id')
        ;
       $list=$db->setQuery($query)->loadObjectList();
        return $list;
    }
}