<?php
namespace App\FHI360\Access\Portal\Controller;
use App\FHI360\Access\Portal\Service\Loader;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use App\FHI360\Access\Suite\Service\APISuiteCRM;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
class DefaultController extends Controller
{
/**
* @Route("/module/site/data", name="site-data")
*/
public function getSiteData()
{
$userId = $this->get('security.token_storage')->getToken()->getUser()->getID();
$tools = Loader::suiteUtils()->getPortalTools($userId);
$tools = array_filter($tools, fn($tool) => $tool['is_dev_tool_c'] != 1);
$data = ['tools' => array_values($tools)];
return new Response(json_encode($data));
}
/**
* @Route("/", name="portal")
*/
public function dashboardAction()
{
$portalURL = "https://{$this->getParameter('portal_domain')}";
// FHI360\Access\SuiteBundle\Service\SuiteUtils
$suiteUtils = $this->container->get('suite_utils');
$user = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user->getID();
$security_group_id = $suiteUtils->getUserSecurityGroup($user->getID());
$contentTypeName = "Alerts";
$alerts = $suiteUtils->getContentManagerRecordsByPermission("alerts", $user_id);
$alertsList = [];
foreach($alerts as $key => $alert){
$name = $alert['name'];
$description = $alert['doc_entry_c'];
$description = strip_tags($description, '<b><a><pre>');
$readMoreUrl = "";
if (strlen($description) > 300) {
// truncate string
$stringCut = substr($description, 0, 300);
$descNumber = $key + 1;
$readMoreUrl = $portalURL . "/alerts#descNum=$descNumber";
$description = substr($stringCut, 0, strrpos($stringCut, ' '))."...";
}
$alertsList[] = [
'title' => $name,
'description' => $description,
'readMoreUrl' => $readMoreUrl,
];
}
//Get User Consent
$userConsent =$suiteUtils->getUserConsentDetails($user->getID());
// Get Portal Tools objects
$tools = $suiteUtils->getPortalTools($user->getID());
// separate the dev tools
$devTools = [];
foreach ($tools as $index => $tool) {
if ($tool['is_dev_tool_c'] != 1) continue;
$devTools[] = $tool;
unset($tools[$index]);
}
// Get the browser check information
$browserDetails = $suiteUtils->getBrowserDetails();
$browserCheckInfo = $suiteUtils->getBrowserCheckInfo($user->getUsername(),$browserDetails);
$save_browser_info = (isset($browserCheckInfo) && sizeof($browserCheckInfo)>0)?'no':'yes';
//get the notification count
$notification_count = $suiteUtils->getUserNotifications($user->getID(),true);
$loginAsNotUsed = true;
$token = $this->get('security.token_storage')->getToken();
if ($token instanceof SwitchUserToken) {
$impersonatorUser = $token->getOriginalToken()->getUser();
$impersonatorUserId = $impersonatorUser->getID();
if($impersonatorUserId != $user_id)
$loginAsNotUsed = false;
}
// Render the template
$templateParams = array(
'user_firstname' => $user->getFirstName(),
'tools' => $tools,
'dev_tools' => $devTools,
'news' => $alertsList,
'save_browser_info' => $save_browser_info,
'browserDetails' => $browserDetails,
'ip_address' => $suiteUtils->getUserIP(),
'notification_count' => $notification_count,
);
if($userConsent['userConsent'] != 'yes' && $loginAsNotUsed){
return $this->render('Portal/UserProfile/user-consent.html.twig', $templateParams);
}
else{
return $this->render('Portal/Default/dashboard.html.twig', $templateParams);
}
}
}