related_items_section.php 2.0 KB

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