src/Service/Kernel/KernelService.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Service\Kernel;
  3. use App\Entity\Kernel\DocumentTemplate;
  4. use App\Entity\Kernel\DocumentTemplateGroup;
  5. use App\Entity\Kernel\TemplateType;
  6. use App\Entity\Kernel\User;
  7. use App\Entity\Kernel\Organization;
  8. use App\Entity\Kernel\ConfigurableList;
  9. use App\Entity\Kernel\ListItem;
  10. use Cassandra\Set;
  11. use Doctrine\Persistence\ObjectManager;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Exception;
  14. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  15. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  16. use Symfony\Component\Security\Core\Security;
  17. use App\Entity\Kernel\SecurityAction;
  18. use App\Entity\Kernel\UserLog;
  19. use App\Entity\Kernel\Setting;
  20. use Symfony\Component\HttpKernel\KernelInterface;
  21. use App\Entity\Kernel\BatchJob;
  22. use App\Entity\Kernel\Widget;
  23. use DateInterval;
  24. class KernelService {
  25.     private $entityManager;
  26.     public function __construct(EntityManagerInterface $entityManager) {
  27.         $this->entityManager $entityManager;
  28.     }
  29.     public function getApplicationInfoValue($key$organization null) {
  30.         try {
  31.             $setting $this->entityManager->getRepository(Setting::class)->findOneBy(array('identifier' => $key'organization' => $organization));
  32.             if (!$setting) {
  33.                 $setting $this->entityManager->getRepository(Setting::class)->findOneByIdentifier($key);
  34.                 if (!$setting) {
  35.                     return "";
  36.                 }
  37.             }
  38.             return $setting->getValue();
  39.         } catch (Exception $e) {
  40.             return "";
  41.         }
  42.     }
  43.     public function getApplicationInfoFile($key) {
  44.         $setting $this->entityManager->getRepository(Setting::class)->findOneByIdentifier($key);
  45.         return $setting->getFileValue();
  46.     }
  47.     /**
  48.      * @param $list
  49.      * @param $organization
  50.      * @return ConfigurableList|null
  51.      */
  52.     public function getList($list$organization null): ?ConfigurableList {
  53.         if ($organization == null)
  54.         {
  55.             $weblist $this->entityManager->getRepository(ConfigurableList::class)->findOneBy(array('identifier' => $list'state' => 0));
  56.         }
  57.         else
  58.         {
  59.             $query $this->entityManager
  60.                 ->createQuery("SELECT s FROM App\Entity\Kernel\ConfigurableList s 
  61.                 WHERE (((s.state = 0) AND (s.identifier = ?1)) AND ((s.organization = ?2) or (s.organization is null)))");
  62.             $query $query->setParameter(1$list);
  63.             $query $query->setParameter(2$organization->getId());
  64.             $weblists $query->getResult();
  65.             if ($weblists) {
  66.                 $weblist $weblists[0];
  67.             }
  68.             else
  69.             {
  70.                 $weblist null;
  71.             }
  72.         }
  73.         if (!$weblist) {
  74.             return null;
  75.         } else {
  76.             return $weblist;
  77.         }
  78.     }
  79.     /**
  80.      * @param string $list
  81.      * @param string $item
  82.      * @param $organization
  83.      * @return ListItem|null
  84.      */
  85.     public function getListItem(string $liststring $item$organization null) {
  86.         $weblist $this->getList($list$organization);
  87.         if (!$weblist) {
  88.             return null;
  89.         } else {
  90.             return $this->entityManager->getRepository(ListItem::class)
  91.                 ->findOneBy(array('configurablelist' => $weblist'name' => $item'state' => 0));
  92.         }
  93.     }
  94.     public function getSetting(string $settindIdentifier) : Setting{
  95.         return $this->entityManager->getRepository(Setting::class)
  96.             ->findOneBy(array('identifier' => $settindIdentifier'state' => 0));
  97.     }
  98.     /**
  99.      * @param string $name
  100.      * @param string $identifier
  101.      * @param $integer1
  102.      * @param $string1
  103.      * @param $string2
  104.      * @param $authorizationtype
  105.      * @param int $state
  106.      * @return ConfigurableList|mixed
  107.      */
  108.     public function createList(
  109.         string $name,
  110.         string $identifier,
  111.         $integer1,
  112.         $string1,
  113.         $string2,
  114.         $authorizationtype,
  115.         int $state
  116.     ) {
  117.         $list $this->entityManager->getRepository(ConfigurableList::class)->findOneByIdentifier($identifier);
  118.         if (!$list) {
  119.             $list = new ConfigurableList();
  120.             $list->setName($name);
  121.             $list->setIdentifier($identifier);
  122.             $list->setInteger1($integer1);
  123.             $list->setString1($string1);
  124.             $list->setString2($string2);
  125.             $list->setAuthorizationtype($authorizationtype);
  126.             $list->setState($state);
  127.         }
  128.         return $list;
  129.     }
  130.     /**
  131.      * @param $object
  132.      * @return void
  133.      */
  134.     public function persistAndFlush($object)
  135.     {
  136.         $this->entityManager->persist($object);
  137.         $this->entityManager->flush();
  138.     }
  139.     /**
  140.      * @param ConfigurableList $list
  141.      * @param string $name
  142.      * @return ListItem
  143.      */
  144.     public function addToConfigurableList(ConfigurableList $liststring $name) : ListItem
  145.     {
  146.         $listitem $this->entityManager->getRepository(ListItem::class)->findOneBy(
  147.             array('name' => $name'configurablelist' => $list'state' => 0)
  148.         );
  149.         if (!$listitem) {
  150.             $listitem = new ListItem();
  151.             $listitem->setConfigurablelist($list);
  152.             $listitem->setName($name);
  153.             $listitem->setState(0);
  154.         }
  155.         return $listitem;
  156.     }
  157.     /**
  158.      * @param ConfigurableList $list
  159.      * @param string $name
  160.      * @return ListItem
  161.      */
  162.     public function addValueTypeToList(ConfigurableList $liststring $name) : ListItem
  163.     {
  164.         $listitem $this->addToConfigurableList($list$name);
  165.         $this->persistAndFlush($listitem);
  166.         return $listitem;
  167.     }
  168.     /**
  169.      * @param string $name
  170.      * @param string $indentifier
  171.      * @param bool $organizationSpecific
  172.      * @param int $state
  173.      * @param string $type
  174.      * @param $authorizationtype
  175.      * @param $fileValue
  176.      * @return Setting
  177.      */
  178.     public function createSetting(
  179.         string $name,
  180.         string $indentifier,
  181.         bool $organizationSpecific,
  182.         int $state,
  183.         string $type,
  184.         $authorizationtype,
  185.         $fileValue
  186.     ) {
  187.         $setting $this->entityManager->getRepository(Setting::class)->findOneByIdentifier($indentifier);
  188.         if (!$setting) {
  189.             $setting = new Setting();
  190.             $setting->setName($name);
  191.             $setting->setIdentifier($indentifier);
  192.             $setting->setOrganizationSpecific($organizationSpecific);
  193.             $setting->setState($state);
  194.             $setting->setType($type);
  195.             $setting->setFileValue($fileValue);
  196.             $setting->setAuthorizationtype($authorizationtype);
  197.         }
  198.         return $setting;
  199.     }
  200.     public function createTemplateType(string $name,string $functionalArea,string $description,bool $parentNeeded,bool $isParent,string $stringPart1 ,string $part1){
  201.         $templateType $this->entityManager->getRepository(TemplateType::class)->findOneByName(
  202.             $name
  203.         );
  204.         if (!$templateType) {
  205.             $templateType = new TemplateType();
  206.             $templateType->setName($name);
  207.             $templateType->setFunctionalArea($functionalArea);
  208.             $templateType->setParameterDescription($description);
  209.             $templateType->setParentNeeded($parentNeeded);
  210.             $templateType->setIsParent($isParent);
  211.             $templateType->setStringPart1($stringPart1);
  212.             $templateType->setPart1($part1);
  213.             $templateType->setState(0);
  214.             $this->persistAndFlush($templateType);
  215.         }
  216.         return $templateType;
  217.     }
  218.     public function createDocumentTemplate($documentTemplateGroup,TemplateType $type,string $stringPart1,string $part1){
  219.         
  220.         
  221.         $documentTemplate $this->entityManager->getRepository(DocumentTemplate::class)->findOneBy(
  222.             array('documenttemplategroup' => $documentTemplateGroup'type' => $type)
  223.         );
  224.         if (!$documentTemplate) {
  225.             $documentTemplate = new DocumentTemplate();
  226.         }
  227.         
  228.         $documentTemplate->setDocumenttemplategroup($documentTemplateGroup);
  229.         $documentTemplate->setType($type);
  230.         $documentTemplate->setState(0);
  231.         $documentTemplate->setStringPart1(
  232.             $stringPart1
  233.         );
  234.         $documentTemplate->setPart1(
  235.             $part1
  236.         );
  237.         $this->persistAndFlush($documentTemplate);
  238.         return $documentTemplate;
  239.     }
  240.     public function createDocumentTemplateGroup(string $name){
  241.         $documentTemplateGroup $this->entityManager->getRepository(DocumentTemplateGroup::class)->findOneByName($name);
  242.         if (!$documentTemplateGroup) {
  243.             $documentTemplateGroup = new DocumentTemplateGroup();
  244.             $documentTemplateGroup->setName($name);
  245.             $documentTemplateGroup->setState(0);
  246.             $this->persistAndFlush($documentTemplateGroup);
  247.         }
  248.         return $documentTemplateGroup;
  249.     }
  250.     public function CreateBatchjob($type$enabled$minute$hour$dayOfMonth$month$dayOfWeek$authorizationtype$organization)
  251.     {
  252.         $batchjobType $this->entityManager->getRepository(ListItem::class)->findOneByName($type); 
  253.       
  254.         $minuteList $this->getListItem("Kernel.Minute"$minute);
  255.         $hourList $this->getListItem("Kernel.Hour"$hour);
  256.         $dayOfMonthList $this->getListItem("Kernel.DayOfMonth"$dayOfMonth);
  257.         $monthList $this->getListItem("Kernel.Month"$month);
  258.         $dayOfWeekList $this->getListItem("Kernel.DayOfWeek"$dayOfWeek);
  259.      
  260.         $batchjob $this->entityManager->getRepository(BatchJob::class)->findOneBy(
  261.             array('type' => $batchjobType'organization' => $organization));
  262.         if(!$batchjob){
  263.             $batchjob = new BatchJob();
  264.         }
  265.         $batchjob->setType$batchjobType );
  266.         $batchjob->setEnabled($enabled);
  267.         $batchjob->addMinute$minuteList );
  268.         $batchjob->addHour($hourList);
  269.         $batchjob->addDayOfMonth($dayOfMonthList);
  270.         $batchjob->addMonth($monthList);
  271.         $batchjob->addDayOfWeek($dayOfWeekList);
  272.         
  273.         $batchjob->setAuthorizationtype($authorizationtype);
  274.         $batchjob->setOrganization($organization);
  275.         
  276.         $batchjob->setState(0);
  277.         $this->entityManager->persist($batchjob);
  278.         $this->entityManager->flush();
  279.         
  280.         return $batchjob;
  281.     }
  282.     
  283.     public function getBatchjob($type)
  284.     {
  285.         return $this->entityManager->getRepository(BatchJob::class)->findOneBy(['type' => $type]);
  286.     }
  287.     
  288.     public function createConfigurableList($identifier$name$string1$string2$boolean1$boolean2$integer1$integer2$float1$float2$text1$text2$list1$list2$list1List$list2List$authorizationtype$organization ) {
  289.         
  290.         $configurableList $this->entityManager->getRepository(ConfigurableList::class)->findOneBy(array('identifier' => $identifier'state' => 0));
  291.         
  292.         if (!$configurableList) {
  293.             $configurableList = new ConfigurableList();
  294.         }
  295.             $configurableList->setIdentifier($identifier);
  296.             $configurableList->setName($name);
  297.             $configurableList->setString1($string1);
  298.             $configurableList->setString2($string2);
  299.             $configurableList->setBoolean1($boolean1);
  300.             $configurableList->setBoolean2($boolean2);
  301.             $configurableList->setInteger1($integer1);
  302.             $configurableList->setInteger2($integer2);
  303.             $configurableList->setFloat1($float1);
  304.             $configurableList->setFloat2($float2);
  305.             $configurableList->setText1($text1);
  306.             $configurableList->setText2($text2);
  307.             $configurableList->setList1($list1);
  308.             $configurableList->setList2($list2);
  309.             $configurableList->setList1List($list1List);
  310.             $configurableList->setList2List($list2List);
  311.             $configurableList->setState(0);
  312.             $configurableList->setOrganization($organization);
  313.             $configurableList->setAuthorizationtype($authorizationtype);
  314.             
  315.             $this->entityManager->persist($configurableList);
  316.             $this->entityManager->flush();
  317.         return $configurableList;
  318.     }
  319.      
  320.     public function CreateWidget(
  321.             $TypeName,
  322.             $name,
  323.             $string1,
  324.             $boolean1,
  325.             $boolean2,
  326.             $boolean3,
  327.             $list1,
  328.             $list1list
  329.     ){
  330.         $ConfigurableList $this->entityManager->getRepository(ConfigurableList::class)->findOneBy(['identifier' => "Kernel.ScreenConfigurationType"]);
  331.         $type $this->entityManager->getRepository(ListItem::class)->findOneBy(
  332.             array('name' => $TypeName'configurablelist' => $ConfigurableList'state' => 0)
  333.         );
  334.            
  335.         $widget $this->entityManager->getRepository(Widget::class)->findOneBy(
  336.             array('name' => $name'type' => $type'state' => 0)
  337.         );
  338.         if (!$widget) {
  339.             $widget = new Widget();
  340.         }    
  341.             $widget->setState(0);
  342.             $widget->setName($name);
  343.             $widget->setType($type);
  344.             $widget->setString1($string1);
  345.             $widget->setBoolean1($boolean1);
  346.             $widget->setBoolean2($boolean2);
  347.             $widget->setBoolean3($boolean3);
  348.             $widget->setList1($list1);
  349.             $widget->setList1List($list1list);
  350.             
  351.             $this->entityManager->persist($widget);
  352.             $this->entityManager->flush();
  353.         
  354.         return $widget;
  355.     }
  356.     public function archiveListItems(ConfigurableList $list){
  357.             foreach ($list->getListitems() as $item){
  358.                 $item->setState(1);
  359.             }
  360.             $this->persistAndFlush($list);
  361.             return $list;
  362.     }
  363.     public function getWidget($name){
  364.         return $this->entityManager->getRepository(Widget::class)->findOneBy(
  365.             array('name' => $name'state' => 0)
  366.         );
  367.     }
  368.     /**
  369.      * @throws Exception
  370.      */
  371.     public function stringToDateTimeInterval(string $durationString):\DateInterval
  372.     {
  373.         $vals explode(':'$durationString);
  374.         if(sizeof($vals) > && strlen($vals[1]) < ){
  375.             $vals[1] = (int)$vals[1]*10;
  376.         }
  377.         if(count($vals) == 2){
  378.             $result 'PT' $vals[0] . 'H' $vals[1] . 'M';
  379.         }else{
  380.             $result 'PT' $vals[0] . 'H';
  381.         }
  382.         return new DateInterval($result);
  383.     }
  384. }