<?php
namespace App\Controller;
use App\Entity\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class AppsController extends AbstractController
{
private $Lo_Client;
private $Lo_Translator;
public function __construct(TranslatorInterface $translator, Client $client){
$this->Lo_Client = $client;
$this->Lo_Translator = $translator;
}
/**
* @Route("/", name="app_root")
*/
public function index()
{
if ($this->getUser()) return $this->redirectToRoute('app_home', ['_locale' => 'de']);
else return $this->redirectToRoute('app_login', ['_locale' => 'de']);
}
/**
* @Route("/{_locale<%app.supported_locales%>}/apps", name="app_home")
*/
public function apps()
{
$Lb_UserHasRoles = false;
$La_ClientCards=[];
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$La_Roles = $this->getUser()->getRoles();
$Li_AmountRoles = count($this->getUser()->getRoles());
$Lo_Data = $this->Lo_Client->getAgentCompanies($this->getUser()->getPersonID(), $this->getUser()->getAddressRoleID(14));
if($Lo_Data->Error == 5) {
return new RedirectResponse('/logout');
}
else $La_Clients = $Lo_Data->Result->ArrayData;
foreach ($La_Clients as $key => $Lo_Client) {
$La_ClientCards[] = [
'title' => $Lo_Client->s_Company,
'description' => $this->Lo_Translator->trans("webtool_client"),
'url' => 'app_agentclientstool',
'id' => $Lo_Client->i_AddressRoleID,
'agentAddressId' => $Lo_Client->i_AgentAddressID,
'image' => 'wert.jpg',
'role' => 'ROLE_CLIENT',
'i_AddressRoleID' => $this->getUser()->getAddressRoleID(14, $Lo_Client->i_AgentAddressID)
];
}
if(!($Li_AmountRoles == 1 && $La_Roles[0] == 'ROLE_USER')) $Lb_UserHasRoles = true;
$La_DataTemplate = [
'controller_name' => 'AppsController',
'user_has_roles' => $Lb_UserHasRoles,
'cards' => [
'salestool' => [
'title' => $this->Lo_Translator->trans("webtool_sales"),
'description' => $this->Lo_Translator->trans("webtool_to_sale_courses"),
'url' => 'app_salestool',
'id' => $this->getUser()->getAddressRoleID(12),
'image' => 'kunden-anlocken.jpg',
'role' => 'ROLE_SALES',
'i_AddressRoleID' => $this->getUser()->getAddressRoleID(12)
],
'member' => [
'title' => $this->Lo_Translator->trans("participant"),
'description' => $this->Lo_Translator->trans("webtool_participant"),
'url' => 'app_participantstool',
'id' => $this->getUser()->getAddressRoleID(2),
'image' => 'frau.jpg',
'role' => 'ROLE_PARTICIPANT',
'i_AddressRoleID' => $this->getUser()->getAddressRoleID(2)
],
'instructor' => [
'title' => $this->Lo_Translator->trans("instructor"),
'description' => $this->Lo_Translator->trans("webtool_instructor"),
'url' => 'app_instructorstool',
'id' => $this->getUser()->getAddressRoleID(3),
'image' => 'webinar.jpg',
'role' => 'ROLE_INSTRUCTOR',
'i_AddressRoleID' => $this->getUser()->getAddressRoleID(3)
],
],
];
$La_DataTemplate['cards'] = array_merge($La_DataTemplate['cards'], $La_ClientCards);
return $this->render('apps/index.html.twig', $La_DataTemplate);
}
/**
* @Route("/{_locale<%app.supported_locales%>}/apps/{vue_route}", name="share", requirements={"vue_route"=".*"})
* @Route("/{_locale<%app.supported_locales%>}/apps/user/profile", name="app_userboard")
* @Route("/{_locale<%app.supported_locales%>}/apps/participantstool/{id}", name="app_participantstool", options={"expose"=true})
* @Route("/{_locale<%app.supported_locales%>}/apps/clientstool/{id}/{agentAddressId}", name="app_agentclientstool", options={"expose"=true})
* @Route("/{_locale<%app.supported_locales%>}/apps/salestool", name="app_salestool")
* @Route("/{_locale<%app.supported_locales%>}/apps/instructorstool/{id}", name="app_instructorstool", options={"expose"=true})
* @Route("/{_locale<%app.supported_locales%>}/apps/user/absences/{id}", name="app_userabsences")
*/
public function vueRouting(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$Ls_BaseUrl = $request->getScheme() . '://' . $request->getHttpHost();
$La_DataTemplate = [
'controller_name' => 'AppsController',
'data' => [
'base_url' => $Ls_BaseUrl,
'vuei18n' => $this->getTranslations($request->getLocale()),
'locale' => $request->getLocale(),
'addressRoleID' => $request->query->get('addressRoleID'),
'roles' => implode(',', $this->getUser()->getRoles()),
'properties' => $this->getUser()->getProperties()
]
];
return $this->render('apps/vue.html.twig', $La_DataTemplate);
}
/**
* @Route("/apps/{no_route}", name="no_route", requirements={"no_route"=".*"})
*/
public function no_route()
{
if ($this->getUser()) return $this->redirectToRoute('app_home', ['_locale' => 'de']);
else return $this->redirectToRoute('app_login', ['_locale' => 'de']);
}
private function getTranslations($As_Locale){
$catalogue = $this->Lo_Translator->getCatalogue($As_Locale);
$Lo_VueI18n = $catalogue->all();
while ($catalogue = $catalogue->getFallbackCatalogue()) {
$Lo_VueI18n = array_replace_recursive($catalogue->all(), $Lo_VueI18n);
}
$new_dictionary = [
'word_english' => $this->Lo_Translator->trans('word_english'),
];
return $Lo_VueI18n['messages'];
}
}