bundles/ADAS/eBudzetBundle/Datatables/BuWnioskiDatatable.php line 268

Open in your IDE?
  1. <?php
  2. namespace ADAS\eBudzetBundle\Datatables;
  3. use ADAS\eBudzetBundle\Entity\BuStatusy;
  4. use ADAS\eBudzetBundle\Entity\BuWnioski;
  5. use ADAS\eBudzetBundle\Services\Wnioski\CzyRenderowacPrzyciskWysylaniaCallback;
  6. use ADAS\eBudzetBundle\Services\Wnioski\CzyRenderowacPrzyciskUsuwaniaCallback;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Exception;
  9. use Sg\DatatablesBundle\Datatable\View\AbstractDatatableView;
  10. use Sg\DatatablesBundle\Datatable\View\Style;
  11. use Symfony\Component\Routing\RouterInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. /**
  16.  * Class BuWnioskiDatatable
  17.  *
  18.  * @package ADAS\eBudzetBundle\Datatables
  19.  */
  20. class BuWnioskiDatatable extends AbstractDatatableView {
  21.     /** @var CzyRenderowacPrzyciskUsuwaniaCallback */
  22.     private $czyRenderowacPrzyciskUsuwaniaCallback;
  23.     /** @var CzyRenderowacPrzyciskWysylaniaCallback */
  24.     private $czyRenderowacPrzyciskWysylaniaCallback;
  25.     /** @var boolean */
  26.     private $podpis;
  27.     /**
  28.      * BuWnioskiDatatable constructor.
  29.      *
  30.      * @param AuthorizationCheckerInterface $authorizationChecker
  31.      * @param TokenStorageInterface $securityToken
  32.      * @param TranslatorInterface $translator
  33.      * @param RouterInterface $router
  34.      * @param EntityManagerInterface $em
  35.      * @param CzyRenderowacPrzyciskUsuwaniaCallback $renderowacPrzyciskUsuwaniaCallback
  36.      * @param CzyRenderowacPrzyciskWysylaniaCallback $czyRenderowacPrzyciskWysylaniaCallback
  37.      */
  38.     public function __construct(AuthorizationCheckerInterface $authorizationChecker, TokenStorageInterface $securityToken, TranslatorInterface $translator, RouterInterface $router, EntityManagerInterface $em, CzyRenderowacPrzyciskWysylaniaCallback $czyRenderowacPrzyciskWysylaniaCallback, CzyRenderowacPrzyciskUsuwaniaCallback $renderowacPrzyciskUsuwaniaCallback, bool $podpis) {
  39.         $this->czyRenderowacPrzyciskUsuwaniaCallback = $renderowacPrzyciskUsuwaniaCallback;
  40.         $this->czyRenderowacPrzyciskWysylaniaCallback = $czyRenderowacPrzyciskWysylaniaCallback;
  41.         $this->podpis = $podpis;
  42.         parent::__construct($authorizationChecker, $securityToken, $translator, $router, $em);
  43.     }
  44.     /**
  45.      *
  46.      * {@inheritdoc}
  47.      */
  48.     public function buildDatatable(array $options = []) {
  49.         $this->ustawOpcjeIParametry();
  50.         $this->dodajPola();
  51.     }
  52.     /**
  53.      *
  54.      * {@inheritdoc}
  55.      */
  56.     public function getEntity() {
  57.         return BuWnioski::class;
  58.     }
  59.     /**
  60.      *
  61.      * {@inheritdoc}
  62.      */
  63.     public function getName() {
  64.         return 'buwnioski_datatable';
  65.     }
  66.     /**
  67.      *
  68.      * @return callable|\Closure|null
  69.      */
  70.     public function getLineFormatter() {
  71.         $formatter = function ($line) {
  72.             if (array_key_exists('rodzaj', $line)) {
  73.                 if ($line ['rodzaj'] == BuWnioski::RODZAJ_WNIOSEK_POCZATKOWY) {
  74.                     $line ['rodzaj'] = 'Wniosek początkowy';
  75.                 } else if ($line ['rodzaj'] == BuWnioski::RODZAJ_WNIOSEK_O_ZMIANE) {
  76.                     $line ['rodzaj'] = 'Wniosek o zmianę';
  77.                 } else {
  78.                     $line ['rodzaj'] = 'brak obsługi';
  79.                 }
  80.             }
  81.             return $line;
  82.         };
  83.         return $formatter;
  84.     }
  85.     /**
  86.      *
  87.      * @throws Exception
  88.      */
  89.     protected function ustawOpcjeIParametry() {
  90.         $this->topActions->set([
  91.                 'start_html' => '<div class="row"><div class="col-sm-3">',
  92.                 'end_html' => '</div></div>',
  93.                 'actions' => [
  94.                         [
  95.                                 'route' => $this->router->generate('buwnioski_new'),
  96.                                 'label' => $this->translator->trans('datatables.actions.new'),
  97.                                 'icon' => 'glyphicon glyphicon-plus',
  98.                                 'attributes' => [
  99.                                         'rel' => 'tooltip',
  100.                                         'title' => $this->translator->trans('datatables.actions.new'),
  101.                                         'class' => 'btn btn-primary',
  102.                                         'role' => 'button'
  103.                                 ]
  104.                         ],
  105.                         [
  106.                                 'route' => $this->router->generate('buwnioski_new', ['fromData' => true]),
  107.                                 'label' => $this->translator->trans('Nowy z danych'),
  108.                                 'icon' => 'glyphicon glyphicon-import',
  109.                                 'attributes' => [
  110.                                         'rel' => 'tooltip',
  111.                                         'title' => $this->translator->trans('datatables.actions.new'),
  112.                                         'class' => 'btn btn-primary',
  113.                                         'role' => 'button'
  114.                                 ]
  115.                         ],
  116.                 ]
  117.         ]);
  118.         $this->callbacks->set([
  119.                 'row_callback' => [
  120.                         'template' => '@ADASeBudzet/datatables/rowCallbackWnioski.js.twig',
  121.                         'vars' => [
  122.                                 'widok' => 'SP'
  123.                         ]
  124.                 ]
  125.         ]);
  126.         $this->features->set([
  127.                 'auto_width' => true,
  128.                 'defer_render' => false,
  129.                 'info' => true,
  130.                 'jquery_ui' => false,
  131.                 'length_change' => true,
  132.                 'ordering' => true,
  133.                 'paging' => true,
  134.                 'processing' => true,
  135.                 'scroll_x' => false,
  136.                 'scroll_y' => '',
  137.                 'searching' => true,
  138.                 'state_save' => false,
  139.                 'delay' => 0,
  140.                 'extensions' => [],
  141.                 'highlight' => false,
  142.                 'highlight_color' => 'red'
  143.         ]);
  144.         $this->ajax->set(array(
  145.                 'url' => $this->router->generate('buwnioski_results'),
  146.                 'type' => 'GET',
  147.                 'pipeline' => 0
  148.         ));
  149.         $this->options->set([
  150.                 'display_start' => 0,
  151.                 'defer_loading' => - 1,
  152.                 'dom' => 'lfrtip',
  153.                 'length_menu' => [
  154.                         10,
  155.                         25,
  156.                         50,
  157.                         100
  158.                 ],
  159.                 'order_classes' => true,
  160.                 'order' => [
  161.                         [
  162.                                 0,
  163.                                 'asc'
  164.                         ]
  165.                 ],
  166.                 'order_multi' => true,
  167.                 'page_length' => 10,
  168.                 'paging_type' => Style::FULL_NUMBERS_PAGINATION,
  169.                 'renderer' => '',
  170.                 'scroll_collapse' => false,
  171.                 'search_delay' => 0,
  172.                 'state_duration' => 7200,
  173.                 'stripe_classes' => [],
  174.                 'class' => Style::BOOTSTRAP_3_STYLE,
  175.                 'individual_filtering' => true,
  176.                 'individual_filtering_position' => 'head',
  177.                 'use_integration_options' => true,
  178.                 'force_dom' => false,
  179.                 'row_id' => 'nrid'
  180.         ]);
  181.     }
  182.     /**
  183.      *
  184.      * @throws Exception
  185.      */
  186.     protected function dodajPola() {
  187.         $this->columnBuilder->add('symbolWniosku', 'column', [
  188.                 'title' => 'Symbol Wniosku',
  189.                                 'searchable' => false
  190.         ])->add('rok', 'column', [
  191.                 'title' => 'Rok',
  192.                                 'width' => '50px'
  193.         ])->add('rStatus.status', 'column', [
  194.                 'title' => 'Status',
  195.                                 'searchable' => false
  196.         ])->add('rodzaj', 'column', [
  197.                 'title' => 'Rodzaj',
  198.                                 'searchable' => false
  199.         ])->add('dataWniosku', 'datetime', [
  200.                 'title' => 'Data Wniosku',
  201.                                 'width' => '200px',
  202.                 'filter' => ['daterange',['class' =>'form-control']]
  203.         ])->add('dataWyslania', 'datetime', [
  204.                 'title' => 'Data Wysłania',
  205.                                 'width' => '200px',
  206.                 'filter' => ['daterange',['class' =>'form-control']]
  207.                 
  208.         ])->add('przekrLimitu', 'column', [
  209.                 'title' => 'PrzekrLimitu',
  210.                 'visible' => false
  211.         ])->add('nrid', 'column', [
  212.                 'title' => 'Nrid',
  213.                 'visible' => false
  214.         ])->add('wydzial.nazwa', 'column', [
  215.                 'title' => 'Wydział',
  216.                                 'searchable' => false
  217.         ])->add('jednostka.nazwa', 'column', [
  218.                 'title' => 'Jednostka',
  219.                                 'searchable' => false
  220.         ])->add('uzytkownikAkceptujacy.id', 'column', [
  221.                 'title' => 'uzytkownikAkceptujacy',
  222.                 'visible' => false,
  223.                                 'searchable' => false
  224.         ]);
  225.         if ($this->podpis) {
  226.             $this->columnBuilder->add('dataPodpisu', 'datetime', [
  227.                 'title' => 'Data Podpisu'
  228.             ])->add('podpisal', 'column', [
  229.                 'title' => 'Podpisał'
  230.             ]);
  231.         }
  232.         
  233.         $this->dodajPoleZAkcjami();
  234.     }
  235.     /**
  236.      *
  237.      * @throws Exception
  238.      */
  239.     protected function dodajPoleZAkcjami(): void
  240.     {
  241.         $this->columnBuilder->add(null, 'action', [
  242.             'title' => $this->translator->trans('datatables.actions.title'),
  243.             'width' => '250px',
  244.             'actions' => [
  245.                 [
  246.                     'route' => 'buwnioski_show',
  247.                     'route_parameters' => [
  248.                         'id' => 'nrid'
  249.                     ],
  250.                     'label' => $this->translator->trans('datatables.actions.show'),
  251.                     'icon' => 'glyphicon glyphicon-eye-open',
  252.                     'attributes' => [
  253.                         'rel' => 'tooltip',
  254.                         'title' => $this->translator->trans('datatables.actions.show'),
  255.                         'class' => 'btn btn-primary btn-xs',
  256.                         'role' => 'button'
  257.                     ]
  258.                 ],
  259.                 [
  260.                     'route' => 'buwnioski_edit',
  261.                     'route_parameters' => [
  262.                         'id' => 'nrid'
  263.                     ],
  264.                     'label' => $this->translator->trans('datatables.actions.edit'),
  265.                     'icon' => 'glyphicon glyphicon-edit',
  266.                     'attributes' => [
  267.                         'rel' => 'tooltip',
  268.                         'title' => $this->translator->trans('datatables.actions.edit'),
  269.                         'class' => 'btn btn-primary btn-xs',
  270.                         'role' => 'button'
  271.                     ],
  272.                     'render_if' => function ($row) {
  273.                         return in_array($row ['rStatus'] ['nrid'], BuStatusy::getStatusyPozwalajaceNaModyfikacjePozycji());
  274.                     }
  275.                 ],
  276.                 [
  277.                     'route' => 'lista_pozycji_wniosku',
  278.                     'route_parameters' => [
  279.                         'nrid' => 'nrid'
  280.                     ],
  281.                     'label' => 'Pozycje',
  282.                     'icon' => 'glyphicon glyphicon-list-alt',
  283.                     'attributes' => [
  284.                         'rel' => 'tooltip',
  285.                         'title' => 'Pozycje',
  286.                         'class' => 'btn btn-primary btn-xs',
  287.                         'role' => 'button'
  288.                     ]
  289.                 ],
  290.                 [
  291.                     'route' => 'buwniosek_udostepnij',
  292.                     'route_parameters' => [
  293.                         'nrid' => 'nrid'
  294.                     ],
  295.                     'label' => 'Udostępnij',
  296.                     'icon' => 'glyphicon glyphicon-share',
  297.                     'attributes' => [
  298.                         'rel' => 'tooltip',
  299.                         'title' => 'Udostępnij',
  300.                         'class' => 'btn btn-primary btn-xs udostepnij',
  301.                         'role' => 'button'
  302.                     ],
  303.                     'render_if' => function ($row) {
  304.                         return in_array($row ['rStatus'] ['nrid'], BuStatusy::getStatusyPozwalajaceNaUdostepnienie());
  305.                     }
  306.                 ],
  307.                 [
  308.                     'route' => 'buwniosek_wyslij',
  309.                     'route_parameters' => [
  310.                         'nrid' => 'nrid'
  311.                     ],
  312.                     'label' => 'Wyślij',
  313.                     'icon' => 'glyphicon glyphicon-flash',
  314.                     'attributes' => [
  315.                         'rel' => 'tooltip',
  316.                         'title' => 'Wyślij',
  317.                         'class' => 'btn btn-primary btn-xs wyslij',
  318.                         'role' => 'button'
  319.                     ],
  320.                     'render_if' => function ($row) {
  321.                         // demo technologiczne - testowanie __invoke
  322.                         return ($this->czyRenderowacPrzyciskWysylaniaCallback)($row);
  323.                     }
  324.                 ],
  325.                 [
  326.                     'route' => 'wniosek_usun',
  327.                     'route_parameters' => [
  328.                         'nrid' => 'nrid'
  329.                     ],
  330.                     'label' => 'Usuń',
  331.                     'icon' => 'glyphicon glyphicon-remove',
  332.                     'attributes' => [
  333.                         'rel' => 'tooltip',
  334.                         'title' => 'Usuń',
  335.                         'class' => 'btn btn-danger btn-xs usun',
  336.                         'role' => 'button'
  337.                     ],
  338.                     'render_if' => function ($row) {
  339.                         // demo technologiczne - testowanie __invoke
  340.                         return ($this->czyRenderowacPrzyciskUsuwaniaCallback)($row);
  341.                     },
  342.                     'confirm' => true,
  343.                     'confirm_message' => 'Czy jesteś pewien, że chcesz usunąć wniosek?'
  344.                 ],
  345.                 [
  346.                     'route' => 'wniosek_podpisz',
  347.                     'route_parameters' => [
  348.                         'id' => 'nrid'
  349.                     ],
  350.                     'label' => 'Podpisz',
  351.                     'icon' => 'glyphicon glyphicon-pencil',
  352.                     'attributes' => [
  353.                         'rel' => 'tooltip',
  354.                         'title' => 'Usuń',
  355.                         'class' => 'btn btn-warning btn-xs podpisz',
  356.                         'role' => 'button'
  357.                     ],
  358.                     'render_if' => function ($row) {
  359.                         return $this->podpis && ($row ['dataPodpisu'] == null);
  360.                     }
  361.                 ],
  362.                 [
  363.                     'route' => 'buwniosek_zatwierdz',
  364.                     'route_parameters' => [
  365.                         'nrid' => 'nrid'
  366.                     ],
  367.                     'label' => 'Zatwierdź',
  368.                     'icon' => 'glyphicon glyphicon-flash',
  369.                     'attributes' => [
  370.                         'rel' => 'tooltip',
  371.                         'title' => 'Zatwierdzone wnioski są zaznaczone kolorem zielonym',
  372.                         'class' => 'btn btn-success btn-xs zatwierdz',
  373.                         'role' => 'button'
  374.                     ],
  375.                     'render_if' => function ($row) {
  376.                         return $row ['rStatus']['nrid'] === BuStatusy::STATUS_WYSLANY && $row["uzytkownikAkceptujacy"] === null;
  377.                     }
  378.                 ]
  379.             ]
  380.         ]);
  381.     }
  382. }