<?php
namespace App\Controller\COMUNICACIONES;
use App\Controller\_USER\Nuser;
use App\Controller\RequestTransform;
use App\Entity\Msg;
use App\Entity\MsgEntry;
use App\Entity\Usuario;
use App\Repository\BaseRepository;
use App\Repository\Sql\CursosRepository;
use App\Repository\Sql\MsgRepository;
use App\Repository\Sql\TemaRepository;
use App\Services\Files\FileUploader;
use App\Services\MsgService\MsgService;
use App\Services\Password\EncoderService;
use App\Services\SqlService\SqlService;
use App\Services\TemaService\TemaService;
use App\Services\UserService\UserService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
class Announcement extends AbstractController
{
private $cursosRepository;
private $temaService;
private $msgRepository;
private $temaRepository;
private $encoderService;
private $em;
private $nuser;
private $msgService;
private $sqlService;
private $userService;
private $mailer;
public function __construct(
EntityManagerInterface $em,
EncoderService $encoderService,
CursosRepository $cursosRepository,
MsgRepository $msgRepository,
TemaRepository $temaRepository,
Nuser $nuser,
TemaService $temaService,
MsgService $msgService,
SqlService $sqlService,
UserService $userService,
MailerInterface $mailer
) {
$this->nuser = $nuser;
$this->em = $em;
$this->encoderService = $encoderService;
$this->msgRepository = $msgRepository;
$this->temaService = $temaService;
$this->msgService = $msgService;
$this->cursosRepository = $cursosRepository;
$this->temaRepository = $temaRepository;
$this->sqlService = $sqlService;
$this->userService = $userService;
$this->mailer = $mailer;
$encoders = [new JsonEncoder()];
$normalizers = [new ObjectNormalizer()];
$this->serializer = new Serializer($normalizers, $encoders);
}
/**
* Show a particular user announcements with no update.
*
* @Route("/api/msg/user/announcement/list", name="get_msg_user_announcement_list", methods={"POST"})
*/
public function getUserAnnouncementList(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$pageNumber = RequestTransform::getRequiredField($request, 'page');
$category = RequestTransform::getRequiredField($request, 'category', false, true) ?: null;
$course = RequestTransform::getRequiredField($request, 'course', false, true) ?: null;
$msgs = $this->msgService->getUserAnnouncementList($userInformation['uuid'], $course, $category, $pageNumber);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_user_announcement_list',
'id' => 200 == $msgs['code'] ? $this->serializer->serialize($msgs['id'], 'json') : $msgs['id'],
]);
}
/**
* Get the number of new announcements for a specific user with no update to read.
*
* @Route("/api/anuncio/new", name="anuncio_new_announcement", methods={"POST"})
*/
public function userAnnouncementsList(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$course = RequestTransform::getRequiredField($request, 'course', false, true) ?: null;
$announcementsAndNews = $this->msgService->getAnnouncementsWithNews($userInformation['uuid'], $course, null, true);
if (!is_null($announcementsAndNews)) {
return new JsonResponse([
'code' => 200,
'message' => 'anuncio_new_announcement',
'result' => $announcementsAndNews,
]);
}
return new JsonResponse([
'code' => 400,
'message' => 'anuncio_new_announcement',
'result' => [],
]);
}
/**
* Show a list of announcements.
*
* @Route("/api/msg/admin/announcement/list", name="get_msg_admin_announcement_list", methods={"POST"})
*/
public function getAdminAnnouncementList(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$pageNumber = RequestTransform::getRequiredField($request, 'page');
$category = RequestTransform::getRequiredField($request, 'category', false, true) ?: null;
$search = RequestTransform::getRequiredField($request, 'search', false, true) ?: null;
$msgs = $this->msgService->getAdminAnnouncementList($userInformation['uuid'], $category, $pageNumber, $search);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_user_announcement_list',
'id' => 200 == $msgs['code'] ? $this->serializer->serialize($msgs['id'], 'json') : $msgs['id'],
]);
}
/**
* Show communications with teachers, secretaries and admins.
*
* @param Request $request when consulting a message
*
* @Route("/api/msg/admin/doubt/list", name="get_msg_admin_doubt_list", methods={"POST"})
*/
public function getMsgAdminDoubtList(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$pageNumber = RequestTransform::getRequiredField($request, 'page');
$msgType = RequestTransform::getRequiredField($request, 'type');
$msgStatus = RequestTransform::getRequiredField($request, 'status');
$area = RequestTransform::getRequiredField($request, 'area', false, true) ?: null;
$sede = RequestTransform::getRequiredField($request, 'sede', false, true) ?: null;
$seeAsTutor = RequestTransform::getRequiredField($request, 'seeAsTutor', false, true) ?: null;
$msgs = $this->msgService->getAdminDoubtsList($userInformation['uuid'], $pageNumber, $msgType, $msgStatus, $area, $sede, $seeAsTutor);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_admin_doubt_list',
'id' => 200 == $msgs['code'] ? $this->serializer->serialize($msgs['id'], 'json') : $msgs['id'],
]);
}
/**
* Show communications created.
*
* @Route("/api/msg/user/doubt/list", name="get_msg_user_doubt_list", methods={"POST"})
*/
public function getMsgUserDoubtList(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$pageNumber = RequestTransform::getRequiredField($request, 'page');
$msgStatus = RequestTransform::getRequiredField($request, 'status');
$msgs = $this->msgService->getUserDoubtsList($userInformation['uuid'], $pageNumber, $msgStatus);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_user_doubt_list',
'id' => 200 == $msgs['code'] ? $this->serializer->serialize($msgs['id'], 'json') : $msgs['id'],
]);
}
/**
* Details about an announcement.
*
* @param string $msg_id ID of the message
*
* @Route("/api/details/announcement/{msg_id}", name="announcement_get_details", methods={"GET"})
*/
public function showDetailsAnnouncement(string $msg_id): JsonResponse
{
$announcement = $this->msgService->getAnnouncementDetails($msg_id);
if ($announcement) {
return new JsonResponse([
'code' => 200,
'message' => 'announcement_get_details',
'result' => $announcement,
]);
}
return new JsonResponse([
'code' => 404,
'message' => 'announcement_get_details',
'result' => $announcement,
]);
}
/**
* Details about an announcement.
*
* @param string $msg_id ID of the message
*
* @Route("/api/msg/user/comunication/{course_id}", name="comunication_get_access", methods={"GET"})
*/
public function hasCourseAccessComunication(string $course_id): JsonResponse
{
$courses = explode(',', $course_id);
$access = $this->msgService->hasCourseAccessComunication($courses);
if ($access) {
return new JsonResponse([
'code' => 200,
'message' => 'comunication_get_access',
'result' => $access,
]);
}
return new JsonResponse([
'code' => 404,
'message' => 'comunication_get_access',
'result' => $access,
]);
}
/**
* Details about an announcement.
*
* @param string $msg_id ID of the message
*
* @Route("/api/msg/user/all/comunication", name="comunication_get_user_access", methods={"GET"})
*/
public function getUserAccessComunication(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$access = $this->msgService->getUserCoursesAccess($userInformation['uuid']);
if ($access) {
return new JsonResponse([
'code' => 200,
'message' => 'comunication_get_user_access',
'result' => $access,
]);
}
return new JsonResponse([
'code' => 404,
'message' => 'comunication_get_user_access',
'result' => $access,
]);
}
/**
* Details about a conversation (doubt).
*
* @param string $msgId ID of the message
* @param Request $request when consulting a message
*
* @Route("/api/msg/doubt/details/{msgId}", name="get_msg_doubt_details", methods={"GET"})
*/
public function getMsgDoubtDetails(string $msgId, Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$msgs = $this->msgService->getDoubtDetails($msgId, $userInformation['uuid']);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_doubt_details',
'result' => $msgs['result'],
]);
}
/**
* Auxiliary functions for creating messages.
*
* @param $msg Msg msg object to creat or edit
* @param $sentBy Usuario user that created the message
* @param $type String type of message: announcement, doubt or feedback
* @param $title String title of the message
* @param $message String content of the message
* @param $keyValueArray array for msg KV
* @param $request Request when a new announcement is submitted
* @param $repository BaseRepository to make SQL calls using ORM
* @param $sqlService SqlService to make SQL calls
*
* @return array
*/
private function createNewMessage(Msg $msg, Usuario $sentBy, string $type, string $title, string $message, array $keyValueArray, Request $request, BaseRepository $repository, SqlService $sqlService)
{
$exception = [];
$today = new \DateTime();
$createdBy = null == $msg->getCreatedBy() ? $sentBy : $msg->getCreatedBy();
$createdAt = null == $msg->getCreatedAt() ? $today : $msg->getCreatedAt();
// Message information
$msg->setCreatedBy($createdBy);
$msg->setCreatedAt($createdAt);
$msg->setModifiedAt($today);
$msg->setTitle($title);
$msg->setType($type);
$exception_msg = $repository->add($msg);
if (200 == $exception_msg['code']) {
// Message Entry information
$msgEntry = $repository->isId($request, MsgEntry::class);
$msgEntry->setIdMsg($msg);
$msgEntry->setCreatedBy($createdBy);
$msgEntry->setModifiedBy($sentBy);
$msgEntry->setCreatedAt($createdAt);
$msgEntry->setModifiedAt($today);
$msgEntry->setText($message);
$exception_msgEntry = $repository->add($msgEntry);
if (200 == $exception_msgEntry['code']) {
// Para cada clave valor crear un insert en Msg_Entry (con su clave, valor).
$exception_msgKv = $sqlService->generateMsgKvSql($msg, $keyValueArray);
if (200 == $exception_msgKv[0]['code']) {
// Exception message if exit
$exception = [
'code' => 200,
'message' => 'success',
'id' => [
'msg' => $exception_msg['id'],
'msgEntry' => $exception_msgEntry['id'],
],
];
$msgKv_ids = [];
foreach ($exception_msgKv as $insert) {
if (200 != $insert['code']) {
return new JsonResponse([
'code' => $insert['code'],
'message' => $insert['message'],
'id' => $insert['id'],
]);
} else {
array_push($msgKv_ids, $insert['id']);
}
}
$exception['id']['msgKv'] = $msgKv_ids;
}
}
}
return $exception;
}
/**
* Create a new Announcement.
*
* @param $request Request when a new announcement is submitted
*
* @Route("/api/anuncio/add", name="anuncio_add", methods={"POST"})
* @Route("/api/anuncio/edit/{id}", name="anuncio_edit", methods={"POST"})
*/
public function newAnnouncement(Request $request): JsonResponse
{
$title = RequestTransform::getRequiredField($request, 'title');
$message = RequestTransform::getRequiredField($request, 'message');
$category = RequestTransform::getRequiredField($request, 'category');
$dateStart = RequestTransform::getRequiredField($request, 'dateStart');
$dateEnd = RequestTransform::getRequiredField($request, 'dateEnd', false, true) ?: null;
$showOnPanel = RequestTransform::getRequiredField($request, 'showOnPanel');
$sendEmail = RequestTransform::getRequiredField($request, 'sendEmail');
$isEnabled = RequestTransform::getRequiredField($request, 'isEnabled');
$sedes = RequestTransform::getRequiredField($request, 'sedes', true, true) ?: null;
$areas = RequestTransform::getRequiredField($request, 'areas', true, true) ?: null;
$currentCursos = RequestTransform::getRequiredField($request, 'currentCursos', true, true);
$previousCursos = RequestTransform::getRequiredField($request, 'previousCursos', true, true);
$nextCursos = RequestTransform::getRequiredField($request, 'nextCursos', true, true);
$superPromotions = RequestTransform::getRequiredField($request, 'superPromotions', true, true);
$users = RequestTransform::getRequiredField($request, 'users') ?: null;
$msgId = RequestTransform::getRequiredField($request, 'id', false, true) ?: null;
$filesToServer = RequestTransform::getRequiredField($request, 'fichero', false, true);
$filesFromServer = RequestTransform::getRequiredField($request, 'filesFromServer', true, true);
$userInformation = $this->userService->decodeToken($request);
$cursos = array_merge($currentCursos, $previousCursos, $nextCursos) ?: null;
$keyValueArray = [
'inicio' => date('d-m-Y', strtotime($dateStart)),
'fin' => $dateEnd ? date('d-m-Y', strtotime($dateEnd)) : null,
'habilitado' => $isEnabled ? 1 : 0,
'visualizar' => $showOnPanel ? 1 : 0,
'email' => $sendEmail ? 1 : 0,
'user' => $users,
'category' => $category,
'curso' => $cursos,
'area' => $areas,
'sede' => $sedes,
'super_promocion' => $superPromotions,
'filesToServer' => $filesToServer ?: null,
'fichero' => $filesFromServer,
];
$announcement = $this->msgService->addNewAnnouncement($userInformation['uuid'], 0, $title, $message, $keyValueArray, $msgId, $filesToServer);
if ($announcement) {
return new JsonResponse([
'code' => 200,
'message' => 'anuncio_add',
'id' => $announcement,
]);
}
return new JsonResponse([
'code' => 400,
'message' => 'anuncio_add',
'id' => $announcement,
]);
}
/**
* Upload a file to a announcement.
*
* @param Request $request from the multi-file-upload.server
*
* @Route("/api/anuncio/add/image", name="fichero_anuncio", methods={"POST"})
*/
public function announcementFiles(Request $request): JsonResponse
{
$title = $request->request->get('title');
$message = $request->request->get('message');
$array_key_values = $request->request->get('key_value_array');
$uploadedFile = $request->files->get('picture');
$me_id = $request->request->get('id');
if ($uploadedFile) {
foreach ($uploadedFile as $key => $value) {
$e[] = $this->msgService->uploadFileToAnnouncement($value, $me_id);
}
$array = (array) json_decode($array_key_values);
if ($title && $message && $array && $e) {
$this->msgService->sendEmail($title, $message, $array, $e);
}
if ($e) {
return new JsonResponse([
'code' => 200,
'message' => 'fichero_anuncio',
'id' => $me_id,
]);
}
return new JsonResponse([
'code' => 500,
'message' => $e->getMessage(),
'id' => $me_id,
]);
}
return new JsonResponse([
'code' => 404,
'message' => 'File not found',
'id' => $me_id,
]);
}
/**
* Create a new Message.
*
* @param Request $request when a new doubt is submitted
* @param BaseRepository $repository to make SQL calls using ORM
* @param SqlService $sqlService to make SQL calls
*
* @Route("/api/duda/add", name="duda_add", methods={"POST"})
*/
public function newDoubt(Request $request, BaseRepository $repository, SqlService $sqlService): JsonResponse
{
// Request
$user_information = $this->userService->decodeToken($request);
$title = RequestTransform::getRequiredField($request, 'title');
$message = RequestTransform::getRequiredField($request, 'message');
$addressee = RequestTransform::getRequiredField($request, 'destino');
$campus = RequestTransform::getRequiredField($request, 'sede');
$grade = RequestTransform::getRequiredField($request, 'curso');
$unit = RequestTransform::getRequiredField($request, 'tema');
$msg = $repository->isId($request, Msg::class);
$sentBy = $this->em->getRepository(Usuario::class)->find($user_information['uuid']);
$keyValueArray = [
'estado' => 0,
];
switch ($addressee) {
case 1: // Unit doubts
$keyValueArray['tema'] = $unit;
$keyValueArray['curso'] = $grade;
break;
case 2: // Secretary
$keyValueArray['sede'] = $campus;
break;
}
$exception = $this->createNewMessage($msg, $sentBy, $addressee, $title, $message, $keyValueArray, $request, $repository, $sqlService);
return new JsonResponse($exception);
}
/**
* Create a new feedback message from test.
*
* @param Request $request when a new doubt is submitted
*
* @Route("/api/retroalimentacion/add", name="feedback_add", methods={"POST"})
*/
public function newFeedback(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$course = RequestTransform::getRequiredField($request, 'course');
$questionId = RequestTransform::getRequiredField($request, 'question');
$testId = RequestTransform::getRequiredField($request, 'test');
$message = RequestTransform::getRequiredField($request, 'message');
$feedback_id = $this->msgService->addNewFeedback($userInformation['uuid'], $course, $questionId, $testId, $message);
return new JsonResponse([
'code' => 200,
'message' => 'feedback_add',
'result' => $feedback_id,
]);
}
/**
* Upload a file to a msg.
*
* @param Request $request from the multi-file-upload.server
* @param FileUploader $fileUploader to upload the image to the server
*
* @Route("/api/details/msg/add/image", name="image_msg", methods={"POST"})
*/
public function msgFiles(Request $request, FileUploader $fileUploader): JsonResponse
{
$uploadedFile = $request->files->get('picture');
$me_id = $request->request->get('id');
if ($uploadedFile) {
try {
$urlFileName = $fileUploader->upload($uploadedFile, '/msg');
$me = $this->em->getRepository(MsgEntry::class)->find($me_id);
$msg_id = $me->getIdMsg()->getId();
$exception = $this->sqlService->genericInsert('msg_kv', [
'id_msg_id' => $msg_id,
'field' => 'fichero',
'value' => $urlFileName,
]);
return new JsonResponse([
'code' => 200,
'message' => $exception,
]);
} catch (\Exception $e) {
return new JsonResponse(['code' => 500, 'message' => $e->getMessage()]);
}
}
return new JsonResponse(['code' => 404, 'message' => 'File not found']);
}
/**
* Answer a conversation.
*
* @param $request Request when a new reply is submitted
*
* @Route("/api/details/msg/add", name="msg_answer", methods={"POST"})
*/
public function newAnswer(Request $request): JsonResponse
{
$user_information = $this->userService->decodeToken($request);
$msg = RequestTransform::getRequiredField($request, 'msg');
$message = RequestTransform::getRequiredField($request, 'message');
$msg_entry_id = $this->msgService->addMsgEntry($user_information['uuid'], $message, $msg);
return new JsonResponse([
'code' => 200,
'message' => 'msg_answer',
'result' => $msg_entry_id,
]);
}
/**
* Answer a conversation and change status to published.
*
* @param $request Request when a new reply is submitted
*
* @Route("/api/details/msg/add/publish", name="msg_answer_and_publish", methods={"POST"})
*/
public function addAnswerAndPublish(Request $request): JsonResponse
{
$user_information = $this->userService->decodeToken($request);
$msg = RequestTransform::getRequiredField($request, 'msg');
$message = RequestTransform::getRequiredField($request, 'message');
$msg_entry_id = $this->msgService->addMsgEntry($user_information['uuid'], $message, $msg);
$msg_id = $msg['id'];
$this->msgService->switchMsgPublishStatus($msg_id, 1);
return new JsonResponse([
'code' => 200,
'message' => 'msg_answer_and_publish',
'result' => $msg_entry_id,
]);
}
/**
* Modify an existing message.
*
* @Route("/api/details/msg/edit", name="msg_answer_edit", methods={"PUT"})
*/
public function editAnswer(Request $request): JsonResponse
{
$user_information = $this->userService->decodeToken($request);
$msg_entry_id = RequestTransform::getRequiredField($request, 'id');
$text = RequestTransform::getRequiredField($request, 'message');
$updated = $this->msgService->editMsgEntry($user_information['uuid'], $text, $msg_entry_id);
if ($updated) {
return new JsonResponse([
'code' => 200,
'message' => 'msg_answer_edit',
'result' => $msg_entry_id,
]);
}
return new JsonResponse([
'code' => 400,
'message' => 'msg_answer_edit',
'result' => $msg_entry_id,
]);
}
/**
* Publish existing messages.
*
* @Route("/api/details/msg/switchPublish", name="msg_switch_publish", methods={"PUT"})
*/
public function switchPublishAnswers(Request $request): JsonResponse
{
$msg_id = RequestTransform::getRequiredField($request, 'msgId');
$published = RequestTransform::getRequiredField($request, 'estadoPublicacion');
$updated = $this->msgService->switchMsgPublishStatus($msg_id, $published);
if ($updated) {
return new JsonResponse([
'code' => 200,
'message' => 'msg_switch_publish',
'result' => $msg_id,
]);
}
return new JsonResponse([
'code' => 400,
'message' => 'msg_switch_publish',
'result' => [],
]);
}
/**
* Change message type.
*
* @Route("/api/details/msg/changeType", name="msg_change_type", methods={"PUT"})
*/
public function changeMsgType(Request $request): JsonResponse
{
$msg_id = RequestTransform::getRequiredField($request, 'msgId');
$msg_type = RequestTransform::getRequiredField($request, 'msgType');
$curso = RequestTransform::getRequiredField($request, 'curso', true, true);
$tema = RequestTransform::getRequiredField($request, 'tema', true, true);
$sede = RequestTransform::getRequiredField($request, 'sede', true, true);
$values = [
'curso' => $curso,
'tema' => $tema,
'sede' => $sede,
];
$type_changed = $this->msgService->changeMsgType($msg_id, $msg_type, $values);
if ($type_changed) {
return new JsonResponse([
'code' => 200,
'message' => 'msg_change_type',
'result' => $type_changed,
]);
}
return new JsonResponse([
'code' => 400,
'message' => 'msg_change_type',
'result' => $type_changed,
]);
}
/**
* Change message status.
*
* @Route("/api/details/msg/changeStatus", name="msg_change_status", methods={"PUT"})
*/
public function changeMsgStatus(Request $request): JsonResponse
{
$msg_id = RequestTransform::getRequiredField($request, 'msgId');
$msg_status = RequestTransform::getRequiredField($request, 'msgStatus');
$status_changed = $this->msgService->changeMsgStatus($msg_id, $msg_status);
if ($status_changed) {
return new JsonResponse([
'code' => 200,
'message' => 'msg_change_status',
'result' => $status_changed,
]);
}
return new JsonResponse([
'code' => 400,
'message' => 'msg_change_status',
'result' => $status_changed,
]);
}
/**
* Switches a Msg (announcement) to be enabled or disabled.
*
* @Route("/api/msg/announcement/enable", name="msg_announcement_enable", methods={"PUT"})
*/
public function switchEnableMsg(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$msgId = RequestTransform::getRequiredField($request, 'msgId');
$isMsgEnabled = $this->msgService->switchMsgEnableStatus($msgId, $userInformation['uuid']);
if (is_null($isMsgEnabled)) {
return new JsonResponse([
'code' => 403,
'message' => 'msg_announcement_enable',
'result' => [],
]);
}
return new JsonResponse([
'code' => 200,
'message' => 'msg_announcement_enable',
'result' => $msgId,
]);
}
/**
* Deletes a messages with all its entries, reads and kvs.
*
* @param string $msg_id Message id
*
* @Route("/api/msg/{msg_id}", name="msg_delete" , methods={"DELETE"})
*/
public function deleteMsg(string $msg_id): JsonResponse
{
if ($msg_id) {
$em = $this->getDoctrine()->getManager();
$msg = $em->getRepository(Msg::class)->find($msg_id);
if ($msg) {
$em->remove($msg);
$em->flush();
$exception = [
'code' => 200,
'message' => 'success',
'id' => $msg_id,
];
} else {
$exception = [
'code' => 404,
'message' => 'Not found',
'id' => $msg_id,
];
}
return new JsonResponse($exception);
}
return new JsonResponse([
'code' => 200,
'message' => 'msg_announcement_enable',
'result' => 'error',
]);
}
/**
* Deletes a Msg.
*
* @Route("/api/details/msg/delete", name="msg_delete_bd", methods={"PUT"})
*/
public function deleteMsgBd(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$msgId = RequestTransform::getRequiredField($request, 'msgId');
$isMsgEnabled = $this->msgService->deleteMsg($msgId, $userInformation['uuid']);
if (is_null($isMsgEnabled)) {
return new JsonResponse([
'code' => 403,
'message' => 'msg_announcement_enable',
'result' => [],
]);
}
return new JsonResponse([
'code' => 200,
'message' => 'msg_announcement_enable',
'result' => $msgId,
]);
}
/**
* Show feedback list.
*
* @Route("/api/msg/feedback/list", name="get_msg_feedback_list", methods={"POST"})
*/
public function getFeedbackList(Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$pageNumber = RequestTransform::getRequiredField($request, 'page');
$msgStatus = RequestTransform::getRequiredField($request, 'status');
$area = RequestTransform::getRequiredField($request, 'area', false, true) ?: null;
$sede = RequestTransform::getRequiredField($request, 'sede', false, true) ?: null;
$seeAsTutor = RequestTransform::getRequiredField($request, 'seeAsTutor', false, true) ?: null;
$msgs = $this->msgService->getFeedbackList($userInformation['uuid'], $pageNumber, $msgStatus, $area, $sede, $seeAsTutor);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_feedback_list',
'id' => 200 == $msgs['code'] ? $this->serializer->serialize($msgs['id'], 'json') : $msgs['id'],
]);
}
/**
* Details about a conversation (feedback).
*
* @param string $msgId ID of the message
* @param Request $request when consulting a message
*
* @Route("/api/msg/feedback/details/{msgId}", name="get_msg_feedback_details", methods={"GET"})
*/
public function getFeedbackDetails(string $msgId, Request $request): JsonResponse
{
$userInformation = $this->userService->decodeToken($request);
$msgs = $this->msgService->getFeedbackDetails($msgId, $userInformation['uuid']);
return new JsonResponse([
'code' => $msgs['code'],
'message' => 'get_msg_feedback_details',
'result' => $msgs['result'],
]);
}
}