Skip to content

Commit

Permalink
Entity references update & misc. code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Kumar committed Jul 28, 2022
1 parent f20b214 commit 500a6ce
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 54 deletions.
16 changes: 9 additions & 7 deletions API/Threads.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace Webkul\UVDesk\ApiBundle\API;

use Webkul\TicketBundle\Entity\Ticket;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketStatus;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;

class Threads extends AbstractController
{
Expand All @@ -30,7 +32,7 @@ public function saveThread(Request $request, $ticketid, ContainerInterface $cont
return new JsonResponse($json, Response::HTTP_BAD_REQUEST);
}

$ticket = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:Ticket')->findOneById($ticketid);
$ticket = $this->getDoctrine()->getRepository(Ticket::class)->findOneById($ticketid);

// Check for empty ticket
if (empty($ticket)) {
Expand All @@ -55,9 +57,9 @@ public function saveThread(Request $request, $ticketid, ContainerInterface $cont
$actAsType = strtolower($data['actAsType']);
$actAsEmail = $data['actAsEmail'];
if ($actAsType == 'customer') {
$user = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
$user = $this->getDoctrine()->getRepository(User::class)->findOneByEmail($data['actAsEmail']);
} else if($actAsType == 'agent' ) {
$user = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
$user = $this->getDoctrine()->getRepository(User::class)->findOneByEmail($data['actAsEmail']);
} else {
$json['error'] = 'Error! invalid actAs details.';
$json['description'] = 'possible values actAsType: customer,agent. Also provide actAsEmail parameter with actAsType agent.';
Expand Down Expand Up @@ -90,7 +92,7 @@ public function saveThread(Request $request, $ticketid, ContainerInterface $cont
];

if (!empty($data['status'])){
$ticketStatus = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:TicketStatus')->findOneByCode($data['status']);
$ticketStatus = $this->getDoctrine()->getRepository(TicketStatus::class)->findOneByCode($data['status']);
$ticket->setStatus($ticketStatus);
}
if (isset($data['to'])) {
Expand Down
19 changes: 10 additions & 9 deletions API/TicketTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Webkul\UVDesk\ApiBundle\API;

use Webkul\TicketBundle\Entity\Ticket;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketType;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;

class TicketTypes extends AbstractController
Expand All @@ -20,15 +20,16 @@ class TicketTypes extends AbstractController
*/
public function ticketTypeList(Request $request)
{
$json = [];
$entityManager = $this->getDoctrine()->getManager();
$ticketTypes = $entityManager->createQueryBuilder()
->select("TT")
->from('UVDeskCoreFrameworkBundle:TicketType', 'TT')
->Where('TT.isActive = 1')
->getQuery()->getArrayResult();
$queryBuilder = $entityManager->createQueryBuilder()
->select("ticket_type")
->from(TicketType::class, 'ticket_type')
->where('ticket_type.isActive = 1')
;

$collection = $queryBuilder->getQuery()->getArrayResult();

return new JsonResponse($ticketTypes);
return new JsonResponse($collection);
}
}

Loading

0 comments on commit 500a6ce

Please sign in to comment.