<?php
namespace EADPlataforma\Controller\Api\v1;
use OpenApi\Annotations as OA;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use EADPlataforma\Controller\Api\AbstractApiController;
use EADPlataforma\Entity\User;
use EADPlataforma\Entity\UserSubscription;
use EADPlataforma\Entity\Course;
use EADPlataforma\Entity\CourseCertificateTemplate;
use EADPlataforma\Entity\Lesson;
use EADPlataforma\Entity\Group;
use EADPlataforma\Entity\GroupUser;
use EADPlataforma\Entity\GroupCourse;
use EADPlataforma\Entity\ProductCourse;
use EADPlataforma\Entity\Enrollment;
use EADPlataforma\Enum\EnrollmentEnum;
use EADPlataforma\Enum\TrashEnum;
use EADPlataforma\Enum\UserLogEnum;
use EADPlataforma\Enum\UserPermissionEnum;
use EADPlataforma\Enum\LessonEnum;
use EADPlataforma\Enum\ErrorEnum;
class EnrollmentApiController extends AbstractApiController {
public function getEntityClass(){
return Enrollment::class;
}
/**
* Listagem de matrículas do EAD.
*
* @Route("/api/1/enrollment", methods={"GET"})
* @OA\Response(
* response=200,
* description="Retorna os cursos do EAD.",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="matricula_id", type="integer", example=1, description="Id da matrícula no EAD."),
* @OA\Property(property="aluno_id", type="integer", example=10, description="Id do aluno no EAD."),
* @OA\Property(property="aluno_nome", type="string", example="Nome do aluno."),
* @OA\Property(property="aluno_email", type="string", example="E-mail do aluno."),
* @OA\Property(property="curso_id", type="integer", example=10, description="Id do curso no EAD."),
* @OA\Property(property="titulo_curso", type="string", example="Nome do curso", description="Título do curso."),
* @OA\Property(property="emitir_certificado", type="integer", example=360, description="Determina se o curso irá emitir certificado. (0-Não / 1-Sim)"),
* @OA\Property(property="cadastro", type="date time", example="2020-01-01 00:00:01", description="Data em que o aluno foi matriculado."),
* @OA\Property(property="inicio", type="date time", example="2020-01-01 00:00:01", description="Data início do curso."),
* @OA\Property(property="suporte", type="date time", example="2020-01-01 00:00:01", description="Data final do suporte."),
* @OA\Property(property="expira", type="date time", example="2020-01-01 00:00:01", description="Data que encerra o acesso ao curso."),
* @OA\Property(property="status", type="integer", example="1", description="Status da matrícula. (1-Ativa / 2-Suspensa / 3-Cancelada / 4-Expirada)"),
* @OA\Property(property="assinatura_id", type="integer", example=10, description="Id da assinatura que originou a matrícula."),
* @OA\Property(property="cupom", type="string", example="CHAVE", description="Cupom utilizado na matrícula."),
* @OA\Property(property="origem", type="integer", example="professor(a)@email.com", description="E-mail do professor(a) cadastrado no EAD. (1-Grátis / 2-Venda / 3-Assinatura / 4-Grupo / 5-Cupom / 6-API / 7-Grátis)"),
* @OA\Property(property="grupo_id", type="integer", example="123", description="Id de um grupo do EAD."),
* @OA\Property(property="grupo_nome", type="string", example="Nome grupo", description="Nome do grupo a que pertence o aluno.")
* )
* )
*
* @OA\Response(
* response=204,
* description="No content"
* )
*
* @OA\Response(
* response=401,
* description="Token not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
* @OA\Property(property="message", type="string", example="Token not found")
* )
* )
*
* @OA\Response(
* response=429,
* description="Too many requests",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
* @OA\Property(property="message", type="string", example="Too many requests")
* )
* )
*
* @OA\Response(
* response=500,
* description="Internal Server Error",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
* @OA\Property(property="message", type="string", example="Internal Server Error")
* )
* )
*
* @OA\Parameter(
* name="id",
* in="query",
* description="Matricula Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="usuario_id",
* in="query",
* description="Usuário Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="curso",
* in="query",
* description="Curso Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="grupo",
* in="query",
* description="Grupo Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="assinatura_id",
* in="query",
* description="Assinatura Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="cupom",
* in="query",
* description="Cupom",
* @OA\Schema(type="string")
* )
*
* @OA\Parameter(
* name="data_inicio",
* in="query",
* description="Data inicial última visualização (yyyy-mm-dd)",
* @OA\Schema(type="string")
* )
*
* @OA\Parameter(
* name="data_fim",
* in="query",
* description="Data final última visualização (yyyy-mm-dd)",
* @OA\Schema(type="string")
* )
*
* @OA\Parameter(
* name="paginate",
* in="query",
* description="Informaçoes para paginação",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="limit",
* in="query",
* description="Número máximo de dados retornados por página, valor padrão 1000",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="offset",
* in="query",
* description="Indica o início da leitura, caso não informado valor padrão será 0",
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Matrículas")
* @Security(name="Bearer")
*
*/
public function getEnrollment(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$columns = [
"e.id AS matricula_id",
"u.id AS aluno_id",
"u.name AS aluno_nome",
"u.email AS aluno_email",
"c.id AS curso_id",
"c.title AS titulo_curso",
"e.certificate AS emitir_certificado",
"DATE_FORMAT(e.dateRegister, '%Y-%m-%d %H:%i:%s') AS cadastro",
"DATE_FORMAT(e.dateStart, '%Y-%m-%d %H:%i:%s') AS inicio",
"DATE_FORMAT(e.dateSupport, '%Y-%m-%d %H:%i:%s') AS suporte",
"DATE_FORMAT(e.datePeriod, '%Y-%m-%d %H:%i:%s') AS expira",
"e.status",
"us.id AS assinatura_id",
"e.couponKey AS cupom",
"g.id AS grupo_id",
"g.name AS grupo_nome",
"e.origin AS origem"
];
$userClass = User::class;
$courseClass = Course::class;
$userSubscription = UserSubscription::class;
$groupClass = Group::class;
$joins = [
"{$userClass} AS u" => "u.id = e.user AND u.deleted = 0",
"{$courseClass} AS c" => "c.id = e.course AND c.deleted = 0",
"{$userSubscription} AS us" => ["LEFT", "us.id = e.userSubscription"],
"{$groupClass} AS g" => ["LEFT", "g.id = e.group"],
];
$enrollmentId = (int)$request->get('id');
$userId = $request->get('usuario_id');
$courseId = (int)$request->get('curso');
$groupId = (int)$request->get('grupo');
$subscriptionId = (int)$request->get('assinatura_id');
$coupom = $request->get('cupom');
$dateStart = $request->get('data_inicio');
$dateEnd = $request->get('data_fim');
$paginate = $request->get('paginate');
$limit = (int)$request->get('limit');
$offset = (int)$request->get('offset');
$filter = [
"e.deleted" => 0,
"e.user" => [ "!=", 1 ]
];
if(empty($limit) || $limit > 1000){
$limit = 1000;
}
if(empty($offset)){
$offset = 0;
}
if($enrollmentId > 0){
$filter["e.id"] = $enrollmentId;
}
if(!empty($userId) && $userId > 1){
$filter["e.user"] = (int)$userId;
}
if($courseId > 0){
$filter["e.course"] = $courseId;
}
if($subscriptionId > 0){
$filter["e.userSubscription"] = $subscriptionId;
}
if(!empty($coupom)){
$filter["e.couponKey"] = $coupom;
}
if($groupId > 0){
$filter["e.group"] = $groupId;
}
if(empty($dateStart) && !empty($dateEnd)){
$dateStart = date('Y-m-d', strtotime("-1 day",strtotime($dateEnd)));
}
if(empty($dateEnd) && !empty($dateStart)){
$dateEnd = date('Y-m-d', strtotime("+1 day",strtotime($dateStart)));
}
if(!empty($dateStart) && !empty($dateEnd)){
$filter["whereText"] = "e.dateStart BETWEEN '{$dateStart}' AND '{$dateEnd}'";
}
$order = ["e.id" => "ASC"];
$data = $this->repository->paginate(
"e",
null,
$columns,
$joins,
$filter,
$order,
$limit,
$offset
);
if(count($data['rows']) == 0){
return $this->eadResponse(null, ErrorEnum::NO_CONTENT, null);
}
foreach ($data['rows'] as $key => $enrollment) {
if($enrollment->status == EnrollmentEnum::STATUS_ACTIVE){
if(strtotime($enrollment->expira) < time()){
$enrollment->status = EnrollmentEnum::STATUS_EXPIRED;
}
}
}
if($paginate == 1){
unset($data['searchText']);
return $this->json($data);
}
return $this->json($data['rows']);
}
/**
* Progresso dos alunos em um curso.
*
* @Route("/api/1/progress", methods={"GET"})
* @OA\Response(
* response=200,
* description="Retorna o progresso dos alunos em um curso",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="curso_id", type="integer", example=10, description="Id do curso no EAD."),
* @OA\Property(property="curso_titulo", type="string", example="Nome Curso", description="Título do curso."),
* @OA\Property(property="aluno_id", type="integer", example=12, description="Id do aluno cadastrado no EAD."),
* @OA\Property(property="aluno_nome", type="string", example="Nome Aluno", description="Nome do aluno."),
* @OA\Property(property="total_aulas", type="integer", example=134, description="Número de aulas de um curso."),
* @OA\Property(property="aulas_acessadas", type="integer", example=55, description="Número de aulas visualizadas."),
* @OA\Property(property="progresso", type="float", example=30, description="Porcentagem concluída do curso."),
* @OA\Property(property="visualizacoes", type="integer", example=60, description="Número de visualizações do aluno no curso."),
* @OA\Property(property="suporte", type="integer", example=2, description="Número de suportes solicitados pelo aluno."),
* @OA\Property(property="ultimo_acesso", type="datetime", example="", description="Data e hora do último acesso do aluno no curso.")
* )
* )
*
* @OA\Response(
* response=204,
* description="No content"
* )
*
* @OA\Response(
* response=401,
* description="Token not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
* @OA\Property(property="message", type="string", example="Token not found")
* )
* )
*
* @OA\Response(
* response=429,
* description="Too many requests",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
* @OA\Property(property="message", type="string", example="Too many requests")
* )
* )
*
* @OA\Response(
* response=500,
* description="Internal Server Error",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
* @OA\Property(property="message", type="string", example="Internal Server Error")
* )
* )
*
* @OA\Parameter(
* name="curso",
* in="query",
* description="Curso Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="grupo_id",
* in="query",
* description="Grupo Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="plano_id",
* in="query",
* description="Plano Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="usuario_id",
* in="query",
* description="Usuário Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="data_inicio",
* in="query",
* description="Data inicial último acesso (yyyy-mm-dd)",
* @OA\Schema(type="string")
* )
*
* @OA\Parameter(
* name="data_fim",
* in="query",
* description="Data final último acesso (yyyy-mm-dd)",
* @OA\Schema(type="string")
* )
*
* @OA\Parameter(
* name="paginate",
* in="query",
* description="Informaçoes para paginação",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="limit",
* in="query",
* description="Número máximo de dados retornados por página, valor padrão 1000",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="offset",
* in="query",
* description="Indica o início da leitura, caso não informado valor padrão será 0",
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Log de acesso e Progresso do aluno")
* @Security(name="Bearer")
*
*/
public function getCourseProgress(Request $request)
{
$discordService = $this->generalService->getService('DiscordService');
$discordService->setChannel('debug');
$this->requestUtil->setRequest($request)->setData();
$columns = [
"e.id AS matricula_id",
"c.id AS curso_id",
"c.title AS curso_titulo",
"c.numberLesson AS total_aulas",
"u.id AS aluno_id",
"u.name AS aluno_nome",
"e.lessonNumberComplete AS aulas_acessadas",
"e.lessonNumberViews AS visualizacoes",
"e.supportNumberRequest AS suporte",
"DATE_FORMAT(e.dateLastAccess, '%Y-%m-%d %H:%i:%s') AS ultimo_acesso"
];
$userClass = User::class;
$courseClass = Course::class;
$joins = [
"{$userClass} AS u" => "u.id = e.user AND u.deleted = 0",
"{$courseClass} AS c" => "c.id = e.course AND c.deleted = 0"
];
$courseId = (int)$request->get('curso');
$userId = (int)$request->get('usuario_id');
$groupId = (int)$request->get('grupo_id');
$planId = (int)$request->get('plano_id');
$dateStart = $request->get('data_inicio');
$dateEnd = $request->get('data_fim');
$paginate = $request->get('paginate');
$limit = (int)$request->get('limit');
$offset = (int)$request->get('offset');
$filter = [
"e.deleted" => 0,
"e.user" => [ "!=", 1 ]
];
$filter["whereText"] = " e.id > 0 ";
if($groupId > 0){
$groupUserClass = GroupUser::class;
$groupCourseClass = GroupCourse::class;
$filter["whereText"] .= "
AND u.id IN (
SELECT
IDENTITY(gUser.user)
FROM {$groupUserClass} AS gUser
WHERE gUser.group = {$groupId}
)
";
$filter["whereText"] .= "
AND c.id IN (
SELECT
IDENTITY(gCourse.course)
FROM {$groupCourseClass} AS gCourse
WHERE gCourse.group = {$groupId}
)
";
}
if($planId > 0){
$userSubscriptionClass = UserSubscription::class;
$productCourseClass = ProductCourse::class;
$filter["whereText"] .= "
AND u.id IN (
SELECT
IDENTITY(us.user)
FROM {$userSubscriptionClass} AS us
WHERE us.product = {$planId}
)
";
$filter["whereText"] .= "
AND c.id IN (
SELECT
IDENTITY(pCourse.course)
FROM {$productCourseClass} AS pCourse
WHERE pCourse.product = {$planId}
)
";
}
if(empty($limit) || $limit > 1000){
$limit = 1000;
}
if(empty($offset)){
$offset = 0;
}
if($courseId > 0){
$filter["e.course"] = $courseId;
}
if(!empty($userId) && $userId > 1){
$filter["e.user"] = $userId;
}
if(empty($dateStart) && !empty($dateEnd)){
$dateStart = date('Y-m-d', strtotime("-1 day",strtotime($dateEnd)));
}
if(empty($dateEnd) && !empty($dateStart)){
$dateEnd = date('Y-m-d', strtotime("+1 day",strtotime($dateStart)));
}
if(!empty($dateStart) && !empty($dateEnd)){
$filter["whereText"] = "e.dateLastAccess BETWEEN '{$dateStart}' AND '{$dateEnd}'";
}
$order = ["e.id" => "ASC"];
try {
$data = $this->em->getRepository(Enrollment::class)->paginate(
"e",
null,
$columns,
$joins,
$filter,
$order,
$limit,
$offset
);
if(count($data['rows']) == 0){
return $this->eadResponse(null, ErrorEnum::NO_CONTENT, null);
}
foreach ($data['rows'] as $key => $value) {
$data['rows'][$key]->progresso = 0;
if($data['rows'][$key]->total_aulas > 0){
$data['rows'][$key]->progresso = round($data['rows'][$key]->aulas_acessadas * 100 / $data['rows'][$key]->total_aulas, 2);
}
}
if($paginate == 1){
unset($data['searchText']);
return $this->json($data);
}
return $this->json($data['rows']);
} catch (Exception $e) {
$discordService->setMessage($e->getMessage());
$discordService->sendDiscord();
}
}
/**
* Inserir uma matrícula no EAD.
*
* @Route("/api/1/enrollment", methods={"POST"})
* consumes={"application/json"}
* produces={"application/json"}
*
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=200, description="Success"),
* @OA\Property(property="message", type="string", example="Success"),
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="inicio", type="string", example="2021-10-11 00:00:00"),
* @OA\Property(property="expira", type="string", example="2022-10-11 00:00:00"),
* @OA\Property(property="suporte", type="string", example="2022-10-11 00:00:00"),
* @OA\Property(property="curso_id", type="integer", example=5),
* @OA\Property(property="aluno_id", type="integer", example=55),
* @OA\Property(property="status", type="integer", example=1),
* @OA\Property(property="emitir_certificado", type="integer", example=1),
* @OA\Property(property="origem", type="integer", example=1),
* @OA\Property(property="cupom", type="string", example="CUPOMKEY"),
* @OA\Property(property="assinatura_id", type="integer", example=222),
* @OA\Property(property="grupo_id", type="integer", example=2)
* )
* )
* )
*
* @OA\Response(
* response=401,
* description="Token not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
* @OA\Property(property="message", type="string", example="Token not found")
* )
* )
*
* @OA\Response(
* response=404,
* description="Not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
* @OA\Property(property="message", type="string", example="Not found"),
* @OA\Property(
* property="data",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="string",
* example="field"
* )
* ),
* )
* )
*
* @OA\Response(
* response=406,
* description="Empty Fields",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
* @OA\Property(property="message", type="string", example="Error"),
* @OA\Property(
* property="data",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="string",
* example="field"
* )
* ),
* )
* )
*
* @OA\Response(
* response=409,
* description="Conflict",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=409, description="Conflict"),
* @OA\Property(property="message", type="string", example="Usuário já matriculado neste curso."),
* @OA\Property(property="data", nullable=true, type="application/json", example="null")
* )
* )
*
* @OA\Response(
* response=429,
* description="Too many requests",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
* @OA\Property(property="message", type="string", example="Too many requests")
* )
* )
*
* @OA\Response(
* response=500,
* description="Internal Server Error",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
* @OA\Property(property="message", type="string", example="Internal Server Error")
* )
* )
*
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="curso_id",
* description="Curso Id",
* type="integer"
* ),
* @OA\Property(
* property="usuario_id",
* description="Usuário Id",
* type="integer"
* ),
* @OA\Property(
* property="expira",
* description="Período de acesso do aluno (Y-m-d H:i:s)",
* type="string"
* ),
* @OA\Property(
* property="suporte",
* description="Período de suporte do aluno (Y-m-d H:i:s)",
* type="string"
* ),
* required={"curso_id", "usuario_id"}
* )
* )
* )
*
* @OA\Tag(name="Matrículas")
* @Security(name="Bearer")
*
*/
public function postEnrollment(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$courseId = $this->requestUtil->getField('curso_id');
$userId = $this->requestUtil->getField('usuario_id');
$datePeriodPost = $this->requestUtil->getField('expira');
$dateSupportPost = $this->requestUtil->getField('suporte');
$course = $this->em->getRepository(Course::class)->findOneBy([
"id" => $courseId,
"deleted" => EnrollmentEnum::ITEM_NO_DELETED
]);
if(!$course){
return $this->eadResponse(['curso_id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$user = $this->em->getRepository(User::class)->findOneBy([
"id" => $userId,
"deleted" => EnrollmentEnum::ITEM_NO_DELETED
]);
if(!$user){
return $this->eadResponse(
[ 'usuario_id' ],
ErrorEnum::FIELD_EMPTY,
ErrorEnum::MESSAGE_EMPTY_FIELD
);
}
$enrollmentService = $this->generalService->getService('EnrollmentService');
$enrollmentService->setEmail(true);
$enrollmentService->setOrigin(EnrollmentEnum::ORIGIN_API);
$dateNow = date('Y-m-d H:i:s');
if(!empty($datePeriodPost)){
$enrollmentService->setAccessDate(
date('Y-m-d H:i:s', strtotime($datePeriodPost))
);
}
if(!empty($dateSupportPost)){
$enrollmentService->setSupportDate(
date('Y-m-d H:i:s', strtotime($dateSupportPost))
);
}
$data = $enrollmentService->enrollUser($user, $course, true, false, true);
if($data->errors){
return $this->eadResponse(
$data->errors,
ErrorEnum::FIELD_EMPTY,
ErrorEnum::MESSAGE_EMPTY_FIELD
);
}
$enrollment = $data->enrollment;
$data = $enrollment->toReturnApi();
$this->userLogService->logInsert(
"enrollment",
$enrollment->getId(),
$data,
UserLogEnum::ORIGIN_CLIENT_API
);
return $this->eadResponse($data, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Atualizar uma matrícula do EAD.
*
* @Route("/api/1/enrollment/{id}", methods={"PUT"})
* consumes={"application/json"}
* produces={"application/json"}
*
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=200, description="Success"),
* @OA\Property(property="message", type="string", example="Success"),
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="inicio", type="string", example="2021-10-11 00:00:00"),
* @OA\Property(property="expira", type="string", example="2022-10-11 00:00:00"),
* @OA\Property(property="suporte", type="string", example="2022-10-11 00:00:00"),
* @OA\Property(property="curso_id", type="integer", example=5),
* @OA\Property(property="aluno_id", type="integer", example=55),
* @OA\Property(property="status", type="integer", example=1),
* @OA\Property(property="emitir_certificado", type="integer", example=1),
* @OA\Property(property="origem", type="integer", example=1),
* @OA\Property(property="cupom", type="string", example="CUPOMKEY"),
* @OA\Property(property="assinatura_id", type="integer", example=222),
* @OA\Property(property="grupo_id", type="integer", example=2)
* )
* )
* )
*
* @OA\Response(
* response=401,
* description="Token not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
* @OA\Property(property="message", type="string", example="Token not found")
* )
* )
*
* @OA\Response(
* response=404,
* description="Not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
* @OA\Property(property="message", type="string", example="Not found"),
* @OA\Property(
* property="data",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="string",
* example="field"
* )
* ),
* )
* )
*
* @OA\Response(
* response=406,
* description="Empty Fields",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
* @OA\Property(property="message", type="string", example="Error"),
* @OA\Property(
* property="data",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="string",
* example="field"
* )
* ),
* )
* )
*
* @OA\Response(
* response=429,
* description="Too many requests",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
* @OA\Property(property="message", type="string", example="Too many requests")
* )
* )
*
* @OA\Response(
* response=500,
* description="Internal Server Error",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
* @OA\Property(property="message", type="string", example="Internal Server Error")
* )
* )
*
* @OA\Parameter(
* name="id",
* in="path",
* description="Matrícula Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\RequestBody(
* required=false,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="expira",
* description="Período de acesso do aluno (Y-m-d H:i:s)",
* type="string"
* ),
* @OA\Property(
* property="suporte",
* description="Período de suporte do aluno (Y-m-d H:i:s)",
* type="string"
* ),
* @OA\Property(
* property="emitir_certificado",
* description="Emitir Certificado. (0-Não / 1-Sim)",
* type="integer"
* ),
* @OA\Property(
* property="periodo_suporte",
* description="Período de Suporte em número de dias",
* type="integer"
* ),
* @OA\Property(
* property="status",
* description="Status da Matrícula. (1-Ativa / 2-Suspensa / 3-Cancelada / 4-Expirada)",
* type="integer"
* ),
* )
* )
* ),
*
* @OA\Tag(name="Matrículas")
* @Security(name="Bearer")
*
*/
public function putEnrollment(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$enrollmentId = $request->get('id');
$enrollment = $this->repository->findOneBy([
"id" => $enrollmentId,
"deleted" => EnrollmentEnum::ITEM_NO_DELETED
]);
if (!$enrollment) {
return $this->eadResponse(null, ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$datePeriod = $this->requestUtil->getField('expira');
if(!empty($datePeriod)){
$this->requestUtil->setField('datePeriod', $datePeriod);
$enrollment->setDatePeriod($datePeriod);
}
$dateSupport = $this->requestUtil->getField('suporte');
if(!empty($dateSupport)){
$enrollment->setDateSupport($dateSupport);
}
$certificate = $this->requestUtil->getField('emitir_certificado');
if(is_numeric($certificate)){
$enrollment->setCertificate($certificate);
}
$status = $this->requestUtil->getField("status");
if(is_numeric($status) && ($status > 0 && $status <= 4)){
$enrollment->setStatus($status);
}
$errors = $this->validateEntity($enrollment);
if($errors){
return $this->eadResponse($errors, ErrorEnum::FIELD_EMPTY, ErrorEnum::MESSAGE_EMPTY_FIELD);
}
$this->em->flush();
$return = $enrollment->toReturnApi();
$this->userLogService->logUpdate("enrollment", $enrollment->getId(), $return, UserLogEnum::ORIGIN_CLIENT_API);
return $this->eadResponse($return, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Excluir uma matrícula do EAD.
*
* @Route("/api/1/enrollment/{id}", methods={"DELETE"})
* @OA\Response(
* response=200,
* description="Success",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=200, description="Success"),
* @OA\Property(property="message", type="string", example="Success"),
* @OA\Property(property="data", nullable=true, type="application/json", example="null"),
* )
* )
*
* @OA\Response(
* response=401,
* description="Token not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
* @OA\Property(property="message", type="string", example="Token not found")
* )
* )
*
* @OA\Response(
* response=404,
* description="Not found",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
* @OA\Property(property="message", type="string", example="Not found"),
* @OA\Property(
* property="data",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="string",
* example="field"
* )
* ),
* )
* )
*
* @OA\Response(
* response=429,
* description="Too many requests",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
* @OA\Property(property="message", type="string", example="Too many requests")
* )
* )
*
* @OA\Response(
* response=500,
* description="Internal Server Error",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
* @OA\Property(property="message", type="string", example="Internal Server Error")
* )
* )
*
* @OA\Parameter(
* name="id",
* in="path",
* description="Matrícula Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Matrículas")
* @Security(name="Bearer")
*
*/
public function deleteEnrollment(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$enrollmentId = $request->get('id');
$enrollment = $this->repository->findOneBy([
"id" => $enrollmentId,
"deleted" => EnrollmentEnum::ITEM_NO_DELETED
]);
if (!$enrollment) {
return $this->eadResponse(null, ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
try {
$this->repository->delete($enrollment, TrashEnum::ENROLLMENT, UserPermissionEnum::HIGH, false);
$this->userLogService->logDelete("enrollment", $enrollment->getId(), null, UserLogEnum::ORIGIN_CLIENT_API);
} catch (Exception $e) {
return $this->eadResponse(null, ErrorEnum::INTERNAL_ERROR, $e->getMessage());
}
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
}