vendor\project-biz\puli-bundle\src\Controller\MpmController.php line 2428

Open in your IDE?
  1. <?php
  2. namespace ProjectBiz\CitiBizBundle\Controller;
  3. use ProjectBiz\CitiBizBundle\Form\Type\KostenberechnungType;
  4. use ProjectBiz\CitiBizBundle\Messages\Controller\OverviewController as BundleMessages;
  5. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaComparison;
  6. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaComposite;
  7. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaConstant;
  8. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaMappedColumn;
  9. use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaUnmappedColumn;
  10. use ProjectBiz\FormBundle\Form\Type\GenericTableType;
  11. use ProjectBiz\PortalBundle\Controller\ControllerInterfaces\UnifiedOptionsConsumerInterface;
  12. use ProjectBiz\PortalBundle\Controller\ControllerTraits\HasOptionsResolverTrait;
  13. use ProjectBiz\PortalBundle\Controller\FormViewController;
  14. use ProjectBiz\PortalBundle\Controller\TableController;
  15. use ProjectBiz\PortalBundle\Exceptions\PortalException;
  16. use ProjectBiz\PortalBundle\Portal\Messages;
  17. use Symfony\Component\Form\Extension\Core\Type\FormType;
  18. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  19. use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
  20. use ProjectBiz\PortalBundle\Exceptions\UnaccessibleObjectException;
  21. use Symfony\Component\HttpFoundation\RedirectResponse;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  25. use Symfony\Component\OptionsResolver\OptionsResolver;
  26. use ProjectBiz\PortalBundle\Controller\ControllerTraits\DataInjectionTrait;
  27. use ProjectBiz\DatabaseBundle\Database\GenericRepository;
  28. class MpmController extends TableController implements UnifiedOptionsConsumerInterface
  29. {
  30.     private $unifiedOptions;
  31.     private $cachedPriceGroups;
  32.     use HasOptionsResolverTrait;
  33.     use DataInjectionTrait;
  34.     const MSG_DELETE 'Löschen';
  35.     const MSG_ARCHIVE 'Archivieren';
  36.     const MSG_CANCEL 'Abbrechen';
  37.     const MSG_DELETE_CANCELLED 'Löschen des Projekts abgebrochen.';
  38.     const MSG_DELETE_SUCCESS 'Projekt erfolgreich gelöscht.';
  39.     const MSG_DELETE_ERROR 'Fehler beim Löschen des Projekts.';
  40.     const MSG_ARCHIVE_CANCELLED 'Archivieren des Projekts abgebrochen.';
  41.     const MSG_ARCHIVE_SUCCESS 'Projekt erfolgreich archiviert.';
  42.     const MSG_ARCHIVE_ERROR 'Fehler beim Archivieren des Projekts.';
  43.     const MSG_PRICEGROUP_ERROR 'Fehler beim Berechnen der Kostengruppen';
  44.     const MSG_PRICEGROUP_SUCCESS 'Berechnung der Kostengruppen erfolgreich';
  45.     const MSG_MPM_MISSING 'Fehlendes MPM';
  46.     const MSG_YELLOWSHEET_SUCCESS 'Berechnung der gelben Zettel erfolgreich';
  47.     const MSG_MPM_PERMISSION_DENIED 'Der Zugriff auf dieses Objekt wurde verweigert.';
  48.     const MSG_PREFIX_EMPTY 'Bitten wählen Sie ein Präfix für das Projekt.';
  49.     const MSG_ERROR_PROJECT_NUMBER 'Bitte geben Sie eine gültige Projektnummer an.';
  50.     private $options = [];
  51.     /**
  52.      * @param Request $request
  53.      * @param           $id
  54.      *
  55.      * @return mixed
  56.      */
  57.     public function edit(Request $requestGenericRepository $repo$id null$targetName 'overview_edit'$targetOptions = [], $breadcrumbKey 'MPM_Projectname')
  58.     {
  59.         return parent::edit($request$this->getMpmRepository(), $id$targetName$targetOptions$breadcrumbKey);
  60.     }
  61.     protected function getMpmRepository($options null)
  62.     {
  63.         return $this->getGenericRepository('MPM'$options);
  64.     }
  65.     /**
  66.      * @param Request $request
  67.      * @param           $id
  68.      * @param           $form
  69.      *
  70.      * @return mixed
  71.      */
  72.     public function formEdit(Request $request$id null$form null)
  73.     {
  74.         if (null === $form) {
  75.             throw new PortalException(BundleMessages::msgMissingForm);
  76.         }
  77.         $resolvedOptions $this->getOptionsResolver()->resolve(
  78.             $this->filterOptionsForOptionResolver(
  79.                     $request->attributes->get('_unified_options')
  80.             )
  81.         );
  82.         $key 'MPM_ID';
  83.         /** @var \ProjectBiz\PortalBundle\Service\FormHelper $formHelper */
  84.         $formHelper $this->get('citibiz.form_helper');
  85.         $formDesc $formHelper->getFormDesc(
  86.             $form,
  87.             $this->getSecurityContextWrapper()
  88.                 ->getUserRights()
  89.         );
  90.         $this->setDebugInfo('form'$formDesc['formname'] . " (id: {$formDesc['id']})");
  91.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  92.         // @todo: IMPORTANT check if this does not corrupt access protection
  93.         $sourceRepo $formHelper->getFormSourceRepo($formDesc); // Tab_MPM
  94.         $targetRepo $formHelper->getFormTargetRepo($formDesc); // Tab_MPM
  95.         $criteria = new CriteriaComparison("=", new CriteriaMappedColumn($key), new CriteriaConstant($id));
  96.         $tableMenuContext $this
  97.             ->get('projectbiz.menu.menu_helper')
  98.             ->beginMenuContext(array(), 'MPM_ID');
  99.         if (!$this->hasPermission($sourceRepo$id)) {
  100.             throw new \Symfony\Component\Security\Core\Exception\AccessDeniedException(self::MSG_MPM_PERMISSION_DENIED);
  101.         }
  102.         $data $sourceRepo->findOneBy($criteria$formLayout['data_columns']);
  103.         if (false == $data) {
  104.             $data $sourceRepo->defaultObject();
  105.             $new_entry true;
  106.         } else {
  107.             $new_entry false;
  108.         }
  109.         if (isset($resolvedOptions['data_injection'])) {
  110.             $data $this->dataInjection($request$data$resolvedOptions['data_injection']);
  111.         }
  112.         $htmlForm $this->createForm(
  113.             GenericTableType::class,
  114.             $data,
  115.             array('repo' => $sourceRepo'columns' => $formLayout['form_columns'])
  116.         );
  117.         $htmlForm->handleRequest($request);
  118.         if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  119.             /* @todo:   maybe add some exception-handling too; know, when no changes
  120.              *          were found and thus the object was not saved.
  121.              */
  122.             $formData $htmlForm->getData();
  123.             $this->handlePricelistEntries($formData);
  124.             $saveAs = ($formData['submitAction'] == 'saveAs');
  125.             unset($formData['save_as']);
  126.             $userRight $this->getSecurityContextWrapper()->getUserRights();
  127.             if(isset($formData['MPM_LINK_Stadt_Budget_Assignment']) && $formData['MPM_LINK_Stadt_Budget_Assignment']){
  128.                 $stadtBudgetRepo $this->getGenericRepository('Stadt_Budget_Assignment'null);
  129.                 $ngdBudgetID $stadtBudgetRepo->findOneBy(
  130.                     new CriteriaComparison(
  131.                         '=',
  132.                         new CriteriaUnmappedColumn('Stadt_Budget_Assignment_ID'),
  133.                         new CriteriaConstant($formData['MPM_LINK_Stadt_Budget_Assignment'])
  134.                     )
  135.                 )['Stadt_Budget_Assignment_LINK_Budget_ID'];
  136.                 if($ngdBudgetID){
  137.                         $formData['MPM_Info_04'] = $ngdBudgetID;
  138.                 }
  139.             }
  140.             if ($saveAs && !$new_entry) {
  141.                 try {
  142.                     $ancestorId $data['MPM_LINK_Ancestor_ID'];
  143.                     $targetRepo->getConnection()->beginTransaction();
  144.                     if ($formData['MPM_LINK_SPM_VersionID'] !== null) {
  145.                         $formData['MPM_LINK_SPM_VersionID'] = 1;
  146.                     }
  147.                     if(isset($formData['MPM_Prefix_02'])){
  148.                         $newNumber $this->generateNumber($formData);
  149.                         $mpmRepo $this->getMpmRepository();
  150.                             $mpmExistingAI $mpmRepo->findOneBy(
  151.                                 new CriteriaComparison(
  152.                                     '=',
  153.                                     new CriteriaMappedColumn('MPM_ProjectNumber'),
  154.                                     new CriteriaConstant($formData['MPM_ProjectNumber'])
  155.                                 )
  156.                             );
  157.                             if($mpmExistingAI){
  158.                                     $aIncNumber $mpmExistingAI['MPM_AutoIncrement'];
  159.                             }else{
  160.                                     $aIncNumber $newNumber['MPM_AutoIncrement'];
  161.                             }
  162.                         $prefix $this->getPrefix($formData);
  163.                         $checkID $prefix $formData['MPM_Prefix_02'] .'-'$aIncNumber  $formData['MPM_Sufix_01'] . ' ' $formData['MPM_Sufix_02'] ;
  164.                         $checkID str_replace(' '''$checkID);
  165.                         $checkNr $this->checkNumber($checkID);
  166.                         if($checkNr){
  167.                             $newNumber $this->generateNumber($formData'add');
  168.                             $formData['MPM_ProjectNumber'] = $newNumber['number'];
  169.                             $formData['MPM_AutoIncrement'] = $newNumber['AutoIncrement'];
  170.                         }else{
  171.                             $string str_replace(' '''$checkID);
  172.                             $formData['MPM_ProjectNumber'] = $string;
  173.                         }
  174.                     }else{
  175.                         $number $sourceRepo->findOneBy(
  176.                             new CriteriaComparison(
  177.                                 '=',
  178.                                 new CriteriaMappedColumn('MPM_ProjectNumber'),
  179.                                 new CriteriaConstant($formData['MPM_ProjectNumber'])
  180.                             )
  181.                         );
  182.                         $formData['MPM_Prefix_01'] = $number['MPM_Prefix_01'];
  183.                         $formData['MPM_Prefix_02'] = $number['MPM_Prefix_02'];
  184.                         $newNumber $this->generateNumber($formData'add');
  185.                         if($number['MPM_AutoIncrement']!=''){
  186.                             $formData['MPM_ProjectNumber'] = $number['MPM_Prefix_01'].$number['MPM_Prefix_02'].'-'.$newNumber['AutoIncrement'].$number['MPM_Sufix_01'].$number['MPM_Sufix_02'];
  187.                         }else{
  188.                            $this->addFlashAndTrans('warning'Messages::msgMissingAutoIncrement);
  189.                         }
  190.                     }
  191.                     $duplicateMpmId $targetRepo->duplicate($formData[$targetRepo->getPrimaryKey()], $formData);
  192.                     $new_id $duplicateMpmId;
  193.                     $spmRepo $this->getSpmRepository();
  194.                     $spmCriteria = new CriteriaComposite(
  195.                         'and', array(
  196.                             new CriteriaComparison(
  197.                                 '=',
  198.                                 new CriteriaUnmappedColumn('SPM_LINK_MPM_Ancestor_ID'),
  199.                                 new CriteriaConstant($ancestorId)
  200.                             ),
  201.                             new CriteriaComparison(
  202.                                 '=',
  203.                                 new CriteriaUnmappedColumn('SPM_VersionID'),
  204.                                 new CriteriaConstant($data['MPM_LINK_SPM_VersionID'])
  205.                             ),
  206.                         )
  207.                     );
  208.                     $spmData $spmRepo->fetchAll($spmRepo->findBy($spmCriteria));
  209.                     foreach ($spmData as $spm) {
  210.                         $spm['SPM_LINK_MPM_Ancestor_ID'] = $duplicateMpmId;
  211.                         $spmRepo->duplicate($spm[$spmRepo->getPrimaryKey()], $spm);
  212.                     }
  213.                     $id $duplicateMpmId;
  214.                 } catch (\Exception $ex) {
  215.                     $targetRepo->getConnection()->rollBack();
  216.                     $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  217.                     return $this->redirect(
  218.                         $this->generateUrl(
  219.                             'overview_form',
  220.                             array(
  221.                                 'id' => $id,
  222.                                 'form' => $form,
  223.                             )
  224.                         )
  225.                     );
  226.                 }
  227.                 $targetRepo->getConnection()->commit();
  228.             } else if($new_entry) {
  229.                 if($formData['MPM_Prefix_01']){
  230.                     $staticSufix null;
  231.                     if($formData['MPM_LINK_Stadt_Workflow_ID']){
  232.                         $swRepo $this->getGenericRepository('Stadt_Workflow'null);
  233.                         $swID $formData['MPM_LINK_Stadt_Workflow_ID'];
  234.                         $shortcut $swRepo->findOneBy(
  235.                             new CriteriaComparison(
  236.                                 '=',
  237.                                 new CriteriaUnmappedColumn('Stadt_Workflow_ID'),
  238.                                 new CriteriaConstant($swID)
  239.                             )
  240.                         )['Stadt_Workflow_Shortcut'];
  241.                         if($shortcut){
  242.                             $formData['MPM_Sufix_01'] = $shortcut;
  243.                         }
  244.                     }
  245.                     $newNumber $this->generateNumber($formData'add');
  246.                     $formData['MPM_ProjectNumber'] = $newNumber['number'];
  247.                     $formData['MPM_AutoIncrement'] = $newNumber['AutoIncrement'];
  248.                     $formData['MPM_Prefix_01'] = $newNumber['Prefix_01'];
  249.                     $stat $newNumber['Status'];
  250.                     $new_id false;
  251.                     if ($stat){
  252.                         if($userRight == '512'){
  253.                             $formData['MPM_Workflow_Status_ID'] = '23';
  254.                         }
  255.                         try {
  256.                             $new_id $targetRepo->persist($formData);
  257.                         } catch (UnaccessibleObjectException $ex) {
  258.                             $this->addFlashAndTrans('danger'$ex->getMessage());
  259.                         }
  260.                     } else {
  261.                         $this->addFlashAndTrans('danger'self::MSG_ERROR_PROJECT_NUMBER);
  262.                     }
  263.                 }else{
  264.                     $this->addFlashAndTrans('danger'self::MSG_PREFIX_EMPTY);
  265.                     $new_id false;
  266.                 }
  267.             } else {
  268.                 $number $sourceRepo->findOneBy(
  269.                     new CriteriaComparison(
  270.                         '=',
  271.                         new CriteriaMappedColumn('MPM_ProjectNumber'),
  272.                         new CriteriaConstant($formData['MPM_ProjectNumber'])
  273.                     )
  274.                 );
  275.                 if($number['MPM_AutoIncrement'] != ''){
  276.                     if(isset($formData['MPM_Sufix_01']) || isset($formData['MPM_Sufix_02']) || isset($formData['MPM_Prefix_02'])){
  277.                         $newNeumber $this->generateNumber($formData);
  278.                         $mpmRepo $this->getMpmRepository();
  279.                             $mpmExistingAI $mpmRepo->findOneBy(
  280.                                 new CriteriaComparison(
  281.                                     '=',
  282.                                     new CriteriaMappedColumn('MPM_ProjectNumber'),
  283.                                     new CriteriaConstant($formData['MPM_ProjectNumber'])
  284.                                 )
  285.                             );
  286.                             if($mpmExistingAI){
  287.                                     $aIncNumber $mpmExistingAI['MPM_AutoIncrement'];
  288.                             }else{
  289.                                     $aIncNumber $newNeumber['MPM_AutoIncrement'];
  290.                             }
  291.                         $formData['MPM_ProjectNumber'] = $newNeumber['Prefix_01'].$formData['MPM_Prefix_02'].'-'.$aIncNumber.$formData['MPM_Sufix_01'].$formData['MPM_Sufix_02'];
  292.                     }
  293.                 }
  294.                 $new_id false;
  295.                 try {
  296.                     $new_id $targetRepo->persist($formData);
  297.                 } catch (UnaccessibleObjectException $ex) {
  298.                     $this->addFlashAndTrans('danger'$ex->getMessage());
  299.                 }
  300.             }
  301.             if ($new_id) {
  302.                 if ($new_entry) {
  303.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  304.                 } else {
  305.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  306.                 }
  307.                 if($userRight == '512'){
  308.                     return $this->redirect($this->generateUrl('overview_mpm_yellowsheet', ['id' => $new_id]));
  309.                 }
  310.                 return $this->redirect(
  311.                     $this->generateUrl(
  312.                         'overview_form',
  313.                         array(
  314.                             'id' => $new_id,
  315.                             'form' => $form,
  316.                         )
  317.                     )
  318.                 );
  319.             } else {
  320.                 if ($new_entry) {
  321.                     $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  322.                 } else {
  323.                     $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  324.                 }
  325.             }
  326.         } elseif ($htmlForm->isSubmitted()) {
  327.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  328.         }
  329.         $breadcrumbs = array(
  330.             array('label' => 'Overview'),
  331.         );
  332.         if ($new_entry) {
  333.             $breadcrumbs[] = array('label' => 'Erstellen');
  334.         } else {
  335.             $breadcrumbs[] = array('label' => $data['MPM_Projectname']);
  336.             $breadcrumbs[] = array('label' => 'Bearbeiten');
  337.         }
  338.         $hasDuplicationPermission false;
  339.         $securityContextWrapper $this->getSecurityContextWrapper();
  340.         // Only users with the role »Stadt« or admins are permitted to duplicate an MPM.
  341.         if ($securityContextWrapper->checkRights(515)) {
  342.             $hasDuplicationPermission true;
  343.         }
  344.         return $this->render('@ProjectBizCitiBiz/Mpm/formEdit.html.twig', [
  345.             'formname' => $formDesc['formname'],
  346.             'form_view' => new FormViewController(
  347.                 $sourceRepo,
  348.                 $formDesc['formname'],
  349.                 $formLayout['layout'],
  350.                 $data
  351.             ),
  352.             'id' => $id,
  353.             'overview' => $data,
  354.             'table_menu' => $tableMenuContext,
  355.             'form' => $htmlForm->createView(),
  356.             'is_new' => $new_entry,
  357.             'breadcrumbs' => $breadcrumbs,
  358.             'has_duplication_permission' => $hasDuplicationPermission,
  359.         ]);
  360.     }
  361.     /**
  362.      * Create one ÖB-Number
  363.      *
  364.      * @param $formData
  365.      * @param $flag
  366.      * @return array (number, Autoincrement, Status, Prefix_01)
  367.      */
  368.     private function generateNumber($formData$flag=null)
  369.     {
  370.         $newNumber '0';
  371.         $stat false;
  372.         $prefix $this->getPrefix($formData);
  373.         $exists false;
  374.         $AutoIncRepo $this->getGenericRepository('AutoIncrement');
  375.         $number $AutoIncRepo->findOneBy(
  376.             new CriteriaComposite(
  377.                 'AND',
  378.                 array(
  379.                     new CriteriaComparison(
  380.                         '=',
  381.                         new CriteriaMappedColumn('AutoIncrement_Prefix'),
  382.                         new CriteriaConstant($prefix)
  383.                     ),
  384.                     new CriteriaComparison(
  385.                         '=',
  386.                         new CriteriaMappedColumn('AutoIncrement_Year'),
  387.                         new CriteriaConstant($formData['MPM_Prefix_02'])
  388.                     )
  389.                 )
  390.             )
  391.         );
  392.         $autoIncId $number['AutoIncrement_ID'];
  393.         $number $number['AutoIncrement_Number'];
  394.         if($flag == 'add'){
  395.             $autoInc $AutoIncRepo->find($autoIncId);
  396.             $autoInc['AutoIncrement_Number']++;
  397.             $AutoIncRepo->persist($autoInc);
  398.             $number++;
  399.         }
  400.         $numberLen strlen($number);
  401.         if($numberLen 3){
  402.             for($a 0$a 3-$numberLen$a++){
  403.                 $number '0'.$number;
  404.             }
  405.         }
  406.         if(isset($formData['MPM_Prefix_02']) ){
  407.             $newNumber $prefix $formData['MPM_Prefix_02'] .'-'$number $formData['MPM_Sufix_01'] . ' ' $formData['MPM_Sufix_02'] ;
  408.             $exists $this->checkNumber($newNumber);
  409.             if(!$exists){
  410.                $stat true;
  411.             }
  412.         }
  413.         $newNumber str_replace(' '''$newNumber);
  414.         $number str_replace(' '''$number);
  415.         $prefix str_replace(' '''$prefix);
  416.         return array(
  417.             'number' => $newNumber,
  418.             'AutoIncrement' => $number,
  419.             'Status' => $stat,
  420.             'Prefix_01' => $prefix,
  421.         );
  422.     }
  423.     /**
  424.      * Check if ÖB-Number already exists
  425.      *
  426.      * @param $newNumber (string)
  427.      * @return $exists   (bool)
  428.      */
  429.     private function checkNumber($newNumber){
  430.         $mpmRepo $this->getMpmRepository();
  431.         $exists $mpmRepo->findOneBy(
  432.             new CriteriaComparison(
  433.                 '=',
  434.                 new CriteriaMappedColumn('MPM_ProjectNumber'),
  435.                 new CriteriaConstant($newNumber)
  436.             )
  437.         );
  438.         return $exists;
  439.     }
  440.     /**
  441.      * Read prefix from $formData
  442.      *
  443.      * @param $formData
  444.      * @return $prefix  (string)
  445.     */
  446.     private function getPrefix($formData){
  447.     $prefix 'Ö';
  448.         if(isset($formData['MPM_Prefix_01'])){
  449.             $prefix $formData['MPM_Prefix_01'];
  450.         }
  451.     return $prefix;
  452.     }
  453.     /**
  454.      * Check record based permissions set by columns MPM_Role_Read_Write or MPM_Project_Owner_LINK_User_ID.
  455.      *
  456.      * @param $sourceRepo
  457.      * @param $id
  458.      * @return bool
  459.      */
  460.     protected function hasPermission($sourceRepo$id)
  461.     {
  462.         $builder $sourceRepo->getConnection()->createQueryBuilder();
  463.         $builder
  464.             ->select('MPM_Role_Read_Write, MPM_Project_Owner_LINK_User_ID')
  465.             ->from('Tab_MPM')
  466.             ->where('MPM_ID = '.$builder->createPositionalParameter($id));
  467.         $result $builder->execute()->fetchAll();
  468.         /*
  469.          * If the record does not exist, permissions are granted what lets the user create a new record.
  470.          */
  471.         if (!$result) {
  472.             return true;
  473.         }
  474.         $row $result[0];
  475.         $securityContextWrapper $this->getSecurityContextWrapper();
  476.         if (!$row['MPM_Role_Read_Write'] || $securityContextWrapper->checkRights(
  477.                 $row['MPM_Role_Read_Write']
  478.             )
  479.             || $row['MPM_Project_Owner_LINK_User_ID'] == $securityContextWrapper->getUserId()
  480.         ) {
  481.             return true;
  482.         }
  483.         return false;
  484.     }
  485.     /**
  486.      * @param $id
  487.      *
  488.      * @return RedirectResponse|array
  489.      * @throws \Exception
  490.      *
  491.      */
  492.     public function archive(Request $request$id)
  493.     {
  494.         $form $this->createForm(FormType::class);
  495.         $form
  496.             ->add(
  497.                 'archive',
  498.                 SubmitType::class,
  499.                 array(
  500.                     'label' => self::MSG_ARCHIVE,
  501.                 )
  502.             )
  503.             ->add(
  504.                 'cancel',
  505.                 SubmitType::class,
  506.                 array(
  507.                     'label' => self::MSG_CANCEL,
  508.                     'attr' => ['class' => 'default'],
  509.                 )
  510.             );
  511.         $form->handleRequest($request);
  512.         if ($form->isSubmitted() && $form->isValid()) {
  513.             if ($form->get('archive')
  514.                 ->isClicked()
  515.             ) {
  516.                 $mpmRepo $this->getMpmRepository();
  517.                 try {
  518.                     // Archive project
  519.                     $mpmRepo->archive($id);
  520.                     $this->addFlashAndTrans('success'self::MSG_ARCHIVE_SUCCESS);
  521.                 } catch (PortalException $ex) {
  522.                     $this->addFlashAndTrans('danger'$ex->getMessageKey(), $ex->getMessageData());
  523.                 } catch (\Exception $ex) {
  524.                     $this->addFlashAndTrans('danger'self::MSG_ARCHIVE_ERROR);
  525.                 }
  526.             } else {
  527.                 $this->addFlashAndTrans('warning'self::MSG_ARCHIVE_CANCELLED);
  528.             }
  529.             return $this->redirect($this->generateUrl('overview'));
  530.         }
  531.         $repo $this->getMpmRepository();
  532.         $mpm $repo->find($id);
  533.         return $this->render('@ProjectBizCitiBiz/Mpm/archive.html.twig', [
  534.             'form' => $form->createView(),
  535.             'overview' => $mpm,
  536.         ]);
  537.     }
  538.     public function delete(Request $request$id)
  539.     {
  540.         $form $this->createForm(FormType::class);
  541.         $form
  542.             ->add(
  543.                 'delete',
  544.                 SubmitType::class,
  545.                 array(
  546.                     'label' => self::MSG_DELETE,
  547.                 )
  548.             )
  549.             ->add(
  550.                 'cancel',
  551.                 SubmitType::class,
  552.                 array(
  553.                     'label' => self::MSG_CANCEL,
  554.                     'attr' => ['class' => 'default'],
  555.                 )
  556.             );
  557.         $form->handleRequest($request);
  558.         if ($form->isSubmitted() && $form->isValid()) {
  559.             if ($form->get('delete')
  560.                 ->isClicked()
  561.             ) {
  562.                 $mpmRepo $this->getMpmRepository();
  563.                 try {
  564.                     // 1. Delete project
  565.                     $mpmRepo->delete($id);
  566.                     // 2. Delete SPM
  567.                     // Do not delete: not accessible when MPM flagged as deleted
  568.                     $this->addFlashAndTrans('success'self::MSG_DELETE_SUCCESS);
  569.                 } catch (PortalException $ex) {
  570.                     $this->addFlashAndTrans('danger'$ex->getMessageKey(), $ex->getMessageData());
  571.                 } catch (\Exception $ex) {
  572.                     $this->addFlashAndTrans('danger'self::MSG_DELETE_ERROR);
  573.                 }
  574.             } else {
  575.                 $this->addFlashAndTrans('warning'self::MSG_DELETE_CANCELLED);
  576.             }
  577.             return $this->redirect($this->generateUrl('overview'));
  578.         }
  579.         $repo $this->getMpmRepository();
  580.         $mpm $repo->find($id);
  581.         return $this->render('@ProjectBizCitiBiz/Mpm/delete.html.twig', [
  582.             'form' => $form->createView(),
  583.             'overview' => $mpm,
  584.         ]);
  585.     }
  586.     protected function getSpmRepository($options null)
  587.     {
  588.         if (!isset($options['man_sort_set'])) {
  589.             $options['man_sort_set'] = array('SPM_LINK_MPM_Ancestor_ID');
  590.         }
  591.         return $this->getGenericRepository('SPM'$options);
  592.     }
  593.     /**
  594.      * @param Request $request
  595.      * @param         $id
  596.      * @param null $document_id
  597.      *
  598.      * @return RedirectResponse|array
  599.      * @throws \Exception
  600.      */
  601.     public function documentsEdit(Request $request$id$document_id null)
  602.     {
  603.         $this->unifiedOptions $request->attributes->get('_unified_options');
  604.         $unifiedOptions $this->filterOptionsForOptionResolver(
  605.             $this->unifiedOptions
  606.         );
  607.         $resolvedOptions $this->getOptionsResolver()->resolve($unifiedOptions);
  608.         $formname 'Formular_Documents';
  609.         $formHelper $this->get('citibiz.form_helper');
  610.         $formDesc $formHelper->getFormDesc(
  611.             $formname,
  612.             $this->getSecurityContextWrapper()
  613.                 ->getUserRights()
  614.         );
  615.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  616.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  617.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  618.         // New or Existing
  619.         $new_entry = !isset($document_id);
  620.         $mpm $request->attributes->get('_access_stack')[0];
  621.         $tableMenuContext $this
  622.             ->get('projectbiz.menu.menu_helper')
  623.             ->beginMenuContext(array(), 'MPM_ID');
  624.         $documentTableName 'Document';
  625.         $documentRepo $this->getGenericRepository($documentTableName);
  626.         if ($new_entry) {
  627.             $documentData $documentRepo->defaultObject();
  628.         } else {
  629.             $documentData $request->attributes->get('_access_stack')[1];
  630.         }
  631.         $htmlForm $this->createForm(
  632.             GenericTableType::class,
  633.             $documentData,
  634.             array('repo' => $documentRepo'columns' => $formLayout['form_columns'])
  635.         );
  636.         $htmlForm->handleRequest($request);
  637.         if ($htmlForm->isValid()) {
  638.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  639.              *          thus the object was not saved.
  640.              */
  641.             $documentData $htmlForm->getData();
  642.             $mpmRepo $this->getMpmRepository();
  643.             $new_id null;
  644.             $new_document_id null;
  645.             $mpmRepo->getConnection()->beginTransaction();
  646.             try {
  647.                 $new_document_id $documentRepo->persist($documentData);
  648.                 $documentIds = array();
  649.                 if ($mpm['MPM_VIRT_Documents'] != '') {
  650.                     $documentIds explode(','$mpm['MPM_VIRT_Documents']);
  651.                     if (isset($document_id)) {
  652.                         $documentIds array_diff($documentIds, array($document_id));
  653.                     }
  654.                 }
  655.                 $documentIds[] = $new_document_id;
  656.                 $mpm['MPM_VIRT_Documents'] = implode(','$documentIds);
  657.                 $new_id $mpmRepo->persist($mpm);
  658.             } catch (\Exception $ex) {
  659.                 $mpmRepo->getConnection()->rollBack();
  660.                 throw($ex);
  661.             }
  662.             $mpmRepo->getConnection()->commit();
  663.             if ($new_id && $new_document_id) {
  664.                 if ($new_entry) {
  665.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  666.                 } else {
  667.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  668.                 }
  669.                 return $this->redirect(
  670.                     $this->generateUrl(
  671.                         'overview_documents_edit',
  672.                         array('id' => $new_id'document_id' => $new_document_id)
  673.                     )
  674.                 );
  675.             } else {
  676.                 if ($new_entry) {
  677.                     $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  678.                 } else {
  679.                     $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  680.                 }
  681.             }
  682.         } elseif ($htmlForm->isSubmitted()) {
  683.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  684.         }
  685.         $breadcrumbs = array(
  686.             array('label' => 'Overview'),
  687.         );
  688.         if ($new_entry) {
  689.             $breadcrumbs[] = array('label' => $mpm['MPM_Projectname']);
  690.             $breadcrumbs[] = array('label' => 'Dokument erstellen');
  691.         } else {
  692.             $breadcrumbs[] = array('label' => $mpm['MPM_Projectname']);
  693.             $breadcrumbs[] = array('label' => 'Dokument bearbeiten');
  694.         }
  695.         return $this->render('@ProjectBizCitiBiz/Mpm/documentsEdit.html.twig', [
  696.             'formname' => $formDesc['formname'],
  697.             'form_view' => new FormViewController(
  698.                 $documentRepo,
  699.                 $formDesc['formname'],
  700.                 $formLayout['layout'],
  701.                 $documentData
  702.             ),
  703.             'id' => $id,
  704.             'overview' => $mpm,
  705.             'table_menu' => $tableMenuContext,
  706.             'form' => $htmlForm->createView(),
  707.             'is_new' => $new_entry,
  708.             'breadcrumbs' => $breadcrumbs,
  709.         ]);
  710.     }
  711.     public function documentsDelete(Request $request$id$document_id)
  712.     {
  713.         $this->unifiedOptions $request->attributes->get('_unified_options');
  714.         $overview $request->attributes->get('_access_stack')[0];
  715.         $overviewRepo $this->getMPMRepository();
  716.         $this->get('database_connection')
  717.             ->beginTransaction();
  718.         try {
  719.             $documentIds = array();
  720.             if ($overview['MPM_VIRT_Documents'] != '') {
  721.                 $documentIds array_diff(explode(','$overview['MPM_VIRT_Documents']), array($document_id));
  722.             }
  723.             $overview['MPM_VIRT_Documents'] = implode(','$documentIds);
  724.             $newOverviewId $overviewRepo->persist($overview);
  725.         } catch (\Exception $ex) {
  726.             $this->get('database_connection')
  727.                 ->rollBack();
  728.             throw($ex);
  729.         }
  730.         $this->get('database_connection')
  731.             ->commit();
  732.         $this->addFlashAndTrans('success'Messages::msgSuccessDelete);
  733.         return $this->redirect(
  734.             $this->generateUrl(
  735.                 'overview_documents',
  736.                 ['id' => $newOverviewId]
  737.             )
  738.         );
  739.     }
  740.     /**
  741.      * @param $id
  742.      * @param $document_id
  743.      *
  744.      * @return Response
  745.      * @throws \Exception
  746.      */
  747.     public function documentsAttachmentAction($id$document_id)
  748.     {
  749.         // Check overview access
  750.         $overviewRepo $this->getOverviewRepository();
  751.         $overview $overviewRepo->findOneBy(
  752.             new CriteriaComparison(
  753.                 '=',
  754.                 new CriteriaMappedColumn($overviewRepo->getPrimaryKey()),
  755.                 new CriteriaConstant($id)
  756.             ),
  757.             array('Overview_Projectname')
  758.         );
  759.         if (!$overview) {
  760.             // Missing overview - either it doesn't exist or the user does not have access rights
  761.             throw new \Exception(BundleMessages::msgOverviewNoAccess);
  762.         }
  763.         // Check if document_id is references by overview
  764.         $documentTableName 'Document';
  765.         $refsRepo $this->getGenericRepository('Refs');
  766.         $criteriaRefs = new CriteriaComposite(
  767.             'AND',
  768.             array(
  769.                 new CriteriaComparison(
  770.                     '=',
  771.                     new CriteriaMappedColumn('Refs_SourceTable'),
  772.                     new CriteriaConstant($documentTableName)
  773.                 ),
  774.                 new CriteriaComparison(
  775.                     '=',
  776.                     new CriteriaMappedColumn('Refs_Source_LINK_ID'),
  777.                     new CriteriaConstant($document_id)
  778.                 ),
  779.                 new CriteriaComparison(
  780.                     '=',
  781.                     new CriteriaMappedColumn('Refs_TargetTable'),
  782.                     new CriteriaConstant('Overview')
  783.                 ),
  784.                 new CriteriaComparison(
  785.                     '=',
  786.                     new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  787.                     new CriteriaConstant($id)
  788.                 ),
  789.             )
  790.         );
  791.         $validRef $refsRepo->findOneBy($criteriaRefs);
  792.         if ($validRef === false) {
  793.             // Missing ref - the document does not belong to overview
  794.             throw new \Exception(BundleMessages::msgMissingRef);
  795.         }
  796.         $documentsRepo $this->getGenericRepository($documentTableName);
  797.         $document $documentsRepo->find($document_id);
  798.         if ($document === null) {
  799.             throw new \Exception(BundleMessages::msgMissingRef); // @todo: maybe throw other exception
  800.         }
  801.         if (!isset($document['Document_LINK_File_ID'])) {
  802.             throw new \Exception(BundleMessages::msgMissingRef); // @todo: maybe throw other exception
  803.         }
  804.         $fileRepo $this->getGenericRepository('File');
  805.         $file $fileRepo->find($document['Document_LINK_File_ID']);
  806.         $storage realpath(
  807.             implode(
  808.                 DIRECTORY_SEPARATOR,
  809.                 [
  810.                     $this->get('kernel')
  811.                         ->getProjectDir(),
  812.                     $this->getParameter('citibiz.upload_dir'),
  813.                     $file['File_Storage'],
  814.                 ]
  815.             )
  816.         );
  817.         if ($storage === false) {
  818.             $this->addFlashAndTrans('warning'BundleMessages::msgMissingFile);
  819.             return $this->redirect($this->generateUrl('overview_documents', array('id' => $id)));
  820.         }
  821.         $response = new Response(file_get_contents($storage));
  822.         $d $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$file['File_Name']);
  823.         $response->headers->set('Content-Disposition'$d);
  824.         $response->headers->set('Content-Type'$file['File_Mime_Type']);
  825.         return $response;
  826.     }
  827.     public function attachment(Request $request$column)
  828.     {
  829.         $accessStack $request->attributes->get('_access_stack');
  830.         if ((null === $accessStack) || (count($accessStack) == 0)) {
  831.             throw new AccessDeniedException();
  832.         }
  833.         $topOfStack array_pop($accessStack);
  834.         $fileColumn $column;
  835.         $fileRepo $this->getGenericRepository('File');
  836.         $file $fileRepo->find($topOfStack[$fileColumn]);
  837.         $storage realpath(
  838.             implode(
  839.                 DIRECTORY_SEPARATOR,
  840.                 [
  841.                     $this->get('kernel')
  842.                         ->getProjectDir(),
  843.                     $this->getParameter('citibiz.upload_dir'),
  844.                     $file['File_Storage'],
  845.                 ]
  846.             )
  847.         );
  848.         if ($storage === false) {
  849.             $this->addFlashAndTrans('warning'BundleMessages::msgMissingFile);
  850.             return $this->redirect($this->generateUrl('overview'));
  851.         }
  852.         $response = new Response(file_get_contents($storage));
  853.         $d $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$file['File_Name']);
  854.         $response->headers->set('Content-Disposition'$d);
  855.         $response->headers->set('Content-Type'$file['File_Mime_Type']);
  856.         return $response;
  857.     }
  858.     /**
  859.      * @param Request $request
  860.      * @param $id
  861.      * @return RedirectResponse
  862.      *
  863.      * @Template()
  864.      */
  865.     public function mpmCalculateAction(Request $request$id)
  866.     {
  867.         /*
  868.          * 1. Get all SPM-Data for this MPM
  869.          * 2. Calculate the SUM of SPM_Offer_LINK_Pricegroup_Calculation and store them to MPM_Offer_PriceGroup_Calculation
  870.          * 3. Store current date in MPM_Offer_PriceGroup_Calculated_Date
  871.          * 4. Create pdf file and store it to MPM_Offer_PriceGroup_Calculation_LINK_File_ID
  872.          */
  873.         $mpmData $this->getMpmData($id);
  874.         if (!$mpmData) {
  875.             return $this->redirectToMpm(array('danger' => self::MSG_MPM_MISSING));
  876.         }
  877.         $spmData $this->getSpmData($mpmData['MPM_LINK_Ancestor_ID']);
  878.         $spmData array_filter(
  879.             $spmData,
  880.             function ($row) {
  881.                 return in_array($row['SPM_Type'], array('module''position''special-position''module-position'));
  882.             }
  883.         );
  884.         $priceGroupPdf $this->get('projectbiz.citibiz.pdf.price_group');
  885.         $mpmData['MPM_Offer_PriceGroup_Calculation'] = $priceGroupPdf->calculateSum(
  886.             $mpmData['MPM_Offer_Addition_711'] + $mpmData['MPM_Offer_Addition_720'] + $mpmData['MPM_Offer_Addition_730'],
  887.             $spmData
  888.         );
  889.         $mpmData['MPM_Offer_PriceGroup_Calculated_Date'] = new \DateTime();
  890.         $form $this->get('form.factory')->createBuilder(
  891.             KostenberechnungType::class,
  892.             array('umsatzsteuer' => 'netto')
  893.         )->getForm();
  894.         $form->handleRequest($request);
  895.         if ($form->isSubmitted() && $form->isValid()) {
  896.             $formData $form->getData();
  897.             $fileId 0;
  898.             try {
  899.                 $this->startTransaction();
  900.                 $fileId $priceGroupPdf->build(
  901.                     $priceGroupPdf->buildFields($mpmData$formData),
  902.                     $mpmData,
  903.                     $spmData
  904.                 );
  905.                 $mpmData['MPM_Offer_PriceGroup_Calculation_LINK_File_ID'] = $fileId;
  906.                 $this->storeMpmData($mpmData);
  907.             } catch (\Exception $ex) {
  908.                 $this->cleanupCalculatePDF($fileId);
  909.                 $this->rollbackTransaction();
  910.                 return $this->redirectToMpm(array('danger' => $ex->getMessage()));
  911.             }
  912.             $this->commitTransaction();
  913.             return $this->redirectToMpm(array('success' => self::MSG_PRICEGROUP_SUCCESS));
  914.         }
  915.         return $this->render('@ProjectBizCitiBiz/Mpm/mpmCalculate.html.twig', [
  916.             'mpm' => $mpmData,
  917.             'form' => $form->createView(),
  918.         ]);
  919.     }
  920.     private function getMpmData($mpmId)
  921.     {
  922.         $mpmRepo $this->getMpmRepository();
  923.         $mpmCriteria = new CriteriaComparison(
  924.             '=',
  925.             new CriteriaUnmappedColumn('MPM_ID'),
  926.             new CriteriaConstant($mpmId)
  927.         );
  928.         return $mpmRepo->findOneBy(
  929.             $mpmCriteria,
  930.             array(
  931.                 'MPM_ID',
  932.                 'MPM_LINK_Ancestor_ID',
  933.                 'MPM_Role_03',
  934.                 'MPM_Role_04',
  935.                 'MPM_Role_05',
  936.                 'MPM_ProjectNumber',
  937.                 'MPM_Projectname',
  938.                 'MPM_Text_10',
  939.                 'MPM_Offer_Addition_711',
  940.                 'MPM_Offer_Addition_720',
  941.                 'MPM_Offer_Addition_730',
  942.                 'MPM_Stadt_Request',
  943.                 'MPM_Stadt_Project_Category_ID',
  944.                 'MPM_Stadt_Workflow_ID',
  945.                 'MPM_Stadt_KAG_Flag',
  946.                 'MPM_Stadt_Department_Answer_Date',
  947.                 'MPM_LINK_Stadt_Workflow_ID',
  948.                 'MPM_Stadt_Amt_Adress',
  949.                 'MPM_Stadt_Amt_Name',
  950.                 'MPM_Stadt_Amt_Telefon',
  951.                 'MPM_Stadt_BV_Adress',
  952.                 'MPM_Stadt_BV_Name',
  953.                 'MPM_Stadt_BV_Telefon',
  954.                 'MPM_Text_01',
  955.                 'MPM_LINK_Stadt_Project_Category_ID',
  956.                 'MPM_Info_18',
  957.                 'MPM_Date_01',
  958.                 'MPM_Date_02',
  959.                 'MPM_Stadt_Appointment_Date',
  960.                 'MPM_Stadt_Appointment_Participants',
  961.                 'MPM_Stadt_Appointment_Participants_2',
  962.                 'MPM_Stadt_Appointment_Participants_3',
  963.                 'MPM_Stadt_Appointment_Location',
  964.                 'MPM_Stadt_Informationfor_SWD',
  965.                 'MPM_Stadt_Department_Name',
  966.                 'MPM_Stadt_Department_Tel',
  967.                 'MPM_Stadt_Request_Name',
  968.                 'MPM_Stadt_Request_Tel',
  969.                 'MPM_LINK_Stadt_Department_ID',
  970.                 'MPM_LINK_Stadt_Informationfor_ID',
  971.                 'MPM_Stadt_Informationfor_Date',
  972.                 'MPM_Stadt_Appointment_Time',
  973.                 'MPM_Stadt_Date_01',
  974.                 'MPM_Stadt_Date_02',
  975.                 'MPM_Stadt_Date_03',
  976.                 'MPM_Stadt_Account_Info',
  977.                 'MPM_Stadt_PSP_Cost_Unit',
  978.                 'MPM_Stadt_Date_06',
  979.                 'MPM_Stadt_Date_07',
  980.                 'MPM_LINK_Stadt_Task_ID',
  981.                 'MPM_Key_26',
  982.                 'MPM_Info_04',
  983.                 'MPM_LINK_Stadt_Budget_Assignment',
  984.             )
  985.         );
  986.     }
  987.     private function getSpmData($mpmAncestor)
  988.     {
  989.         $spmRepo $this->getSpmRepository();
  990.         $systemCriteria = new CriteriaComparison(
  991.             '=',
  992.             new CriteriaUnmappedColumn('SPM_LINK_MPM_Ancestor_ID'),
  993.             new CriteriaConstant($mpmAncestor)
  994.         );
  995.         return $spmRepo->fetchAll(
  996.             $spmRepo->findBy(
  997.                 $systemCriteria,
  998.                 null,
  999.                 array(
  1000.                     'SPM_ID',
  1001.                     'SPM_Type',
  1002.                     'SPM_Offer_PriceGroup_Calculation',
  1003.                     'SPM_Offer_PriceGroup_UnitPrice_Rounded',
  1004.                     'SPM_Offer_LINK_PriceGroup_ID',
  1005.                     'SPM_Offer_Position'// Modul-Nr. Stadt
  1006.                     'SPM_Offer_Shorttext'// Kurzbezeichnung
  1007.                     'SPM_Offer_04'// Wert 1
  1008.                     'SPM_Offer_05'// Wert 2
  1009.                     'SPM_Offer_06'// Wert 3
  1010.                     'SPM_Offer_07'// Faktor
  1011.                     'SPM_Offer_08'// Einheit
  1012.                     'SPM_Offer_09'// Menge
  1013.                     'SPM_Offer_10'// VK-Einzelpreis (netto)
  1014.                     'SPM_Offer_12'// VK-Preis netto
  1015.                     'SPM_Offer_13'// VK-Preis brutto
  1016.                     'SPM_Calc_10'// EK-Einzelpreis (netto)
  1017.                 )
  1018.             )
  1019.         );
  1020.     }
  1021.     private function storeMpmData($mpmData)
  1022.     {
  1023.         $this->getMpmRepository()->persist($mpmData);
  1024.     }
  1025.     private function cleanupCalculatePDF($fileId)
  1026.     {
  1027.         if ($fileId == 0) {
  1028.             return;
  1029.         }
  1030.     }
  1031.     private function startTransaction()
  1032.     {
  1033.         $this->getMpmRepository()->getConnection()->beginTransaction();
  1034.     }
  1035.     private function rollbackTransaction()
  1036.     {
  1037.         $this->getMpmRepository()->getConnection()->rollBack();
  1038.     }
  1039.     private function commitTransaction()
  1040.     {
  1041.         $this->getMpmRepository()->getConnection()->commit();
  1042.     }
  1043.     private function redirectToMpm($messages)
  1044.     {
  1045.         foreach ($messages as $level => $message) {
  1046.             $this->addFlashAndTrans($level$message);
  1047.         }
  1048.         return $this->redirect($this->generateUrl('overview'));
  1049.     }
  1050.     protected function getPriceRepository($options null)
  1051.     {
  1052.         return $this->getGenericRepository('Price01'$options);
  1053.     }
  1054.     private function handlePricelistEntries(&$data)
  1055.     {
  1056.         $this->copyToKeyIfItDoesNotExist(
  1057.             'MPM_LINK_Pricelist_Offer_VersionID',
  1058.             'MPM_LINK_Pricelist_Bill_VersionID',
  1059.             $data
  1060.         );
  1061.         $this->copyToKeyIfItDoesNotExist(
  1062.             'MPM_LINK_Pricelist_Calc_VersionID',
  1063.             'MPM_LINK_Pricelist_Meas_VersionID',
  1064.             $data
  1065.         );
  1066.     }
  1067.     private function copyToKeyIfItDoesNotExist($fromKey$toKey, &$data)
  1068.     {
  1069.         if (
  1070.             array_key_exists($fromKey$data) &&
  1071.             !array_key_exists($toKey$data)
  1072.         ) {
  1073.             $data[$toKey] = $data[$fromKey];
  1074.         }
  1075.     }
  1076.     public function getDefaultOptions()
  1077.     {
  1078.         return $this->options;
  1079.     }
  1080.     protected function setupOptionsResolver(OptionsResolver $resolver)
  1081.     {
  1082.         $resolver->setDefaults(array(
  1083.             'data_injection' => null
  1084.         ));
  1085.     }
  1086.     /**
  1087.      * 1. Get all MPM-Data for this ID
  1088.      * 2. Store current date in MPM_Date_22
  1089.      * 3. Create pdf file and store it to MPM_Yellow_Sheet_LINK_File_ID
  1090.      */
  1091.     public function mpmYellowSheet(Request $request$id)
  1092.     {
  1093.         $mpmData $this -> getMpmData($id);
  1094.         if (!$mpmData) {
  1095.             return $this->redirectToMpm(array('danger' => self::MSG_MPM_MISSING));
  1096.         }
  1097.         $yellowsheetPdf $this->get('projectbiz.citibiz.pdf.yellowsheet');
  1098.         $mpmData['MPM_Date_22'] = new \DateTime();
  1099.         $mpmData['MPM_Yellow_Sheet_Creater'] = $this->getsecurityContextWrapper()->getUser()->getRealname();
  1100.         $fileId 0;
  1101.         try {
  1102.             $this->startTransaction();
  1103.             $fileId $yellowsheetPdf->build(
  1104.                 $yellowsheetPdf->buildFields($mpmData),
  1105.                 $mpmData
  1106.             );
  1107.             $mpmData['MPM_Yellow_Sheet_LINK_File_ID'] = $fileId;
  1108.             $this->storeMpmData($mpmData);
  1109.         } catch (\Exception $ex) {
  1110.             $this->cleanupCalculatePDF($fileId);
  1111.             $this->rollbackTransaction();
  1112.             return $this->redirectToMpm(['danger' => $ex->getMessage()]);
  1113.         }
  1114.         $this->commitTransaction();
  1115.         return $this->redirectToMpm(['success' => self::MSG_YELLOWSHEET_SUCCESS]);
  1116.     }
  1117.     /**
  1118.      * @param Request $request
  1119.      * @param         $id
  1120.      * @param null $spmcad_id
  1121.      *
  1122.      * @return RedirectResponse|array
  1123.      * @throws \Exception
  1124.      */
  1125.      public function bauspmcadEdit(Request $request$id$spmcad_id null)
  1126.  {
  1127.      $this->unifiedOptions $request->attributes->get('_unified_options');
  1128.      $unifiedOptions $this->filterOptionsForOptionResolver(
  1129.          $this->unifiedOptions
  1130.      );
  1131.      $resolvedOptions $this->getOptionsResolver()->resolve($unifiedOptions);
  1132.      $formname 'Form_SPMCAD';
  1133.      $formHelper $this->get('citibiz.form_helper');
  1134.      $formDesc $formHelper->getFormDesc(
  1135.          $formname,
  1136.          $this->getSecurityContextWrapper()
  1137.              ->getUserRights()
  1138.      );
  1139.      $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1140.      //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1141.      //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1142.      // New or Existing
  1143.      $new_entry = !isset($spmcad_id);
  1144.      $mpm $request->attributes->get('_access_stack')[0];
  1145.      $tableMenuContext $this
  1146.          ->get('projectbiz.menu.menu_helper')
  1147.          ->beginMenuContext([], 'MPM_ID');
  1148.      $spmcadTableName 'SPMCAD';
  1149.      $spmcadRepo $this->getGenericRepository($spmcadTableName);
  1150.      if ($new_entry) {
  1151.          $spmcadData $spmcadRepo->defaultObject();
  1152.      } else {
  1153.          $spmcadData $request->attributes->get('_access_stack')[1];
  1154.      }
  1155.      $htmlForm $this->createForm(
  1156.          GenericTableType::class,
  1157.          $spmcadData,
  1158.          [
  1159.              'repo' => $spmcadRepo,
  1160.              'columns' => $formLayout['form_columns']
  1161.          ]
  1162.      );
  1163.      $htmlForm->handleRequest($request);
  1164.      if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  1165.          /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1166.           *          thus the object was not saved.
  1167.           */
  1168.          $spmcadData $htmlForm->getData();
  1169.          $mpmRepo $this->getMPMRepository();
  1170.          $new_id null;
  1171.          $new_spmcad_id null;
  1172.          $mpmRepo->getConnection()->beginTransaction();
  1173.          try {
  1174.              $new_spmcad_id $spmcadRepo->persist($spmcadData);
  1175.              $spmcadIds = array();
  1176.              if ($mpm['MPM_VIRT_SPMCAD'] != '') {
  1177.                  $spmcadIds explode(','$mpm['MPM_VIRT_SPMCAD']);
  1178.                  if (isset($spmcad_id)) {
  1179.                      $spmcadIds array_diff($spmcadIds, array($spmcad_id));
  1180.                  }
  1181.              }
  1182.              $spmcadIds[] = $new_spmcad_id;
  1183.              $mpm['MPM_VIRT_SPMCAD'] = implode(','$spmcadIds);
  1184.              $refsRepo $this->getGenericRepository('Refs');
  1185.              $refsData $refsRepo->findBy(
  1186.                new CriteriaComparison(
  1187.                    '=',
  1188.                    new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1189.                    new CriteriaConstant($mpm['MPM_ID'])
  1190.                )
  1191.          );
  1192.              $new_id $mpmRepo->persist($mpm);
  1193.          }
  1194.          catch (\Exception $ex) {
  1195.             // $mpmRepo->getConnection()->rollBack();
  1196.              throw($ex);
  1197.          }
  1198.          $mpmRepo->getConnection()->commit();
  1199.          if ($new_id && $new_spmcad_id) {
  1200.              if ($new_entry) {
  1201.                  $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1202.              } else {
  1203.                  $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1204.              }
  1205.              return $this->redirect(
  1206.                  $this->generateUrl(
  1207.                      'bau_mpm_spmcad_edit',
  1208.                      [
  1209.                          'id' => $new_id,
  1210.                          'spmcad_id' => $new_spmcad_id
  1211.                      ]
  1212.                  )
  1213.              );
  1214.          } else {
  1215.              if ($new_entry) {
  1216.                  $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1217.              } else {
  1218.                  $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1219.              }
  1220.          }
  1221.      } elseif ($htmlForm->isSubmitted()) {
  1222.          $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  1223.      }
  1224.      $breadcrumbs = [
  1225.          ['label' => 'MPM'],
  1226.      ];
  1227.      $breadcrumbs[] = ['label' => $mpm['MPM_Projectname']];
  1228.      if ($new_entry) {
  1229.          $breadcrumbs[] = ['label' => 'CAD-Eintrag erstellen'];
  1230.      } else {
  1231.          $breadcrumbs[] = ['label' => 'CAD-Eintrag bearbeiten'];
  1232.      }
  1233.      return $this->render('@ProjectBizCitiBiz/Mpm/spmCADEdit.html.twig', [
  1234.          'formname' => $formDesc['formname'],
  1235.          'form_view' => new FormViewController(
  1236.              $spmcadRepo,
  1237.              $formDesc['formname'],
  1238.              $formLayout['layout'],
  1239.              $spmcadData
  1240.          ),
  1241.          'id' => $id,
  1242.          'mpm' => $mpm,
  1243.          'table_menu' => $tableMenuContext,
  1244.          'form' => $htmlForm->createView(),
  1245.          'is_new' => $new_entry,
  1246.          'breadcrumbs' => $breadcrumbs,
  1247.      ]);
  1248.  }
  1249.     /**
  1250.      * @param Request $request
  1251.      * @param         $id
  1252.      * @param null $spm_id
  1253.      *
  1254.      * @return RedirectResponse|array
  1255.      * @throws \Exception
  1256.      */
  1257.     public function bauspmEdit(Request $request$id$spm_id null)
  1258.     {
  1259.         $this->unifiedOptions $request->attributes->get('_unified_options');
  1260.     
  1261.         $formname 'Form_SPM_Main';
  1262.         $formHelper $this->get('citibiz.form_helper');
  1263.         $formDesc $formHelper->getFormDesc(
  1264.             $formname,
  1265.             $this->getSecurityContextWrapper()
  1266.                 ->getUserRights()
  1267.         );
  1268.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1269.     
  1270.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1271.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1272.     
  1273.         // New or Existing
  1274.         $new_entry = !isset($spm_id);
  1275.     
  1276.         $mpm $request->attributes->get('_access_stack')[0];
  1277.     
  1278.         $tableMenuContext $this
  1279.             ->get('projectbiz.menu.menu_helper')
  1280.             ->beginMenuContext([], 'MPM_ID');
  1281.     
  1282.         $spmTableName 'SPM';
  1283.         $spmRepo $this->getGenericRepository($spmTableName);
  1284.         if ($new_entry) {
  1285.             $spmData $spmRepo->defaultObject();
  1286.         } else {
  1287.             $spmData $request->attributes->get('_access_stack')[1];
  1288.         }
  1289.     
  1290.         $htmlForm $this->createForm(
  1291.             GenericTableType::class,
  1292.             $spmData,
  1293.             [
  1294.                 'repo' => $spmRepo,
  1295.                 'columns' => $formLayout['form_columns']
  1296.             ]
  1297.         );
  1298.         $htmlForm->handleRequest($request);
  1299.     
  1300.         if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  1301.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1302.              *          thus the object was not saved.
  1303.              */
  1304.             $spmData $htmlForm->getData();
  1305.             $mpmRepo $this->getMPMRepository();
  1306.     
  1307.             $new_id null;
  1308.             $new_spm_id null;
  1309.             $mpmRepo->getConnection()->beginTransaction();
  1310.             try {
  1311.                 $new_spm_id $spmRepo->persist($spmData);
  1312.     
  1313.                 $spmIds = [];
  1314.                 if ($mpm['MPM_VIRT_SPMMPM'] != '') {
  1315.                     $spmIds explode(','$mpm['MPM_VIRT_SPMMPM']);
  1316.                     if (isset($spm_id)) {
  1317.                         $spmIds array_diff($spmIds, [$spm_id]);
  1318.                     }
  1319.     
  1320.                 }
  1321.                 $spmIds[] = $new_spm_id;
  1322.                 $mpm['MPM_VIRT_SPMMPM'] = implode(','$spmIds);
  1323.                 $refsRepo $this->getGenericRepository('Refs');
  1324.                 $refsData $refsRepo->findBy(
  1325.                   new CriteriaComparison(
  1326.                       '=',
  1327.                       new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1328.                       new CriteriaConstant($mpm['MPM_ID'])
  1329.                   )
  1330.             );
  1331.                 $new_id $mpmRepo->persist($mpm);
  1332.             }
  1333.             catch (\Exception $ex) {
  1334.                // $mpmRepo->getConnection()->rollBack();
  1335.                 throw($ex);
  1336.             }
  1337.     
  1338.             $mpmRepo->getConnection()->commit();
  1339.     
  1340.             if ($new_id && $new_spm_id) {
  1341.                 if ($new_entry) {
  1342.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1343.                 } else {
  1344.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1345.                 }
  1346.     
  1347.                 return $this->redirect(
  1348.                     $this->generateUrl(
  1349.                         'bau_mpm_spm_edit',
  1350.                         ['id' => $new_id'spm_id' => $new_spm_id]
  1351.                     )
  1352.                 );
  1353.             } else if ($new_entry) {
  1354.                 $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1355.             } else {
  1356.                 $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1357.             }
  1358.         } elseif ($htmlForm->isSubmitted()) {
  1359.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  1360.         }
  1361.     
  1362.         $breadcrumbs = [
  1363.             ['label' => 'MPM'],
  1364.         ];
  1365.         $breadcrumbs[] = ['label' => $mpm['MPM_Projectname']];
  1366.         if ($new_entry) {
  1367.             $breadcrumbs[] = ['label' => 'SPM-Eintrag erstellen'];
  1368.         } else {
  1369.             $breadcrumbs[] = ['label' => 'SPM-Eintrag bearbeiten'];
  1370.         }
  1371.         return $this->render('@ProjectBizCitiBiz/Spm/spmEdit.html.twig', [
  1372.             'formname' => $formDesc['formname'],
  1373.             'form_view' => new FormViewController(
  1374.                 $spmRepo,
  1375.                 $formDesc['formname'],
  1376.                 $formLayout['layout'],
  1377.                 $spmData
  1378.             ),
  1379.             'id' => $id,
  1380.             'mpm' => $mpm,
  1381.             'table_menu' => $tableMenuContext,
  1382.             'form' => $htmlForm->createView(),
  1383.             'is_new' => $new_entry,
  1384.             'breadcrumbs' => $breadcrumbs,
  1385.         ]);
  1386.     }
  1387.     /**
  1388.      * @param Request $request
  1389.      * @param         $id
  1390.      * @param null $spm_id
  1391.      *
  1392.      * @return RedirectResponse|array
  1393.      * @throws \Exception
  1394.      */
  1395.     public function bauspmFormEdit(Request $request$id$spm_id null$form)
  1396.     {
  1397.         $this->unifiedOptions $request->attributes->get('_unified_options');
  1398.         $formname $form;
  1399.         $formHelper $this->get('citibiz.form_helper');
  1400.         $formDesc $formHelper->getFormDesc(
  1401.             $formname,
  1402.             $this->getSecurityContextWrapper()
  1403.                 ->getUserRights()
  1404.         );
  1405.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1406.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1407.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1408.         // New or Existing
  1409.         $new_entry = !isset($spm_id);
  1410.         $mpm $request->attributes->get('_access_stack')[0];
  1411.         $tableMenuContext $this
  1412.             ->get('projectbiz.menu.menu_helper')
  1413.             ->beginMenuContext([], 'MPM_ID');
  1414.         $spmTableName 'SPM';
  1415.         $spmRepo $this->getGenericRepository($spmTableName);
  1416.         if ($new_entry) {
  1417.             $spmData $spmRepo->defaultObject();
  1418.         } else {
  1419.             $spmData $request->attributes->get('_access_stack')[1];
  1420.         }
  1421.         $htmlForm $this->createForm(
  1422.             GenericTableType::class,
  1423.             $spmData,
  1424.             [
  1425.                 'repo' => $spmRepo,
  1426.                 'columns' => $formLayout['form_columns']
  1427.             ]
  1428.         );
  1429.         $htmlForm->handleRequest($request);
  1430.         if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  1431.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1432.              *          thus the object was not saved.
  1433.              */
  1434.             $spmData $htmlForm->getData();
  1435.             $mpmRepo $this->getMPMRepository();
  1436.             
  1437.             $mpmRepo->getConnection()->beginTransaction();
  1438.             try {
  1439.                 $new_spm_id $spmRepo->persist($spmData);
  1440.                 $spmIds = [];
  1441.                 if ($mpm['MPM_VIRT_SPMMPM'] != '') {
  1442.                     $spmIds explode(','$mpm['MPM_VIRT_SPMMPM']);
  1443.                     if (isset($spm_id)) {
  1444.                         $spmIds array_diff($spmIds, [$spm_id]);
  1445.                     }
  1446.                 }
  1447.                 $spmIds[] = $new_spm_id;
  1448.                 $mpm['MPM_VIRT_SPMMPM'] = implode(','$spmIds);
  1449.                 $refsRepo $this->getGenericRepository('Refs');
  1450.                 $refsData $refsRepo->findBy(
  1451.                     new CriteriaComparison(
  1452.                         '=',
  1453.                         new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1454.                         new CriteriaConstant($mpm['MPM_ID'])
  1455.                     )
  1456.                 );
  1457.                 $new_id $mpmRepo->persist($mpm);
  1458.             } catch (\Exception $ex) {
  1459.                 // $mpmRepo->getConnection()->rollBack();
  1460.                 throw($ex);
  1461.             }
  1462.             $mpmRepo->getConnection()->commit();
  1463.             if ($new_id && $new_spm_id) {
  1464.                 if ($new_entry) {
  1465.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1466.                 } else {
  1467.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1468.                 }
  1469.                 return $this->redirect(
  1470.                     $this->generateUrl(
  1471.                         'bau_spm_maindocuments_redirect',
  1472.                         ['id' => $new_spm_id]
  1473.                     )
  1474.                 );
  1475.             } else if ($new_entry) {
  1476.                 $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1477.             } else {
  1478.                 $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1479.             }
  1480.         } elseif ($htmlForm->isSubmitted()) {
  1481.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  1482.         }
  1483.         $breadcrumbs = [
  1484.             ['label' => 'MPM'],
  1485.         ];
  1486.         $breadcrumbs[] = ['label' => $mpm['MPM_Projectname']];
  1487.         if ($new_entry) {
  1488.             $breadcrumbs[] = ['label' => 'SPM-Eintrag erstellen'];
  1489.         } else {
  1490.             $breadcrumbs[] = ['label' => 'SPM-Eintrag bearbeiten'];
  1491.         }
  1492.         return $this->render('@ProjectBizCitiBiz/Mpm/formEdit.html.twig', [
  1493.             'formname' => $formDesc['formname'],
  1494.             'form_view' => new FormViewController(
  1495.                 $spmRepo,
  1496.                 $formDesc['formname'],
  1497.                 $formLayout['layout'],
  1498.                 $spmData
  1499.             ),
  1500.             'id' => $id,
  1501.             'mpm' => $mpm,
  1502.             'table_menu' => $tableMenuContext,
  1503.             'form' => $htmlForm->createView(),
  1504.             'is_new' => $new_entry,
  1505.             'breadcrumbs' => $breadcrumbs,
  1506.         ]);
  1507.     }
  1508.     /**
  1509.       * @param Request $request
  1510.       * @param         $id
  1511.       * @param null $skill_id
  1512.       *
  1513.       * @return RedirectResponse|array
  1514.       * @throws \Exception
  1515.       */
  1516.     public function bauskillEdit(Request $request$id$skill_id null)
  1517.     {
  1518.         $this->unifiedOptions $request->attributes->get('_unified_options');
  1519.         $formname 'Form_Skill';
  1520.         $formHelper $this->get('citibiz.form_helper');
  1521.         $formDesc $formHelper->getFormDesc(
  1522.             $formname,
  1523.             $this->getSecurityContextWrapper()
  1524.                 ->getUserRights()
  1525.         );
  1526.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1527.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1528.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1529.         // New or Existing
  1530.         $new_entry = !isset($skill_id);
  1531.         $functionworkplace $request->attributes->get('_access_stack')[0];
  1532.         $tableMenuContext $this
  1533.             ->get('projectbiz.menu.menu_helper')
  1534.             ->beginMenuContext([], 'FunctionWorkplace_ID');
  1535.         $skillTableName 'Skill';
  1536.         $skillRepo $this->getGenericRepository($skillTableName);
  1537.         if ($new_entry) {
  1538.             $skillData $skillRepo->defaultObject();
  1539.         } else {
  1540.             $skillData $request->attributes->get('_access_stack')[1];
  1541.         }
  1542.         $htmlForm $this->createForm(
  1543.             GenericTableType::class,
  1544.             $skillData,
  1545.             [
  1546.                 'repo' => $skillRepo
  1547.                 'columns' => $formLayout['form_columns']
  1548.             ]
  1549.         );
  1550.         $htmlForm->handleRequest($request);
  1551.         if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  1552.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1553.              *          thus the object was not saved.
  1554.              */
  1555.             $skillData $htmlForm->getData();
  1556.             $functionworkplaceTableName 'FunctionWorkplace';
  1557.             $functionworkplaceRepo $this->getGenericRepository($functionworkplaceTableName);
  1558.             $functionworkplaceRepo->getConnection()->beginTransaction();
  1559.             try {
  1560.                 $new_skill_id $skillRepo->persist($skillData);
  1561.                 $skillIds = [];
  1562.                 if ($functionworkplace['FunctionWorkplace_VIRT_Skill'] != '') {
  1563.                     $skillIds explode(','$functionworkplace['FunctionWorkplace_VIRT_Skill']);
  1564.                     if (isset($skill_id)) {
  1565.                         $skillIds array_diff($skillIds, [$skill_id]);
  1566.                     }
  1567.                 }
  1568.                 $skillIds[] = $new_skill_id;
  1569.                 $functionworkplace['FunctionWorkplace_VIRT_Skill'] = implode(','$skillIds);
  1570.                 $refsRepo $this->getGenericRepository('Refs');
  1571.                 $refsData $refsRepo->findBy(
  1572.                     new CriteriaComparison(
  1573.                         '=',
  1574.                         new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1575.                         new CriteriaConstant($functionworkplace['FunctionWorkplace_ID'])
  1576.                     )
  1577.                 );
  1578.                 $new_id $functionworkplaceRepo->persist($functionworkplace);
  1579.             } catch (\Exception $ex) {
  1580.                 // $functionworkplaceRepo->getConnection()->rollBack();
  1581.                 throw($ex);
  1582.             }
  1583.             $functionworkplaceRepo->getConnection()->commit();
  1584.             if ($new_id && $new_skill_id) {
  1585.                 if ($new_entry) {
  1586.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1587.                 } else {
  1588.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1589.                 }
  1590.                 return $this->redirect(
  1591.                     $this->generateUrl(
  1592.                         'bau_functionworkplace_skill_edit',
  1593.                         ['id' => $new_id'skill_id' => $new_skill_id]
  1594.                     )
  1595.                 );
  1596.             } else if ($new_entry) {
  1597.                 $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1598.             } else {
  1599.                 $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1600.             }
  1601.         } elseif ($htmlForm->isSubmitted()) {
  1602.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  1603.         }
  1604.         $breadcrumbs = [
  1605.             ['label' => 'FunctionWorkplace'],
  1606.         ];
  1607.         $breadcrumbs[] = ['label' => $functionworkplace['FunctionWorkplace_Name']];
  1608.         if ($new_entry) {
  1609.             $breadcrumbs[] = ['label' => 'Skill-Eintrag erstellen'];
  1610.         } else {
  1611.             $breadcrumbs[] = ['label' => 'Skill-Eintrag bearbeiten'];
  1612.         }
  1613.         return $this->render('@ProjectBizCitiBiz/Mpm/skillEdit.html.twig', [
  1614.             'formname' => $formDesc['formname'],
  1615.             'form_view' => new FormViewController(
  1616.                 $skillRepo,
  1617.                 $formDesc['formname'],
  1618.                 $formLayout['layout'],
  1619.                 $skillData
  1620.             ),
  1621.             'id' => $id,
  1622.             'functionworkplace' => $functionworkplace,
  1623.             'table_menu' => $tableMenuContext,
  1624.             'form' => $htmlForm->createView(),
  1625.             'is_new' => $new_entry,
  1626.             'breadcrumbs' => $breadcrumbs,
  1627.         ]);
  1628.     }
  1629.     /**
  1630.       * @param Request $request
  1631.       * @param         $id
  1632.       * @param null $technicalstandards_id
  1633.       *
  1634.       * @return RedirectResponse|array
  1635.       * @throws \Exception
  1636.       */
  1637.     public function bautechnicalstandardsEdit(Request $request$id$technicalstandards_id null)
  1638.     {
  1639.           $this->unifiedOptions $request->attributes->get('_unified_options');
  1640.     
  1641.           $unifiedOptions $this->filterOptionsForOptionResolver(
  1642.               $this->unifiedOptions
  1643.           );
  1644.     
  1645.           $resolvedOptions $this->getOptionsResolver()->resolve($unifiedOptions);
  1646.     
  1647.           $formname 'Form_TechnicalStandards';
  1648.     
  1649.           $formHelper $this->get('citibiz.form_helper');
  1650.           $formDesc $formHelper->getFormDesc(
  1651.               $formname,
  1652.               $this->getSecurityContextWrapper()
  1653.                   ->getUserRights()
  1654.           );
  1655.           $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1656.     
  1657.           //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1658.           //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1659.     
  1660.           // New or Existing
  1661.           $new_entry = !isset($technicalstandards_id);
  1662.     
  1663.           $skill $request->attributes->get('_access_stack')[0];
  1664.     
  1665.           $tableMenuContext $this
  1666.               ->get('projectbiz.menu.menu_helper')
  1667.               ->beginMenuContext([], 'Skill_ID');
  1668.     
  1669.           $technicalstandardsTableName 'TechnicalStandards';
  1670.           $technicalstandardsRepo $this->getGenericRepository($technicalstandardsTableName);
  1671.           if ($new_entry) {
  1672.               $technicalstandardsData $technicalstandardsRepo->defaultObject();
  1673.           } else {
  1674.               $technicalstandardsData $request->attributes->get('_access_stack')[1];
  1675.           }
  1676.     
  1677.           $htmlForm $this->createForm(
  1678.               GenericTableType::class,
  1679.               $technicalstandardsData,
  1680.               [
  1681.                   'repo' => $technicalstandardsRepo,
  1682.                   'columns' => $formLayout['form_columns']
  1683.               ]
  1684.           );
  1685.           $htmlForm->handleRequest($request);
  1686.     
  1687.           if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  1688.               /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1689.                *          thus the object was not saved.
  1690.                */
  1691.               $technicalstandardsData $htmlForm->getData();
  1692.               $skillTableName 'Skill';
  1693.               $skillRepo $this->getGenericRepository($skillTableName);
  1694.     
  1695.               $new_id null;
  1696.               $new_technicalstandards_id null;
  1697.               $skillRepo->getConnection()->beginTransaction();
  1698.               try {
  1699.                   $new_technicalstandards_id $technicalstandardsRepo->persist($technicalstandardsData);
  1700.     
  1701.                   $technicalstandardsIds = [];
  1702.                   if ($skill['Skill_VIRT_TechnicalStandards'] != '') {
  1703.                       $technicalstandardsIds explode(','$skill['Skill_VIRT_TechnicalStandards']);
  1704.                       if (isset($technicalstandards_id)) {
  1705.                           $technicalstandardsIds array_diff($technicalstandardsIds, array($technicalstandards_id));
  1706.                       }
  1707.     
  1708.                   }
  1709.                   $technicalstandardsIds[] = $new_technicalstandards_id;
  1710.                   $skill['Skill_VIRT_TechnicalStandards'] = implode(','$technicalstandardsIds);
  1711.                   $refsRepo $this->getGenericRepository('Refs');
  1712.                   $refsData $refsRepo->findBy(
  1713.                       new CriteriaComparison(
  1714.                           '=',
  1715.                           new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1716.                           new CriteriaConstant($skill['Skill_ID'])
  1717.                       )
  1718.                   );
  1719.                   $new_id $skillRepo->persist($skill);
  1720.               } catch (\Exception $ex) {
  1721.                   // $skillRepo->getConnection()->rollBack();
  1722.                   throw($ex);
  1723.               }
  1724.     
  1725.               $skillRepo->getConnection()->commit();
  1726.     
  1727.               if ($new_id && $new_technicalstandards_id) {
  1728.                   if ($new_entry) {
  1729.                       $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1730.                   } else {
  1731.                       $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1732.                   }
  1733.     
  1734.                   return $this->redirect(
  1735.                       $this->generateUrl(
  1736.                           'bau_skill_technicalstandards_edit',
  1737.                           array('id' => $new_id'technicalstandards_id' => $new_technicalstandards_id)
  1738.                       )
  1739.                   );
  1740.               } else if ($new_entry) {
  1741.                   $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1742.               } else {
  1743.                   $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1744.               }
  1745.           } elseif ($htmlForm->isSubmitted()) {
  1746.               $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  1747.           }
  1748.     
  1749.           $breadcrumbs = [
  1750.               ['label' => 'Skill'],
  1751.           ];
  1752.           $breadcrumbs[] = ['label' => $skill['Skill_Name']];
  1753.           if ($new_entry) {
  1754.               $breadcrumbs[] = ['label' => 'TechnicalStandards-Eintrag erstellen'];
  1755.           } else {
  1756.               $breadcrumbs[] = ['label' => 'TechnicalStandards-Eintrag bearbeiten'];
  1757.           }
  1758.     
  1759.           return $this->render('@ProjectBizCitiBiz/Mpm/TechnicalStandardsEdit.html.twig', [
  1760.               'formname' => $formDesc['formname'],
  1761.               'form_view' => new FormViewController(
  1762.                   $technicalstandardsRepo,
  1763.                   $formDesc['formname'],
  1764.                   $formLayout['layout'],
  1765.                   $technicalstandardsData
  1766.               ),
  1767.               'id' => $id,
  1768.               'skill' => $skill,
  1769.               'table_menu' => $tableMenuContext,
  1770.               'form' => $htmlForm->createView(),
  1771.               'is_new' => $new_entry,
  1772.               'breadcrumbs' => $breadcrumbs,
  1773.           ]);
  1774.     }
  1775.     /**
  1776.      * @param Request $request
  1777.      * @param         $id
  1778.      * @param null $operationcenter_id
  1779.      *
  1780.      * @return RedirectResponse|array
  1781.      * @throws \Exception
  1782.      */
  1783.     public function bauoperationcenterEdit(Request $request$id$operationcenter_id null)
  1784.     {
  1785.         $this->unifiedOptions $request->attributes->get('_unified_options');
  1786.         $formname 'Form_OperationCenter';
  1787.         $formHelper $this->get('citibiz.form_helper');
  1788.         $formDesc $formHelper->getFormDesc(
  1789.             $formname,
  1790.             $this->getSecurityContextWrapper()
  1791.                 ->getUserRights()
  1792.         );
  1793.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1794.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1795.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1796.         // New or Existing
  1797.         $new_entry = !isset($operationcenter_id);
  1798.         $functionworkplace $request->attributes->get('_access_stack')[0];
  1799.         $tableMenuContext $this
  1800.             ->get('projectbiz.menu.menu_helper')
  1801.             ->beginMenuContext([], 'FunctionWorkplace_ID');
  1802.         $operationcenterTableName 'OperationCenter';
  1803.         $operationcenterRepo $this->getGenericRepository($operationcenterTableName);
  1804.         if ($new_entry) {
  1805.             $operationcenterData $operationcenterRepo->defaultObject();
  1806.         } else {
  1807.             $operationcenterData $request->attributes->get('_access_stack')[1];
  1808.         }
  1809.         $htmlForm $this->createForm(
  1810.             GenericTableType::class,
  1811.             $operationcenterData,
  1812.             [
  1813.                 'repo' => $operationcenterRepo,
  1814.                 'columns' => $formLayout['form_columns']
  1815.             ]
  1816.         );
  1817.         $htmlForm->handleRequest($request);
  1818.         if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  1819.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1820.              *          thus the object was not saved.
  1821.              */
  1822.             $operationcenterData $htmlForm->getData();
  1823.             $functionworkplaceTableName 'FunctionWorkplace';
  1824.             $functionworkplaceRepo $this->getGenericRepository($functionworkplaceTableName);
  1825.             $functionworkplaceRepo->getConnection()->beginTransaction();
  1826.             try {
  1827.                 $new_operationcenter_id $operationcenterRepo->persist($operationcenterData);
  1828.                 $operationcenterIds = [];
  1829.                 if ($functionworkplace['FunctionWorkplace_VIRT_OperationCenter'] != '') {
  1830.                     $operationcenterIds explode(','$functionworkplace['FunctionWorkplace_VIRT_OperationCenter']);
  1831.                     if (isset($operationcenter_id)) {
  1832.                         $operationcenterIds array_diff($operationcenterIds, [$operationcenter_id]);
  1833.                     }
  1834.                 }
  1835.                 $operationcenterIds[] = $new_operationcenter_id;
  1836.                 $functionworkplace['FunctionWorkplace_VIRT_OperationCenter'] = implode(','$operationcenterIds);
  1837.                 $refsRepo $this->getGenericRepository('Refs');
  1838.                 $refsData $refsRepo->findBy(
  1839.                     new CriteriaComparison(
  1840.                         '=',
  1841.                         new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1842.                         new CriteriaConstant($functionworkplace['FunctionWorkplace_ID'])
  1843.                     )
  1844.                 );
  1845.                 $new_id $functionworkplaceRepo->persist($functionworkplace);
  1846.             } catch (\Exception $ex) {
  1847.                 // $functionworkplaceRepo->getConnection()->rollBack();
  1848.                 throw($ex);
  1849.             }
  1850.             $functionworkplaceRepo->getConnection()->commit();
  1851.             if ($new_id && $new_operationcenter_id) {
  1852.                 if ($new_entry) {
  1853.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1854.                 } else {
  1855.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1856.                 }
  1857.                 return $this->redirect(
  1858.                     $this->generateUrl(
  1859.                         'bau_functionworkplace_operationcenter_edit',
  1860.                         [
  1861.                             'id' => $new_id,
  1862.                             'operationcenter_id' => $new_operationcenter_id
  1863.                         ]
  1864.                     )
  1865.                 );
  1866.             } else if ($new_entry) {
  1867.                 $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1868.             } else {
  1869.                 $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1870.             }
  1871.         } elseif ($htmlForm->isSubmitted()) {
  1872.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  1873.         }
  1874.         $breadcrumbs = [
  1875.             ['label' => 'FunctionWorkplace'],
  1876.         ];
  1877.         $breadcrumbs[] = ['label' => $functionworkplace['FunctionWorkplace_Name']];
  1878.         if ($new_entry) {
  1879.             $breadcrumbs[] = ['label' => 'Betriebswarte-Eintrag erstellen'];
  1880.         } else {
  1881.             $breadcrumbs[] = ['label' => 'OperationCenter-Eintrag bearbeiten'];
  1882.         }
  1883.         return $this->render('@ProjectBizCitiBiz/Mpm/OperationCenterEdit.html.twig', [
  1884.             'formname' => $formDesc['formname'],
  1885.             'form_view' => new FormViewController(
  1886.                 $operationcenterRepo,
  1887.                 $formDesc['formname'],
  1888.                 $formLayout['layout'],
  1889.                 $operationcenterData
  1890.             ),
  1891.             'id' => $id,
  1892.             'functionworkplace' => $functionworkplace,
  1893.             'table_menu' => $tableMenuContext,
  1894.             'form' => $htmlForm->createView(),
  1895.             'is_new' => $new_entry,
  1896.             'breadcrumbs' => $breadcrumbs,
  1897.         ]);
  1898.     }
  1899. /**
  1900.   * @Template("ProjectBizCitiBizBundle:Mpm:SPMRfPEdit.html.twig")
  1901.   *
  1902.   * @param Request $request
  1903.   * @param         $id
  1904.   * @param null $spmrfp_id
  1905.   *
  1906.   * @return RedirectResponse|array
  1907.   * @throws \Exception
  1908.   */
  1909.   public function bauspmrfpEditAction(Request $request$id$spmrfp_id null)
  1910. {
  1911.   $this->unifiedOptions $request->attributes->get('_unified_options');
  1912.   $unifiedOptions $this->filterOptionsForOptionResolver(
  1913.       $this->unifiedOptions
  1914.   );
  1915.   $resolvedOptions $this->getOptionsResolver()->resolve($unifiedOptions);
  1916.   $formname 'Form_SPMRfP';
  1917.   $formHelper $this->get('citibiz.form_helper');
  1918.   $formDesc $formHelper->getFormDesc(
  1919.       $formname,
  1920.       $this->getSecurityContextWrapper()
  1921.           ->getUserRights()
  1922.   );
  1923.   $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  1924.   //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  1925.   //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  1926.   // New or Existing
  1927.   $new_entry = !isset($spmrfp_id);
  1928.   $functionworkplace $request->attributes->get('_access_stack')[0];
  1929.   $tableMenuContext $this
  1930.       ->get('projectbiz.menu.menu_helper')
  1931.       ->beginMenuContext(array(), 'FunctionWorkplace_ID');
  1932.   $spmrfpTableName 'SPMRfP';
  1933.   $spmrfpRepo $this->getGenericRepository($spmrfpTableName);
  1934.   if ($new_entry) {
  1935.       $spmrfpData $spmrfpRepo->defaultObject();
  1936.   } else {
  1937.       $spmrfpData $request->attributes->get('_access_stack')[1];
  1938.   }
  1939.   $htmlForm $this->createForm(
  1940.       GenericTableType::class,
  1941.       $spmrfpData,
  1942.       array('repo' => $spmrfpRepo'columns' => $formLayout['form_columns'])
  1943.   );
  1944.   $htmlForm->handleRequest($request);
  1945.   if ($htmlForm->isValid()) {
  1946.       /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  1947.        *          thus the object was not saved.
  1948.        */
  1949.       $spmrfpData $htmlForm->getData();
  1950.       $functionworkplaceTableName 'FunctionWorkplace';
  1951.       $functionworkplaceRepo $this->getGenericRepository($functionworkplaceTableName);
  1952.       $new_id null;
  1953.       $new_spmrfp_id null;
  1954.       $functionworkplaceRepo->getConnection()->beginTransaction();
  1955.       try {
  1956.           $new_spmrfp_id $spmrfpRepo->persist($spmrfpData);
  1957.           $spmrfpIds = array();
  1958.           if ($functionworkplace['FunctionWorkplace_VIRT_SPMRfP'] != '') {
  1959.               $spmrfpIds explode(','$functionworkplace['FunctionWorkplace_VIRT_SPMRfP']);
  1960.               if (isset($spmrfp_id)) {
  1961.                   $spmrfpIds array_diff($spmrfpIds, array($spmrfp_id));
  1962.               }
  1963.           }
  1964.           $spmrfpIds[] = $new_spmrfp_id;
  1965.           $functionworkplace['FunctionWorkplace_VIRT_SPMRfP'] = implode(','$spmrfpIds);
  1966.           $refsRepo $this->getGenericRepository('Refs');
  1967.           $refsData $refsRepo->findBy(
  1968.             new CriteriaComparison(
  1969.                 '=',
  1970.                 new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  1971.                 new CriteriaConstant($functionworkplace['FunctionWorkplace_ID'])
  1972.             )
  1973.       );
  1974.           $new_id $functionworkplaceRepo->persist($functionworkplace);
  1975.       }
  1976.       catch (\Exception $ex) {
  1977.          // $functionworkplaceRepo->getConnection()->rollBack();
  1978.           throw($ex);
  1979.       }
  1980.       $functionworkplaceRepo->getConnection()->commit();
  1981.       if ($new_id && $new_spmrfp_id) {
  1982.           if ($new_entry) {
  1983.               $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  1984.           } else {
  1985.               $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  1986.           }
  1987.           return $this->redirect(
  1988.               $this->generateUrl(
  1989.                   'bau_functionworkplace_spmrfp_edit',
  1990.                   array('id' => $new_id'spmrfp_id' => $new_spmrfp_id)
  1991.               )
  1992.           );
  1993.       } else {
  1994.           if ($new_entry) {
  1995.               $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  1996.           } else {
  1997.               $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  1998.           }
  1999.       }
  2000.   } elseif ($htmlForm->isSubmitted()) {
  2001.       $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  2002.   }
  2003.   $breadcrumbs = array(
  2004.       array('label' => 'FunctionWorkplace'),
  2005.   );
  2006.   if ($new_entry) {
  2007.       $breadcrumbs[] = array('label' => $functionworkplace['FunctionWorkplace_Name']);
  2008.       $breadcrumbs[] = array('label' => 'Betriebswarte-Eintrag erstellen');
  2009.   } else {
  2010.       $breadcrumbs[] = array('label' =>$functionworkplace['FunctionWorkplace_Name']);
  2011.       $breadcrumbs[] = array('label' => 'SPMRfP-Eintrag bearbeiten');
  2012.   }
  2013.   return array(
  2014.       'formname' => $formDesc['formname'],
  2015.       'form_view' => new FormViewController(
  2016.           $spmrfpRepo,
  2017.           $formDesc['formname'],
  2018.           $formLayout['layout'],
  2019.           $spmrfpData
  2020.       ),
  2021.       'id' => $id,
  2022.       'functionworkplace' => $functionworkplace,
  2023.       'table_menu' => $tableMenuContext,
  2024.       'form' => $htmlForm->createView(),
  2025.       'is_new' => $new_entry,
  2026.       'breadcrumbs' => $breadcrumbs,
  2027.   );
  2028. }
  2029.     /**
  2030.      * @param Request $request
  2031.      * @param         $id
  2032.      * @param null $document_id
  2033.      *
  2034.      * @return RedirectResponse|array
  2035.      * @throws \Exception
  2036.      */
  2037.     public function mailsEdit(Request $request$id$document_id null)
  2038.     {
  2039.         $this->unifiedOptions $request->attributes->get('_unified_options');
  2040.     
  2041.         $unifiedOptions $this->filterOptionsForOptionResolver(
  2042.             $this->unifiedOptions
  2043.         );
  2044.     
  2045.         $resolvedOptions $this->getOptionsResolver()->resolve($unifiedOptions);
  2046.     
  2047.         $formname 'Form_Documents_Email';
  2048.     
  2049.         $formHelper $this->get('citibiz.form_helper');
  2050.         $formDesc $formHelper->getFormDesc(
  2051.             $formname,
  2052.             $this->getSecurityContextWrapper()
  2053.                 ->getUserRights()
  2054.         );
  2055.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  2056.     
  2057.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  2058.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  2059.     
  2060.         // New or Existing
  2061.         $new_entry = !isset($document_id);
  2062.     
  2063.         $mpm $request->attributes->get('_access_stack')[0];
  2064.     
  2065.         $tableMenuContext $this
  2066.             ->get('projectbiz.menu.menu_helper')
  2067.             ->beginMenuContext(array(), 'MPM_ID');
  2068.     
  2069.         $documentTableName 'Document';
  2070.         $documentRepo $this->getGenericRepository($documentTableName);
  2071.         if ($new_entry) {
  2072.             $documentData $documentRepo->defaultObject();
  2073.         } else {
  2074.             $documentData $request->attributes->get('_access_stack')[1];
  2075.         }
  2076.     
  2077.         $htmlForm $this->createForm(
  2078.             GenericTableType::class,
  2079.             $documentData,
  2080.             array('repo' => $documentRepo'columns' => $formLayout['form_columns'])
  2081.         );
  2082.         $htmlForm->handleRequest($request);
  2083.     
  2084.         if ($htmlForm->isValid()) {
  2085.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  2086.              *          thus the object was not saved.
  2087.              */
  2088.             $documentData $htmlForm->getData();
  2089.             $mpmRepo $this->getMpmRepository();
  2090.     
  2091.             $new_id null;
  2092.             $new_document_id null;
  2093.             $mpmRepo->getConnection()->beginTransaction();
  2094.             try {
  2095.                 $new_document_id $documentRepo->persist($documentData);
  2096.     
  2097.                 $documentIds = array();
  2098.                 if ($mpm['MPM_VIRT_Documents'] != '') {
  2099.                     $documentIds explode(','$mpm['MPM_VIRT_Documents']);
  2100.                     if (isset($document_id)) {
  2101.                         $documentIds array_diff($documentIds, array($document_id));
  2102.                     }
  2103.     
  2104.                 }
  2105.                 $documentIds[] = $new_document_id;
  2106.                 $mpm['MPM_VIRT_Documents'] = implode(','$documentIds);
  2107.                 $new_id $mpmRepo->persist($mpm);
  2108.             } catch (\Exception $ex) {
  2109.                 $mpmRepo->getConnection()->rollBack();
  2110.                 throw($ex);
  2111.             }
  2112.     
  2113.             $mpmRepo->getConnection()->commit();
  2114.     
  2115.             if ($new_id && $new_document_id) {
  2116.                 if ($new_entry) {
  2117.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  2118.                 } else {
  2119.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  2120.                 }
  2121.     
  2122.                 return $this->redirect(
  2123.                     $this->generateUrl(
  2124.                         'overview_documents_edit',
  2125.                         array('id' => $new_id'document_id' => $new_document_id)
  2126.                     )
  2127.                 );
  2128.             }
  2129.             if ($new_entry) {
  2130.                 $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  2131.             } else {
  2132.                 $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  2133.             }
  2134.         } elseif ($htmlForm->isSubmitted()) {
  2135.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  2136.         }
  2137.     
  2138.         $breadcrumbs = array(
  2139.             array('label' => 'Overview'),
  2140.         );
  2141.         if ($new_entry) {
  2142.             $breadcrumbs[] = array('label' => $mpm['MPM_Projectname']);
  2143.             $breadcrumbs[] = array('label' => 'Dokument erstellen');
  2144.         } else {
  2145.             $breadcrumbs[] = array('label' => $mpm['MPM_Projectname']);
  2146.             $breadcrumbs[] = array('label' => 'Dokument bearbeiten');
  2147.         }
  2148.     
  2149.         return $this->render('@ProjectBizCitiBiz/Mpm/mailsEdit.html.twig', [
  2150.             'formname' => $formDesc['formname'],
  2151.             'form_view' => new FormViewController(
  2152.                 $documentRepo,
  2153.                 $formDesc['formname'],
  2154.                 $formLayout['layout'],
  2155.                 $documentData
  2156.             ),
  2157.             'id' => $id,
  2158.             'overview' => $mpm,
  2159.             'table_menu' => $tableMenuContext,
  2160.             'form' => $htmlForm->createView(),
  2161.             'is_new' => $new_entry,
  2162.             'breadcrumbs' => $breadcrumbs,
  2163.         ]);
  2164.     }
  2165.     /**
  2166.      * @param Request $request
  2167.      * @param         $id
  2168.      * @param null $spmcost_id
  2169.      *
  2170.      * @return RedirectResponse|array
  2171.      * @throws \Exception
  2172.      */
  2173.     public function bauspmcostEdit(Request $request$id$spmcost_id null$form)
  2174.     {
  2175.         $this->unifiedOptions $request->attributes->get('_unified_options');
  2176.         $formname $form;
  2177.         $formHelper $this->get('citibiz.form_helper');
  2178.         $formDesc $formHelper->getFormDesc(
  2179.             $formname,
  2180.             $this->getSecurityContextWrapper()
  2181.                 ->getUserRights()
  2182.         );
  2183.         $formLayout $formHelper->getFormLayout($formDesc); // returns [layout, columns]
  2184.         //$sourceRepo             = $formHelper->getFormSourceRepo($formDesc);
  2185.         //$targetRepo             = $formHelper->getFormTargetRepo($formDesc);
  2186.         // New or Existing
  2187.         $new_entry = !isset($spmcost_id);
  2188.         $mpm $request->attributes->get('_access_stack')[0];
  2189.         $tableMenuContext $this
  2190.             ->get('projectbiz.menu.menu_helper')
  2191.             ->beginMenuContext([], 'MPM_ID');
  2192.         $spmTableName 'SPMCost';
  2193.         $spmRepo $this->getGenericRepository($spmTableName);
  2194.         if ($new_entry) {
  2195.             $spmData $spmRepo->defaultObject();
  2196.         } else {
  2197.             $spmData $request->attributes->get('_access_stack')[1];
  2198.         }
  2199.         $htmlForm $this->createForm(
  2200.             GenericTableType::class,
  2201.             $spmData,
  2202.             [
  2203.                 'repo' => $spmRepo,
  2204.                 'columns' => $formLayout['form_columns']
  2205.             ]
  2206.         );
  2207.         $htmlForm->handleRequest($request);
  2208.         if ($htmlForm->isSubmitted() && $htmlForm->isValid()) {
  2209.             /* @todo:   maybe add some exception-handling too; know, when no changes were found and
  2210.              *          thus the object was not saved.
  2211.              */
  2212.             $spmData $htmlForm->getData();
  2213.             $mpmRepo $this->getMPMRepository();
  2214.             
  2215.             $mpmRepo->getConnection()->beginTransaction();
  2216.             try {
  2217.                 $new_spmcost_id $spmRepo->persist($spmData);
  2218.                 $spmIds = [];
  2219.                 if ($mpm['MPM_VIRT_SPMCOST'] !== '') {
  2220.                     $spmIds explode(','$mpm['MPM_VIRT_SPMCOST']);
  2221.                     if (isset($spmcost_id)) {
  2222.                         $spmIds array_diff($spmIds, [$spmcost_id]);
  2223.                     }
  2224.                 }
  2225.                 $spmIds[] = $new_spmcost_id;
  2226.                 $mpm['MPM_VIRT_SPMCOST'] = implode(','$spmIds);
  2227.                 $refsRepo $this->getGenericRepository('Refs');
  2228.                 $refsData $refsRepo->findBy(
  2229.                     new CriteriaComparison(
  2230.                         '=',
  2231.                         new CriteriaMappedColumn('Refs_Target_LINK_ID'),
  2232.                         new CriteriaConstant($mpm['MPM_ID'])
  2233.                     )
  2234.                 );
  2235.                 $new_id $mpmRepo->persist($mpm);
  2236.             } catch (\Exception $ex) {
  2237.                 // $mpmRepo->getConnection()->rollBack();
  2238.                 throw($ex);
  2239.             }
  2240.             $mpmRepo->getConnection()->commit();
  2241.             if ($new_id && $new_spmcost_id) {
  2242.                 if ($new_entry) {
  2243.                     $this->addFlashAndTrans('success'Messages::msgSuccessCreate);
  2244.                 } else {
  2245.                     $this->addFlashAndTrans('success'Messages::msgSuccessSave);
  2246.                 }
  2247.                 return $this->redirect(
  2248.                     $this->generateUrl(
  2249.                         'bau_mpm_spmcost_edit',
  2250.                         [
  2251.                             'id' => $new_id
  2252.                             'spmcost_id' => $new_spmcost_id
  2253.                         ]
  2254.                     )
  2255.                 );
  2256.             }
  2257.             if ($new_entry) {
  2258.                 $this->addFlashAndTrans('danger'Messages::msgErrorCreate);
  2259.             } else {
  2260.                 $this->addFlashAndTrans('danger'Messages::msgErrorSave);
  2261.             }
  2262.         } elseif ($htmlForm->isSubmitted()) {
  2263.             $this->addFlashAndTrans('danger'Messages::msgFormValidationFailed);
  2264.         }
  2265.         $breadcrumbs = [
  2266.             ['label' => 'MPM'],
  2267.         ];
  2268.         $breadcrumbs[] = ['label' => $mpm['MPM_Projectname']];
  2269.         if ($new_entry) {
  2270.             $breadcrumbs[] = ['label' => 'Kosten-Eintrag erstellen'];
  2271.         } else {
  2272.             $breadcrumbs[] = ['label' => 'Kosten-Eintrag bearbeiten'];
  2273.         }
  2274.         return $this->render('@ProjectBizCitiBiz/Mpm/spmcostEdit.html.twig', [
  2275.             'formname' => $formDesc['formname'],
  2276.             'form_view' => new FormViewController(
  2277.                 $spmRepo,
  2278.                 $formDesc['formname'],
  2279.                 $formLayout['layout'],
  2280.                 $spmData
  2281.             ),
  2282.             'id' => $id,
  2283.             'mpm' => $mpm,
  2284.             'table_menu' => $tableMenuContext,
  2285.             'form' => $htmlForm->createView(),
  2286.             'is_new' => $new_entry,
  2287.             'breadcrumbs' => $breadcrumbs,
  2288.         ]);
  2289.     }
  2290. }