related_items_section.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use Exception;
  4. /**
  5. * @var Sale $sale
  6. * @var Document $document
  7. * @var Model $current
  8. */
  9. if(isset($sale)) {
  10. $title = $sale->getTitle();
  11. $child_documents = $sale->getChildDocuments();
  12. $is_current = $sale->is($current);
  13. $url = $sale->getUrl();
  14. $tickets = $sale->getTickets();
  15. $location = $sale->getLocation();
  16. $company = $sale->getCompany();
  17. }
  18. else if(isset($document)) {
  19. $title = $document->getTitle();
  20. $child_documents = $document->getChildDocuments();
  21. $is_current = $document->is($current);
  22. $url = $document->getUrl();
  23. $tickets = $document->getTickets();
  24. $location = $document->getLocation();
  25. $company = $document->getCompany();
  26. }
  27. else {
  28. return;
  29. }
  30. $customer = $location->getCustomer();
  31. ?>
  32. <section class="mb-4">
  33. <h4><?=htmlspecialchars(__("Related Items"))?></h4>
  34. <?php
  35. /**
  36. * @param Document[] $documents
  37. * @param Model $current
  38. * @return void
  39. * @throws Exception
  40. */
  41. function renderDocumentList(array $documents, Model $current): void {
  42. if(!$documents) {
  43. return;
  44. }
  45. ?>
  46. <ul>
  47. <?php
  48. foreach($documents as $document) {
  49. ?>
  50. <li>
  51. <?php
  52. if($document->is($current)) {
  53. ?>
  54. <?=htmlspecialchars($document->getTitle())?>
  55. <span class="badge text-bg-primary"><?=htmlspecialchars(__("Current"))?></span>
  56. <?php
  57. }
  58. else {
  59. ?>
  60. <a href="<?=htmlspecialchars($document->getUrl())?>"><?=htmlspecialchars($document->getTitle())?></a>
  61. <?php
  62. }
  63. ?>
  64. <?php
  65. renderDocumentList($document->getChildDocuments(), $current);
  66. ?>
  67. </li>
  68. <?php
  69. }
  70. ?>
  71. </ul>
  72. <?php
  73. }
  74. ?>
  75. <ul>
  76. <li>
  77. <?php
  78. if($is_current) {
  79. ?>
  80. <?=htmlspecialchars($title)?>
  81. <span class="badge text-bg-primary"><?=htmlspecialchars(__("Current"))?></span>
  82. <?php
  83. }
  84. else {
  85. ?>
  86. <a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($title)?></a>
  87. <?php
  88. }
  89. renderDocumentList($child_documents, $current);
  90. foreach($tickets as $ticket) {
  91. ?>
  92. <ul>
  93. <li>
  94. <a href="<?=htmlspecialchars($ticket->getUrl())?>">
  95. <?=htmlspecialchars($ticket->getTitle())?>
  96. </a>
  97. </li>
  98. </ul>
  99. <?php
  100. }
  101. ?>
  102. </li>
  103. <li>
  104. <a href="<?=htmlspecialchars($customer->getUrl())?>"><?=htmlspecialchars($customer->name)?></a>
  105. <ul>
  106. <li>
  107. <a href="<?=htmlspecialchars($location->getUrl())?>"><?=htmlspecialchars($location->name)?></a>
  108. </li>
  109. </ul>
  110. </li>
  111. <li>
  112. <a href="<?=htmlspecialchars($company->getUrl())?>"><?=htmlspecialchars($company->name)?></a>
  113. </li>
  114. </ul>
  115. </section>