projects.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. Core::addBreadcrumb("/account", "Account");
  3. Core::addBreadcrumb("/account/projects", "Projects");
  4. Core::addScript("public/js/app-projects.js");
  5. Core::$allow_all_customers = true;
  6. $customer_id = http::value("customer_id");
  7. if(Core::$user->isAdmin() && $customer_id == "ALL") {
  8. $page_title = "All Projects";
  9. Core::addBreadcrumb("/account/projects?customer_id=ALL", $page_title);
  10. $nvp = [];
  11. $customer = new Customer;
  12. $customer->id = "ALL";
  13. $customer->name = "All";
  14. }
  15. else {
  16. $customer = Customer::getForAdmin();
  17. $page_title = "$customer->name Projects";
  18. Core::addBreadcrumb("/account/projects?customer_id=$customer->id", $page_title);
  19. $nvp = ["customer_id" => $customer->id];
  20. }
  21. $id = http::value("id", "int");
  22. $name = http::value("name", "trim");
  23. $year = http::value("year", "int");
  24. $report_month = http::value("report_month", "db");
  25. if($year === false) {
  26. $year = date("Y");
  27. }
  28. if($id) $nvp["id"] = $id;
  29. if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
  30. if($year) {
  31. $min_dts = "{$year}-01-01 00:00:00";
  32. $max_dts = "{$year}-12-31 23:59:59";
  33. $nvp["dts_start"] = (new Constraint("BETWEEN"))->setValues($min_dts, $max_dts);
  34. }
  35. if($report_month) {
  36. $nvp["dts_report"] = (new Constraint("BEGINS_WITH"))->setValues($report_month);
  37. }
  38. $projects = Project::query($nvp, ["sort" => "dts_start", "order" => "desc"]);
  39. $templates = Template::load(array_column($projects, "template_id"));
  40. $filter_count = count($nvp);
  41. View::includeOnce("header", compact("page_title"));
  42. View::include("projects", compact("customer", "filter_count", "projects", "year", "report_month"));
  43. View::includeOnce("footer");