account.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. $page_title = __("Account");
  3. $customer = null;
  4. $test_count = 0;
  5. $pass_count = 0;
  6. $pass_fail_test_count = 0;
  7. $completed_tests = null;
  8. $year_cycle_start_text = null;
  9. $pass_rate = null;
  10. $logo_path = null;
  11. $user = Core::$user;
  12. if($user->isCustomer()) {
  13. $customers = $user->getCustomers();
  14. if($customers) {
  15. $customer = $customers[0];
  16. $logo_path = $customer->getLogoPath();
  17. $page_title = __("%s Dashboard", $customer->name);
  18. $year_cycle = $customer->getYearCycleDates();
  19. list($start, $end) = $year_cycle;
  20. $dt = new DateTime($start);
  21. $year_cycle_start_text = $dt->format("jS M");
  22. $projects = $customer->getFinishedProjects();
  23. $project_ids = array_column($projects, "id");
  24. $tests = Test::query([
  25. "project_id" => $project_ids,
  26. "status" => Test::STATUS_COMPLETED,
  27. ]);
  28. $test_result_set = new TestResultSet($tests);
  29. $tests = $test_result_set->filterByDateRange($start, $end);
  30. $test_count = count($tests);
  31. $pass_fail_tests = array_filter($tests, function(Test $test) {
  32. $project = $test->getProject();
  33. $template = $project->getTemplate();
  34. return $template->hasPassFail();
  35. });
  36. $pass_fail_test_count = count($pass_fail_tests);
  37. if($pass_fail_test_count) {
  38. $passed_tests = array_filter($pass_fail_tests, function(Test $test) {
  39. return $test->pass;
  40. });
  41. $pass_count = count($passed_tests);
  42. $pass_rate = $pass_count / $pass_fail_test_count;
  43. }
  44. }
  45. }
  46. Core::addBreadcrumb("/account", $page_title);
  47. $users_pending_verification = 0;
  48. $tests_pending_verification = 0;
  49. $tests_remaining = 0;
  50. $icons = [];
  51. if($user->canAccessCustomers()) {
  52. $icons[] = new AccountIcon(__("Customers"), "/account/customers", "warehouse");
  53. }
  54. if($user->canAccessMapOverview()) {
  55. $icons[] = new AccountIcon(__("Map Overview"), "/account/map-overview", "map-marked");
  56. }
  57. if($user->canAccessUsers()) {
  58. $users = User::query(["level" => User::LEVEL_UNVERIFIED]);
  59. $tests = Test::query(["status" => Test::STATUS_PENDING_VERIFICATION]);
  60. $users_pending_verification = count($users);
  61. $tests_pending_verification = count($tests);
  62. $icons[] = new AccountIcon(($user->isSuperAdmin() ? __("Users") : __("Testers")), "/account/users", "users");
  63. }
  64. if($user->canAccessProjects()) {
  65. $icons[] = new AccountIcon(__("Projects"), "/account/projects", "list");
  66. }
  67. if($user->canAccessTemplates()) {
  68. $icons[] = new AccountIcon(__("Templates"), "/account/templates", "file-alt");
  69. }
  70. if($user->canAccessVenueTypes()) {
  71. $icons[] = new AccountIcon(__("Venue Types"), "/account/venue-types", "list-alt");
  72. }
  73. if($user->canAccessLog()) {
  74. $icons[] = new AccountIcon(__("Log"), "/account/log", "database");
  75. }
  76. if($user->canAccessInvoices()) {
  77. $pending_tester_invoice_test_count = count(Test::query(["status_tester_invoice" => Test::STATUS_TESTER_INVOICE_PENDING]));
  78. $invoice_icon = new AccountIcon(__("Invoices"), "/account/tests?status_tester_invoice=100", "file-invoice");
  79. $invoice_icon->setCounter($pending_tester_invoice_test_count);
  80. $icons[] = $invoice_icon;
  81. }
  82. if($user->canAccessLocations()) {
  83. $icons[] = new AccountIcon(__("Locations"), "/account/locations", "map-marker");
  84. }
  85. if($user->canAccessReports()) {
  86. $icons[] = new AccountIcon(__("Reports"), "/account/reports", "chart-pie");
  87. }
  88. if($user->canAccessTestResults()) {
  89. $icons[] = new AccountIcon(__("Test Results"), "/account/test-results", "clipboard-list-check");
  90. }
  91. if($user->canAccessTests()) {
  92. $tests = $user->getPendingTests();
  93. $tests_remaining = count($tests);
  94. $tests_url = $user->isAdmin() ? "/account/tests?custom=overdue_test" : "/account/tests";
  95. $tests_icon = new AccountIcon(__("Tests"), $tests_url, "clipboard-check");
  96. $tests_icon->setCounter($tests_remaining);
  97. $icons[] = $tests_icon;
  98. }
  99. if($user->canAccessPractice()) {
  100. $icons[] = new AccountIcon(__("Practice"), "/account/practice", "chalkboard-teacher");
  101. }
  102. if($user->canAccessAddresses()) {
  103. $icons[] = new AccountIcon(__("Addresses"), "/account/addresses", "address-book");
  104. }
  105. if($user->canAccessCompletedTests()) {
  106. $icons[] = new AccountIcon(__("Tests (Completed)"), "/account/tests/completed", "check");
  107. }
  108. if($user->canSubmitId()) {
  109. $submit_id_icon = new AccountIcon(__("Submit ID"), "/account/submit-id", "id-card");
  110. $submit_id_icon->setButtonClass("btn-warning");
  111. $icons[] = $submit_id_icon;
  112. }
  113. if(!$user->terms_accepted) {
  114. $icons = [];
  115. }
  116. $icons[] = new AccountIcon(__("Settings"), "/account/settings", "cog");
  117. usort($icons, function($a, $b) {
  118. return $a->name <=> $b->name;
  119. });
  120. // Actions
  121. $actions = [];
  122. if($user->canReactivate()) {
  123. $actions[] = new AccountIcon(__("Reactivate Account"), "/account/reactivate", "user-check");
  124. }
  125. if($user->canDeactivate()) {
  126. $actions[] = new AccountIcon(__("Deactivate Account..."), "/account/deactivate", "user-times");
  127. }
  128. $actions[] = new AccountIcon(__("Delete Account..."), "/account/delete", "user-slash");
  129. // To-do
  130. $to_do = [];
  131. if($users_pending_verification) {
  132. $icon = new AccountIcon(__("Verify Users"), "/account/users?level=" . User::LEVEL_UNVERIFIED, "user-check");
  133. $icon->setCounter($users_pending_verification);
  134. $to_do[] = $icon;
  135. }
  136. if($tests_pending_verification) {
  137. $icon = new AccountIcon(__("Verify Tests"), "/account/tests?status=" . Test::STATUS_PENDING_VERIFICATION, "clipboard-check");
  138. $icon->setCounter($tests_pending_verification);
  139. $to_do[] = $icon;
  140. }
  141. $referrals = $user->getReferrals();
  142. View::includeOnce("header", compact("page_title"));
  143. View::include("account", compact("page_title", "icons", "actions", "to_do", "referrals", "customer", "logo_path", "year_cycle_start_text", "pass_rate", "pass_count", "pass_fail_test_count", "test_count"));
  144. View::includeOnce("footer");