newTicketValidator = $newTicketValidator; $this->trackingIdGenerator = $trackingIdGenerator; $this->autoassigner = $autoassigner; $this->statusGateway = $statusGateway; $this->ticketGateway = $ticketGateway; } /** * Ticket attachments are NOT handled here! * * @param $ticketRequest CreateTicketByCustomerModel * @param $heskSettings array HESK settings * @param $modsForHeskSettings array Mods for HESK settings * @return Ticket The newly created ticket * @throws ValidationException When a required field in $ticket_request is missing * */ function createTicketByCustomer($ticketRequest, $heskSettings, $modsForHeskSettings, $userContext) { $validationModel = $this->newTicketValidator->validateNewTicketForCustomer($ticketRequest, $heskSettings, $userContext); if (count($validationModel->errorKeys) > 0) { // Validation failed $validationModel->valid = false; throw new ValidationException($validationModel); } // Create the ticket $ticket = new Ticket(); $ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings); if ($heskSettings['autoassign']) { $ticket->ownerId = $this->autoassigner->getNextUserForTicket($ticketRequest->category, $heskSettings); } // Transform one-to-one properties $ticket->name = $ticketRequest->name; $ticket->email = $ticketRequest->email; $ticket->priorityId = $ticketRequest->priority; $ticket->categoryId = $ticketRequest->category; $ticket->subject = $ticketRequest->subject; $ticket->message = $ticketRequest->message; $ticket->usesHtml = $ticketRequest->html; $ticket->customFields = $ticketRequest->customFields; $ticket->location = $ticketRequest->location; $ticket->suggestedArticles = $ticketRequest->suggestedKnowledgebaseArticleIds; $ticket->userAgent = $ticketRequest->userAgent; $ticket->screenResolution = $ticketRequest->screenResolution; $ticket->ipAddress = $ticketRequest->ipAddress; $ticket->language = $ticketRequest->language; $status = $this->statusGateway->getStatusForDefaultAction(DefaultStatusForAction::NEW_TICKET, $heskSettings); if ($status === null) { throw new \Exception("Could not find the default status for a new ticket!"); } $ticket->statusId = $status->id; $ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $heskSettings); $ticket->dateCreated = $ticketGatewayGeneratedFields->dateCreated; $ticket->lastChanged = $ticketGatewayGeneratedFields->dateModified; $ticket->archived = false; $ticket->locked = false; $ticket->id = $ticketGatewayGeneratedFields->id; $ticket->openedBy = 0; $ticket->numberOfReplies = 0; $ticket->numberOfStaffReplies = 0; $ticket->timeWorked = '00:00:00'; $ticket->lastReplier = 0; return $ticket; } }