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 Jun 19, 2021
2 parents eb7b224 + 9e5db48 commit 4542c16
Show file tree
Hide file tree
Showing 21 changed files with 1,391 additions and 41 deletions.
124 changes: 124 additions & 0 deletions Controller/Announcement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Webkul\UVDesk\SupportCenterBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Webkul\UVDesk\SupportCenterBundle\Entity\Website;
use Webkul\UVDesk\SupportCenterBundle\Entity\Announcement as MarketingAnnouncement;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Webkul\UVDesk\CoreFrameworkBundle\FileSystem\FileSystem;
use Symfony\Component\Translation\TranslatorInterface;

Class Announcement extends Controller
{
private $translator;
private $userService;

public function __construct(TranslatorInterface $translator, UserService $userService)
{
$this->translator = $translator;
$this->userService = $userService;
}

public function listAnnouncement(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_KNOWLEDGEBASE')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

return $this->render('@UVDeskSupportCenter/Staff/Announcement/listAnnouncement.html.twig');
}

public function listAnnouncementXHR(Request $request)
{
$json = array();
$repository = $this->getDoctrine()->getRepository('UVDeskSupportCenterBundle:Announcement');
$json = $repository->getAllAnnouncements($request->query, $this->container);
$response = new Response(json_encode($json));
$response->headers->set('Content-Type', 'application/json');
return $response;
}

public function updateAnnouncement(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_KNOWLEDGEBASE')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

$em = $this->getDoctrine()->getManager();

if($request->attributes->get('announcementId')){
$announcement = $this->getDoctrine()->getRepository('UVDeskSupportCenterBundle:Announcement')
->findOneBy([
'id' => $request->attributes->get('announcementId')
]);
$announcement->setCreatedAt(new \DateTime('now'));
if(!$announcement)
$this->noResultFound();
} else {
$announcement = new MarketingAnnouncement;
$announcement->setCreatedAt(new \DateTime('now'));
}

if($request->getMethod() == "POST") {
$request = $request->request->get('announcement_form');
$group = $em->getRepository('UVDeskCoreFrameworkBundle:SupportGroup')->find($request['group']);

$announcement->setTitle($request['title']);
$announcement->setPromoText($request['promotext']);
$announcement->setPromotag($request['promotag']);
$announcement->setTagColor($request['tagColor']);
$announcement->setLinkText($request['linkText']);
$announcement->setLinkURL($request['linkURL']);
$announcement->setIsActive($request['status']);
$announcement->setGroup($group);
$em->persist($announcement);
$em->flush();

$this->addFlash('success', 'Success! Announcement data saved successfully.');
return $this->redirect($this->generateUrl('helpdesk_member_knowledgebase_marketing_announcement'));

}

return $this->render('@UVDeskSupportCenter/Staff/Announcement/announcementForm.html.twig', [
'announcement' => $announcement,
'errors' => ''
]);
}

public function removeAnnouncementXHR(Request $request)
{
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_KNOWLEDGEBASE')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

$entityManager = $this->getDoctrine()->getManager();
$knowledgebaseAnnouncementId = $request->attributes->get('id');

$knowledgebaseAnnouncement = $entityManager->getRepository(Announcement::class)->findOneBy([
'id' => $knowledgebaseAnnouncementId
]);

if ($knowledgebaseAnnouncement) {
$entityManager->remove($knowledgebaseAnnouncement);
$entityManager->flush();

$json = [
'alertClass' => 'success',
'alertMessage' => 'Announcement deleted successfully!',
];
$responseCode = 200;
} else {
$json = [
'alertClass' => 'warning',
'alertMessage' => 'Announcement not found!',
];
}

$response = new Response(json_encode($json));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
54 changes: 43 additions & 11 deletions Controller/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ public function ticketadd(Request $request)

$thread = $this->ticketService->createTicketBase($data);

if ($thread) {
$request->getSession()->getFlashBag()->set('success', $this->translator->trans('Success ! Ticket has been created successfully.'));
if (!empty($thread)) {
$ticket = $thread->getTicket();
if($request->request->get('customFields') || $request->files->get('customFields')) {
$this->get('ticket.service')->addTicketCustomFields($ticket, $request->request->get('customFields'), $request->files->get('customFields'));
}
$request->getSession()->getFlashBag()->set('success', sprintf('Success ! Ticket #%s has been created successfully.', $ticket->getId()));
} else {
$request->getSession()->getFlashBag()->set('warning', $this->translator->trans('Warning ! Can not create ticket, invalid details.'));
$this->addFlash('warning', $this->translator->trans('Warning ! Can not create ticket, invalid details.'));
}

// Trigger ticket created event
$event = new GenericEvent(CoreWorkflowEvents\Ticket\Create::getId(), [
'entity' => $thread->getTicket(),
Expand Down Expand Up @@ -280,13 +283,22 @@ public function saveReply(int $id, Request $request)
$data['ticket'] = $ticket;
$data['user'] = $this->userService->getCurrentUser();

// Checking if reply is from collaborator end
$isTicketCollaborator = $ticket->getCollaborators() ? $ticket->getCollaborators()->toArray() : [];
$isCollaborator = false;
foreach ($isTicketCollaborator as $value) {
if($value->getId() == $data['user']->getId()){
$isCollaborator = true;
}
}

// @TODO: Refactor -> Why are we filtering only these two characters?
$data['message'] = str_replace(['&lt;script&gt;', '&lt;/script&gt;'], '', $data['message']);

$userDetail = $this->userService->getCustomerPartialDetailById($data['user']->getId());
$data['fullname'] = $userDetail['name'];
$data['source'] = 'website';
$data['createdBy'] = 'customer';
$data['createdBy'] = $isCollaborator ? 'collaborator' : 'customer';
$data['attachments'] = $request->files->get('attachments');
$thread = $this->ticketService->createThread($ticket, $data);

Expand All @@ -303,10 +315,15 @@ public function saveReply(int $id, Request $request)
$em->flush();
}

// Trigger customer reply event
$event = new GenericEvent(CoreWorkflowEvents\Ticket\CustomerReply::getId(), [
'entity' => $ticket,
]);
if ($thread->getcreatedBy() == 'customer') {
$event = new GenericEvent(CoreWorkflowEvents\Ticket\CustomerReply::getId(), [
'entity' => $ticket,
]);
} else {
$event = new GenericEvent(CoreWorkflowEvents\Ticket\CollaboratorReply::getId(), [
'entity' => $ticket,
]);
}

$this->eventDispatcher->dispatch('uvdesk.automation.workflow.execute', $event);

Expand All @@ -327,9 +344,23 @@ public function tickets(Request $request)
{
$this->isWebsiteActive();

// List Announcement if any
$announcements = $this->getDoctrine()->getRepository('UVDeskSupportCenterBundle:Announcement')->findBy(['isActive' => 1]);

$groupAnnouncement = [];
foreach($announcements as $announcement) {
$announcementGroupId = $announcement->getGroup();
$isTicketExist = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:Ticket')->findBy(['supportGroup' => $announcementGroupId, 'customer' => $this->userService->getCurrentUser()]);

if (!empty($isTicketExist)) {
$groupAnnouncement[] = $announcement;
}
}

return $this->render('@UVDeskSupportCenter/Knowledgebase/ticketList.html.twig',
array(
'searchDisable' => true
'searchDisable' => true,
'groupAnnouncement' => $groupAnnouncement
)
);
}
Expand Down Expand Up @@ -511,6 +542,7 @@ public function downloadAttachment(Request $request)

$response->headers->set('Content-type', $attachment->getContentType());
$response->headers->set('Content-Disposition', 'attachment; filename='. $attachment->getName());
$response->headers->set('Content-Length', $attachment->getSize());
$response->sendHeaders();
$response->setContent(readfile($path));

Expand Down Expand Up @@ -577,4 +609,4 @@ public function ticketCollaboratorXhr(Request $request)
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
}
Loading

0 comments on commit 4542c16

Please sign in to comment.