<?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\Group;
use EADPlataforma\Entity\Enrollment;
use EADPlataforma\Enum\GroupEnum;
use EADPlataforma\Enum\CourseEnum;
use EADPlataforma\Enum\TrashEnum;
use EADPlataforma\Enum\UserLogEnum;
use EADPlataforma\Enum\UserEnum;
use EADPlataforma\Enum\UserPermissionEnum;
use EADPlataforma\Enum\ErrorEnum;
class GroupApiController extends AbstractApiController {
public function getEntityClass(){
return Group::class;
}
/**
* Listagem de grupos do EAD.
*
* @Route("/api/1/group", methods={"GET"})
* @OA\Response(
* response=200,
* description="Listagem de grupos do EAD.",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="grupo_id", type="integer", example=1, description="Id do grupo cadastrado no EAD."),
* @OA\Property(property="grupo_nome", type="string", example="Grupo Nome", description="Nome do grupo cadastrado no EAD."),
* @OA\Property(property="status", type="integer", example=0, description="Estado do grupo cadastrado no EAD(0-Liberado / 1-Bloqueado).")
* )
* )
*
* @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="Grupo 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="Grupos")
* @Security(name="Bearer")
*
*/
public function getGroup(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$columns = [
"g.id AS grupo_id",
"g.name AS grupo_nome",
"g.status"
];
$joins = [];
$groupId = (int)$request->get('id');
$paginate = $request->get('paginate');
$limit = (int)$request->get('limit');
$offset = (int)$request->get('offset');
$filter = [
"g.deleted" => 0
];
if(empty($limit) || $limit > 1000){
$limit = 1000;
}
if(empty($offset)){
$offset = 0;
}
if($groupId > 0){
$filter["g.id"] = $groupId;
}
$order = ["g.id" => "ASC"];
$data = $this->repository->paginate("g", null, $columns, $joins, $filter, $order, $limit, $offset);
if(count($data['rows']) == 0){
return $this->eadResponse(null, ErrorEnum::NO_CONTENT, null);
}
if($paginate == 1){
unset($data['searchText']);
return $this->json($data);
}
return $this->json($data['rows']);
}
/**
* Listagem de alunos por grupos do EAD.
*
* @Route("/api/1/groupstudent/{id}", methods={"GET"})
* @OA\Response(
* response=200,
* description="Retorna os alunos de um grupo do EAD.",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="grupo_id", type="integer", example=1, description="Id do grupo cadastrado no EAD."),
* @OA\Property(property="grupo_nome", type="string", example="Grupo Nome", description="Nome do grupo cadastrado no EAD."),
* @OA\Property(property="aluno_id", type="integer", example=44, description="Id do aluno cadastrado no EAD."),
* @OA\Property(property="nome", type="string", example="Nome Exemplo", description="Nome do usuário cadastrado no EAD."),
* @OA\Property(property="email", type="string", example="email@email.com", description="E-mail do usuário cadastrado no EAD.")
* )
* )
*
* @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="path",
* description="Grupo Id",
* required=true,
* @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="Grupos")
* @Security(name="Bearer")
*
*/
public function getGroupStudent(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$columns = [
"g.id AS grupo_id",
"g.name AS grupo_nome",
"u.id AS aluno_id",
"u.name AS name",
"u.email"
];
$groupClass = Group::class;
$groupId = (int)$request->get('id');
$paginate = $request->get('paginate');
$limit = (int)$request->get('limit');
$offset = (int)$request->get('offset');
$joins = [
"{$groupClass} AS g" => "g.id = {$groupId}",
];
$filter = [
"u.deleted" => 0,
"u.id" => [ "!=", 1 ],
"whereText" => "u MEMBER OF g.user"
];
if(empty($limit) || $limit > 1000){
$limit = 1000;
}
if(empty($offset)){
$offset = 0;
}
$order = ["u.id" => "ASC"];
$data = $this->em->getRepository(User::class)->paginate("u", null, $columns, $joins, $filter, $order, $limit, $offset);
if(count($data['rows']) == 0){
return $this->eadResponse(null, ErrorEnum::NO_CONTENT, null);
}
if($paginate == 1){
unset($data['searchText']);
return $this->json($data);
}
return $this->json($data['rows']);
}
/**
* Listagem de cursos por grupos do EAD.
*
* @Route("/api/1/groupcourse/{id}", methods={"GET"})
* @OA\Response(
* response=200,
* description="Retorna os cursos de um grupo do EAD.",
* @OA\Schema(
* type="object",
* @OA\Property(property="grupo_id", type="integer", example=1, description="Id do grupo cadastrado no EAD."),
* @OA\Property(property="grupo_nome", type="string", example="Grupo Nome", description="Nome do grupo cadastrado no EAD."),
* @OA\Property(property="curso_id", type="integer", example=44, description="Id do curso cadastrado no EAD."),
* @OA\Property(property="curso_titulo", type="string", example="Nome Exemplo", description="Nome do curso cadastrado no EAD."),
* @OA\Property(property="curso_status", type="integer", example=2, description="Status do curso(0-Rascunho / 1-Publicado / 2-Restrito).")
* )
* )
*
* @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="path",
* description="Grupo Id",
* required=true,
* @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="Grupos")
* @Security(name="Bearer")
*
*/
public function getGroupCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$columns = [
"g.id AS grupo_id",
"g.name AS grupo_nome",
"c.id AS curso_id",
"c.title AS curso_titulo",
"c.status"
];
$groupClass = Group::class;
$groupId = (int)$request->get('id');
$paginate = $request->get('paginate');
$limit = (int)$request->get('limit');
$offset = (int)$request->get('offset');
$joins = [
"{$groupClass} AS g" => "g.id = {$groupId}",
];
$filter = [
"c.deleted" => 0,
"whereText" => "c MEMBER OF g.course"
];
if(empty($limit) || $limit > 1000){
$limit = 1000;
}
if(empty($offset)){
$offset = 0;
}
$order = ["c.id" => "ASC"];
$data = $this->em->getRepository(Course::class)->paginate("c", null, $columns, $joins, $filter, $order, $limit, $offset);
if(count($data['rows']) == 0){
return $this->eadResponse(null, ErrorEnum::NO_CONTENT, null);
}
if($paginate == 1){
unset($data['searchText']);
return $this->json($data);
}
return $this->json($data['rows']);
}
/**
* Inserir um novo grupo no EAD.
*
* @Route("/api/1/group", 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="grupo_nome", type="string", example="Nome do grupo"),
* @OA\Property(property="status", type="integer", example=1),
* @OA\Property(property="aluno", type="array", collectionFormat="multi", @OA\Items(type="string"), example="[]"),
* @OA\Property(property="curso", type="array", collectionFormat="multi", @OA\Items(type="string"), example="[]")
* )
* )
* )
*
* @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=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="nome",
* description="Nome do Grupo",
* type="string(250)"
* ),
* @OA\Property(
* property="userManager",
* description="Id do usuário administrador do grupo",
* type="int"
* ),
* required={"nome", "userManager"}
* )
* )
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*
*/
public function postGroup(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$group = new Group();
$name = $this->requestUtil->getField('nome');
$this->requestUtil->setField('name', $name);
$userManagerId = $this->requestUtil->getField('userManager');
if($userManagerId == 1){
return $this->eadResponse(['userManager'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$userManager = $this->em->getRepository(User::class)->findOneBy([
"id" => $userManagerId,
"deleted" => UserEnum::ITEM_NO_DELETED
]);
$this->requestUtil->setField('userManager', $userManager);
$group = $this->setAllFields($group);
$errors = $this->validateEntity($group);
if($errors){
return $this->eadResponse($errors, ErrorEnum::FIELD_EMPTY, ErrorEnum::MESSAGE_EMPTY_FIELD);
}
$this->em->persist($group);
$this->em->flush();
$return = $group->toReturnApi();
//$this->userLogService->logInsert("group", $group->getId(), $return, UserLogEnum::ORIGIN_CLIENT_API);
return $this->eadResponse($return, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Inserir um aluno em um grupo do EAD.
*
* @Route("/api/1/groupstudent", 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", 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\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="id",
* description="Grupo id",
* type="integer"
* ),
* @OA\Property(
* property="usuario_id",
* description="Usuário id",
* type="integer"
* ),
* required={"id", "usuario_id"}
* )
* )
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*
*/
public function postGroupStudent(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$groupId = $request->get('id');
$group = $this->repository->findOneBy([
"id" => $groupId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$group) {
return $this->eadResponse(['id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$userId = $request->get('usuario_id');
$user = $this->em->getRepository(User::class)->findOneBy([
"id" => $userId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$user) {
return $this->eadResponse(['usuario_id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$group->addUser($user);
$this->em->flush();
$this->repository->enrollUsers($group, [ $user ]);
$data = $group->toReturn();
$clientDomain = '//'.$this->eadDomain.'/';
$emailTitle = $this->configuration->getLanguage('user_in_group.subject1', 'email').$group->getName().$this->configuration->getLanguage('user_in_group.subject2', 'email');
$emailService = $this->generalService->getService('EmailService');
if($emailService->checkUserToSend($user)){
$emailService->setToEmail($user->getEmail());
$emailService->setToName($user->getName());
$emailService->setSubject($emailTitle);
$emailService->setData([
"userName" => $user->getName(),
"btnLink" => 'https:'.$clientDomain,
"groupName" => $group->getName()
]);
$emailService->setTemplateBody("user_in_group");
$emailService->send();
}
/*$this->userLogService->logInsert(
"group_x_user",
$group->getId(),
$data,
UserLogEnum::ORIGIN_CLIENT_API
);*/
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Inserir um curso em um grupo do EAD.
*
* @Route("/api/1/groupcourse", 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", 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\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="id",
* description="Grupo id",
* type="integer"
* ),
* @OA\Property(
* property="curso",
* description="Curso id",
* type="integer"
* ),
* required={"id", "curso"}
* )
* )
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*
*/
public function postGroupCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$groupId = (int)$request->get('id');
$group = $this->repository->findOneBy([
"id" => $groupId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$group) {
return $this->eadResponse(['id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$courseId = (int)$request->get('curso');
$courseRepository = $this->em->getRepository(Course::class);
$course = $courseRepository->findOneBy([
"id" => $courseId,
"status" => CourseEnum::PUBLISHED,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$course) {
return $this->eadResponse(
[ 'curso' ],
ErrorEnum::NOT_FOUND,
ErrorEnum::MESSAGE_NOT_FOUND
);
}
$group->addCourse($course);
$this->em->flush();
$this->repository->enrollUsers($group, null, [ $course ]);
$data = $group->toReturn();
/*$this->userLogService->logInsert(
"group_x_course",
$group->getId(),
$data,
UserLogEnum::ORIGIN_CLIENT_API
);*/
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Atualizar um grupo do EAD.
*
* @Route("/api/1/group/{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="grupo_nome", type="string", example="Nome do grupo"),
* @OA\Property(property="status", type="integer", example=1),
* @OA\Property(
* property="aluno",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="object",
* @OA\Property(property="id", type="integer", example=100),
* @OA\Property(property="nome", type="string", example="Nome do aluno")
* )
* ),
* @OA\Property(
* property="curso",
* type="array",
* collectionFormat="multi",
* @OA\Items(
* type="object",
* @OA\Property(property="id", type="integer", example=2),
* @OA\Property(property="titulo", type="string", example="Título do curso")
* )
* ),
* )
* )
* )
*
* @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="Grupo Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="nome",
* description="Nome do Grupo",
* type="string(250)"
* ),
* @OA\Property(
* property="userManager",
* description="Id do usuário administrador do grupo",
* type="int"
* )
* )
* )
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*
*/
public function putGroup(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$groupId = (int)$request->get('id');
$group = $this->repository->findOneBy([
"id" => $groupId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$group) {
return $this->eadResponse(['id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
if(!empty($this->requestUtil->getField('nome'))){
$name = $this->requestUtil->getField('nome');
$group->setName($name);
}
if(is_numeric($this->requestUtil->getField('userManager'))){
$userManagerId = $this->requestUtil->getField('userManager');
if($userManagerId == 1){
return $this->eadResponse(['userManager'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$userManager = $this->em->getRepository(User::class)->findOneBy([
"id" => $userManagerId,
"deleted" => UserEnum::ITEM_NO_DELETED
]);
$group->setUserManager($userManager);
}
$errors = $this->validateEntity($group);
if($errors){
return $this->eadResponse($errors, ErrorEnum::FIELD_EMPTY, ErrorEnum::MESSAGE_EMPTY_FIELD);
}
$this->em->flush();
$return = $group->toReturnApi();
//$this->userLogService->logUpdate("group", $group->getId(), $return, UserLogEnum::ORIGIN_CLIENT_API);
return $this->eadResponse($return, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Excluir um grupo do EAD.
*
* @Route("/api/1/group/{id}/{excluir_matriculas}", 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="Grupo Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="excluir_matriculas",
* in="path",
* required=true,
* description="0-Não / 1-Sim",
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*/
public function deleteGroup(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$groupId = (int)$request->get('id');
$group = $this->repository->findOneBy([
"id" => $groupId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$group) {
return $this->eadResponse(null, ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$deleteEnrollment = (int)$request->get('excluir_matriculas');
$this->repository->delete($group, TrashEnum::GROUP, UserPermissionEnum::HIGH, false, $deleteEnrollment);
$this->userLogService->logDelete("group", $groupId, null, UserLogEnum::ORIGIN_CLIENT_API);
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Excluir um aluno de um grupo do EAD.
*
*
* @Route("/api/1/groupstudent/{id}/{usuario_id}/{excluir_matriculas}", 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="Grupo Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="usuario_id",
* in="path",
* required=true,
* description="Usuário Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="excluir_matriculas",
* in="path",
* required=true,
* description="0-Não / 1-Sim",
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*
*/
public function deleteGroupStudent(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$groupId = (int)$request->get('id');
$group = $this->repository->findOneBy([
"id" => $groupId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$group) {
return $this->eadResponse(['id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$userId = (int)$request->get('usuario_id');
$user = $this->em->getRepository(User::class)->findOneBy([
"id" => $userId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$user) {
return $this->eadResponse(['usuario_id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$deleteEnrollment = (int)$request->get('excluir_matriculas');
if($deleteEnrollment == GroupEnum::YES){
$enrollments = $this->em->getRepository(Enrollment::class)->getEnrollmentsByGroup($groupId, null, $userId);
foreach ($enrollments as $key => $enrollment) {
$this->em->getRepository(Enrollment::class)->delete($enrollment, TrashEnum::ENROLLMENT, UserPermissionEnum::HIGH, false);
}
}
$group->removeUser($user);
$this->em->flush();
$this->userLogService->logDelete("group_x_user", $groupId, null, UserLogEnum::ORIGIN_CLIENT_API);
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
/**
* Excluir um curso de um grupo do EAD.
*
* @Route("/api/1/groupcourse/{id}/{curso}/{excluir_matriculas}", 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="Grupo Id",
* required=true,
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="curso",
* in="path",
* required=true,
* description="Curso Id",
* @OA\Schema(type="integer")
* )
*
* @OA\Parameter(
* name="excluir_matriculas",
* in="path",
* required=true,
* description="0-Não / 1-Sim",
* @OA\Schema(type="integer")
* )
*
* @OA\Tag(name="Grupos")
* @Security(name="Bearer")
*
*/
public function deleteGroupCourse(Request $request)
{
$this->requestUtil->setRequest($request)->setData();
$groupId = (int)$request->get('id');
$group = $this->repository->findOneBy([
"id" => $groupId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$group) {
return $this->eadResponse(['id'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$courseId = (int)$request->get('curso');
$course = $this->em->getRepository(Course::class)->findOneBy([
"id" => $courseId,
"deleted" => GroupEnum::ITEM_NO_DELETED
]);
if (!$course) {
return $this->eadResponse(['curso'], ErrorEnum::NOT_FOUND, ErrorEnum::MESSAGE_NOT_FOUND);
}
$deleteEnrollment = (int)$request->get('excluir_matriculas');
if($deleteEnrollment == GroupEnum::YES){
$enrollments = $this->em->getRepository(Enrollment::class)->getEnrollmentsByGroup($groupId, null, null, $courseId);
foreach ($enrollments as $key => $enrollment) {
$this->em->getRepository(Enrollment::class)->delete($enrollment, TrashEnum::ENROLLMENT, UserPermissionEnum::HIGH, false);
}
}
$group->removeCourse($course);
$this->em->flush();
$this->userLogService->logDelete("group_x_course", $groupId, null, UserLogEnum::ORIGIN_CLIENT_API);
return $this->eadResponse(null, ErrorEnum::SUCCESS, ErrorEnum::MESSAGE_SUCCESS);
}
}