<?php
namespace App\Helpers\Services;
use App\Entity\Animals\MixerCategory;
use App\Entity\Animals\Size;
use App\Entity\Animals\Type;
use App\Entity\Services\PriceGroup;
use App\Entity\Services\Service;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Symfony\Component\Yaml\Parser;
use Doctrine\ORM\EntityManagerInterface;
use \App\Helpers\System\ConfigHelper;
class ServiceHelper
{
protected $container;
protected $em;
protected $config;
public function __construct(Container $container, EntityManagerInterface $em, ConfigHelper $configHelper)
{
$this->container = $container;
$this->em = $em;
$this->configHelper = $configHelper;
}
public function getPrice(Service $service, Type $type, Size $size, ?MixerCategory $mixerCategory = null, ?PriceGroup $priceGroup = null, ?\DateTime $lookupDate = null, $method = null)
{
// Price lookup
$lookup = array(
'size' => $size,
'animalType' => $type,
'service' => $service
);
// Got a mixer category
if($mixerCategory)
$lookup["mixerCategory"] = $mixerCategory;
// Got a price group?
if($priceGroup)
$lookup['priceGroup'] = $priceGroup;
// Got a specific lookup date?
if(is_object($lookupDate))
$lookup['enabledForDate'] = $lookupDate;
// Find the price
$price = $this->em->getRepository(\App\Entity\Services\Price::class)->findOneFiltered($lookup, [
"pg.startDate" => "DESC"
]);
// Price not found?
if(!$price)
return null;
if($method)
{
$method = "get" . ucFirst($method) . "()";
// Method does not exist?
if(!method_exists($price, $method))
throw new \Exception("Method: " . $method . ' does not exists on price.');
return $price->$method;
}
// Return the whole price
return $price;
}
}