src/FHI360/Access/Portal/Controller/DefaultController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\FHI360\Access\Portal\Controller;
  3. use App\FHI360\Access\Portal\Service\Loader;
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  5. use App\FHI360\Access\Suite\Service\APISuiteCRM;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
  11. class DefaultController extends Controller
  12. {
  13.     /**
  14.      * @Route("/module/site/data", name="site-data")
  15.      */
  16.     public function getSiteData()
  17.     {
  18.         $userId $this->get('security.token_storage')->getToken()->getUser()->getID();
  19.         $tools Loader::suiteUtils()->getPortalTools($userId);
  20.         $tools array_filter($tools, fn($tool) => $tool['is_dev_tool_c'] != 1);
  21.         $data = ['tools' => array_values($tools)];
  22.         return new Response(json_encode($data));
  23.     }
  24.     /**
  25.      * @Route("/", name="portal")
  26.      */
  27.     public function dashboardAction()
  28.     {
  29.         $portalURL "https://{$this->getParameter('portal_domain')}";
  30.         // FHI360\Access\SuiteBundle\Service\SuiteUtils
  31.         $suiteUtils $this->container->get('suite_utils');
  32.         $user $this->get('security.token_storage')->getToken()->getUser();
  33.         $user_id $user->getID();
  34.         $security_group_id $suiteUtils->getUserSecurityGroup($user->getID());
  35.         $contentTypeName "Alerts";
  36.         $alerts $suiteUtils->getContentManagerRecordsByPermission("alerts"$user_id);
  37.         $alertsList = [];
  38.         foreach($alerts as $key => $alert){
  39.             $name $alert['name'];
  40.             $description $alert['doc_entry_c'];
  41.             
  42.             $description strip_tags($description'<b><a><pre>');
  43.             $readMoreUrl "";
  44.             if (strlen($description) > 300) {
  45.             
  46.                 // truncate string
  47.                 $stringCut substr($description0300);
  48.                 $descNumber $key 1;
  49.                 $readMoreUrl $portalURL "/alerts#descNum=$descNumber";
  50.                 $description substr($stringCut0strrpos($stringCut' '))."...";
  51.             }
  52.             $alertsList[] = [
  53.                 'title' => $name,
  54.                 'description' => $description,
  55.                 'readMoreUrl' =>  $readMoreUrl,
  56.             ];
  57.         }
  58.         //Get User Consent
  59.         $userConsent =$suiteUtils->getUserConsentDetails($user->getID());
  60.         
  61.         // Get Portal Tools objects
  62.         $tools $suiteUtils->getPortalTools($user->getID());
  63.         // separate the dev tools
  64.         $devTools = [];
  65.         foreach ($tools as $index => $tool) {
  66.             if ($tool['is_dev_tool_c'] != 1) continue;
  67.             $devTools[] = $tool;
  68.             unset($tools[$index]);
  69.         }
  70.         
  71.         // Get the browser check information 
  72.         $browserDetails $suiteUtils->getBrowserDetails();
  73.         $browserCheckInfo $suiteUtils->getBrowserCheckInfo($user->getUsername(),$browserDetails);
  74.         $save_browser_info = (isset($browserCheckInfo) && sizeof($browserCheckInfo)>0)?'no':'yes';
  75.         //get the notification count
  76.         $notification_count $suiteUtils->getUserNotifications($user->getID(),true);
  77.         
  78.        
  79.         $loginAsNotUsed true;
  80.         
  81.        $token $this->get('security.token_storage')->getToken();
  82.        if ($token instanceof SwitchUserToken) {
  83.            $impersonatorUser $token->getOriginalToken()->getUser();
  84.            $impersonatorUserId $impersonatorUser->getID();
  85.            
  86.            if($impersonatorUserId != $user_id)
  87.                $loginAsNotUsed false;
  88.        }
  89.        
  90.         // Render the template
  91.         $templateParams = array(
  92.             'user_firstname' => $user->getFirstName(),
  93.             'tools' => $tools,
  94.             'dev_tools' => $devTools,
  95.             'news' => $alertsList,
  96.             'save_browser_info' => $save_browser_info,
  97.             'browserDetails' => $browserDetails,
  98.             'ip_address' => $suiteUtils->getUserIP(),
  99.             'notification_count' => $notification_count,
  100.         );
  101.         if($userConsent['userConsent'] != 'yes' && $loginAsNotUsed){
  102.             return $this->render('Portal/UserProfile/user-consent.html.twig'$templateParams);
  103.         }
  104.         else{
  105.             return $this->render('Portal/Default/dashboard.html.twig'$templateParams);
  106.         }
  107.     }
  108. }