local/modules/PayboxDisplay/Hook/FrontHook.php line 30

  1. <?php
  2. /*************************************************************************************/
  3. /*      This file is part of the Thelia package.                                     */
  4. /*                                                                                   */
  5. /*      Copyright (c) OpenStudio                                                     */
  6. /*      email : dev@thelia.net                                                       */
  7. /*      web : http://www.thelia.net                                                  */
  8. /*                                                                                   */
  9. /*      For the full copyright and license information, please view the LICENSE.txt  */
  10. /*      file that was distributed with this source code.                             */
  11. /*************************************************************************************/
  12. namespace PayboxDisplay\Hook;
  13. use Thelia\Core\Event\Hook\HookRenderBlockEvent;
  14. use Thelia\Model\ModuleImageQuery;
  15. use Thelia\Core\Hook\BaseHook;
  16. use Thelia\Log\Tlog;
  17. use Thelia\Model\ConfigQuery;
  18. use Thelia\Core\Event\Image\ImageEvent;
  19. use Thelia\Core\Event\TheliaEvents;
  20. /**
  21.  * Class FrontHook
  22.  * @package PayboxDisplay\Hook
  23.  * @author François Carfantan
  24.  */
  25. class FrontHook extends BaseHook {
  26.     public function onMainFooterBody(HookRenderBlockEvent $event)
  27.     {
  28.         $content="";
  29.         $moduleId $this->getModule()->getModuleId();
  30.         $image ModuleImageQuery::create()->findOneByModuleId($this->getModule()->getModuleId());
  31.         if($image){
  32.             $imageFileName $image->getFile();
  33.          $localMediaPath $this->getImageUrl($moduleId);
  34.             $content trim($this->render("main-footer-body.html",['localMediaPath' => $localMediaPath]));
  35.         }
  36.         if ("" != $content){
  37.             $event->add(array(
  38.                 "id" => "paybox-display",
  39.                 "class" => "default",
  40.                 "content" => $content
  41.             ));
  42.         }
  43.     }
  44.     private function getImageUrl($moduleId){
  45.         $imageFileName ModuleImageQuery::create()->findOneByModuleId($moduleId)->getFile();
  46.         $payboxDisplay = new \PayboxDisplay\PayboxDisplay();
  47.         $uploadDir $payboxDisplay->getUploadDir();
  48.         $event = new ImageEvent();
  49.         $event->setSourceFilepath(DS.$uploadDir DS $imageFileName)
  50.             ->setCacheSubdirectory('paybox');
  51.         $this->dispatcher->dispatch($event,TheliaEvents::IMAGE_PROCESS);
  52.         return $event->getFileUrl();
  53.     }