<?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\Course;
use EADPlataforma\Entity\CourseTeam;
use EADPlataforma\Entity\Category;
use EADPlataforma\Entity\CourseCertificateTemplate;
use EADPlataforma\Entity\Lesson;
use EADPlataforma\Entity\LessonModule;
use EADPlataforma\Enum\CourseEnum;
use EADPlataforma\Enum\UserLogEnum;
use EADPlataforma\Enum\UserPermissionEnum;
use EADPlataforma\Enum\TrashEnum;
use EADPlataforma\Enum\ErrorEnum;
class CourseApiController extends AbstractApiController {
public function getEntityClass(){
return Course::class;
}
/**
* Listagem dos cursos do EAD.
*
* @Route("/api/1/course", methods={"GET"})
* @OA\Response(
* response=200,
* description="Retorna os cursos do EAD.",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="curso_id", type="integer", example=1, description="Id do curso cadastrado no EAD."),
* @OA\Property(property="categoria_id", type="integer", example=10, description="Id da categoria do curso."),
* @OA\Property(property="categoria_titulo", type="string", example="Categoria Exemplo", description="Título da categoria."),
* @OA\Property(property="curso_titulo", type="string", example="Curso Exemplo", description="Título do curso."),
* @OA\Property(property="data_lancamento", type="datetime", example="2020-01-01 00:00:01", description="Data de lançamento do Curso."),
* @OA\Property(property="carga_horaria", type="string", example="500", description="Carga horária do Curso."),
* @OA\Property(property="periodo_acesso", type="integer", example=360, description="Período de Acesso em número de dias."),
* @OA\Property(property="suporte", type="integer", example=10, description="Período de Suporte em número de dias."),
* @OA\Property(property="emitir_certificado", type="integer", example=1, description="Emitir ou não certificados. (0-Não / 1-Sim)"),
* @OA\Property(property="ordem_curso", type="integer", example=3, description="Ordem que o curso aparecerá na categoria."),
* @OA\Property(property="nome_professor", type="string", example="Professor(a) Exemplo", description="Nome do professor(a) cadastrado no EAD."),
* @OA\Property(property="foto_professor", type="string", example="foto.jpg", description="Imagem do professor(a) cadastrado no EAD."),
* @OA\Property(property="professor_id", type="integer", example=12, description="Id do professor(a) cadastrado no EAD."),
* @OA\Property(property="email_professor", type="string", example="professor(a)@email.com", description="E-mail do professor(a) cadastrado no EAD."),
* @OA\Property(property="status", type="integer", example=1, description="Status do curso. (0-Rascunho / 1-Publicado / 2-Grátis)"),
* @OA\Property(property="liberado", type="integer", example=1, description="Curso liberado gratuitamente aos alunos do EAD. (0-Não / 1-Sim)"),
* @OA\Property(property="foto", type="string", example="foto.jpg", description="Imagem do curso."),
* @OA\Property(property="cover", type="string", example="cover.jpg", description="Imagem de background da página curso."),
* @OA\Property(property="media_emitir", type="integer", example=6, description="Média a se atingir para gerar o certificado."),
* @OA\Property(property="certificado_template_id", type="integer", example=1, description="Id do template de certificado que será usado neste curso."),
* @OA\Property(property="total_aulas", type="integer", example=60, description="Número total de aulas cadastradas no curso."),
* @OA\Property(property="total_modulos", type="integer", example=4, description="Número total de módulos cadastradas 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="id",
* in="query",
* description="Curso Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="categoria",
* in="query",
* description="Categoria Id",
* @OA\Schema(type="integer")
* )
*
* @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="Cursos")
* @Security(name="Bearer")
*
*/
public function getCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$columns = [
"c.id AS curso_id",
"cc.id AS categoria_id",
"cc.category AS categoria_titulo",
"c.title AS titulo",
"c.dateRelease AS data_lancamento",
"c.workload AS carga_horaria",
"c.lifetimePeriod AS acesso_vitalicio",
"c.accessPeriod AS periodo_acesso",
"c.lifetimeSupport AS suporte_vitalicio",
"c.supportPeriod AS suporte",
"c.certificate AS emitir_certificado",
"c.order AS ordem_curso",
"u.name AS nome_professor",
"u.photo AS foto_professor",
"u.id AS professor_id",
"u.email AS professor_email",
"c.status",
"c.free AS liberado",
"c.photo AS foto",
"c.cover",
"c.certificateAverage AS media_emitir",
"ct.id AS certificado_template_id"
];
$userClass = User::class;
$categoryClass = Category::class;
$courseCertificate = CourseCertificateTemplate::class;
$joins = [
"{$userClass} AS u" => "u.id = c.user",
"{$categoryClass} AS cc" => "cc.id = c.category",
"{$courseCertificate} AS ct" => ["LEFT", "ct.id = c.courseCertificateTemplate"]
];
$courseId = (int)$request->get('id');
$categoryId = (int)$request->get('categoria');
$paginate = $request->get('paginate');
$limit = (int)$request->get('limit');
$offset = (int)$request->get('offset');
$filter = [
"c.deleted" => 0
];
if(empty($limit) || $limit > 1000){
$limit = 1000;
}
if(empty($offset)){
$offset = 0;
}
if($courseId > 0){
$filter["c.id"] = $courseId;
}
if($categoryId > 0){
$filter["c.category"] = $categoryId;
}
$order = ["c.id" => "ASC"];
$data = $this->repository->paginate(
"c",
null,
$columns,
$joins,
$filter,
$order,
$limit,
$offset
);
$clientDomain = "//{$this->eadDomain}/";
if(count($data['rows']) == 0){
return $this->eadResponse(null, ErrorEnum::NO_CONTENT, null);
}
foreach ($data['rows'] as $key => $value) {
$filterLesson = [
"course" => $data['rows'][$key]->curso_id,
"deleted" => CourseEnum::ITEM_NO_DELETED
];
$data['rows'][$key]->total_aulas = $this->em->getRepository(Lesson::class)->count(
$filterLesson
);
$filterLessonModule = [
"course" => $data['rows'][$key]->curso_id,
"deleted" => CourseEnum::ITEM_NO_DELETED
];
$data['rows'][$key]->total_modulos = $this->em->getRepository(LessonModule::class)->count(
$filterLessonModule
);
$data['rows'][$key]->foto_professor = $clientDomain."upload/profiles/".$data['rows'][$key]->foto_professor;
$data['rows'][$key]->foto = $clientDomain."upload/store/".$data['rows'][$key]->foto;
$data['rows'][$key]->cover = $clientDomain."upload/covers/".$data['rows'][$key]->cover;
}
if($paginate == CourseEnum::YES){
unset($data['searchText']);
return $this->json($data);
}
return $this->json($data['rows']);
}
/**
* Inserir um novo curso no EAD.
*
* @Route("/api/1/course", 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="ordem_curso", type="integer", example=4),
* @OA\Property(property="curso_titulo", type="string", example="Programação"),
* @OA\Property(property="emitir_certificado", type="integer", example=1),
* @OA\Property(property="media_emitir", type="integer", example=7),
* @OA\Property(property="data_lancamento", type="string", example="2021-12-01 00:00:00"),
* @OA\Property(property="foto", type="string", example="caminho.imagem.com"),
* @OA\Property(property="cover", type="string", example="caminho.imagem.com"),
* @OA\Property(property="suporte", type="integer", example=365),
* @OA\Property(property="carga_horaria", type="string", example="400:00"),
* @OA\Property(property="status", type="integer", example=1),
* @OA\Property(property="liberado", type="integer", example=1),
* @OA\Property(property="periodo_acesso", type="integer", example=365),
* @OA\Property(property="certificado_template_id", type="integer", example=1),
* @OA\Property(property="categoria_id", type="integer", example=1),
* @OA\Property(property="professor_id", type="integer", example=10),
* @OA\Property(property="nome_professor", type="string", example="Nome Professor(a)"),
* @OA\Property(property="foto_professor", type="string", example="caminho.imagem.com")
* )
* )
* )
*
* @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\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="categoria_id",
* description="Categoria Id",
* type="integer"
* ),
* @OA\Property(
* property="titulo",
* description="Título do curso",
* type="string(125)"
* ),
* @OA\Property(
* property="professor_id",
* description="Professor(a) Id",
* type="integer"
* ),
* @OA\Property(
* property="periodo_acesso",
* description="Período de Acesso em número de dias",
* type="integer"
* ),
* @OA\Property(
* property="periodo_suporte",
* description="Período de Suporte em número de dias",
* type="integer"
* ),
* @OA\Property(
* property="carga_horaria",
* description="Carga Horaria (000:00)",
* type="string"
* ),
* required={"categoria_id", "titulo", "professor_id", "periodo_acesso", "periodo_suporte", "carga_horaria"}
* )
* )
* )
*
* @OA\Tag(name="Cursos")
* @Security(name="Bearer")
*
*/
public function postCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$course = new Course();
$categoryId = $this->requestUtil->getField('categoria_id');
if($categoryId > 0){
$category = $this->em->getRepository(Category::class)->findOneBy([
"id" => $categoryId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if(empty($category)){
return $this->eadResponse(
[ 'categoria_id' ],
ErrorEnum::NOT_FOUND,
ErrorEnum::MESSAGE_NOT_FOUND
);
}
$this->requestUtil->setField('category', $category);
}
$userId = $this->requestUtil->getField('professor_id');
if($userId > 0){
$user = $this->em->getRepository(User::class)->findOneBy([
"id" => $userId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if(empty($user)){
return $this->eadResponse(
[ 'professor_id' ],
ErrorEnum::NOT_FOUND,
ErrorEnum::MESSAGE_NOT_FOUND
);
}
$this->requestUtil->setField('user', $user);
}
$title = $this->requestUtil->getField('titulo');
$this->requestUtil->setField('title', $title);
$accessPeriod = $this->requestUtil->getField('periodo_acesso');
$this->requestUtil->setField('accessPeriod', $accessPeriod);
$supportPeriod = $this->requestUtil->getField('periodo_suporte');
$this->requestUtil->setField('supportPeriod', $supportPeriod);
$workload = $this->requestUtil->getField('carga_horaria');
$this->requestUtil->setField('workload', $workload);
$course = $this->setAllFields($course);
//Define Course order
$order = $course->getOrder();
$course->setStatus(CourseEnum::DRAFT);
$lastOrder = $this->repository->count([
"deleted" => CourseEnum::ITEM_NO_DELETED
]) + 1;
if(empty($order) || ($order > $lastOrder)){
$course->setOrder($lastOrder);
$order = $lastOrder;
}
$errors = $this->validateEntity($course);
if($errors){
return $this->eadResponse(
$errors,
ErrorEnum::FIELD_EMPTY,
ErrorEnum::MESSAGE_EMPTY_FIELD
);
}
//Update all register to understand the new order
$this->repository->refreshOrder(null, $order);
$courseTeam = new CourseTeam();
$courseTeam->setCourse($course);
$courseTeam->setUser($course->getUser());
$this->em->persist($course);
$this->em->persist($courseTeam);
$this->em->flush();
$return = $course->toReturnApi();
$this->userLogService->logInsert(
"course",
$course->getId(),
$return,
UserLogEnum::ORIGIN_CLIENT_API
);
return $this->eadResponse($return, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Atualizar um curso do EAD.
*
* @Route("/api/1/course/{id}", methods={"PUT"}, requirements = { "id" = "\d+" })
* 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="ordem_curso", type="integer", example=4),
* @OA\Property(property="curso_titulo", type="string", example="Programação"),
* @OA\Property(property="emitir_certificado", type="integer", example=1),
* @OA\Property(property="media_emitir", type="integer", example=7),
* @OA\Property(property="data_lancamento", type="string", example="2021-12-01 00:00:00"),
* @OA\Property(property="foto", type="string", example="caminho.imagem.com"),
* @OA\Property(property="cover", type="string", example="caminho.imagem.com"),
* @OA\Property(property="suporte", type="integer", example=365),
* @OA\Property(property="carga_horaria", type="string", example="400:00"),
* @OA\Property(property="status", type="integer", example=1),
* @OA\Property(property="liberado", type="integer", example=1),
* @OA\Property(property="periodo_acesso", type="integer", example=365),
* @OA\Property(property="certificado_template_id", type="integer", example=1),
* @OA\Property(property="categoria_id", type="integer", example=1),
* @OA\Property(property="professor_id", type="integer", example=10),
* @OA\Property(property="nome_professor", type="string", example="Nome Professor(a)"),
* @OA\Property(property="foto_professor", type="string", example="caminho.imagem.com")
* )
* )
* )
*
* @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="Curso Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\RequestBody(
* required=false,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="categoria_id",
* description="Categoria Id",
* type="integer"
* ),
* @OA\Property(
* property="titulo",
* description="Título do curso",
* type="string(125)"
* ),
* @OA\Property(
* property="professor_id",
* description="Professor(a) Id",
* type="integer"
* ),
* @OA\Property(
* property="periodo_acesso",
* description="Período de Acesso em número de dias",
* type="integer"
* ),
* @OA\Property(
* property="periodo_suporte",
* description="Período de Suporte em número de dias",
* type="integer"
* ),
* @OA\Property(
* property="carga_horaria",
* description="Carga Horaria (000:00)",
* type="string"
* ),
* @OA\Property(
* property="status",
* description="0-Rascunho / 1-Publicado / 2-Restrito",
* type="integer"
* ),
* @OA\Property(
* property="liberado",
* description="Curso liberado gratuitamente aos alunos do EAD. (0-Não / 1-Sim)",
* type="integer"
* ),
* @OA\Property(
* property="emitir_certificado",
* description="0-Não / 1-Sim",
* type="integer"
* ),
* @OA\Property(
* property="ordem_curso",
* description="Ordem de exibição do curso",
* type="integer"
* ),
* @OA\Property(
* property="media_emitir",
* description="Média a se atingir para gerar o certificado",
* type="integer"
* ),
* @OA\Property(
* property="certificado_template_id",
* description="Id do template de certificado que será usado neste curso",
* type="integer"
* ),
* @OA\Property(
* property="lancamento",
* description="Data de lançamento",
* type="datetime"
* ),
* )
* )
* ),
*
* @OA\Tag(name="Cursos")
* @Security(name="Bearer")
*
*/
public function putCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$courseId = (int)$request->get('id');
$course = $this->repository->findOneBy([
"id" => $courseId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if (!$course) {
return $this->eadResponse(null, ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
if(!empty($this->requestUtil->issetField('certificado_template_id'))){
$courseCertificateTemplateId = (int)$this->requestUtil->getField(
'certificado_template_id'
);
$templateRepository = $this->em->getRepository(CourseCertificateTemplate::class);
$certificateTemplate = $templateRepository->findOneBy([
"id" => $courseCertificateTemplateId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if($certificateTemplate){
$course->setCourseCertificateTemplate($certificateTemplate);
}
}
if(!empty($this->requestUtil->issetField('professor_id'))){
$courseTeamId = (int)$this->requestUtil->getField('professor_id');
if($this->userPermissionUtil->isHigh($permission)){
$courseTeam = $this->em->getRepository(CourseTeam::class)->findOneBy([
"id" => $courseTeamId,
"course" => $course->getId(),
"deleted" => CourseTeamEnum::ITEM_NO_DELETED
]);
if($courseTeam){
$course->setUser($courseTeam->getUser());
}
}
}
if(!empty($this->requestUtil->issetField('categoria_id'))){
$categoryId = (int)$this->requestUtil->getField('categoria_id');
$category = $this->em->getRepository(Category::class)->findOneBy([
"id" => $categoryId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if($category){
$course->setCategory($category);
}
}
$courseOrder = $this->requestUtil->getField("ordem_curso");
if(is_numeric($courseOrder)){
$course->setOrder($courseOrder);
}
$order = $this->requestUtil->getField('ordem_curso');
$oldOrder = $course->getOrder();
if($order > 0){
if($order != $oldOrder){
$this->requestUtil->setField('order', $order);
}
}
$title = $this->requestUtil->getField("titulo");
if(!empty($title)){
$course->setTitle($title);
}
$accessPeriod = $this->requestUtil->getField("periodo_acesso");
if(is_numeric($accessPeriod)){
$course->setAccessPeriod($accessPeriod);
}
$supportPeriod = $this->requestUtil->getField("periodo_suporte");
if(is_numeric($supportPeriod)){
$course->setSupportPeriod($supportPeriod);
}
$workload = $this->requestUtil->getField('carga_horaria');
if(!empty($workload)){
$course->setWorkload($workload);
}
$oldStatus = $course->getStatus();
$status = $this->requestUtil->getField("status");
if(is_numeric($status)){
$course->setStatus($status);
}
$free = $this->requestUtil->getField("liberado");
if(is_numeric($free)){
$course->setFree($free);
}
$cerficate = $this->requestUtil->getField("emitir_certificado");
if(is_numeric($cerficate)){
$course->setCertificate($cerficate);
}
$certificateAverage = $this->requestUtil->getField("media_emitir");
if(is_numeric($certificateAverage)){
$course->setCertificateAverage($certificateAverage);
}
$dateRelease = $this->requestUtil->getField('lancamento');
if(!empty($dateRelease)){
$course->setDateRelease($dateRelease);
}
$lastOrder = $this->repository->count([ "deleted" => CourseEnum::ITEM_NO_DELETED ]);
$newOrder = $course->getOrder();
if(empty($newOrder) || $newOrder > $lastOrder){
$course->setOrder($lastOrder);
$newOrder = $lastOrder;
}
$errors = $this->validateEntity($course);
if($errors){
return $this->eadResponse(
$errors,
ErrorEnum::FIELD_EMPTY,
ErrorEnum::MESSAGE_EMPTY_FIELD
);
}
if(!$this->configuration->checkModuleIsAbleOnPlan('unlimitedCourseFunction')){
$publishCourses = $this->repository->count([
"deleted" => CourseEnum::ITEM_NO_DELETED,
"status" => CourseEnum::PUBLISHED
]);
if(
!empty($publishCourses) &&
$course->getStatus() == CourseEnum::PUBLISHED &&
$oldStatus != $course->getStatus()
){
return $this->eadResponse([ "status" ], ErrorEnum::FIELD_EMPTY);
}
}
if($oldOrder != $newOrder){
$this->repository->refreshOrder($oldOrder, $newOrder);
}
$this->em->flush();
$return = $course->toReturnApi();
$this->userLogService->logUpdate(
"course",
$course->getId(),
$return,
UserLogEnum::ORIGIN_CLIENT_API
);
if(!empty($return['foto_professor'])){
$return['foto_professor'] = "//{$this->eadDomain}{$return['foto_professor']}";
}
if(!empty($return['foto'])){
$return['foto'] = "//{$this->eadDomain}{$return['foto']}";
}
if(!empty($return['cover'])){
$return['cover'] = "//{$this->eadDomain}{$return['cover']}";
}
return $this->eadResponse($return, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Excluir um curso do EAD.
*
* @Route("/api/1/course/{id}", methods={"DELETE"}, requirements = { "id" = "\d+" })
* @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="Curso Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Cursos")
* @Security(name="Bearer")
*
*/
public function deleteCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$courseId = $request->get('id');
$course = $this->repository->findOneBy([
"id" => $courseId,
"deleted" => CourseEnum::ITEM_NO_DELETED
]);
if (!$course) {
return $this->eadResponse(null, ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$this->repository->delete($course, TrashEnum::COURSE, UserPermissionEnum::HIGH, false);
$this->userLogService->logDelete(
"course",
$course->getId(),
null,
UserLogEnum::ORIGIN_CLIENT_API
);
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
}