src/Controller/ContactController.php line 64

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Elements.at New Media Solutions GmbH
  4.  *
  5.  */
  6. namespace App\Controller;
  7. use App\Twig\ConfigHelper;
  8. use Pimcore\Model\DataObject\Contact;
  9. use Pimcore\Model\DataObject\Location;
  10. use Pimcore\Model\DataObject\SiteConfig;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. class ContactController extends AbstractController
  14. {
  15.     public function __construct(private ConfigHelper $configHelper)
  16.     {
  17.     }
  18.     /**
  19.      *
  20.      * @param Request $request
  21.      *
  22.      * @return Response
  23.      */
  24.     public function overviewAction(Request $request): Response
  25.     {
  26.         $siteConfig $this->configHelper->getSiteConfig();
  27.         $resort $this->document->getProperty('resort');
  28.         $subResort $this->document->getProperty('subResort');
  29.         $contacts = new Contact\Listing();
  30.         $contacts->addConditionParam("name != '' AND firstname != '' AND (notShow IS NULL OR notShow = 0)");
  31.         $contacts->addConditionParam('config LIKE :config', ['config' => '%' $siteConfig->getId() . '%']);
  32.         if($resort != null){
  33.             $contacts->addConditionParam("resorts LIKE :resort", ['resort' => '%,' $resort ',%']);
  34.         }
  35.         if($subResort != null){
  36.             $contacts->addConditionParam("subResorts LIKE :subResort OR subResorts IS NULL OR subResorts = ''", ['subResort' => '%,' $subResort ',%']);
  37.         }
  38.         if ($request->get('q')) {
  39.             $contacts->addConditionParam('name LIKE :q OR firstname LIKE :q or sellArea LIKE :q OR position LIKE :q OR department__id IN
  40.             (SELECT o_id FROM object_localized_Departments_' $request->getLocale() . ' WHERE name LIKE :q)', ['q' => '%' $request->get('q') . '%']);
  41.         }
  42.         $contacts->setOrderKey(['sorter''name']);
  43.         $contacts->setOrder(['ASC''ASC']);
  44.         $returnArray = [
  45.             'contactPersons' => $contacts,
  46.         ];
  47.         if ($request->isXmlHttpRequest() && $request->get('ajax')) {
  48.             return $this->json([
  49.                 'success' => true,
  50.                 'html' => $this->render('contact/includes/contact-content.html.twig'$returnArray)->getContent(),
  51.             ]);
  52.         }
  53.         return $this->renderTemplate('contact/overview.html.twig'$returnArray);
  54.     }
  55. }