src/Controller/basisController/UserBasisController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller\basisController;
  3. use App\Repository\ChatRepository;
  4. use App\Repository\UserRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. class UserBasisController extends AbstractController
  8. {
  9.     public $session;
  10.     public $userRepository;
  11.     public $chatRepository;
  12.     public function __construct(RequestStack $requestStackUserRepository $userRepositoryChatRepository $chatRepository)
  13.     {
  14.         $this->session $requestStack->getSession();
  15.         $this->session->start();
  16.         $this->session->set('lastUse'time());
  17.         $this->userRepository $userRepository;
  18.         $this->chatRepository $chatRepository;
  19.     }
  20.     public function getRechteTabellenzeileId($sichtbar$zugriffsrechte$alleFirmengruppen)
  21.     {
  22.         $idErlaubt false;
  23.         $userId $this->getUser()->getId();
  24.         if ($sichtbar != null) {
  25.             $rechte json_decode($sichtbartrue);
  26.             if (count($rechte) == 0) {
  27.                 $idErlaubt true;
  28.             } else {
  29.                 foreach ($rechte as $recht) {
  30.                     if ($recht == $this->getUser()->getUserProfil()->getFirmenposition()) {
  31.                         $idErlaubt true;
  32.                     }
  33.                     foreach ($alleFirmengruppen as $firmengruppe) {
  34.                         if ($firmengruppe->getId() == $recht) {
  35.                             $firmengruppeUser json_decode($firmengruppe->getGruppenMitarbeiter(), true);
  36.                             if (in_array($userId$firmengruppeUser)) {
  37.                                 $idErlaubt true;
  38.                             }
  39.                         }
  40.                     }
  41.                 }
  42.                 if ($zugriffsrechte != null && in_array($userIdjson_decode($zugriffsrechtetrue))) {
  43.                     $idErlaubt true;
  44.                 }
  45.             }
  46.         } else {
  47.             if ($zugriffsrechte != null && in_array($userIdjson_decode($zugriffsrechtetrue))) {
  48.                 $idErlaubt true;
  49.             }
  50.         }
  51.         return $idErlaubt// Liefert true oder false zurück ob der Mitarbeiter diese Tabellenzeile der Mitarbeiter sehen darf.
  52.     }
  53.     public function getUserBC_FirmenmitgliederGeordnet($sort 'ASC')
  54.     {
  55.         $firmenprofil $this->getUser()->getFirmenProfil();
  56.         $sortNach1 'vorname';
  57.         $sortNach2 'nachname';
  58.         if ($firmenprofil->getNamenSortieren() == 12) {
  59.             $sortNach1 'nachname';
  60.             $sortNach2 'vorname';
  61.         }
  62.         return $this->userRepository->findUserFirmenmitglieder($firmenprofil->getId(), $sortNach1$sortNach2$sort); // Liefert Firmenmitglieder
  63.     }
  64.     public function getUserBC_Firmenmitglieder_ohne_provisorischer_mitarbeiter()
  65.     {
  66.         $firmenprofil $this->getUser()->getFirmenProfil();
  67.         return $this->userRepository->findBy(['firmen_profil' => $firmenprofil->getId(), 'provisorischer_mitarbeiter' => null]);
  68.     }
  69.     public function getLableInternerBereich($userId 0)
  70.     {
  71.         $lable = [];
  72.         $lable['news'] = 'News';
  73.         $lable['events'] = 'Events';
  74.         $lable['umfragen'] = 'Umfragen';
  75.         $lable['dokumente'] = 'Dokumente';
  76.         $lable['dateien'] = 'Dateien';
  77.         $lable['notdienstkalender'] = 'Notdienstkalender';
  78.         $lable['mitarbeiter'] = 'Mitarbeiter';
  79.         $lable['direktChat'] = 'Direkt-Chat';
  80.         $lable['gruppenChat'] = 'Gruppen-Chat';
  81.         // Auch in AdminBasisController vorhanden
  82.         $freigabe null;
  83.         if ($userId == 0) {
  84.             if ($this->getUser()?->getFirmenprofil()?->getMitarbeiterInternMenuFreigabe() != null) {
  85.                 $freigabe json_decode($this->getUser()->getFirmenprofil()->getMitarbeiterInternMenuFreigabe(), true);
  86.             }
  87.         } else {
  88.             $user $this->userRepository->findOneBy(['id' => $userId]);
  89.             if ($user?->getFirmenProfil()?->getMitarbeiterInternMenuFreigabe() != null) {
  90.                 $freigabe json_decode($user->getFirmenprofil()->getMitarbeiterInternMenuFreigabe(), true);
  91.             }
  92.         }
  93.         if ($freigabe != null) {
  94.             if (isset($freigabe['lable_news']) && strlen($freigabe['lable_news']) > 2) {
  95.                 $lable['news'] = $freigabe['lable_news'];
  96.             }
  97.             if (isset($freigabe['lable_events']) && strlen($freigabe['lable_events']) > 2) {
  98.                 $lable['events'] = $freigabe['lable_events'];
  99.             }
  100.             if (isset($freigabe['lable_umfragen']) && strlen($freigabe['lable_umfragen']) > 2) {
  101.                 $lable['umfragen'] = $freigabe['lable_umfragen'];
  102.             }
  103.             if (isset($freigabe['lable_dokumente']) && strlen($freigabe['lable_dokumente']) > 2) {
  104.                 $lable['dokumente'] = $freigabe['lable_dokumente'];
  105.             }
  106.             if (isset($freigabe['lable_dateien']) && strlen($freigabe['lable_dateien']) > 2) {
  107.                 $lable['dateien'] = $freigabe['lable_dateien'];
  108.             }
  109.             if (isset($freigabe['lable_notdienstkalender']) && strlen($freigabe['lable_notdienstkalender']) > 2) {
  110.                 $lable['notdienstkalender'] = $freigabe['lable_notdienstkalender'];
  111.             }
  112.             if (isset($freigabe['lable_mitarbeiter']) && strlen($freigabe['lable_mitarbeiter']) > 2) {
  113.                 $lable['mitarbeiter'] = $freigabe['lable_mitarbeiter'];
  114.             }
  115.             if (isset($freigabe['lable_direktChat']) && strlen($freigabe['lable_direktChat']) > 2) {
  116.                 $lable['direktChat'] = $freigabe['lable_direktChat'];
  117.             }
  118.             if (isset($freigabe['lable_gruppenChat']) && strlen($freigabe['lable_gruppenChat']) > 2) {
  119.                 $lable['gruppenChat'] = $freigabe['lable_gruppenChat'];
  120.             }
  121.         }
  122.         return $lable;
  123.     }
  124.     public function getUserBC_Chateintrag2($chatId$neuerTag$projektgruppe null)
  125.     {
  126.         $chatNachricht $this->chatRepository->findOneBy(['id' => $chatId]);
  127.         $user $this->userRepository->findOneBy(['id' => $chatNachricht->getUserId()]);
  128.         $profilBild $user->getUserProfil()->getProfilbild();
  129.         if ($profilBild != null) {
  130.             $profilBildLink $this->generateUrl('admin_user_profilbild', ['id' => $chatNachricht->getUserId()]) . '?v=' $profilBild;
  131.         } else {
  132.             $profilBildLink $this->generateUrl('admin_user_profilbild', ['id' => 0]);
  133.         }
  134.         $strNachricht '';
  135.         if ($neuerTag != null) {
  136.             $strNachricht '<div class="col-12 border-bottom mt-4 mb-3 small"><b>' $neuerTag '</b></div>';
  137.         }
  138.         $odd '';
  139.         $zeitFarbe '';
  140.         $haken '';
  141.         if ($this->getUser()->getId() == $chatNachricht->getUserId()) {
  142.             $odd ' odd';
  143.             if ($chatNachricht->getGruppe() == null) {
  144.                 if ($chatNachricht->getGelesen() == 0) {
  145.                     $zeitFarbe 'ms-2 chat-haken text-muted opacity-50';
  146.                     $haken '<span class="mdi mdi-check-all"></span>';
  147.                 }
  148.                 if ($chatNachricht->getGelesen() == 1) {
  149.                     $zeitFarbe 'ms-2 chat-haken text-success';
  150.                     $haken '<span class="mdi mdi-check-all"></span>';
  151.                 }
  152.             }
  153.         }
  154.         $bildHTML '';
  155.         if ($chatNachricht->getDateiname() != null) {
  156.             $bildGrosseStyle '';
  157.             if ($chatNachricht->getBildHoehe() != null && $chatNachricht->getBildBreite() != null) {
  158.                 $bildGrosseStyle ' height="' $chatNachricht->getBildHoehe() . '" width="' $chatNachricht->getBildBreite() . '"';
  159.             }
  160.             if ($projektgruppe != null) {
  161.                 $bildHTML '<img src="/user/firma/gruppenchat/upload_datei/ansehen/' $chatNachricht->getDateiname() . '" class="img-fluid chat-image mt-2 mb-2" loading="lazy" ' $bildGrosseStyle '>';
  162.             } else {
  163.                 $bildHTML '<img src="/user/firma/chat/upload_datei/ansehen/' $chatId '" class="img-fluid chat-image mt-2 mb-2" loading="lazy" ' $bildGrosseStyle '>';
  164.             }
  165.         }
  166.         $nachricht htmlspecialchars($chatNachricht->getNachricht());
  167.         $linkNachricht '';
  168.         foreach ($chatNachricht->getLinks() as $link) {
  169.             $linkeingabe $link->getLink();
  170.             $nachricht str_replace($linkeingabe'<a href="' $linkeingabe '" target="_blank" class="text-accent" style="word-break:break-all;">' $linkeingabe '</a>'$nachricht);
  171.             //$nachricht = str_replace($linkeingabe, 'LINK', $nachricht);
  172.             $linkNachricht .= '<div class="card mt-1"><div class="card-body p-2 text-start">';
  173.             if ($link->getTyp() == 0) {
  174.                 $linkNachricht .= '<a href="' $linkeingabe .'" target="_blank" class="text-dark">';
  175.                 $imgDiv '';
  176.                 if($link->getBildUrl() != null) {
  177.                     $imgDiv '<div class="mt-1 mb-1"><img class="img-fluid" src="' $link->getBildUrl() . '"/></div>';
  178.                 }
  179.                 $beschreibungDiv '';
  180.                 if($link->getBeschreibung() != null) {
  181.                     $beschreibungDiv '<div>' $link->getBeschreibung() . '</div>';
  182.                 }
  183.                 $linkNachricht .= '<div class="fs-6">' $link->getTitle() . '</div>' $imgDiv $beschreibungDiv;
  184.                 $linkNachricht .= '</a>';
  185.             }
  186.             if ($link->getTyp() == 1) {
  187.                 $linkNachricht .= '<div><a href="' $linkeingabe .'" target="_blank"><img class="img-fluid" src="' $linkeingabe '"/></a></div>';
  188.             }
  189.             if ($link->getTyp() == 2) {
  190.                 if (!str_contains($linkeingabe'/embed/')) {
  191.                     $splitBildUrl explode('/'$link->getBildUrl());
  192.                     $youtubeId $splitBildUrl[count($splitBildUrl) - 2];
  193.                     if (str_starts_with($linkeingabe'https://www.youtube.com/')) {
  194.                         $linkeingabe 'https://www.youtube.com//embed/' $youtubeId;
  195.                     }
  196.                     if (str_starts_with($linkeingabe'https://youtube.com')) {
  197.                         $linkeingabe 'https://youtube.com/embed/' $youtubeId;
  198.                     }
  199.                     if (str_starts_with($linkeingabe'https://www.youtube.de')) {
  200.                         $linkeingabe 'https://www.youtube.de/embed/' $youtubeId;
  201.                     }
  202.                     if (str_starts_with($linkeingabe'https://youtube.de')) {
  203.                         $linkeingabe 'https://youtube.de/embed/' $youtubeId;
  204.                     }
  205.                     if (str_starts_with($linkeingabe'https://youtu.be/')) {
  206.                         $linkeingabe 'https://www.youtube.com/embed/' $youtubeId;
  207.                     }
  208.                 }
  209.                 $linkNachricht .= '<div class="fs-6">' $link->getTitle() . '</div>
  210.                                         <div class="mt-1 mb-1">
  211.                                             <div class="videolink-video ratio ratio-16x9">
  212.                                                 <iframe class="video-iframe" src="' $linkeingabe '" title="Video" allowfullscreen></iframe>
  213.                                             </div>
  214.                                         </div>
  215.                                    <div>' $link->getBeschreibung() . '</div>
  216.                                    ';
  217.             }
  218.             $linkNachricht .= '</div></div>';
  219.         }
  220.         //$linkNachricht = '';
  221.         $strNachricht .= '<li class="clearfix' $odd ' chat-li" data-chat-id="' $chatId '">
  222.                     <div class="chat-avatar"><img src="' $profilBildLink '" class="rounded-circle" alt="Profilbild"><i>' $chatNachricht->getGesendetAm()->format('H:i') . '</i></div>
  223.                     <div class="conversation-text"><div class="ctext-wrap"><i>' $user->getUserProfil()->getVorname() . ' ' $user->getUserProfil()->getNachname() . '<span class="' $zeitFarbe '">' $haken '</span></i>
  224.                     ' $bildHTML '
  225.                     <p>' $nachricht '</p>' $linkNachricht '</div></div></li>';
  226.         return $strNachricht;
  227.     }
  228.     public function getUserBC_script_bildupload(): array
  229.     {
  230.         $uploadTemplateScript '<script id="template-upload" type="text/x-tmpl">
  231.                                   {% for (var i=0, file; file=o.files[i]; i++) { %}
  232.                                       <tr class="template-upload fade{%=o.options.loadImageFileTypes.test(file.type)?\' image\':\'\'%}">
  233.                                           <td>
  234.                                               <div>
  235.                                                 <span class="preview"></span>
  236.                                               </div>
  237.                                               <div>
  238.                                                   <p class="name">{%=file.name%}</p>
  239.                                                   <strong class="error text-danger"></strong>
  240.                                               </div>
  241.                                      
  242.                                               <div>
  243.                                                   <p class="size">Upload...</p>
  244.                                                   <div class="progress progress-striped active bg-white" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
  245.                                                     <div class="progress-bar progress-bar-success" style="width:0%;"></div>
  246.                                                   </div>
  247.                                               </div>
  248.                                                <div>
  249.                                                      {% if (!o.options.autoUpload && o.options.edit && o.options.loadImageFileTypes.test(file.type)) { %}
  250.                                                         <button class="btn btn-sm btn-success edit" data-index="{%=i%}" disabled>
  251.                                                             <i class="glyphicon glyphicon-edit"></i>
  252.                                                             <span>Edit</span>
  253.                                                         </button>
  254.                                                       {% } %}
  255.                                                       {% if (!i && !o.options.autoUpload) { %}
  256.                                                           <button class="btn btn-sm btn-info start me-3" disabled>
  257.                                                               <i class="glyphicon glyphicon-upload"></i>
  258.                                                               <span>Upload starten</span>
  259.                                                           </button>
  260.                                                       {% } %}
  261.                                                       {% if (!i) { %}
  262.                                                           <button class="btn btn-sm btn-danger cancel">
  263.                                                               <i class="glyphicon glyphicon-ban-circle"></i>
  264.                                                               <span>Abbrechen</span>
  265.                                                           </button>
  266.                                                       {% } %}
  267.                                               </div>
  268.                                           </td>
  269.                                       </tr>
  270.                                   {% } %}
  271.                                 </script>';
  272.         $downloadTemplateScript '<script id="template-download" type="text/x-tmpl">
  273.                                       {% for (var i=0, file; file=o.files[i]; i++) { %}
  274.                                           <tr class="template-download fade{%=file.thumbnailUrl?\' image\':\'\'%}">
  275.                                               <td>
  276.                                                   <span class="preview">
  277.                                                       {% if (file.thumbnailUrl) { %}
  278.                                                           <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
  279.                                                       {% } %}
  280.                                                   </span>
  281.                                               </td>
  282.                                               <td>
  283.                                                   <p class="name">
  284.                                                       {% if (file.url) { %}
  285.                                                           <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?\'data-gallery\':\'\'%}>{%=file.name%}</a>
  286.                                                       {% } else { %}
  287.                                                           <span>{%=file.name%}</span>
  288.                                                       {% } %}
  289.                                                   </p>
  290.                                                   {% if (file.error) { %}
  291.                                                       <div><span class="label label-danger">Error</span> {%=file.error%}</div>
  292.                                                   {% } %}
  293.                                               </td>
  294.                                               <td>
  295.                                                   <span class="size">{%=o.formatFileSize(file.size)%}</span>
  296.                                               </td>
  297.                                               <td>
  298.                                                   {% if (file.deleteUrl) { %}
  299.                                                       <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields=\'{"withCredentials":true}\'{% } %}>
  300.                                                           <i class="glyphicon glyphicon-trash"></i>
  301.                                                           <span>Delete</span>
  302.                                                       </button>
  303.                                                       <input type="checkbox" name="delete" value="1" class="toggle">
  304.                                                   {% } else { %}
  305.                                                       <button class="btn btn-warning cancel">
  306.                                                           <i class="glyphicon glyphicon-ban-circle"></i>
  307.                                                           <span>Cancel</span>
  308.                                                       </button>
  309.                                                   {% } %}
  310.                                               </td>
  311.                                           </tr>
  312.                                       {% } %}
  313.                                     </script>';
  314.         $arrayScript = [$uploadTemplateScript$downloadTemplateScript];
  315.         return $arrayScript;
  316.     }
  317. }