src/Twig/StyleExtension.php line 47

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Twig/StyleExtension.php
  4. //----------------------------------------------------------------------
  5. namespace App\Twig;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Symfony\Component\Security\Core\Security;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Twig\Extension\AbstractExtension;
  10. use Twig\TwigFilter;
  11. use App\Entity\Client\Client;
  12. use App\Entity\Client\Zone;
  13. use App\Entity\Common\Attachment;
  14. use App\Entity\Equipment\Vehicle;
  15. use App\Entity\HR\Application\Application;
  16. use App\Entity\HR\HumanResource;
  17. use App\Entity\Ikea\ServiceOrder;
  18. use App\Entity\Ikea\ServiceOrderUpdate;
  19. use App\Entity\Location\Address;
  20. use App\Entity\Mission\Mission;
  21. use App\Entity\Planning\ExternalTask;
  22. use App\Entity\Planning\Task;
  23. use App\Entity\Platform\Command\Command;
  24. use App\Entity\Platform\Cost\Cost;
  25. use App\Entity\Platform\Demand\Demand;
  26. use App\Entity\Platform\Devis\Devis;
  27. use App\Entity\Platform\Devis\ExternalDevis;
  28. use App\Entity\Platform\ExternalMessage\ExternalMessage;
  29. use App\Entity\Platform\Invoice\ExternalInvoice;
  30. use App\Entity\Platform\Invoice\Invoice;
  31. use App\Entity\Platform\Society;
  32. use App\Entity\Platform\SocietyGroup\SocietyGroupCommand;
  33. use App\Entity\Platform\SocietyGroup\SocietyGroupInvoice;
  34. use App\Entity\Platform\Supplier;
  35. use App\Entity\Product\Product;
  36. use App\Entity\Product\Template;
  37. use App\Entity\SocietyGroup;
  38. use App\Entity\Webapp\Document;
  39. use App\Entity\Webapp\ExternalDocument;
  40. use App\Services\LogTools;
  41. class StyleExtension extends AbstractExtension
  42. {
  43.     public function __construct(Security $securityUrlGeneratorInterface $routerTranslatorInterface $translatorLogTools $logTools)
  44.     {
  45.         $this->security $security;
  46.         $this->router $router;
  47.         $this->translator $translator;
  48.         $this->logTools $logTools;
  49.     }
  50.     public function getFilters(): array
  51.     {
  52.         return [
  53.             new TwigFilter('style_address',                 [$this'styleAddress']),
  54.             new TwigFilter('style_address_gps',             [$this'styleAddressGps']),
  55.             new TwigFilter('style_application',             [$this'styleApplication']),
  56.             new TwigFilter('style_attachment',                 [$this'styleAttachment']),
  57.             new TwigFilter('style_client',                     [$this'styleClient']),
  58.             new TwigFilter('style_client_list',             [$this'styleClientList']),
  59.             new TwigFilter('style_command',                 [$this'styleCommand']),
  60.             new TwigFilter('style_cost',                     [$this'styleCost']),
  61.             new TwigFilter('style_demand',                     [$this'styleDemand']),
  62.             new TwigFilter('style_devis',                     [$this'styleDevis']),
  63.             new TwigFilter('style_document',                 [$this'styleDocument']),
  64.             new TwigFilter('style_external_devis',             [$this'styleExternalDevis']),
  65.             new TwigFilter('style_external_document',         [$this'styleExternalDocument']),
  66.             new TwigFilter('style_external_invoice',         [$this'styleExternalInvoice']),
  67.             new TwigFilter('style_external_message',         [$this'styleExternalMessage']),
  68.             new TwigFilter('style_external_task',             [$this'styleExternalTask']),
  69.             new TwigFilter('style_human_resource',             [$this'styleHumanResource']),
  70.             new TwigFilter('style_invoice',                 [$this'styleInvoice']),
  71.             new TwigFilter('style_mission',                 [$this'styleMission']),
  72.             new TwigFilter('style_society',                 [$this'styleSociety']),
  73.             new TwigFilter('style_society_group',             [$this'styleSocietyGroup']),
  74.             new TwigFilter('style_society_group_invoice',     [$this'styleSocietyGroupInvoice']),
  75.             new TwigFilter('style_society_group_command',     [$this'styleSocietyGroupCommand']),
  76.             new TwigFilter('style_supplier',                 [$this'styleSupplier']),
  77.             new TwigFilter('style_task',                     [$this'styleTask']),
  78.             new TwigFilter('style_template',                 [$this'styleTemplate']),
  79.             new TwigFilter('style_product',                 [$this'styleProduct']),
  80.             new TwigFilter('style_vehicle',                 [$this'styleVehicle']),
  81.             new TwigFilter('style_ikea_service_order',            [$this'styleIkeaServiceOrder']),
  82.             new TwigFilter('style_ikea_service_order_update',    [$this'styleIkeaServiceOrderUpdate']),
  83.             new TwigFilter('style_zone',                    [$this'styleZone']),
  84.         ];
  85.     }
  86.     /**
  87.      * @param Zone|null $object
  88.      * @return string
  89.      */
  90.     public function styleZone($object)
  91.     {
  92.         if (!($object instanceof Zone))
  93.         {
  94.             return "";
  95.         }
  96.         // if ($object->isEmptyValue())
  97.         // {
  98.         //     return $object->display();
  99.         // }
  100.         $url $this->router->generate('icod_platform_zone_view', array(
  101.             'id' =>    $object->getId(),
  102.         ));
  103.         $print '<a href="' $url '">';
  104.         $print .= $object->display();
  105.         $print .= '</a>';
  106.         return $print;
  107.     }
  108.     /**
  109.      * @param Product|null $object
  110.      * @param bool $displayFull = true
  111.      * @param bool $isGranted = true : If true, permission to view the object is checked
  112.      *                                    If false, link is displayed witout checking permission
  113.      * @return string
  114.      */
  115.     public function styleProduct($objectbool $displayFull truebool $isGranted true)
  116.     {
  117.         if (!($object instanceof Product))
  118.         {
  119.             return "";
  120.         }
  121.         $print "";
  122.         $display $object->displayFull();
  123.         if (!$displayFull)
  124.         {
  125.             $display $object->getRef();
  126.         }
  127.         // Check Permissions ?
  128.         if ($isGranted)
  129.         {
  130.             if ($this->security->isGranted('view_product'$object))
  131.             {
  132.                 $url $this->router->generate('icod_platform_product_view', array(
  133.                     'id' =>    $object->getId(),
  134.                 ));
  135.                 $print .= '<a href="' $url '">';
  136.                 $print .= $display;
  137.                 $print .= '</a>';
  138.             }
  139.             else
  140.             {
  141.                 $print .= $display;
  142.             }
  143.             return $print;
  144.         }
  145.         $url $this->router->generate('icod_platform_product_view', array(
  146.             'id' =>    $object->getId(),
  147.         ));
  148.         $print '<a href="' $url '">';
  149.         $print .= $display;
  150.         $print .= '</a>';
  151.         return $print;
  152.     }
  153.     /**
  154.      * @param Template|null $object
  155.      * @param bool $isGranted = true : If true, permission to view the object is checked
  156.      *                                    If false, link is displayed witout checking permission
  157.      * @return string
  158.      */
  159.     public function styleTemplate($object$isGranted true): string
  160.     {
  161.         if (!($object instanceof Template))
  162.         {
  163.             return "";
  164.         }
  165.         $print "";
  166.         $display $object->display();
  167.         // Check Permissions ?
  168.         if ($isGranted)
  169.         {
  170.             if ($this->security->isGranted('view_template'$object))
  171.             {
  172.                 $url $this->router->generate('icod_platform_template_view', array(
  173.                     'id' =>    $object->getId(),
  174.                 ));
  175.                 $print .= '<a href="' $url '">';
  176.                 $print .= $display;
  177.                 $print .= '</a>';
  178.             }
  179.             else
  180.             {
  181.                 $print .= $display;
  182.             }
  183.             return $print;
  184.         }
  185.         $url $this->router->generate('icod_platform_template_view', array(
  186.             'id' =>    $object->getId(),
  187.         ));
  188.         $print '<a href="' $url '">';
  189.         $print .= $display;
  190.         $print .= '</a>';
  191.         return $print;
  192.     }
  193.     public function styleIkeaServiceOrder($objectbool $displayFull false)
  194.     {
  195.         if (!($object instanceof ServiceOrder))
  196.         {
  197.             return "";
  198.         }
  199.         if ($displayFull)
  200.         {
  201.             $display $object->displayOp();
  202.         }
  203.         else
  204.         {
  205.             $display $object->getRef();
  206.         }
  207.         $print '';
  208.         if ($this->security->isGranted('view_ikea_service_order'$object))
  209.         {
  210.             $url $this->router->generate('icod_platform_ikea_service_order_view', array(
  211.                 'id' =>    $object->getId(),
  212.             ));
  213.             $print .= '<a href="' $url '">';
  214.             $print .= $display;
  215.             $print .= '</a>';
  216.         }
  217.         else
  218.         {
  219.             $print .= $display;
  220.         }
  221.         return $print;
  222.     }
  223.     public function styleIkeaServiceOrderUpdate($object)
  224.     {
  225.         if (!($object instanceof ServiceOrderUpdate))
  226.         {
  227.             return "";
  228.         }
  229.         // Build display
  230.         $display "";
  231.         if ($object->getCreationDate() !== null)
  232.         {
  233.             $display .= "[" $object->getCreationDate()->format("d/m/Y H:i:s") . "]";
  234.         }
  235.         if (!empty($display)) $display .= " ";
  236.         $display .= $object->getOrderNumber();
  237.         $display .= ", version " $object->getVersion();
  238.         // Build html
  239.         $print '';
  240.         if ($this->security->isGranted('view_ikea_service_order'$object->getServiceOrder()))
  241.         {
  242.             $url $this->router->generate('icod_platform_ikea_service_order_update_view', array(
  243.                 'id' =>    $object->getId(),
  244.             ));
  245.             $print .= '<a href="' $url '">';
  246.             $print .= $display;
  247.             $print .= '</a>';
  248.         }
  249.         else
  250.         {
  251.             $print .= $display;
  252.         }
  253.         return $print;
  254.     }
  255.     public function styleSocietyGroup($objectbool $isAdmin false): string
  256.     {
  257.         if (!($object instanceof SocietyGroup))
  258.         {
  259.             return "";
  260.         }
  261.         $display $object->display();
  262.         if ($isAdmin)
  263.         {
  264.             $url $this->router->generate('icod_admin_society_group_view', array(
  265.                 'id' =>    $object->getId(),
  266.             ));
  267.         }
  268.         else
  269.         {
  270.             $url $this->router->generate('icod_platform_society_group_view', array(
  271.                 'id' =>    $object->getId(),
  272.             ));
  273.         }
  274.         $print '';
  275.         if ($this->security->isGranted('view_society_group'$object))
  276.         {
  277.             $print .= '<a href="' $url '">';
  278.             $print .= $display;
  279.             $print .= '</a>';
  280.         }
  281.         else
  282.         {
  283.             $print .= $display;
  284.         }
  285.         return $print;
  286.     }
  287.     public function styleVehicle($object): string
  288.     {
  289.         if (!($object instanceof Vehicle))
  290.         {
  291.             return "";
  292.         }
  293.         $display $object->display();
  294.         $url $this->router->generate('icod_equipment_vehicle_view', array(
  295.             'id' => $object->getId(),
  296.         ));
  297.         $print '';
  298.         if ($this->security->isGranted('view_equipment'$object->getEquipment()))
  299.         {
  300.             $print .= '<a href="' $url '">';
  301.             $print .= $display;
  302.             $print .= '</a>';
  303.         }
  304.         else
  305.         {
  306.             $print .= $display;
  307.         }
  308.         return $print;
  309.     }
  310.     public function styleHumanResource($object$withDisplay false): string
  311.     {
  312.         if (!($object instanceof HumanResource))
  313.         {
  314.             return "";
  315.         }
  316.         if ($withDisplay)
  317.         {
  318.             $display $object->display();
  319.         }
  320.         else
  321.         {
  322.             $display $object->getEmail();
  323.         }
  324.         $url $this->router->generate('icod_platform_human_resource_view', array(
  325.             'id' => $object->getId(),
  326.         ));
  327.         $print '';
  328.         if ($this->security->isGranted('view_human_resource'$object))
  329.         {
  330.             $print .= '<a href="' $url '">';
  331.             $print .= $display;
  332.             $print .= '</a>';
  333.         }
  334.         else
  335.         {
  336.             $print .= $display;
  337.         }
  338.         return $print;
  339.     }
  340.     public function styleAttachment($objectstring $textToDisplay ''bool $withOwner false): string
  341.     {
  342.         if (!($object instanceof Attachment))
  343.         {
  344.             return "";
  345.         }
  346.         if (!empty($textToDisplay))
  347.         {
  348.             $display $textToDisplay;
  349.         }
  350.         else
  351.         {
  352.             $display $object->display();
  353.         }
  354.         $url $this->router->generate('icod_platform_attachment_view', array(
  355.             'id' => $object->getId(),
  356.         ));
  357.         // Build the print for twig
  358.         $print '';
  359.         if ($this->security->isGranted('view_attachment'$object))
  360.         {
  361.             $print .= '<a href="' $url '" rel="noreferrer" target="_blank">';
  362.             $print .= $display;
  363.             $print .= '</a>';
  364.         }
  365.         else
  366.         {
  367.             $print .= $display;
  368.         }
  369.         if ($withOwner)
  370.         {
  371.             if ($object->getMission() !== null)
  372.             {
  373.                 $ref $object->getMission()->getRef();
  374.                 $print .= "&nbsp;[$ref]";
  375.             }
  376.             else
  377.             {
  378.                 if ($object->getDevis() !== null)
  379.                 {
  380.                     $ref $object->getDevis()->getRef();
  381.                     $print .= "&nbsp;[$ref]";
  382.                 }
  383.             }
  384.         }
  385.         return $print;
  386.     }
  387.     public function styleTask($object): string
  388.     {
  389.         if (!($object instanceof Task))
  390.         {
  391.             return "";
  392.         }
  393.         $display $object->display();
  394.         $id $object->getId();
  395.         $print '';
  396.         if ($this->security->isGranted('view_task'$object) || $this->security->isGranted('edit_task'$object))
  397.         {
  398.             $print .= '<a href="javascript:void(0);" onclick="openTask(' $id ')">';
  399.             $print .= $display;
  400.             $print .= '</a>';
  401.         }
  402.         else
  403.         {
  404.             $print .= $display;
  405.         }
  406.         return $print;
  407.     }
  408.     public function styleSociety($object): string
  409.     {
  410.         if (!($object instanceof Society))
  411.         {
  412.             return "";
  413.         }
  414.         $display $object->display();
  415.         $url $this->router->generate('icod_platform_society_view', array(
  416.             'id' => $object->getId(),
  417.         ));
  418.         $print '';
  419.         if ($this->security->isGranted('view_society'$object))
  420.         {
  421.             $print .= '<a href="' $url '">';
  422.             $print .= $display;
  423.             $print .= '</a>';
  424.         }
  425.         else
  426.         {
  427.             $print .= $display;
  428.         }
  429.         return $print;
  430.     }
  431.     public function styleClient($object): string
  432.     {
  433.         if (!($object instanceof Client))
  434.         {
  435.             return "";
  436.         }
  437.         $display $object->display();
  438.         $url $this->router->generate('icod_platform_client_view', array(
  439.             'id' => $object->getId(),
  440.         ));
  441.         $print '';
  442.         if ($this->security->isGranted('view_client'$object))
  443.         {
  444.             $print .= '<a href="' $url '">';
  445.             $print .= $display;
  446.             $print .= '</a>';
  447.         }
  448.         else
  449.         {
  450.             $print .= $display;
  451.         }
  452.         return $print;
  453.     }
  454.     public function styleClientList($object): string
  455.     {
  456.         if (!($object instanceof Client))
  457.         {
  458.             return "";
  459.         }
  460.         $url "";
  461.         $translation "";
  462.         $print "";
  463.         if ($object->getIndividual() !== null)
  464.         {
  465.             if ($object->isProspect())
  466.             {
  467.                 $url $this->router->generate('icod_platform_client_prospect_list');
  468.                 $translation $this->translator->trans('prospects');
  469.             }
  470.             else
  471.             {
  472.                 $url $this->router->generate('icod_platform_client_individual_list');
  473.                 $translation $this->translator->trans('clients');
  474.             }
  475.         }
  476.         else
  477.         {
  478.             if ($object->getStore() !== null)
  479.             {
  480.                 $url $this->router->generate('icod_platform_client_store_list');
  481.                 $translation $this->translator->trans('emitters');
  482.             }
  483.         }
  484.         if (!empty($url) && !empty($translation))
  485.         {
  486.             $print .= '<a href="' $url '">';
  487.             $print .= $translation;
  488.             $print .= '</a>';
  489.         }
  490.         return $print;
  491.     }
  492.     public function styleDocument($object): string
  493.     {
  494.         if (!($object instanceof Document))
  495.         {
  496.             return "";
  497.         }
  498.         $display $object->display();
  499.         $url $this->router->generate('icod_pdf_document_create_pdf', array(
  500.             'id' => $object->getId(),
  501.         ));
  502.         $print '';
  503.         if ($this->security->isGranted('view_pdf_document'$object))
  504.         {
  505.             $print .= '<a href="' $url '">';
  506.             $print .= $display;
  507.             $print .= '</a>';
  508.         }
  509.         else
  510.         {
  511.             $print .= $display;
  512.         }
  513.         return $print;
  514.     }
  515.     public function styleExternalDevis($object): string
  516.     {
  517.         if (!($object instanceof ExternalDevis))
  518.         {
  519.             return "";
  520.         }
  521.         $display $object->display();
  522.         $url $this->router->generate('icod_platform_external_devis_view', array(
  523.             'id' => $object->getId(),
  524.         ));
  525.         $print '';
  526.         if ($object->getAttachment() !== null && $this->security->isGranted('view_external_devis'$object))
  527.         {
  528.             $print .= '<a href="' $url '">';
  529.             $print .= $display;
  530.             $print .= '</a>';
  531.         }
  532.         else
  533.         {
  534.             $print .= $display;
  535.         }
  536.         return $print;
  537.     }
  538.     public function styleExternalInvoice($object): string
  539.     {
  540.         if (!($object instanceof ExternalInvoice))
  541.         {
  542.             return "";
  543.         }
  544.         $display $object->display();
  545.         $url $this->router->generate('icod_platform_external_invoice_view', array(
  546.             'id' => $object->getId(),
  547.         ));
  548.         $print '';
  549.         if ($object->getAttachment() !== null && $this->security->isGranted('view_external_invoice'$object))
  550.         {
  551.             $print .= '<a href="' $url '">';
  552.             $print .= $display;
  553.             $print .= '</a>';
  554.         }
  555.         else
  556.         {
  557.             $print .= $display;
  558.         }
  559.         return $print;
  560.     }
  561.     public function styleExternalDocument($object): string
  562.     {
  563.         if (!($object instanceof ExternalDocument))
  564.         {
  565.             return "";
  566.         }
  567.         $display $object->display();
  568.         $url $this->router->generate('icod_platform_external_document_view', array(
  569.             'id' => $object->getId(),
  570.         ));
  571.         $print '';
  572.         if ($object->getAttachment() !== null && $this->security->isGranted('view_external_document'$object))
  573.         {
  574.             $print .= '<a href="' $url '">';
  575.             $print .= $display;
  576.             $print .= '</a>';
  577.         }
  578.         else
  579.         {
  580.             $print .= $display;
  581.         }
  582.         return $print;
  583.     }
  584.     public function styleExternalTask($object): string
  585.     {
  586.         if (!($object instanceof ExternalTask))
  587.         {
  588.             return "";
  589.         }
  590.         return $object->display();
  591.     }
  592.     public function styleDevis($object): string
  593.     {
  594.         if (!($object instanceof Devis))
  595.         {
  596.             return "";
  597.         }
  598.         $display $object->display();
  599.         $url "";
  600.         // Try to find the right route
  601.         if ($this->security->isGranted('view_devis'$object))
  602.         {
  603.             $url $this->router->generate('icod_platform_devis_view', array(
  604.                 'id' => $object->getId(),
  605.             ));
  606.         }
  607.         else
  608.         {
  609.             if ($this->security->isGranted('view_pdf_devis_with_price'$object))
  610.             {
  611.                 $url $this->router->generate('icod_pdf_devis_ht_public_pdf', array(
  612.                     'id' => $object->getId(),
  613.                 ));
  614.             }
  615.             else
  616.             {
  617.                 if ($this->security->isGranted('view_pdf_devis_no_price'$object))
  618.                 {
  619.                     $url $this->router->generate('icod_pdf_devis_without_price', array(
  620.                         'id' => $object->getId(),
  621.                     ));
  622.                 }
  623.             }
  624.         }
  625.         // Build the returned print
  626.         $print '';
  627.         if (!empty($url))
  628.         {
  629.             $print .= '<a href="' $url '">';
  630.             $print .= $display;
  631.             $print .= '</a>';
  632.         }
  633.         else
  634.         {
  635.             $print .= $display;
  636.         }
  637.         return $print;
  638.     }
  639.     public function styleInvoice($object): string
  640.     {
  641.         if (!($object instanceof Invoice))
  642.         {
  643.             return "";
  644.         }
  645.         $display $object->display();
  646.         $url "";
  647.         // Try to find the right route
  648.         if ($this->security->isGranted('view_invoice'$object))
  649.         {
  650.             $url $this->router->generate('icod_platform_invoice_view', array(
  651.                 'id' => $object->getId(),
  652.             ));
  653.         }
  654.         else
  655.         {
  656.             if ($this->security->isGranted('view_pdf_invoice'$object))
  657.             {
  658.                 if ($object->isCredit() or $object->isCreditFree())
  659.                 {
  660.                     $url $this->router->generate('icod_pdf_credit_pdf', array(
  661.                         'id' => $object->getId(),
  662.                     ));
  663.                 }
  664.                 else
  665.                 {
  666.                     $url $this->router->generate('icod_pdf_invoice_pdf', array(
  667.                         'id' => $object->getId(),
  668.                     ));
  669.                 }
  670.             }
  671.         }
  672.         // Build the returned print
  673.         $print '';
  674.         if (!empty($url))
  675.         {
  676.             $print .= '<a href="' $url '">';
  677.             $print .= $display;
  678.             $print .= '</a>';
  679.         }
  680.         else
  681.         {
  682.             $print .= $display;
  683.         }
  684.         return $print;
  685.     }
  686.     public function styleSocietyGroupInvoice($object): string
  687.     {
  688.         if (!($object instanceof SocietyGroupInvoice))
  689.         {
  690.             return "";
  691.         }
  692.         $display $object->display();
  693.         $url "";
  694.         // Try to find the right route
  695.         if ($this->security->isGranted('view_society_group_invoice'$object))
  696.         {
  697.             $url $this->router->generate('icod_platform_society_group_invoice_view', array(
  698.                 'id' => $object->getId(),
  699.             ));
  700.         }
  701.         else
  702.         {
  703.             if ($this->security->isGranted('view_pdf_society_group_invoice'$object))
  704.             {
  705.                 $url $this->router->generate('icod_pdf_society_group_invoice_pdf', array(
  706.                     'id' => $object->getId(),
  707.                 ));
  708.             }
  709.         }
  710.         // Build the returned print
  711.         $print '';
  712.         if (!empty($url))
  713.         {
  714.             $print .= '<a href="' $url '">';
  715.             $print .= $display;
  716.             $print .= '</a>';
  717.         }
  718.         else
  719.         {
  720.             $print .= $display;
  721.         }
  722.         return $print;
  723.     }
  724.     public function styleSocietyGroupCommand($object): string
  725.     {
  726.         if (!($object instanceof SocietyGroupCommand))
  727.         {
  728.             return "";
  729.         }
  730.         $display $object->display();
  731.         $url "";
  732.         // Try to find the right route
  733.         if ($this->security->isGranted('view_society_group_command'$object))
  734.         {
  735.             $url $this->router->generate('icod_platform_society_group_command_view', array(
  736.                 'id' => $object->getId(),
  737.             ));
  738.         }
  739.         else
  740.         {
  741.             if ($this->security->isGranted('view_pdf_society_group_command'$object))
  742.             {
  743.                 $url $this->router->generate('icod_pdf_society_group_command_pdf', array(
  744.                     'id' => $object->getId(),
  745.                 ));
  746.             }
  747.         }
  748.         // Build the returned print
  749.         $print '';
  750.         if (!empty($url))
  751.         {
  752.             $print .= '<a href="' $url '">';
  753.             $print .= $display;
  754.             $print .= '</a>';
  755.         }
  756.         else
  757.         {
  758.             $print .= $display;
  759.         }
  760.         return $print;
  761.     }
  762.     public function styleMission($object$withLabel false): string
  763.     {
  764.         if (!($object instanceof Mission))
  765.         {
  766.             return "";
  767.         }
  768.         if ($withLabel)
  769.         {
  770.             $display $object->displayWithTitle();
  771.         }
  772.         else
  773.         {
  774.             $display $object->display();
  775.         }
  776.         $url $this->router->generate('icod_platform_mission_view', array(
  777.             'id' => $object->getId(),
  778.         ));
  779.         $print '';
  780.         if ($this->security->isGranted('view_mission'$object))
  781.         {
  782.             $print .= '<a href="' $url '">';
  783.             $print .= $display;
  784.             $print .= '</a>';
  785.         }
  786.         else
  787.         {
  788.             $print .= $display;
  789.         }
  790.         return $print;
  791.     }
  792.     public function styleDemand($object): string
  793.     {
  794.         if (!($object instanceof Demand))
  795.         {
  796.             return "";
  797.         }
  798.         $display $object->display();
  799.         $url $this->router->generate('icod_platform_demand_view', array(
  800.             'id' => $object->getId(),
  801.         ));
  802.         $print '';
  803.         if ($this->security->isGranted('view_demand'$object))
  804.         {
  805.             $print .= '<a href="' $url '">';
  806.             $print .= $display;
  807.             $print .= '</a>';
  808.         }
  809.         else
  810.         {
  811.             $print .= $display;
  812.         }
  813.         return $print;
  814.     }
  815.     public function styleCommand($object): string
  816.     {
  817.         if (!($object instanceof Command))
  818.         {
  819.             return "";
  820.         }
  821.         $display $object->display();
  822.         $url $this->router->generate('icod_platform_command_view', array(
  823.             'id' => $object->getId(),
  824.         ));
  825.         $print '';
  826.         if ($this->security->isGranted('view_command'$object))
  827.         {
  828.             $print .= '<a href="' $url '">';
  829.             $print .= $display;
  830.             $print .= '</a>';
  831.         }
  832.         else
  833.         {
  834.             $print .= $display;
  835.         }
  836.         return $print;
  837.     }
  838.     public function styleCost($object): string
  839.     {
  840.         if (!($object instanceof Cost))
  841.         {
  842.             return "";
  843.         }
  844.         $display $object->display();
  845.         $url $this->router->generate('icod_platform_cost_view', array(
  846.             'id' => $object->getId(),
  847.         ));
  848.         $print '';
  849.         if ($this->security->isGranted('view_cost'$object))
  850.         {
  851.             $print .= '<a href="' $url '">';
  852.             $print .= $display;
  853.             $print .= '</a>';
  854.         }
  855.         else
  856.         {
  857.             $print .= $display;
  858.         }
  859.         return $print;
  860.     }
  861.     public function styleSupplier($object): string
  862.     {
  863.         if (!($object instanceof Supplier))
  864.         {
  865.             return "";
  866.         }
  867.         $display $object->display();
  868.         $url $this->router->generate('icod_platform_supplier_view', array(
  869.             'id' => $object->getId(),
  870.         ));
  871.         $print '';
  872.         if ($this->security->isGranted('view_supplier'$object))
  873.         {
  874.             $print .= '<a href="' $url '">';
  875.             $print .= $display;
  876.             $print .= '</a>';
  877.         }
  878.         else
  879.         {
  880.             $print .= $display;
  881.         }
  882.         return $print;
  883.     }
  884.     public function styleExternalMessage($object$emptyText ''): string
  885.     {
  886.         if (!($object instanceof ExternalMessage))
  887.         {
  888.             return "";
  889.         }
  890.         $display $object->getRef();
  891.         $url $this->router->generate('icod_platform_external_message_view', array(
  892.             'id' => $object->getId(),
  893.         ));
  894.         if (empty($display))
  895.         {
  896.             $display $emptyText;
  897.         }
  898.         $print '';
  899.         if ($this->security->isGranted('view_external_message'$object))
  900.         {
  901.             $print .= '<a href="' $url '">';
  902.             $print .= $display;
  903.             $print .= '</a>';
  904.         }
  905.         else
  906.         {
  907.             $print .= $display;
  908.         }
  909.         return $print;
  910.     }
  911.     public function styleApplication($object): string
  912.     {
  913.         if (!($object instanceof Application))
  914.         {
  915.             return "";
  916.         }
  917.         $display $object->displayName();
  918.         $url $this->router->generate('icod_human_resource_application_view', array(
  919.             'id' => $object->getId(),
  920.         ));
  921.         $print '';
  922.         if ($this->security->isGranted('view_application'$object))
  923.         {
  924.             $print .= '<a href="' $url '">';
  925.             $print .= $display;
  926.             $print .= '</a>';
  927.         }
  928.         else
  929.         {
  930.             $print .= $display;
  931.         }
  932.         return $print;
  933.     }
  934.     /**
  935.      * Format :
  936.      *     address
  937.      *     complement
  938.      *     postal_code, town
  939.      *  country
  940.      */
  941.     public function styleAddress($objectbool $displayEmpty falsebool $billingAddress false): string
  942.     {
  943.         // If $object is null or not an Address Object, return default string ('none_provided' or "")
  944.         if (!($object instanceof Address))
  945.         {
  946.             if ($displayEmpty)
  947.             {
  948.                 $translation $this->translator->trans('none_provided');
  949.                 $print '<span class="text-danger">' $translation '</span>';
  950.                 return $print;
  951.             }
  952.             return "";
  953.         }
  954.         $print "";
  955.         if (!empty($object->getName()))
  956.         {
  957.             $print .= $object->getName();
  958.             if (!empty($print))
  959.             {
  960.                 $print .= "<br>";
  961.             }
  962.         }
  963.         if (!empty($object->getAddress()))
  964.         {
  965.             $print .= $object->getAddress();
  966.         }
  967.         if (!empty($object->getComplement()))
  968.         {
  969.             if (!empty($print))
  970.             {
  971.                 $print .= "<br>";
  972.             }
  973.             $print .= $object->getComplement();
  974.         }
  975.         if (!empty($print))
  976.         {
  977.             $print .= "<br>";
  978.         }
  979.         if (!empty($object->getPostalCode()))
  980.         {
  981.             $print .= $object->getPostalCode() . ", ";
  982.         }
  983.         if (!empty($object->getTown()))
  984.         {
  985.             $print .= $object->getTown();
  986.         }
  987.         if (!empty($object->getCountry()))
  988.         {
  989.             if (!empty($print))
  990.             {
  991.                 $print .= "<br>";
  992.             }
  993.             $print .= $object->getCountry();
  994.         }
  995.         return $print;
  996.     }
  997.     /**
  998.      * Format :
  999.      *     address complement postal_code, town country
  1000.      */
  1001.     public function styleAddressGps($object): string
  1002.     {
  1003.         // If $object is null or not an Address Object, return default string ('none_provided' or "")
  1004.         if (!($object instanceof Address))
  1005.         {
  1006.             return "";
  1007.         }
  1008.         $print "";
  1009.         $print "";
  1010.         if (!empty($object->getAddress()))
  1011.         {
  1012.             $print .= $object->getAddress();
  1013.         }
  1014.         if (!empty($object->getComplement()))
  1015.         {
  1016.             if (!empty($print))
  1017.             {
  1018.                 $print .= "&nbsp;";
  1019.             }
  1020.             $print .= $object->getComplement();
  1021.         }
  1022.         if (!empty($print))
  1023.         {
  1024.             $print .= "&nbsp;";
  1025.         }
  1026.         if (!empty($object->getPostalCode()))
  1027.         {
  1028.             $print .= $object->getPostalCode() . ",&nbsp;";
  1029.         }
  1030.         if (!empty($object->getTown()))
  1031.         {
  1032.             $print .= $object->getTown();
  1033.         }
  1034.         if (!empty($object->getCountry()))
  1035.         {
  1036.             if (!empty($print))
  1037.             {
  1038.                 $print .= "&nbsp;";
  1039.             }
  1040.             $print .= $object->getCountry();
  1041.         }
  1042.         return $print;
  1043.     }
  1044. }