| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Constraint\NotEqualsConstraint;
- use App\Constraint\NotInConstraint;
- use App\Enums\TicketStatuses;
- use RuntimeException;
- $core = Core::getInstance();
- $core->addBreadcrumb("/tickets", __("Tickets"));
- $core = Core::getInstance();
- $core->addScript("/js/ticket-modal.js");
- $request = Request::fromRequest();
- $batch_submit = $request->int("batch_submit");
- if($batch_submit) {
- $ticket_ids = $request->int("ticket_ids");
- $tickets = [];
- foreach($ticket_ids as $ticket_id) {
- $tickets[] = Ticket::require($ticket_id);
- }
- $assign_to_user = null;
- $assign_to_user_id = $request->int("assign_to");
- if($assign_to_user_id) {
- $assign_to_user = User::requireStaff($assign_to_user_id);
- }
- $status = $request->int("status");
- if($status !== null && !TicketStatuses::validate($status)) {
- throw new RuntimeException(__("Invalid status."));
- }
- foreach($tickets as $ticket) {
- if($assign_to_user_id) {
- $ticket->assign($assign_to_user);
- }
- if($status !== null) {
- $ticket->status = $status;
- $ticket->commit();
- }
- }
- Session::addAlert("success", __("Batch action applied successfully."));
- Http::redirect("/tickets");
- }
- $nvp = [
- "dts_deleted" => null
- ];
- $customer_id = $request->int("customer_id");
- if($customer_id) {
- $customer = Customer::get($customer_id);
- if($customer) {
- $nvp["location_id"] = array_column($customer->getLocations(), "id");
- }
- else {
- $nvp["location_id"] = 0;
- }
- }
- $location_id = $request->int("location_id");
- if($location_id) {
- $nvp["location_id"] = $location_id;
- }
- $status = $request->int("status");
- if($status !== null) {
- $nvp["status"] = $status;
- }
- $number = $request->int("number");
- if($number !== null) {
- $nvp["id"] = $number;
- }
- $assigned_user_id = $request->int("assigned_user_id");
- if($assigned_user_id !== null) {
- $nvp["assigned_user_id"] = $assigned_user_id;
- }
- $custom_filter = $request->string("custom_filter");
- switch($custom_filter) {
- case "open":
- $nvp["status"] = new NotEqualsConstraint(TicketStatuses::CLOSED);
- break;
- case "unsolved":
- $nvp["status"] = new NotInConstraint(TicketStatuses::CLOSED, TicketStatuses::SOLVED);
- break;
- case "unassigned":
- $nvp["assigned_user_id"] = null;
- break;
- }
- $count = Ticket::count($nvp);
- $pagination = new Pagination($count);
- $pagination->setTerms(__("%s ticket"), __("%s tickets"));
- $tickets = Ticket::query($nvp, [
- "sort" => "dts_updated",
- "order" => "desc",
- "offset" => $pagination->getOffset(),
- "limit" => $pagination->getPageSize()
- ]);
- View::include("header");
- View::include("tickets", compact("tickets", "pagination", "customer_id", "location_id", "status", "assigned_user_id", "custom_filter"));
- View::include("modals/ticket");
- View::include("footer");
|