<?php
namespace App\Controller;
use Pimcore\Model\DataObject\TeamMember;
use Pimcore\Model\DataObject\TeamPosition;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class BToBController extends AbstractController {
public function portalAction(Request $request) {
return $this->renderTemplate('BToB/portal.html.twig');
}
public function teamOverviewAction(Request $request) {
$teamPositions = $this->getDocumentEditable('relations', 'b2b-teampositions')->getData();
$teamItems = [];
if(!empty($teamPositions)) {
foreach($teamPositions as $position) {
if($position instanceof TeamPosition) {
$teamItems[$position->getId()] = [
'title' => $position->getName(),
'members' => [],
];
}
}
} else {
$positionList = new TeamPosition\Listing();
$positionList->setCondition('name != "" AND name IS NOT NULL');
$positionList->setOrderKey('sorting');
$positionList->setOrder('ASC');
foreach ($positionList as $position) {
$teamItems[$position->getId()] = [
'title' => $position->getName(),
'members' => [],
];
}
}
$memberList = new TeamMember\Listing();
$memberList->addConditionParam('name != "" AND name IS NOT NULL');
if($regionData = $this->getDocumentEditable('relation', 'prefilter-team-region')->getData()) {
if ($regionData['id']){
$memberList->addConditionParam('regions LIKE "%,' . $regionData['id'] . ',%"');
}
}
$memberList->setOrderKey('sorting');
$memberList->setOrder('ASC');
foreach($memberList as $member) {
if($member->getPositions()) {
foreach($member->getPositions() as $position) {
if(isset($teamItems[$position->getId()])) {
$teamItems[$position->getId()]['members'][] = $member;
}
}
}
}
return $this->renderTemplate('BToB/teamOverview.html.twig', [
"teamItems" => $teamItems
]);
}
/**
* @Route("/team/member-modal", name="team-modal")
* @param Request $request
* @return JsonResponse
*/
public function teamModal(Request $request) {
$teamMember = TeamMember::getById($request->get('id', ''));
$request->setLocale($request->get('lang', 'en'));
return new JsonResponse([
'success' => true,
'html' => $this->renderView('BToB/Includes/teammember-modal.html.twig',[
'member' => $teamMember,
]),
]);
}
}