src/Controller/AlkanbariDocumentController.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  *  AlkanbariDocumentController extends BaseController extends FrontendController 
  4.  * 
  5. */
  6. namespace App\Controller;
  7. use Pimcore\Controller\FrontendController;
  8. use Pimcore\Model\Asset;
  9. use Pimcore\Model\Document;
  10. use Pimcore\Tool\DeviceDetector;
  11. use Pimcore\Translation\Translator;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Carbon\Carbon;
  17. use App\Captcha\Captcha;
  18. class AlkanbariDocumentController extends BaseController
  19. {
  20.     /**
  21.      *  Document homepage action
  22.     */
  23.     public function homepageAction(
  24.         Request $request, 
  25.         Translator $translator
  26.     ) {
  27.         $device = \Pimcore\Tool\DeviceDetector::getInstance();
  28.         $config = $this->getSiteConfig('/_Config/Alkanbari');
  29.         if (!$config instanceof \Pimcore\Model\DataObject\SiteConfig)
  30.             return new Response('Failed loading site config: /_Config/Alkanbari.');
  31.         
  32.         return $this->render('alkanbari/document/homepage.html.twig', [
  33.             'languages'   => $this->getValidLanguages(),
  34.             'config'      => $config,
  35.             'locale'      => $request->getLocale(),
  36.             'device'      => $device
  37.         ]);
  38.     }    
  39.     
  40.     /**
  41.      *  Document document action
  42.     */
  43.     public function documentAction(
  44.         Request $request, 
  45.         Translator $translator
  46.     ) {
  47.         $device = \Pimcore\Tool\DeviceDetector::getInstance();
  48.         $config = $this->getSiteConfig('/_Config/Alkanbari');
  49.         if (!$config instanceof \Pimcore\Model\DataObject\SiteConfig)
  50.             return new Response('Failed loading site config: /_Config/Alkanbari.');
  51.         
  52.         return $this->render('alkanbari/document/document.html.twig', [
  53.             'languages'   => $this->getValidLanguages(),
  54.             'config'      => $config,
  55.             'locale'      => $request->getLocale(),
  56.             'device'      => $device
  57.         ]);
  58.     }
  59.     
  60.     /**
  61.      *  Document contact action
  62.     */
  63.     public function contactAction(
  64.         Request $request, 
  65.         Translator $translator
  66.     ) {
  67.         $device = \Pimcore\Tool\DeviceDetector::getInstance();
  68.         $config = $this->getSiteConfig('/_Config/Alkanbari');
  69.         if (!$config instanceof \Pimcore\Model\DataObject\SiteConfig)
  70.             return new Response('Failed loading site config: /_Config/Alkanbari.');
  71.         
  72.         $locations = new \Pimcore\Model\DataObject\Location\Listing();
  73.         $locations ->setCondition("o_path LIKE '".$config->getSiteContactsPath()."%'");
  74.         $locations ->setOrderKey("position");
  75.         $locations ->setOrder("asc");
  76.         
  77.         return $this->render('alkanbari/document/document.html.twig', [
  78.             'languages'   => $this->getValidLanguages(),
  79.             'config'      => $config,
  80.             'locale'      => $request->getLocale(),
  81.             'device'      => $device,
  82.             'locations'   => $locations,
  83.             'loadOSM'     => true
  84.         ]);
  85.     }
  86.     
  87.     /**
  88.      *  imageGalleryAction
  89.     */
  90.     public function imageGalleryAction(
  91.         Request $request
  92.     ) {
  93.         if ('asset' === $request->get('type')) 
  94.         {
  95.             $asset = Asset::getById($request->get('id'));
  96.             if ('folder' === $asset->getType()) 
  97.             {                
  98.                 return $this->render('alkanbari/document/imageGallery.html.twig', ['assets' => $asset->getChildren()]);
  99.             }
  100.         }    
  101.         return [];
  102.     }    
  103.     
  104.     /**
  105.      *  defaultMailAction
  106.     */
  107.     public function defaultMailAction(
  108.         Request $request, 
  109.         Translator $translator     
  110.     ) {
  111.         $device = \Pimcore\Tool\DeviceDetector::getInstance();
  112.         
  113.         return $this->render('alkanbari/document/defaultMailTemplate.html.twig', [
  114.             'device'        => $device,
  115.             'languages'     => $this->getValidLanguages(),
  116.             'locale'        => $request->getLocale()
  117.         ]);
  118.     }
  119.       
  120.     /**
  121.      *  ajaxMailAction 
  122.     */
  123.     public function ajaxMailAction (
  124.         Request $request, 
  125.         Translator $translator     
  126.     ) {
  127.         $config = $this->getSiteConfig('/_Config/Alkanbari');
  128.         $status = new class {};
  129.         
  130.         // get post form data
  131.         $post_vars  = $request->request->all();
  132.         $formdata = [];
  133.         foreach ($post_vars as $key => $var) {           
  134.             $formdata[$key] = $var;                       
  135.         }
  136.         // check trap field
  137.         $spam_detected = false;
  138.         if (isset($formdata['emailAddress']) && strlen($formdata['emailAddress']))
  139.             $spam_detected = true;    
  140.         
  141.         if ( !$formdata['contactToken'] || $spam_detected )
  142.         {
  143.             $status = new class {};
  144.             $status ->code = 400;
  145.             $status ->message = 'Kritischer Fehler.';   
  146.         }
  147.         else
  148.         {
  149.             if ( filter_var($formdata['contactEmail'], FILTER_VALIDATE_EMAIL) && $spam_detected === false ) 
  150.             {
  151.                 $mail = new \Pimcore\Mail();
  152.                 // $mail ->setCharset('utf-8');
  153.                 $mail ->addTo( $formdata['contactEmail'] );
  154.                 $mail ->addTo( $config->getWebsiteEmailAddress() );
  155.                 $mail ->addBcc( 'k.klauer@78-media.de' );
  156.                 $mail ->addReplyTo( $formdata['contactEmail'] );
  157.                 $mail ->setSubject( 'Ihre Anfrage bei '.$config->getWebsiteName() );
  158.                 $mail ->setDocument( Document::getByPath( '/alkanbari/email-templates/contact-default' ) );                    
  159.                 $mail ->setParams( $formdata );                         
  160.                 $mail ->send(); 
  161.     
  162.                 $status ->code = 200;
  163.                 $status ->message = 'Vielen Dank. Ihre Nachricht wurde versendet.';   
  164.             } 
  165.             else 
  166.             {
  167.                 $status = new class {};
  168.                 $status ->code = 500;
  169.                 $status ->message = 'Es ist ein Fehler aufgetreten: SPAM oder ungueltige Eingaben.';  
  170.             }
  171.         }
  172.   
  173.         return new Response( json_encode($status) );
  174.     }
  175.  
  176. }
  177. ?>