src/Controller/Api/v1/CourseApiController.php line 782

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Api\v1;
  3. use OpenApi\Annotations as OA;
  4. use Nelmio\ApiDocBundle\Annotation\Model;
  5. use Nelmio\ApiDocBundle\Annotation\Security;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use EADPlataforma\Controller\Api\AbstractApiController;
  9. use EADPlataforma\Entity\User;
  10. use EADPlataforma\Entity\Course;
  11. use EADPlataforma\Entity\CourseTeam;
  12. use EADPlataforma\Entity\Category;
  13. use EADPlataforma\Entity\CourseCertificateTemplate;
  14. use EADPlataforma\Entity\Lesson;
  15. use EADPlataforma\Entity\LessonModule;
  16. use EADPlataforma\Enum\CourseEnum;
  17. use EADPlataforma\Enum\UserLogEnum;
  18. use EADPlataforma\Enum\UserPermissionEnum;
  19. use EADPlataforma\Enum\TrashEnum;
  20. use EADPlataforma\Enum\ErrorEnum;
  21. class CourseApiController extends AbstractApiController {
  22.     public function getEntityClass(){
  23.         return Course::class;
  24.     }
  25.     /**
  26.      * Listagem dos cursos do EAD.
  27.      *
  28.      * @Route("/api/1/course", methods={"GET"})
  29.      * @OA\Response(
  30.      *     response=200,
  31.      *     description="Retorna os cursos do EAD.",
  32.      *     @OA\JsonContent(
  33.      *         type="object",
  34.      *         @OA\Property(property="curso_id", type="integer", example=1, description="Id do curso cadastrado no EAD."),
  35.      *         @OA\Property(property="categoria_id", type="integer", example=10, description="Id da categoria do curso."),
  36.      *         @OA\Property(property="categoria_titulo", type="string", example="Categoria Exemplo", description="Título da categoria."),
  37.      *         @OA\Property(property="curso_titulo", type="string", example="Curso Exemplo", description="Título do curso."),
  38.      *         @OA\Property(property="data_lancamento", type="datetime", example="2020-01-01 00:00:01", description="Data de lançamento do Curso."),
  39.      *         @OA\Property(property="carga_horaria", type="string", example="500", description="Carga horária do Curso."),
  40.      *         @OA\Property(property="periodo_acesso", type="integer", example=360, description="Período de Acesso em número de dias."),
  41.      *         @OA\Property(property="suporte", type="integer", example=10, description="Período de Suporte em número de dias."),
  42.      *         @OA\Property(property="emitir_certificado", type="integer", example=1, description="Emitir ou não certificados. (0-Não / 1-Sim)"),
  43.      *         @OA\Property(property="ordem_curso", type="integer", example=3, description="Ordem que o curso aparecerá na categoria."),
  44.      *         @OA\Property(property="nome_professor", type="string", example="Professor(a) Exemplo", description="Nome do professor(a) cadastrado no EAD."),
  45.      *         @OA\Property(property="foto_professor", type="string", example="foto.jpg", description="Imagem do professor(a) cadastrado no EAD."),
  46.      *         @OA\Property(property="professor_id", type="integer", example=12, description="Id do professor(a) cadastrado no EAD."),
  47.      *         @OA\Property(property="email_professor", type="string", example="professor(a)@email.com", description="E-mail do professor(a) cadastrado no EAD."),
  48.      *         @OA\Property(property="status", type="integer", example=1, description="Status do curso. (0-Rascunho / 1-Publicado / 2-Grátis)"),
  49.      *         @OA\Property(property="liberado", type="integer", example=1, description="Curso liberado gratuitamente aos alunos do EAD. (0-Não / 1-Sim)"),
  50.      *         @OA\Property(property="foto", type="string", example="foto.jpg", description="Imagem do curso."),         
  51.      *         @OA\Property(property="cover", type="string", example="cover.jpg", description="Imagem de background da página curso."), 
  52.      *         @OA\Property(property="media_emitir", type="integer", example=6, description="Média a se atingir para gerar o certificado."),
  53.      *         @OA\Property(property="certificado_template_id", type="integer", example=1, description="Id do template de certificado que será usado neste curso."),
  54.      *         @OA\Property(property="total_aulas", type="integer", example=60, description="Número total de aulas cadastradas no curso."),
  55.      *         @OA\Property(property="total_modulos", type="integer", example=4, description="Número total de módulos cadastradas no curso.")
  56.      *     )
  57.      * )
  58.      * 
  59.      * @OA\Response(
  60.      *     response=204,
  61.      *     description="No content"
  62.      * )
  63.      * 
  64.      * @OA\Response(
  65.      *     response=401,
  66.      *     description="Token not found",
  67.      *     @OA\JsonContent(
  68.      *         type="object",
  69.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  70.      *         @OA\Property(property="message", type="string", example="Token not found")
  71.      *     )
  72.      * )
  73.      * 
  74.      * @OA\Response(
  75.      *     response=429,
  76.      *     description="Too many requests",
  77.      *     @OA\JsonContent(
  78.      *         type="object",
  79.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  80.      *         @OA\Property(property="message", type="string", example="Too many requests")
  81.      *     )
  82.      * )
  83.      * 
  84.      * @OA\Response(
  85.      *     response=500,
  86.      *     description="Internal Server Error",
  87.      *     @OA\JsonContent(
  88.      *         type="object",
  89.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  90.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  91.      *     )
  92.      * )
  93.      * 
  94.      * @OA\Parameter(
  95.      *     name="id",
  96.      *     in="query",
  97.      *     description="Curso Id",
  98.      *     @OA\Schema(type="integer")
  99.      * )
  100.      * 
  101.      * @OA\Parameter(
  102.      *     name="categoria",
  103.      *     in="query",
  104.      *     description="Categoria Id",
  105.      *     @OA\Schema(type="integer")
  106.      * )
  107.      * 
  108.      * @OA\Parameter(
  109.      *     name="paginate",
  110.      *     in="query",
  111.      *     description="Informaçoes para paginação",
  112.      *     @OA\Schema(type="integer")
  113.      * )
  114.      * 
  115.      * @OA\Parameter(
  116.      *      name="limit",
  117.      *      in="query",
  118.      *      description="Número máximo de dados retornados por página, valor padrão 1000",
  119.      *     @OA\Schema(type="integer")
  120.      * )
  121.      * 
  122.      * @OA\Parameter(
  123.      *      name="offset",
  124.      *      in="query",
  125.      *      description="Indica o início da leitura, caso não informado valor padrão será 0",
  126.      *     @OA\Schema(type="integer")
  127.      * )
  128.      * 
  129.      * @OA\Tag(name="Cursos")
  130.      * @Security(name="Bearer")
  131.      * 
  132.      */
  133.     public function getCourse(Request $request)
  134.     {
  135.        
  136.         $this->requestUtil->setRequest($request)->setData();
  137.         $columns = [
  138.             "c.id AS curso_id"
  139.             "cc.id AS categoria_id",
  140.             "cc.category AS categoria_titulo",
  141.             "c.title AS titulo",
  142.             "c.dateRelease AS data_lancamento",
  143.             "c.workload AS carga_horaria",
  144.             "c.lifetimePeriod AS acesso_vitalicio",
  145.             "c.accessPeriod AS periodo_acesso",
  146.             "c.lifetimeSupport AS suporte_vitalicio",
  147.             "c.supportPeriod AS suporte",
  148.             "c.certificate AS emitir_certificado",
  149.             "c.order AS ordem_curso",
  150.             "u.name AS nome_professor"
  151.             "u.photo AS foto_professor",
  152.             "u.id AS professor_id",
  153.             "u.email AS professor_email",
  154.             "c.status",
  155.             "c.free AS liberado",
  156.             "c.photo AS foto",
  157.             "c.cover",
  158.             "c.certificateAverage AS media_emitir",
  159.             "ct.id AS certificado_template_id"
  160.         ];
  161.         $userClass User::class;
  162.         $categoryClass Category::class;
  163.         $courseCertificate CourseCertificateTemplate::class;
  164.         $joins = [
  165.             "{$userClass} AS u" => "u.id = c.user",
  166.             "{$categoryClass} AS cc" => "cc.id = c.category",
  167.             "{$courseCertificate} AS ct" => ["LEFT""ct.id = c.courseCertificateTemplate"]
  168.         ];
  169.         $courseId = (int)$request->get('id');
  170.         $categoryId = (int)$request->get('categoria');
  171.         $paginate $request->get('paginate');
  172.         $limit = (int)$request->get('limit');
  173.         $offset = (int)$request->get('offset');
  174.         $filter = [
  175.             "c.deleted" => 0
  176.         ];
  177.         if(empty($limit) || $limit 1000){
  178.             $limit 1000;
  179.         }
  180.         if(empty($offset)){
  181.             $offset 0;
  182.         }
  183.         if($courseId 0){
  184.             $filter["c.id"] = $courseId;
  185.         }
  186.         if($categoryId 0){
  187.             $filter["c.category"] = $categoryId;
  188.         }
  189.         $order = ["c.id" => "ASC"];
  190.         $data $this->repository->paginate(
  191.             "c"
  192.             null
  193.             $columns
  194.             $joins
  195.             $filter
  196.             $order
  197.             $limit
  198.             $offset
  199.         );
  200.         $clientDomain "//{$this->eadDomain}/";
  201.         if(count($data['rows']) == 0){
  202.             return $this->eadResponse(nullErrorEnum::NO_CONTENTnull);
  203.         }
  204.         foreach ($data['rows'] as $key => $value) {
  205.               
  206.             $filterLesson = [ 
  207.                 "course" => $data['rows'][$key]->curso_id
  208.                 "deleted" => CourseEnum::ITEM_NO_DELETED 
  209.             ];
  210.             $data['rows'][$key]->total_aulas $this->em->getRepository(Lesson::class)->count(
  211.                 $filterLesson
  212.             );
  213.             $filterLessonModule = [ 
  214.                 "course" => $data['rows'][$key]->curso_id
  215.                 "deleted" => CourseEnum::ITEM_NO_DELETED 
  216.             ];
  217.             $data['rows'][$key]->total_modulos $this->em->getRepository(LessonModule::class)->count(
  218.                 $filterLessonModule
  219.             );
  220.             $data['rows'][$key]->foto_professor $clientDomain."upload/profiles/".$data['rows'][$key]->foto_professor;
  221.             $data['rows'][$key]->foto $clientDomain."upload/store/".$data['rows'][$key]->foto;
  222.             $data['rows'][$key]->cover $clientDomain."upload/covers/".$data['rows'][$key]->cover;
  223.         }
  224.         if($paginate == CourseEnum::YES){
  225.             unset($data['searchText']);
  226.             return $this->json($data);
  227.         }
  228.         return $this->json($data['rows']);
  229.     }
  230.     /**
  231.      * Inserir um novo curso no EAD.
  232.      *
  233.      * @Route("/api/1/course", methods={"POST"})
  234.      * consumes={"application/json"}
  235.      * produces={"application/json"}
  236.      * 
  237.      * @OA\Response(
  238.      *     response=200,
  239.      *     description="Success",
  240.      *     @OA\JsonContent(
  241.      *         type="object",
  242.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  243.      *         @OA\Property(property="message", type="string", example="Success"),
  244.      *         @OA\Property(
  245.      *              property="data", 
  246.      *              type="object", 
  247.      *              @OA\Property(property="id", type="integer", example=1), 
  248.      *              @OA\Property(property="ordem_curso", type="integer", example=4),
  249.      *              @OA\Property(property="curso_titulo", type="string", example="Programação"),
  250.      *              @OA\Property(property="emitir_certificado", type="integer", example=1),
  251.      *              @OA\Property(property="media_emitir", type="integer", example=7),
  252.      *              @OA\Property(property="data_lancamento", type="string", example="2021-12-01 00:00:00"),
  253.      *              @OA\Property(property="foto", type="string", example="caminho.imagem.com"),
  254.      *              @OA\Property(property="cover", type="string", example="caminho.imagem.com"),
  255.      *              @OA\Property(property="suporte", type="integer", example=365),
  256.      *              @OA\Property(property="carga_horaria", type="string", example="400:00"),
  257.      *              @OA\Property(property="status", type="integer", example=1),
  258.      *              @OA\Property(property="liberado", type="integer", example=1),
  259.      *              @OA\Property(property="periodo_acesso", type="integer", example=365),
  260.      *              @OA\Property(property="certificado_template_id", type="integer", example=1),
  261.      *              @OA\Property(property="categoria_id", type="integer", example=1),
  262.      *              @OA\Property(property="professor_id", type="integer", example=10),
  263.      *              @OA\Property(property="nome_professor", type="string", example="Nome Professor(a)"),
  264.      *              @OA\Property(property="foto_professor", type="string", example="caminho.imagem.com")
  265.      *         )  
  266.      *     )
  267.      * )
  268.      * 
  269.      * @OA\Response(
  270.      *     response=401,
  271.      *     description="Token not found",
  272.      *     @OA\JsonContent(
  273.      *         type="object",
  274.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  275.      *         @OA\Property(property="message", type="string", example="Token not found")
  276.      *     )
  277.      * )
  278.      * 
  279.      * @OA\Response(
  280.      *     response=404,
  281.      *     description="Not found",
  282.      *     @OA\JsonContent(
  283.      *         type="object",
  284.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  285.      *         @OA\Property(property="message", type="string", example="Not found"),
  286.      *         @OA\Property(
  287.      *              property="data", 
  288.      *              type="array", 
  289.      *              collectionFormat="multi", 
  290.      *              @OA\Items(
  291.      *                  type="string",
  292.      *                  example="field"
  293.      *              )
  294.      *         ),
  295.      *     )
  296.      * )
  297.      * 
  298.      * @OA\Response(
  299.      *     response=406,
  300.      *     description="Empty Fields",
  301.      *     @OA\JsonContent(
  302.      *         type="object",
  303.      *         @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
  304.      *         @OA\Property(property="message", type="string", example="Error"),
  305.      *         @OA\Property(
  306.      *              property="data", 
  307.      *              type="array", 
  308.      *              collectionFormat="multi", 
  309.      *              @OA\Items(
  310.      *                  type="string",
  311.      *                  example="field"
  312.      *              )
  313.      *         ),
  314.      *     )
  315.      * )
  316.      * 
  317.      * @OA\Response(
  318.      *     response=429,
  319.      *     description="Too many requests",
  320.      *     @OA\JsonContent(
  321.      *         type="object",
  322.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  323.      *         @OA\Property(property="message", type="string", example="Too many requests")
  324.      *     )
  325.      * )
  326.      * 
  327.      * @OA\Response(
  328.      *     response=500,
  329.      *     description="Internal Server Error",
  330.      *     @OA\JsonContent(
  331.      *         type="object",
  332.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  333.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  334.      *     )
  335.      * )
  336.      * 
  337.      * @OA\RequestBody(
  338.      *      required=true,
  339.      *      @OA\MediaType(
  340.      *          mediaType="multipart/form-data",
  341.      *          @OA\Schema(
  342.      *              type="object",
  343.      *              @OA\Property(
  344.      *                  property="categoria_id",
  345.      *                  description="Categoria Id",
  346.      *                  type="integer"
  347.      *              ),
  348.      *              @OA\Property(
  349.      *                  property="titulo",
  350.      *                  description="Título do curso",
  351.      *                  type="string(125)"
  352.      *              ),
  353.      *              @OA\Property(
  354.      *                  property="professor_id",
  355.      *                  description="Professor(a) Id",
  356.      *                  type="integer"
  357.      *              ),
  358.      *              @OA\Property(
  359.      *                  property="periodo_acesso",
  360.      *                  description="Período de Acesso em número de dias",
  361.      *                  type="integer"
  362.      *              ),
  363.      *              @OA\Property(
  364.      *                  property="periodo_suporte",
  365.      *                  description="Período de Suporte em número de dias",
  366.      *                  type="integer"
  367.      *              ),
  368.      *              @OA\Property(
  369.      *                  property="carga_horaria",
  370.      *                  description="Carga Horaria (000:00)",
  371.      *                  type="string"
  372.      *              ),
  373.      *              required={"categoria_id", "titulo", "professor_id", "periodo_acesso", "periodo_suporte", "carga_horaria"}
  374.      *          )
  375.      *      )
  376.      * )
  377.      * 
  378.      * @OA\Tag(name="Cursos")
  379.      * @Security(name="Bearer")
  380.      * 
  381.      */
  382.     public function postCourse(Request $request)
  383.     {
  384.         $this->requestUtil->setRequest($request)->setData();
  385.         $course = new Course();
  386.         $categoryId $this->requestUtil->getField('categoria_id');
  387.         if($categoryId 0){
  388.             $category $this->em->getRepository(Category::class)->findOneBy([
  389.                 "id" => $categoryId,
  390.                 "deleted" => CourseEnum::ITEM_NO_DELETED
  391.             ]);
  392.             if(empty($category)){
  393.                 return $this->eadResponse(
  394.                     [ 'categoria_id' ], 
  395.                     ErrorEnum::NOT_FOUND
  396.                     ErrorEnum::MESSAGE_NOT_FOUND
  397.                 );
  398.             }
  399.             $this->requestUtil->setField('category'$category);
  400.         }
  401.         $userId $this->requestUtil->getField('professor_id');
  402.         if($userId 0){
  403.             $user $this->em->getRepository(User::class)->findOneBy([
  404.                 "id" => $userId,
  405.                 "deleted" => CourseEnum::ITEM_NO_DELETED
  406.             ]);
  407.             if(empty($user)){
  408.                 return $this->eadResponse(
  409.                     [ 'professor_id' ], 
  410.                     ErrorEnum::NOT_FOUND
  411.                     ErrorEnum::MESSAGE_NOT_FOUND
  412.                 );
  413.             }
  414.             $this->requestUtil->setField('user'$user);
  415.         }
  416.         $title $this->requestUtil->getField('titulo');
  417.         $this->requestUtil->setField('title'$title);
  418.         
  419.         $accessPeriod $this->requestUtil->getField('periodo_acesso');
  420.         $this->requestUtil->setField('accessPeriod'$accessPeriod);
  421.         $supportPeriod $this->requestUtil->getField('periodo_suporte');
  422.         $this->requestUtil->setField('supportPeriod'$supportPeriod);
  423.         $workload $this->requestUtil->getField('carga_horaria');
  424.         $this->requestUtil->setField('workload'$workload);
  425.         
  426.         $course $this->setAllFields($course);
  427.         //Define Course order 
  428.         $order $course->getOrder();
  429.         $course->setStatus(CourseEnum::DRAFT);
  430.         $lastOrder $this->repository->count([ 
  431.             "deleted" => CourseEnum::ITEM_NO_DELETED 
  432.         ]) + 1;
  433.                 
  434.         if(empty($order) || ($order $lastOrder)){
  435.             $course->setOrder($lastOrder);
  436.             $order $lastOrder;
  437.         }
  438.         $errors $this->validateEntity($course);
  439.         
  440.         if($errors){
  441.             return $this->eadResponse(
  442.                 $errors
  443.                 ErrorEnum::FIELD_EMPTY
  444.                 ErrorEnum::MESSAGE_EMPTY_FIELD
  445.             );
  446.         }
  447.         //Update all register to understand the new order
  448.         $this->repository->refreshOrder(null$order);
  449.         $courseTeam = new CourseTeam();
  450.         $courseTeam->setCourse($course);
  451.         $courseTeam->setUser($course->getUser());
  452.         $this->em->persist($course);
  453.         $this->em->persist($courseTeam);
  454.         $this->em->flush();
  455.         $return $course->toReturnApi();
  456.         $this->userLogService->logInsert(
  457.             "course"
  458.             $course->getId(), 
  459.             $return
  460.             UserLogEnum::ORIGIN_CLIENT_API
  461.         );
  462.         return $this->eadResponse($returnErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  463.     }
  464.     /**
  465.      * Atualizar um curso do EAD.
  466.      *
  467.      * @Route("/api/1/course/{id}", methods={"PUT"}, requirements  = { "id" = "\d+" })
  468.      * consumes={"application/json"}
  469.      * produces={"application/json"}
  470.      * 
  471.      * @OA\Response(
  472.      *     response=200,
  473.      *     description="Success",
  474.      *     @OA\JsonContent(
  475.      *         type="object",
  476.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  477.      *         @OA\Property(property="message", type="string", example="Success"),
  478.      *         @OA\Property(
  479.      *              property="data", 
  480.      *              type="object", 
  481.      *              @OA\Property(property="id", type="integer", example=1), 
  482.      *              @OA\Property(property="ordem_curso", type="integer", example=4),
  483.      *              @OA\Property(property="curso_titulo", type="string", example="Programação"),
  484.      *              @OA\Property(property="emitir_certificado", type="integer", example=1),
  485.      *              @OA\Property(property="media_emitir", type="integer", example=7),
  486.      *              @OA\Property(property="data_lancamento", type="string", example="2021-12-01 00:00:00"),
  487.      *              @OA\Property(property="foto", type="string", example="caminho.imagem.com"),
  488.      *              @OA\Property(property="cover", type="string", example="caminho.imagem.com"),
  489.      *              @OA\Property(property="suporte", type="integer", example=365),
  490.      *              @OA\Property(property="carga_horaria", type="string", example="400:00"),
  491.      *              @OA\Property(property="status", type="integer", example=1),
  492.      *              @OA\Property(property="liberado", type="integer", example=1),
  493.      *              @OA\Property(property="periodo_acesso", type="integer", example=365),
  494.      *              @OA\Property(property="certificado_template_id", type="integer", example=1),
  495.      *              @OA\Property(property="categoria_id", type="integer", example=1),
  496.      *              @OA\Property(property="professor_id", type="integer", example=10),
  497.      *              @OA\Property(property="nome_professor", type="string", example="Nome Professor(a)"),
  498.      *              @OA\Property(property="foto_professor", type="string", example="caminho.imagem.com")
  499.      *         )  
  500.      *     )
  501.      * )
  502.      * 
  503.      * @OA\Response(
  504.      *     response=401,
  505.      *     description="Token not found",
  506.      *     @OA\JsonContent(
  507.      *         type="object",
  508.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  509.      *         @OA\Property(property="message", type="string", example="Token not found")
  510.      *     )
  511.      * )
  512.      * 
  513.      * @OA\Response(
  514.      *     response=404,
  515.      *     description="Not found",
  516.      *     @OA\JsonContent(
  517.      *         type="object",
  518.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  519.      *         @OA\Property(property="message", type="string", example="Not found"),
  520.      *         @OA\Property(
  521.      *              property="data", 
  522.      *              type="array", 
  523.      *              collectionFormat="multi", 
  524.      *              @OA\Items(
  525.      *                  type="string",
  526.      *                  example="field"
  527.      *              )
  528.      *         ),
  529.      *     )
  530.      * )
  531.      * 
  532.      * @OA\Response(
  533.      *     response=406,
  534.      *     description="Empty Fields",
  535.      *     @OA\JsonContent(
  536.      *         type="object",
  537.      *         @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
  538.      *         @OA\Property(property="message", type="string", example="Error"),
  539.      *         @OA\Property(
  540.      *              property="data", 
  541.      *              type="array", 
  542.      *              collectionFormat="multi", 
  543.      *              @OA\Items(
  544.      *                  type="string",
  545.      *                  example="field"
  546.      *              )
  547.      *         ),
  548.      *     )
  549.      * )
  550.      * 
  551.      * @OA\Response(
  552.      *     response=429,
  553.      *     description="Too many requests",
  554.      *     @OA\JsonContent(
  555.      *         type="object",
  556.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  557.      *         @OA\Property(property="message", type="string", example="Too many requests")
  558.      *     )
  559.      * )
  560.      * 
  561.      * @OA\Response(
  562.      *     response=500,
  563.      *     description="Internal Server Error",
  564.      *     @OA\JsonContent(
  565.      *         type="object",
  566.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  567.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  568.      *     )
  569.      * )
  570.      * 
  571.      * @OA\Parameter(
  572.      *     name="id",
  573.      *     in="path",
  574.      *     description="Curso Id",
  575.      *     required=true,
  576.      *     @OA\Schema(type="integer")
  577.      * )
  578.      * 
  579.      * @OA\RequestBody(
  580.      *      required=false,
  581.      *      @OA\MediaType(
  582.      *          mediaType="multipart/form-data",
  583.      *          @OA\Schema(
  584.      *              type="object",
  585.      *              @OA\Property(
  586.      *                  property="categoria_id",
  587.      *                  description="Categoria Id",
  588.      *                  type="integer"
  589.      *              ),
  590.      *              @OA\Property(
  591.      *                  property="titulo",
  592.      *                  description="Título do curso",
  593.      *                  type="string(125)"
  594.      *              ),
  595.      *              @OA\Property(
  596.      *                  property="professor_id",
  597.      *                  description="Professor(a) Id",
  598.      *                  type="integer"
  599.      *              ),
  600.      *             @OA\Property(
  601.      *                  property="periodo_acesso",
  602.      *                  description="Período de Acesso em número de dias",
  603.      *                  type="integer"
  604.      *              ),
  605.      *             @OA\Property(
  606.      *                  property="periodo_suporte",
  607.      *                  description="Período de Suporte em número de dias",
  608.      *                  type="integer"
  609.      *              ),
  610.      *             @OA\Property(
  611.      *                  property="carga_horaria",
  612.      *                  description="Carga Horaria (000:00)",
  613.      *                  type="string"
  614.      *              ),
  615.      *             @OA\Property(
  616.      *                  property="status",
  617.      *                  description="0-Rascunho / 1-Publicado / 2-Restrito",
  618.      *                  type="integer"
  619.      *              ),
  620.      *             @OA\Property(
  621.      *                  property="liberado",
  622.      *                  description="Curso liberado gratuitamente aos alunos do EAD. (0-Não / 1-Sim)",
  623.      *                  type="integer"
  624.      *              ),
  625.      *             @OA\Property(
  626.      *                  property="emitir_certificado",
  627.      *                  description="0-Não / 1-Sim",
  628.      *                  type="integer"
  629.      *              ),
  630.      *             @OA\Property(
  631.      *                  property="ordem_curso",
  632.      *                  description="Ordem de exibição do curso",
  633.      *                  type="integer"
  634.      *              ),
  635.      *             @OA\Property(
  636.      *                  property="media_emitir",
  637.      *                  description="Média a se atingir para gerar o certificado",
  638.      *                  type="integer"
  639.      *              ),
  640.      *              @OA\Property(
  641.      *                  property="certificado_template_id",
  642.      *                  description="Id do template de certificado que será usado neste curso",
  643.      *                  type="integer"
  644.      *              ),
  645.      *              @OA\Property(
  646.      *                  property="lancamento",
  647.      *                  description="Data de lançamento",
  648.      *                  type="datetime"
  649.      *              ),
  650.      *           )
  651.      *       )
  652.      *   ),
  653.      *
  654.      * @OA\Tag(name="Cursos")
  655.      * @Security(name="Bearer")
  656.      * 
  657.      */
  658.     public function putCourse(Request $request)
  659.     {
  660.         $this->requestUtil->setRequest($request)->setData();
  661.     
  662.         $courseId = (int)$request->get('id');
  663.         $course $this->repository->findOneBy([
  664.             "id" => $courseId,
  665.             "deleted" => CourseEnum::ITEM_NO_DELETED
  666.         ]);
  667.         if (!$course) {
  668.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  669.         }
  670.         if(!empty($this->requestUtil->issetField('certificado_template_id'))){
  671.             $courseCertificateTemplateId = (int)$this->requestUtil->getField(
  672.                 'certificado_template_id'
  673.             );
  674.             $templateRepository $this->em->getRepository(CourseCertificateTemplate::class);
  675.             $certificateTemplate $templateRepository->findOneBy([
  676.                 "id" => $courseCertificateTemplateId,
  677.                 "deleted" => CourseEnum::ITEM_NO_DELETED
  678.             ]);
  679.             
  680.             if($certificateTemplate){
  681.                 $course->setCourseCertificateTemplate($certificateTemplate);
  682.             }
  683.         }
  684.         if(!empty($this->requestUtil->issetField('professor_id'))){
  685.             $courseTeamId = (int)$this->requestUtil->getField('professor_id');
  686.             if($this->userPermissionUtil->isHigh($permission)){
  687.                 $courseTeam $this->em->getRepository(CourseTeam::class)->findOneBy([
  688.                     "id" => $courseTeamId,
  689.                     "course" => $course->getId(),
  690.                     "deleted" => CourseTeamEnum::ITEM_NO_DELETED
  691.                 ]);
  692.                 
  693.                 if($courseTeam){
  694.                     $course->setUser($courseTeam->getUser());
  695.                 }
  696.             }
  697.         }
  698.         if(!empty($this->requestUtil->issetField('categoria_id'))){
  699.             $categoryId = (int)$this->requestUtil->getField('categoria_id');
  700.             $category $this->em->getRepository(Category::class)->findOneBy([
  701.                 "id" => $categoryId,
  702.                 "deleted" => CourseEnum::ITEM_NO_DELETED
  703.             ]);
  704.             
  705.             if($category){
  706.                 $course->setCategory($category);
  707.             }
  708.         }
  709.         $courseOrder $this->requestUtil->getField("ordem_curso");
  710.         if(is_numeric($courseOrder)){
  711.             $course->setOrder($courseOrder);
  712.         }
  713.         $order $this->requestUtil->getField('ordem_curso');
  714.         $oldOrder $course->getOrder();
  715.         if($order 0){
  716.             if($order != $oldOrder){
  717.                 $this->requestUtil->setField('order'$order);
  718.             }
  719.         }
  720.         $title $this->requestUtil->getField("titulo");
  721.         if(!empty($title)){
  722.             $course->setTitle($title);
  723.         }
  724.         $accessPeriod $this->requestUtil->getField("periodo_acesso");
  725.         if(is_numeric($accessPeriod)){
  726.             $course->setAccessPeriod($accessPeriod);
  727.         }
  728.         $supportPeriod $this->requestUtil->getField("periodo_suporte");
  729.         if(is_numeric($supportPeriod)){
  730.             $course->setSupportPeriod($supportPeriod);
  731.         }
  732.         $workload $this->requestUtil->getField('carga_horaria');
  733.         if(!empty($workload)){
  734.             $course->setWorkload($workload);
  735.         }
  736.         $oldStatus $course->getStatus();
  737.         $status $this->requestUtil->getField("status");
  738.         if(is_numeric($status)){
  739.             $course->setStatus($status);
  740.         }
  741.         $free $this->requestUtil->getField("liberado");
  742.         if(is_numeric($free)){
  743.             $course->setFree($free);
  744.         }
  745.         $cerficate $this->requestUtil->getField("emitir_certificado");
  746.         if(is_numeric($cerficate)){
  747.             $course->setCertificate($cerficate);
  748.         }
  749.         $certificateAverage $this->requestUtil->getField("media_emitir");
  750.         if(is_numeric($certificateAverage)){
  751.             $course->setCertificateAverage($certificateAverage);
  752.         }
  753.         $dateRelease $this->requestUtil->getField('lancamento');
  754.         if(!empty($dateRelease)){
  755.             $course->setDateRelease($dateRelease);
  756.         }
  757.         $lastOrder $this->repository->count([ "deleted" => CourseEnum::ITEM_NO_DELETED ]);
  758.         $newOrder $course->getOrder();
  759.         
  760.         if(empty($newOrder) || $newOrder $lastOrder){
  761.             $course->setOrder($lastOrder);
  762.             $newOrder $lastOrder;
  763.         }
  764.         $errors $this->validateEntity($course);
  765.         if($errors){
  766.             return $this->eadResponse(
  767.                 $errors
  768.                 ErrorEnum::FIELD_EMPTY
  769.                 ErrorEnum::MESSAGE_EMPTY_FIELD
  770.             );
  771.         }
  772.         if(!$this->configuration->checkModuleIsAbleOnPlan('unlimitedCourseFunction')){
  773.             $publishCourses $this->repository->count([
  774.                 "deleted" => CourseEnum::ITEM_NO_DELETED,
  775.                 "status" => CourseEnum::PUBLISHED
  776.             ]);
  777.             if(
  778.                 !empty($publishCourses) && 
  779.                 $course->getStatus() == CourseEnum::PUBLISHED &&
  780.                 $oldStatus != $course->getStatus()
  781.             ){
  782.                 return $this->eadResponse([ "status" ], ErrorEnum::FIELD_EMPTY);
  783.             }
  784.         }
  785.         if($oldOrder != $newOrder){
  786.             $this->repository->refreshOrder($oldOrder$newOrder);
  787.         }
  788.         $this->em->flush();
  789.         $return $course->toReturnApi();
  790.         $this->userLogService->logUpdate(
  791.             "course"
  792.             $course->getId(), 
  793.             $return
  794.             UserLogEnum::ORIGIN_CLIENT_API
  795.         );
  796.         if(!empty($return['foto_professor'])){
  797.             $return['foto_professor'] = "//{$this->eadDomain}{$return['foto_professor']}";
  798.         }
  799.         if(!empty($return['foto'])){
  800.             $return['foto'] = "//{$this->eadDomain}{$return['foto']}";
  801.         }
  802.         if(!empty($return['cover'])){
  803.             $return['cover'] = "//{$this->eadDomain}{$return['cover']}";
  804.         }
  805.         return $this->eadResponse($returnErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  806.     }
  807.     /**
  808.      * Excluir um curso do EAD.
  809.      *
  810.      * @Route("/api/1/course/{id}", methods={"DELETE"}, requirements = { "id" = "\d+" })
  811.      * @OA\Response(
  812.      *     response=200,
  813.      *     description="Success",
  814.      *     @OA\JsonContent(
  815.      *         type="object",
  816.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  817.      *         @OA\Property(property="message", type="string", example="Success"),
  818.      *         @OA\Property(property="data", nullable=true, type="application/json", example="null"),  
  819.      *     )
  820.      * )
  821.      * 
  822.      * @OA\Response(
  823.      *     response=401,
  824.      *     description="Token not found",
  825.      *     @OA\JsonContent(
  826.      *         type="object",
  827.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  828.      *         @OA\Property(property="message", type="string", example="Token not found")
  829.      *     )
  830.      * )
  831.      * 
  832.      * @OA\Response(
  833.      *     response=404,
  834.      *     description="Not found",
  835.      *     @OA\JsonContent(
  836.      *         type="object",
  837.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  838.      *         @OA\Property(property="message", type="string", example="Not found"),
  839.      *         @OA\Property(
  840.      *              property="data", 
  841.      *              type="array", 
  842.      *              collectionFormat="multi", 
  843.      *              @OA\Items(
  844.      *                  type="string",
  845.      *                  example="field"
  846.      *              )
  847.      *         ),
  848.      *     )
  849.      * )
  850.      * 
  851.      * @OA\Response(
  852.      *     response=429,
  853.      *     description="Too many requests",
  854.      *     @OA\JsonContent(
  855.      *         type="object",
  856.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  857.      *         @OA\Property(property="message", type="string", example="Too many requests")
  858.      *     )
  859.      * )
  860.      * 
  861.      * @OA\Response(
  862.      *     response=500,
  863.      *     description="Internal Server Error",
  864.      *     @OA\JsonContent(
  865.      *         type="object",
  866.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  867.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  868.      *     )
  869.      * )
  870.      *
  871.      * @OA\Parameter(
  872.      *     name="id",
  873.      *     in="path",
  874.      *     description="Curso Id",
  875.      *     required=true,
  876.      *     @OA\Schema(type="integer")
  877.      * )
  878.      * 
  879.      * @OA\Tag(name="Cursos")
  880.      * @Security(name="Bearer")
  881.      * 
  882.      */
  883.     public function deleteCourse(Request $request)
  884.     {
  885.         $this->requestUtil->setRequest($request)->setData();
  886.         $courseId $request->get('id');
  887.         $course $this->repository->findOneBy([
  888.             "id" => $courseId,
  889.             "deleted" => CourseEnum::ITEM_NO_DELETED
  890.         ]);
  891.         if (!$course) {
  892.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  893.         }
  894.         $this->repository->delete($courseTrashEnum::COURSEUserPermissionEnum::HIGHfalse);
  895.         $this->userLogService->logDelete(
  896.             "course"
  897.             $course->getId(), 
  898.             null
  899.             UserLogEnum::ORIGIN_CLIENT_API
  900.         );
  901.         return $this->eadResponse(nullErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  902.     }
  903. }