local/modules/PayboxDisplay/Hook/FrontHook.php line 30
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace PayboxDisplay\Hook;
use Thelia\Core\Event\Hook\HookRenderBlockEvent;
use Thelia\Model\ModuleImageQuery;
use Thelia\Core\Hook\BaseHook;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Event\Image\ImageEvent;
use Thelia\Core\Event\TheliaEvents;
/**
* Class FrontHook
* @package PayboxDisplay\Hook
* @author François Carfantan
*/
class FrontHook extends BaseHook {
public function onMainFooterBody(HookRenderBlockEvent $event)
{
$content="";
$moduleId = $this->getModule()->getModuleId();
$image = ModuleImageQuery::create()->findOneByModuleId($this->getModule()->getModuleId());
if($image){
$imageFileName = $image->getFile();
$localMediaPath = $this->getImageUrl($moduleId);
$content = trim($this->render("main-footer-body.html",['localMediaPath' => $localMediaPath]));
}
if ("" != $content){
$event->add(array(
"id" => "paybox-display",
"class" => "default",
"content" => $content
));
}
}
private function getImageUrl($moduleId){
$imageFileName = ModuleImageQuery::create()->findOneByModuleId($moduleId)->getFile();
$payboxDisplay = new \PayboxDisplay\PayboxDisplay();
$uploadDir = $payboxDisplay->getUploadDir();
$event = new ImageEvent();
$event->setSourceFilepath(DS.$uploadDir . DS . $imageFileName)
->setCacheSubdirectory('paybox');
$this->dispatcher->dispatch($event,TheliaEvents::IMAGE_PROCESS);
return $event->getFileUrl();
}
}