src/Controller/BToBController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Model\DataObject\TeamMember;
  4. use Pimcore\Model\DataObject\TeamPosition;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class BToBController extends AbstractController {
  9.     public function portalAction(Request $request) {
  10.         return $this->renderTemplate('BToB/portal.html.twig');
  11.     }
  12.     public function teamOverviewAction(Request $request) {
  13.         $teamPositions $this->getDocumentEditable('relations''b2b-teampositions')->getData();
  14.         $teamItems = [];
  15.         if(!empty($teamPositions)) {
  16.             foreach($teamPositions as $position) {
  17.                 if($position instanceof TeamPosition) {
  18.                     $teamItems[$position->getId()] = [
  19.                         'title' => $position->getName(),
  20.                         'members' => [],
  21.                     ];
  22.                 }
  23.             }
  24.         } else {
  25.             $positionList = new TeamPosition\Listing();
  26.             $positionList->setCondition('name != "" AND name IS NOT NULL');
  27.             $positionList->setOrderKey('sorting');
  28.             $positionList->setOrder('ASC');
  29.             foreach ($positionList as $position) {
  30.                 $teamItems[$position->getId()] = [
  31.                     'title' => $position->getName(),
  32.                     'members' => [],
  33.                 ];
  34.             }
  35.         }
  36.         $memberList = new TeamMember\Listing();
  37.         $memberList->addConditionParam('name != "" AND name IS NOT NULL');
  38.         if($regionData $this->getDocumentEditable('relation''prefilter-team-region')->getData()) {
  39.             if ($regionData['id']){
  40.                 $memberList->addConditionParam('regions LIKE "%,' $regionData['id'] . ',%"');
  41.             }
  42.         }
  43.         $memberList->setOrderKey('sorting');
  44.         $memberList->setOrder('ASC');
  45.         foreach($memberList as $member) {
  46.             if($member->getPositions()) {
  47.                 foreach($member->getPositions() as $position) {
  48.                     if(isset($teamItems[$position->getId()])) {
  49.                         $teamItems[$position->getId()]['members'][] = $member;
  50.                     }
  51.                 }
  52.             }
  53.         }
  54.         return $this->renderTemplate('BToB/teamOverview.html.twig', [
  55.           "teamItems" => $teamItems
  56.         ]);
  57.     }
  58.     /**
  59.      * @Route("/team/member-modal", name="team-modal")
  60.      * @param Request $request
  61.      * @return JsonResponse
  62.      */
  63.     public function teamModal(Request $request) {
  64.         $teamMember TeamMember::getById($request->get('id'''));
  65.         $request->setLocale($request->get('lang''en'));
  66.         return new JsonResponse([
  67.             'success' => true,
  68.             'html' => $this->renderView('BToB/Includes/teammember-modal.html.twig',[
  69.                 'member' => $teamMember,
  70.             ]),
  71.         ]);
  72.     }
  73. }