Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.0' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjeev Papnoi committed Mar 3, 2021
2 parents 7c6105d + 537c563 commit df19f22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
11 changes: 8 additions & 3 deletions API/Threads.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function saveThread(Request $request, $ticketid)
$actAsType = strtolower($data['actAsType']);
$actAsEmail = $data['actAsEmail'];
if ($actAsType == 'customer') {
$customer = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
$user = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
} else if($actAsType == 'agent' ) {
$user = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
} else {
Expand All @@ -72,7 +72,12 @@ public function saveThread(Request $request, $ticketid)
if ($actAsType == 'agent') {
$data['user'] = isset($user) && $user ? $user : $this->get('user.service')->getCurrentUser();
} else {
$data['user'] = $customer;
$data['user'] = $user;
}

$attachments = $request->files->get('attachments');
if (!empty($attachments)) {
$attachments = is_array($attachments) ? $attachments : [$attachments];
}

$threadDetails = [
Expand All @@ -81,7 +86,7 @@ public function saveThread(Request $request, $ticketid)
'source' => 'api',
'threadType' => strtolower($data['threadType']),
'message' => str_replace(['<script>', '</script>'], '', $data['message']),
'attachments' => $request->files->get('attachments')
'attachments' => $attachments
];

if (!empty($data['status'])){
Expand Down
28 changes: 20 additions & 8 deletions API/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ public function fetchTickets(Request $request)
if ($request->query->get('actAsType')) {
switch($request->query->get('actAsType')) {
case 'customer':
$customer = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
$email = $request->query->get('actAsEmail');
$customer = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);

if ($customer) {
$json = $repository->getAllCustomerTickets($request->query, $this->container, $customer);
$json = $ticketRepository->getAllCustomerTickets($request->query, $this->container, $customer);
} else {
$json['error'] = $this->get('translator')->trans('Error! Resource not found.');
return new JsonResponse($json, Response::HTTP_NOT_FOUND);
}
return new JsonResponse($json);
break;
case 'agent':
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);

$email = $request->query->get('actAsEmail');
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);

if ($user) {
$request->query->set('agent', $user->getId());
} else {
Expand Down Expand Up @@ -181,7 +183,7 @@ public function createTicket(Request $request)
return new JsonResponse($json, Response::HTTP_BAD_REQUEST);
}
} else {
$json['warning'] = $this->get('translator')->trans('Warning ! For Customer spacify actAsType as customer and for Agent spacify both parameter actASType as agent and actAsEmail as agent email');
$json['warning'] = $this->get('translator')->trans('Warning ! For Customer specify actAsType as customer and for Agent specify both parameter actASType as agent and actAsEmail as agent email');
$statusCode = Response::HTTP_BAD_REQUEST;
return new JsonResponse($json, $statusCode);
}
Expand All @@ -204,6 +206,11 @@ public function createTicket(Request $request)
} else {
$data['user'] = $customer;
}

$attachments = $request->files->get('attachments');
if (!empty($attachments)) {
$attachments = is_array($attachments) ? $attachments : [$attachments];
}

$ticketData['user'] = $data['user'];
$ticketData['subject'] = $data['subject'];
Expand All @@ -212,9 +219,14 @@ public function createTicket(Request $request)
$ticketData['source'] = 'api';
$ticketData['threadType'] = 'create';
$ticketData['createdBy'] = $actAsType;
$ticketData['attachments'] = $request->files->get('attachments');
$ticketData['attachments'] = $attachments;

$extraKeys = ['tags', 'group', 'priority', 'status', 'agent', 'createdAt', 'updatedAt'];

if (array_key_exists('type', $data)) {
$ticketType = $entityManager->getRepository('UVDeskCoreFrameworkBundle:TicketType')->findOneByCode($data['type']);
$ticketData['type'] = $ticketType;
}

$requestData = $data;
foreach ($extraKeys as $key) {
Expand Down Expand Up @@ -509,9 +521,9 @@ public function addRemoveTicketCollaborator(Request $request)
*/
public function downloadAttachment(Request $request)
{
$attachmendId = $request->attributes->get('attachmendId');
$attachmentId = $request->attributes->get('attachmentId');
$attachmentRepository = $this->getDoctrine()->getManager()->getRepository('UVDeskCoreFrameworkBundle:Attachment');
$attachment = $attachmentRepository->findOneById($attachmendId);
$attachment = $attachmentRepository->findOneById($attachmentId);
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();

if (!$attachment) {
Expand Down

0 comments on commit df19f22

Please sign in to comment.