src/Controller/Api/v1/UserApiController.php line 800

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\UserCustomField;
  11. use EADPlataforma\Entity\UserProfile;
  12. use EADPlataforma\Entity\City;
  13. use EADPlataforma\Entity\State;
  14. use EADPlataforma\Entity\Country;
  15. use EADPlataforma\Entity\Session;
  16. use EADPlataforma\DataTransferObject\UserDTO;
  17. use EADPlataforma\Enum\TrashEnum;
  18. use EADPlataforma\Enum\UserEnum;
  19. use EADPlataforma\Enum\UserLogEnum;
  20. use EADPlataforma\Enum\UserCustomFieldEnum;
  21. use EADPlataforma\Enum\UserPermissionEnum;
  22. use EADPlataforma\Enum\ErrorEnum;
  23. class UserApiController extends AbstractApiController {
  24.     public function getEntityClass(){
  25.         return User::class;
  26.     }
  27.     /**
  28.      * Listagem dos usuários do EAD.
  29.      *
  30.      * @Route("/api/1/student", methods={"GET"})
  31.      * @OA\Response(
  32.      *     response=200,
  33.      *     description="Retorna os cursos do EAD.",
  34.      *     @OA\JsonContent(
  35.      *         type="object",
  36.      *         @OA\Property(property="aluno_id", type="integer", example=12, description="Id do aluno cadastrado no EAD."),
  37.      *         @OA\Property(property="nome", type="string", example="Exemplo", description="Nome do aluno cadastrado no EAD."),
  38.      *         @OA\Property(property="email", type="string", example="email@email.com", description="E-mail do aluno cadastrado no EAD."),
  39.      *         @OA\Property(property="username", type="string", example="UserName", description="Apelido do aluno no EAD."),
  40.      *         @OA\Property(property="tipo", type="integer", example=1, description="Tipo do usuário (1-Aluno / 2-Tutor / 3-Professor(a) / 4-Administrador)."),
  41.      *         @OA\Property(property="data_cadastro", type="date time", example="2019-01-01 09:00:00", description="Data e hora de cadastro do usuário."),
  42.      *         @OA\Property(property="status", type="integer", example=1, description="Status atual da conta (0-Aguardando confirmação / 1-Confirmado / 2-Bloqueado)."),
  43.      *         @OA\Property(property="cpf", type="datetime", example="2020-01-01 00:00:01", description="CPF do aluno."),
  44.      *         @OA\Property(property="profissao", example="SP", type="string"),
  45.      *         @OA\Property(property="biografia", type="string"),
  46.      *         @OA\Property(property="curriculum", type="string"),
  47.      *         @OA\Property(property="personalizado", type="string", description="Informações adicionais."),
  48.      *         @OA\Property(property="anotacoes", type="string", description="Informações adicionais."),
  49.      *         @OA\Property(property="nascimento", type="string", example="500", description="Data de nascimento."),
  50.      *         @OA\Property(property="cidade", type="string"),
  51.      *         @OA\Property(property="uf", type="string", description="Estado."),
  52.      *         @OA\Property(property="telefone", type="string"),
  53.      *         @OA\Property(property="cep", type="string"),
  54.      *         @OA\Property(property="endereco", type="string"),
  55.      *         @OA\Property(property="numero", type="string"),
  56.      *         @OA\Property(property="complemento", type="string"),
  57.      *         @OA\Property(property="bairro", type="string"),
  58.      *         @OA\Property(property="site", type="string", description="Endereço do site de um usuário."),         
  59.      *         @OA\Property(property="twitter", type="string"), 
  60.      *         @OA\Property(property="facebook", type="string"),
  61.      *         @OA\Property(property="linkedin", type="string"),
  62.      *         @OA\Property(property="youtube", type="string"),
  63.      *         @OA\Property(property="instagram", type="string"),
  64.      *         @OA\Property(property="tiktok", type="string"),
  65.      *         @OA\Property(property="ultimo_acesso", type="date time", example="2019-01-01 09:00:00", description="Data e hora do último acesso do usuário."),
  66.      *         @OA\Property(property="foto", type="string", example="seudominio/upload/profiles/foto.png", description="Imagem do perfil."),
  67.      *         @OA\Property(property="campos_personalizados", type="string", description="Campos adicionais criados na plataforma pelo admin.")
  68.      *     )
  69.      * )
  70.      * 
  71.      * @OA\Response(
  72.      *     response=204,
  73.      *     description="No content"
  74.      * )
  75.      * 
  76.      * @OA\Response(
  77.      *     response=401,
  78.      *     description="Token not found",
  79.      *     @OA\JsonContent(
  80.      *         type="object",
  81.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  82.      *         @OA\Property(property="message", type="string", example="Token not found")
  83.      *     )
  84.      * )
  85.      * 
  86.      * @OA\Response(
  87.      *     response=429,
  88.      *     description="Too many requests",
  89.      *     @OA\JsonContent(
  90.      *         type="object",
  91.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  92.      *         @OA\Property(property="message", type="string", example="Too many requests")
  93.      *     )
  94.      * )
  95.      * 
  96.      * @OA\Response(
  97.      *     response=500,
  98.      *     description="Internal Server Error",
  99.      *     @OA\JsonContent(
  100.      *         type="object",
  101.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  102.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  103.      *     )
  104.      * )
  105.      * 
  106.      * @OA\Parameter(
  107.      *     name="id",
  108.      *     in="query",
  109.      *     description="Usuário Id",
  110.      *     @OA\Schema(type="integer")
  111.      * )
  112.      * 
  113.      * @OA\Parameter(
  114.      *     name="email",
  115.      *     in="query",
  116.      *     description="E-mail",
  117.      *     @OA\Schema(type="string")
  118.      * )
  119.      * 
  120.      * @OA\Parameter(
  121.      *     name="status",
  122.      *     in="query",
  123.      *     description="Status (0-Aguardando confirmação / 1-Confirmado / 2-Bloqueado)",
  124.      *     @OA\Schema(type="integer")
  125.      * )
  126.      * 
  127.      * @OA\Parameter(
  128.      *     name="data_inicio",
  129.      *     in="query",
  130.      *     description="Data inicial data de cadastro (yyyy-mm-dd)",
  131.      *     @OA\Schema(type="string")
  132.      * )
  133.      * 
  134.      * @OA\Parameter(
  135.      *     name="data_fim",
  136.      *     in="query",
  137.      *     description="Data final data de cadastro (yyyy-mm-dd)",
  138.      *     @OA\Schema(type="string")
  139.      * )
  140.      * 
  141.      * @OA\Parameter(
  142.      *     name="paginate",
  143.      *     in="query",
  144.      *     description="Informaçoes para paginação",
  145.      *     @OA\Schema(type="integer")
  146.      * )
  147.      * 
  148.      * @OA\Parameter(
  149.      *      name="limit",
  150.      *      in="query",
  151.      *      description="Número máximo de dados retornados por página, valor padrão 1000",
  152.      *      @OA\Schema(type="integer")
  153.      * )
  154.      * 
  155.      * @OA\Parameter(
  156.      *      name="offset",
  157.      *      in="query",
  158.      *      description="Indica o início da leitura, caso não informado valor padrão será 0",
  159.      *      @OA\Schema(type="integer")
  160.      * )
  161.      * 
  162.      * @OA\Tag(name="Usuários")
  163.      * @Security(name="Bearer")
  164.      * 
  165.     */
  166.     public function getStudent(Request $request)
  167.     {
  168.        
  169.         $this->requestUtil->setRequest($request)->setData();
  170.         $columns =  [ 
  171.             "u.id AS aluno_id"
  172.             "u.name AS nome"
  173.             "u.email"
  174.             "up.name AS username"
  175.             "u.type AS tipo",
  176.             "DATE_FORMAT(u.dateRegister, '%Y-%m-%d %H:%i:%s') AS data_cadastro"
  177.             "u.status"
  178.             "u.document AS cpf"
  179.             "u.occupation AS profissao"
  180.             "u.biography AS biografia"
  181.             "u.resume AS curriculum"
  182.             "u.custom AS personalizado"
  183.             "u.notes AS anotacoes"
  184.             "DATE_FORMAT(u.birthDate, '%Y-%m-%d') AS nascimento",
  185.             "ci.name cidade",
  186.             "st.name AS uf"
  187.             "u.phone AS telefone"
  188.             "u.zipCode AS cep"
  189.             "u.address AS endereco"
  190.             "u.addressNumber AS numero"
  191.             "u.addressComplement AS complemento"
  192.             "u.addressNeighborhood AS bairro",
  193.             "u.website AS site",
  194.             "u.twitter",
  195.             "u.facebook",
  196.             "u.linkedin",
  197.             "u.youtube",
  198.             "u.instagram",
  199.             "u.tiktok",
  200.             "DATE_FORMAT(u.dateLastAccess, '%Y-%m-%d %H:%i:%s') AS ultimo_acesso"
  201.             "u.photo AS foto"
  202.             "u.customField AS campos_personalizados",
  203.             "'' AS campos_personalizados_decoded"
  204.         ];
  205.         
  206.         $profileClass UserProfile::class;
  207.         $cityClass City::class;
  208.         $stateClass State::class;
  209.         $countryClass Country::class;
  210.         $filter = [];
  211.         
  212.         $joins = [
  213.             "{$profileClass} AS up" => "up.id = u.userProfile",
  214.             "{$cityClass} AS ci" => ["LEFT""u.city = ci.id"],
  215.             "{$stateClass} AS st" => ["LEFT""u.state = st.id"],
  216.             "{$countryClass} AS co" => ["LEFT""u.country = co.id"]
  217.         ];
  218.         $userId $request->get('id');
  219.         $email $request->get('email');
  220.         $status $request->get('status');
  221.         $dateStart $request->get('data_inicio');
  222.         $dateEnd $request->get('data_fim');
  223.         $paginate $request->get('paginate');
  224.         $limit = (int)$request->get('limit');
  225.         $offset = (int)$request->get('offset');
  226.         
  227.         $filter = [
  228.             "u.id" => ["!="],
  229.             "u.deleted" => 0
  230.         ];
  231.         if(empty($limit) || $limit 1000){
  232.             $limit 1000;
  233.         }
  234.         if(empty($offset)){
  235.             $offset 0;
  236.         }
  237.         if(!empty($userId) && $userId 1){
  238.             $filter["u.id"] = (int)$userId;
  239.         }
  240.         if(!is_null($email)){
  241.             $filter["u.email"] = $email;
  242.         }
  243.         if(!is_null($status)){
  244.             $filter["u.status"] = (int)$status;
  245.         }
  246.         if(empty($dateStart) && !empty($dateEnd)){
  247.             $dateStart date('Y-m-d'strtotime("-1 day",strtotime($dateEnd)));  
  248.         }
  249.         if(empty($dateEnd) && !empty($dateStart)){
  250.             $dateEnd date('Y-m-d'strtotime("+1 day",strtotime($dateStart))); 
  251.         }
  252.         if(!empty($dateStart) && !empty($dateEnd)){
  253.             $filter["whereText"] = "u.dateRegister BETWEEN '{$dateStart}' AND '{$dateEnd}'"
  254.         }
  255.         $order = [ "u.id" => "ASC" ];
  256.       
  257.         $data $this->repository->paginate("u"null$columns$joins$filter$order$limit$offset);
  258.         $clientDomain '//'.$this->eadDomain.'/';
  259.         if(count($data['rows']) == 0){
  260.             return $this->eadResponse(nullErrorEnum::NO_CONTENTnull);
  261.         }
  262.         $customFields $this->em->getRepository(UserCustomField::class)->findBy([
  263.             "status" => UserCustomFieldEnum::PUBLISHED,
  264.             "deleted" => UserEnum::ITEM_NO_DELETED
  265.         ]);
  266.         $fields = [];
  267.         $userCustomField null;
  268.        
  269.         foreach ($data['rows'] as $key => $value) {
  270.             if(!empty($value->foto)){
  271.                 $value->foto $clientDomain."upload/profiles/".$data['rows'][$key]->foto;
  272.             }
  273.             if(!empty($value->campos_personalizados) && !empty($customFields)){
  274.                 
  275.                 $userCustomField json_decode($value->campos_personalizados);
  276.             
  277.                 foreach ($customFields as $keyCustom => $customField) {
  278.                     $idCustomField $customField->getId();
  279.                     if(!empty($userCustomField->{$idCustomField})){
  280.                         if(!empty($userCustomField->{$idCustomField}->fieldId)){
  281.                             $fieldId $userCustomField->{$idCustomField}->fieldId;
  282.                             if($userCustomField->{$idCustomField}->type == UserCustomFieldEnum::FIELD_MULTIPLE){
  283.                                 $userCustomField->{$idCustomField}->value = (array)$userCustomField->{$idCustomField}->value;
  284.                                 $userCustomField->{$idCustomField}->value implode(','$userCustomField->{$idCustomField}->value);
  285.                             }elseif($userCustomField->{$idCustomField}->type == UserCustomFieldEnum::FIELD_FILE){
  286.                                 $userCustomField->{$idCustomField}->value "{$clientDomain}user/download/custom/file/{$value->aluno_id}/{$idCustomField}";
  287.                             }elseif($userCustomField->{$idCustomField}->type == UserCustomFieldEnum::FIELD_OPTION_SELECT && is_array($userCustomField->{$idCustomField}->value)){
  288.                                 $userCustomField->{$idCustomField}->value = (array)$userCustomField->{$idCustomField}->value;
  289.                                 $userCustomField->{$idCustomField}->value implode(','$userCustomField->{$idCustomField}->value);
  290.                             }
  291.                             if($userCustomField->{$idCustomField}->fieldId == $idCustomField && !empty($userCustomField->{$idCustomField}->value)){
  292.                                 $fields[$customField->getName()] = $userCustomField->{$idCustomField}->value;
  293.                             }else{
  294.                                 $fields[$customField->getName()] = "";
  295.                             }
  296.                         }else{
  297.                             $fields[$customField->getName()] = "";
  298.                         }
  299.                     }else{
  300.                         $fields[$customField->getName()]= "";
  301.                     }   
  302.                 }
  303.                 
  304.                 $value->campos_personalizados_decoded $fields;
  305.             }
  306.         }
  307.         if($paginate == 1){
  308.             unset($data['searchText']);
  309.             return $this->json($data);
  310.         }
  311.         return $this->json($data['rows']);
  312.     }
  313.     /**
  314.      * Inserir um novo usuário no EAD.
  315.      *
  316.      * @Route("/api/1/student", methods={"POST"})
  317.      * consumes={"application/json"}
  318.      * produces={"application/json"}
  319.      * 
  320.      * @OA\Response(
  321.      *     response=200,
  322.      *     description="Success",
  323.      *     @OA\JsonContent(
  324.      *         type="object",
  325.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  326.      *         @OA\Property(property="message", type="string", example="Success"),
  327.      *         @OA\Property(
  328.      *              property="data", 
  329.      *              type="object", 
  330.      *              @OA\Property(property="aluno_id", type="integer", example=12), 
  331.      *              @OA\Property(property="nome", type="string", example="Nome do aluno"),
  332.      *              @OA\Property(property="email", type="string", example="email@email.com"),
  333.      *              @OA\Property(property="senha", type="string", example="password"),
  334.      *              @OA\Property(property="username", type="string", example="username"),
  335.      *              @OA\Property(property="tipo", type="integer", example=1),
  336.      *              @OA\Property(property="permissao_id", type="integer", example=2),
  337.      *              @OA\Property(property="status", type="integer", example=1),
  338.      *              @OA\Property(property="cpf", type="string", example="222.222.222-22"),
  339.      *              @OA\Property(property="foto", type="string", example="caminhodaimagem.com"),
  340.      *              @OA\Property(property="ocupacao", type="string", example="Desenvolvedor"),
  341.      *              @OA\Property(property="personalizado", type="string", example="Personalizado"),
  342.      *              @OA\Property(property="anotacoes", type="string", example="Anotacoes"),
  343.      *              @OA\Property(property="nascimento", type="string", example="1974-10-03"),
  344.      *              @OA\Property(property="telefone", type="string", example="(88)88888-8888"),
  345.      *              @OA\Property(property="cep", type="string", example="11111111"),
  346.      *              @OA\Property(property="endereco", type="string", example="Endereco"),
  347.      *              @OA\Property(property="numero", type="string", example="222"),
  348.      *              @OA\Property(property="complemento", type="string", example="Complemento"),
  349.      *              @OA\Property(property="bairro", type="string", example="Bairro")
  350.      *         )  
  351.      *     )
  352.      * )
  353.      * 
  354.      * @OA\Response(
  355.      *     response=401,
  356.      *     description="Token not found",
  357.      *     @OA\JsonContent(
  358.      *         type="object",
  359.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  360.      *         @OA\Property(property="message", type="string", example="Token not found")
  361.      *     )
  362.      * )
  363.      * 
  364.      * @OA\Response(
  365.      *     response=406,
  366.      *     description="Empty Fields",
  367.      *     @OA\JsonContent(
  368.      *         type="object",
  369.      *         @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
  370.      *         @OA\Property(property="message", type="string", example="Error"),
  371.      *         @OA\Property(
  372.      *              property="data", 
  373.      *              type="array", 
  374.      *              collectionFormat="multi", 
  375.      *              @OA\Items(
  376.      *                  type="string",
  377.      *                  example="field"
  378.      *              )
  379.      *         ),
  380.      *     )
  381.      * )
  382.      * 
  383.      * @OA\Response(
  384.      *     response=429,
  385.      *     description="Too many requests",
  386.      *     @OA\JsonContent(
  387.      *         type="object",
  388.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  389.      *         @OA\Property(property="message", type="string", example="Too many requests")
  390.      *     )
  391.      * )
  392.      * 
  393.      * @OA\Response(
  394.      *     response=500,
  395.      *     description="Internal Server Error",
  396.      *     @OA\JsonContent(
  397.      *         type="object",
  398.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  399.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  400.      *     )
  401.      * )
  402.      * 
  403.      * @OA\RequestBody(
  404.      *      required=true,
  405.      *      @OA\MediaType(
  406.      *          mediaType="multipart/form-data",
  407.      *          @OA\Schema(
  408.      *              type="object",
  409.      *              @OA\Property(
  410.      *                  property="email",
  411.      *                  description="E-mail do Usuário",
  412.      *                  type="string(75)"
  413.      *              ),
  414.      *              @OA\Property(
  415.      *                  property="nome",
  416.      *                  description="Nome do Usuário",
  417.      *                  type="string(75)"
  418.      *              ),
  419.      *              @OA\Property(
  420.      *                  property="tipo",
  421.      *                  description="Tipo do usuário (1-Aluno / 2-Tutor / 3-Professor(a) / 4-Administrador)",
  422.      *                  type="integer"
  423.      *              ),
  424.      *             @OA\Property(
  425.      *                  property="permissao_id",
  426.      *                  description="Id do template de permissão",
  427.      *                  type="integer"
  428.      *              ),
  429.      *             @OA\Property(
  430.      *                  property="status",
  431.      *                  description="Status atual da conta (0-Aguardando confirmação / 1-Confirmado / 2-Bloqueado)",
  432.      *                  type="integer"
  433.      *              ),
  434.      *             @OA\Property(
  435.      *                  property="senha",
  436.      *                  description="Senha Provisória",
  437.      *                  type="string(40)"
  438.      *              ),
  439.      *             @OA\Property(
  440.      *                  property="telefone",
  441.      *                  description="Telefone do usuário",
  442.      *                  type="string(40)"
  443.      *              ),
  444.      *             @OA\Property(
  445.      *                  property="data_cadastro",
  446.      *                  description="Data de Cadastro",
  447.      *                  type="datetime"
  448.      *              ),
  449.      *             @OA\Property(
  450.      *                  property="personalizado",
  451.      *                  description="Qualquer informação adicional, visível apenas para admin",
  452.      *                  type="string"
  453.      *             ),
  454.      *             @OA\Property(
  455.      *                  property="anotacoes",
  456.      *                  description="Observação sobre o usuário, visível apenas para admin",
  457.      *                  type="string"
  458.      *             ),
  459.      *             @OA\Property(
  460.      *                  property="notificar",
  461.      *                  description="Notificar por e-mail 0-Não / 1-Sim",
  462.      *                  type="integer"
  463.      *             ),
  464.      *             required={"tipo", "nome", "email", "status"}
  465.      *          )
  466.      *      )
  467.      * )
  468.      * 
  469.      * @OA\Tag(name="Usuários")
  470.      * @Security(name="Bearer")
  471.      * 
  472.     */
  473.     public function postUser(Request $request)
  474.     {
  475.        
  476.         $this->requestUtil->setRequest($request)->setData();
  477.         $type $this->requestUtil->getField('tipo');
  478.         $status $this->requestUtil->getField('status');
  479.         $name $this->requestUtil->getField('nome');
  480.         $email $this->requestUtil->getField('email');
  481.         $phone $this->requestUtil->getField('telefone');
  482.         $password $this->requestUtil->getField('senha');
  483.         $dateRegister $this->requestUtil->getField('data_cadastro');
  484.         $custom $this->requestUtil->getField('personalizado');
  485.         $notes $this->requestUtil->getField('anotacoes');
  486.         if(!empty($this->requestUtil->getField('tipo'))){
  487.             $type = (int)$this->requestUtil->getField('tipo');
  488.         }
  489.         
  490.         if(!empty($this->requestUtil->getField('status'))){
  491.             $status = (int)$this->requestUtil->getField('status');
  492.         }
  493.         if(is_numeric($this->requestUtil->getField('permissao_id'))){
  494.             $userProfileId $this->requestUtil->getField('permissao_id');
  495.         }else{
  496.             $userProfileId $type;
  497.         }
  498.         if(is_numeric($this->requestUtil->getField('notificar'))){
  499.             $notify $this->requestUtil->getField('notificar');
  500.         }else{
  501.             $notify null;
  502.         }
  503.         $totalEmail $this->repository->countByEmail($email);
  504.         if(!empty($totalEmail))
  505.         {
  506.             $user $this->repository->findOneBy([
  507.                 "email" => $email,
  508.                 "deleted" => UserEnum::ITEM_ON_TRASH
  509.             ]);
  510.             if($user){
  511.                 $this->repository->delete($usernullnullnullnullnullnullnulltrue);
  512.                 $this->userLogService->logDelete("user"$user->getId(), nullUserLogEnum::ORIGIN_CLIENT_API);
  513.             }else{
  514.                 return $this->eadResponse([ 'email' ], ErrorEnum::CONFLICT"Email já cadastrado.");
  515.             }
  516.         }
  517.         $dataUser = [
  518.             "type" => $type,
  519.             "status" => $status,
  520.             "dateRegister" => $dateRegister,
  521.             "name" => $name,
  522.             "email" => $email,
  523.             "password" => $password,
  524.             "phone" => $phone,
  525.             "custom" => $custom,
  526.             "notes" => $notes,
  527.             "userProfileId" => $userProfileId,
  528.             "notify" => $notify
  529.         ];
  530.         
  531.         $userDTO = new UserDTO($dataUser);
  532.         $data $this->repository->newUser($userDTO);
  533.         if($data->errors){
  534.             return $this->eadResponse($data->errorsErrorEnum::FIELD_EMPTYErrorEnum::MESSAGE_EMPTY_FIELD);
  535.         }
  536.         $user $data->user;
  537.         $return $user->toReturnApi();
  538.         $this->userLogService->logInsert("user"$user->getId(), $returnUserLogEnum::ORIGIN_CLIENT_API);
  539.         return $this->eadResponse($returnErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  540.     }
  541.     /**
  542.      * Atualizar um usuário do EAD.
  543.      *
  544.      * @Route("/api/1/student/{aluno_id}", methods={"PUT"})
  545.      * consumes={"application/json"}
  546.      * produces={"application/json"}
  547.      * 
  548.      * @OA\Response(
  549.      *     response=200,
  550.      *     description="Success",
  551.      *     @OA\JsonContent(
  552.      *         type="object",
  553.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  554.      *         @OA\Property(property="message", type="string", example="Success"),
  555.      *         @OA\Property(
  556.      *              property="data", 
  557.      *              type="object", 
  558.      *              @OA\Property(property="aluno_id", type="integer", example=12), 
  559.      *              @OA\Property(property="nome", type="string", example="Nome do aluno"),
  560.      *              @OA\Property(property="email", type="string", example="email@email.com"),
  561.      *              @OA\Property(property="senha", type="string", example="password"),
  562.      *              @OA\Property(property="username", type="string", example="username"),
  563.      *              @OA\Property(property="tipo", type="integer", example=1),
  564.      *              @OA\Property(property="permissao_id", type="integer", example=2),
  565.      *              @OA\Property(property="status", type="integer", example=1),
  566.      *              @OA\Property(property="cpf", type="string", example="222.222.222-22"),
  567.      *              @OA\Property(property="foto", type="string", example="caminhodaimagem.com"),
  568.      *              @OA\Property(property="ocupacao", type="string", example="Desenvolvedor"),
  569.      *              @OA\Property(property="personalizado", type="string", example="Personalizado"),
  570.      *              @OA\Property(property="anotacoes", type="string", example="Anotacoes"),
  571.      *              @OA\Property(property="nascimento", type="string", example="1974-10-03"),
  572.      *              @OA\Property(property="telefone", type="string", example="(88)88888-8888"),
  573.      *              @OA\Property(property="cep", type="string", example="11111111"),
  574.      *              @OA\Property(property="endereco", type="string", example="Endereco"),
  575.      *              @OA\Property(property="numero", type="string", example="222"),
  576.      *              @OA\Property(property="complemento", type="string", example="Complemento"),
  577.      *              @OA\Property(property="bairro", type="string", example="Bairro")
  578.      *         )  
  579.      *     )
  580.      * )
  581.      * 
  582.      * @OA\Response(
  583.      *     response=401,
  584.      *     description="Token not found",
  585.      *     @OA\JsonContent(
  586.      *         type="object",
  587.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  588.      *         @OA\Property(property="message", type="string", example="Token not found")
  589.      *     )
  590.      * )
  591.      * 
  592.      * @OA\Response(
  593.      *     response=404,
  594.      *     description="Not found",
  595.      *     @OA\JsonContent(
  596.      *         type="object",
  597.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  598.      *         @OA\Property(property="message", type="string", example="Not found"),
  599.      *         @OA\Property(
  600.      *              property="data", 
  601.      *              type="array", 
  602.      *              collectionFormat="multi", 
  603.      *              @OA\Items(
  604.      *                  type="string",
  605.      *                  example="field"
  606.      *              )
  607.      *         ),
  608.      *     )
  609.      * )
  610.      * 
  611.      * @OA\Response(
  612.      *     response=406,
  613.      *     description="Empty Fields",
  614.      *     @OA\JsonContent(
  615.      *         type="object",
  616.      *         @OA\Property(property="http_status", type="integer", example=406, description="Empty Field"),
  617.      *         @OA\Property(property="message", type="string", example="Error"),
  618.      *         @OA\Property(
  619.      *              property="data", 
  620.      *              type="array", 
  621.      *              collectionFormat="multi", 
  622.      *              @OA\Items(
  623.      *                  type="string",
  624.      *                  example="field"
  625.      *              )
  626.      *         ),
  627.      *     )
  628.      * )
  629.      * 
  630.      * @OA\Response(
  631.      *     response=429,
  632.      *     description="Too many requests",
  633.      *     @OA\JsonContent(
  634.      *         type="object",
  635.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  636.      *         @OA\Property(property="message", type="string", example="Too many requests")
  637.      *     )
  638.      * )
  639.      * 
  640.      * @OA\Response(
  641.      *     response=500,
  642.      *     description="Internal Server Error",
  643.      *     @OA\JsonContent(
  644.      *         type="object",
  645.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  646.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  647.      *     )
  648.      * )
  649.      * 
  650.      * @OA\Parameter(
  651.      *     name="aluno_id",
  652.      *     in="path",
  653.      *     description="Aluno Id",
  654.      *     required=true,
  655.      *     @OA\Schema(type="integer")
  656.      * )
  657.      * 
  658.      * @OA\RequestBody(
  659.      *      required=false,
  660.      *      @OA\MediaType(
  661.      *          mediaType="multipart/form-data",
  662.      *          @OA\Schema(
  663.      *              type="object",
  664.      *              @OA\Property(
  665.      *                  property="tipo",
  666.      *                  description="Tipo do usuário (1-Aluno / 2-Tutor / 3-Professor(a) / 4-Administrador)",
  667.      *                  type="integer"
  668.      *              ),
  669.      *              @OA\Property(
  670.      *                  property="status",
  671.      *                  description="Status atual da conta (0-Aguardando confirmação / 1-Confirmado / 2-Bloqueado)",
  672.      *                  type="integer"
  673.      *              ),
  674.      *              @OA\Property(
  675.      *                  property="nome",
  676.      *                  description="Nome do Usuário",
  677.      *                  type="string(75)"
  678.      *              ),
  679.      *              @OA\Property(
  680.      *                  property="email",
  681.      *                  description="E-mail do Usuário",
  682.      *                  type="string(75)"
  683.      *              ),
  684.      *              @OA\Property(
  685.      *                  property="telefone",
  686.      *                  description="Telefone do usuário",
  687.      *                  type="string(40)"
  688.      *              ),
  689.      *              @OA\Property(
  690.      *                  property="senha",
  691.      *                  description="Senha",
  692.      *                  type="string"
  693.      *              ),
  694.      *              @OA\Property(
  695.      *                  property="username",
  696.      *                  description="Username",
  697.      *                  type="string(75)"
  698.      *              ),
  699.      *              @OA\Property(
  700.      *                  property="cpf",
  701.      *                  description="CPF somente números",
  702.      *                  type="string(40)"
  703.      *              ),
  704.      *              @OA\Property(
  705.      *                  property="nascimento",
  706.      *                  description="Data de nascimento (YYYY-MM-DD)",
  707.      *                  type="date"
  708.      *              ),
  709.      *              @OA\Property(
  710.      *                  property="endereco",
  711.      *                  description="Endereço",
  712.      *                  type="string(115)"
  713.      *              ),
  714.      *              @OA\Property(
  715.      *                  property="numero",
  716.      *                  description="Número",
  717.      *                  type="string(10)"
  718.      *              ),
  719.      *              @OA\Property(
  720.      *                  property="complemento",
  721.      *                  description="Complemento",
  722.      *                  type="string(115)"
  723.      *              ),
  724.      *              @OA\Property(
  725.      *                  property="bairro",
  726.      *                  description="Bairro",
  727.      *                  type="string(60)"
  728.      *              ),
  729.      *              @OA\Property(
  730.      *                  property="cep",
  731.      *                  description="CEP",
  732.      *                  type="string(40)"
  733.      *              ),
  734.      *              @OA\Property(
  735.      *                  property="profissao",
  736.      *                  description="Profissão",
  737.      *                  type="string(45)"
  738.      *              ),
  739.      *              @OA\Property(
  740.      *                  property="personalizado",
  741.      *                  description="Qualquer informação adicional, visível apenas para admin",
  742.      *                  type="string"
  743.      *              ),
  744.      *              @OA\Property(
  745.      *                  property="anotacoes",
  746.      *                  description="Observação sobre o usuário, visível apenas para admin",
  747.      *                  type="string"
  748.      *              ),
  749.      *              @OA\Property(
  750.      *                  property="notificar",
  751.      *                  description="Notificar por e-mail 0-Não / 1-Sim",
  752.      *                  type="integer"
  753.      *              ),
  754.      *           )
  755.      *       )
  756.      *   ),
  757.      * 
  758.      * @OA\Tag(name="Usuários")
  759.      * @Security(name="Bearer")
  760.      * 
  761.     */
  762.     public function putUser(Request $request)
  763.     {
  764.        
  765.         $this->requestUtil->setRequest($request)->setData();
  766.         
  767.         $userId $request->get('aluno_id');
  768.         
  769.         if ($userId == 1) {
  770.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  771.         }
  772.         $user $this->repository->findOneBy([
  773.             "id" => $userId,
  774.             "deleted" => UserEnum::ITEM_NO_DELETED
  775.         ]);
  776.         if (!$user) {
  777.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  778.         }
  779.         $type = (int)$this->requestUtil->getField('tipo');
  780.         if(is_numeric($type) && $type >= && $type <= 4){
  781.             $user->setType($type);
  782.         }
  783.         $status $this->requestUtil->getField('status');
  784.         if(is_numeric($status) && $status >= && $type <= 2){
  785.             $user->setStatus($status);
  786.         }
  787.         $name $this->requestUtil->getField('nome');
  788.         if(!empty($name)){
  789.             $user->setName($name);
  790.         }
  791.         $email $this->requestUtil->getField('email');
  792.         if(!empty($email))
  793.         {
  794.             if($user->getEmail() != $email)
  795.             {
  796.                 $totalEmail $this->repository->countByEmail($email);
  797.                 if(!empty($totalEmail))
  798.                 {
  799.                     return $this->eadResponse([ 'email' ], ErrorEnum::CONFLICT"Email já cadastrado.");
  800.                 }
  801.                 $user->setEmail(strtolower($email));
  802.             }
  803.         }
  804.         $phone $this->requestUtil->getField('telefone');
  805.         if(!empty($phone)){
  806.             $user->setPhone($phone);
  807.         }
  808.         $updatePassword false;
  809.         $password $this->requestUtil->getField('senha');
  810.         if(!empty($password)){
  811.             $oldPassword $user->getPassword();
  812.             $user->setPassword($password);
  813.             $oldPass $user->getOldPassword(true);
  814.             if(in_array($user->getPassword(), $oldPass)){
  815.                 return $this->eadResponse(
  816.                     [ 'senha' ], 
  817.                     ErrorEnum::CONFLICT
  818.                     "Nova senha precisa ser diferente da anterior!"
  819.                 );
  820.             }
  821.             $updatePassword true;
  822.             if($oldPassword != UserEnum::PASSWORD_RESET){
  823.                 $user->setOldPassword($oldPassword);
  824.             }
  825.         }
  826.         $username $this->requestUtil->getField('username');
  827.         if(!empty($username))
  828.         {
  829.             if($user->getUsername() != $username)
  830.             {
  831.                 $totalUsername $this->repository->countByUsername($username);
  832.                 if(!empty($totalUsername))
  833.                 {
  834.                     return $this->eadResponse(
  835.                         [ 'username' ], 
  836.                         ErrorEnum::CONFLICT
  837.                         "Username já cadastrado."
  838.                     );
  839.                 }
  840.                 
  841.                 $user->setUsername($username);
  842.             }
  843.         }
  844.         $document $this->requestUtil->getField('cpf');
  845.         if(!empty($document)){
  846.             $user->setDocument($document);
  847.         }
  848.         $birthDate $this->requestUtil->getField('nascimento');
  849.         if(!empty($birthDate)){
  850.             $user->setBirthDate($birthDate);
  851.         }
  852.         $address $this->requestUtil->getField('endereco');
  853.         if(!empty($address)){
  854.             $user->setAddress($address);
  855.         }
  856.         $addressNumber $this->requestUtil->getField('numero');
  857.         if(!empty($addressNumber)){
  858.             $user->setAddressNumber($addressNumber);
  859.         }
  860.         $addressComplement $this->requestUtil->getField('complemento');
  861.         if(!empty($addressComplement)){
  862.             $user->setAddressComplement($addressComplement);
  863.         }
  864.         $addressNeighborhood $this->requestUtil->getField('bairro');
  865.         if(!empty($addressNeighborhood)){
  866.             $user->setAddressNeighborhood($addressNeighborhood);
  867.         }
  868.         $zipCode $this->requestUtil->getField('cep');
  869.         if(!empty($zipCode)){
  870.             $user->setZipCode($zipCode);
  871.         }
  872.         $occupation $this->requestUtil->getField('profissao');
  873.         if(!empty($occupation)){
  874.             $user->setOccupation($occupation);
  875.         }
  876.         $custom $this->requestUtil->getField('personalizado');
  877.         if(!empty($custom)){
  878.             $user->setCustom($custom);
  879.         }
  880.         $notes $this->requestUtil->getField('anotacoes');
  881.         if(!empty($notes)){
  882.             $user->setNotes($notes);
  883.         }
  884.         $notify = (int)$this->requestUtil->getField('notificar');
  885.         $errors $this->validateEntity($user);
  886.         if($errors){
  887.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTYErrorEnum::MESSAGE_EMPTY_FIELD);
  888.         }
  889.         if($updatePassword){
  890.             $this->em->getRepository(Session::class)->resetSessions($user);
  891.             if($notify == UserEnum::YES){
  892.                 $emailService $this->generalService->getService('EmailService');
  893.                 if(
  894.                     $emailService->checkUserToSend($userfalse) ||
  895.                     $this->configuration->get("allow_send_email_user") == UserEnum::YES
  896.                 ){
  897.                     $hashData = [
  898.                         "today" => date('Ymd'),
  899.                         "userId" => $user->getId()
  900.                     ];
  901.             
  902.                     $hash $stringUtil->encodeHex(base64_encode(json_encode($hashData)));
  903.                     $emailService->setToEmail($user->getEmail());
  904.                     $emailService->setToName($user->getName());
  905.                     $subject $this->configuration->getLanguage('change_password.subject''email')." - ".$this->client->getBrand();
  906.                     $emailService->setSubject($subject);
  907.                     $emailService->setData([
  908.                         "userName" => $user->getName(),
  909.                         "btnLink" => 'https://'.$this->client->getDomainPrimary()."/profile",
  910.                     ]);
  911.                     $emailService->setTemplateBody("change_password");
  912.                     $emailService->send();
  913.                 }
  914.             }
  915.         }
  916.         if($user->getState()){
  917.             $country $user->getState()->getCountry();
  918.             if($country){
  919.                 $user->setCountry($country);
  920.             }
  921.         }
  922.         
  923.         $this->em->flush();
  924.         $return $user->toReturnApi();
  925.         $this->userLogService->logUpdate("user"$user->getId(), $returnUserLogEnum::ORIGIN_CLIENT_API);
  926.         if(!empty($return['foto'])){
  927.             $return['foto'] = '//'.$this->eadDomain.$return['foto'];
  928.         }
  929.         return $this->eadResponse($returnErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  930.     }
  931.     /**
  932.      * Excluir um usuário do EAD.
  933.      *
  934.      *
  935.      * @Route("/api/1/student/{id}", methods={"DELETE"})
  936.      * @OA\Response(
  937.      *     response=200,
  938.      *     description="Success",
  939.      *     @OA\JsonContent(
  940.      *         type="object",
  941.      *         @OA\Property(property="http_status", type="integer", example=200, description="Success"),
  942.      *         @OA\Property(property="message", type="string", example="Success"),
  943.      *         @OA\Property(property="data", nullable=true, type="application/json", example="null"),  
  944.      *     )
  945.      * )
  946.      * 
  947.      * @OA\Response(
  948.      *     response=401,
  949.      *     description="Token not found",
  950.      *     @OA\JsonContent(
  951.      *         type="object",
  952.      *         @OA\Property(property="http_status", type="integer", example=401, description="Token not found"),
  953.      *         @OA\Property(property="message", type="string", example="Token not found")
  954.      *     )
  955.      * )
  956.      * 
  957.      * @OA\Response(
  958.      *     response=404,
  959.      *     description="Not found",
  960.      *     @OA\JsonContent(
  961.      *         type="object",
  962.      *         @OA\Property(property="http_status", type="integer", example=404, description="Not found"),
  963.      *         @OA\Property(property="message", type="string", example="Not found"),
  964.      *         @OA\Property(
  965.      *              property="data", 
  966.      *              type="array", 
  967.      *              collectionFormat="multi", 
  968.      *              @OA\Items(
  969.      *                  type="string",
  970.      *                  example="field"
  971.      *              )
  972.      *         ),
  973.      *     )
  974.      * )
  975.      * 
  976.      * @OA\Response(
  977.      *     response=429,
  978.      *     description="Too many requests",
  979.      *     @OA\JsonContent(
  980.      *         type="object",
  981.      *         @OA\Property(property="http_status", type="integer", example=429, description="Too many requests"),
  982.      *         @OA\Property(property="message", type="string", example="Too many requests")
  983.      *     )
  984.      * )
  985.      * 
  986.      * @OA\Response(
  987.      *     response=500,
  988.      *     description="Internal Server Error",
  989.      *     @OA\JsonContent(
  990.      *         type="object",
  991.      *         @OA\Property(property="http_status", type="integer", example=500, description="Internal Server Error"),
  992.      *         @OA\Property(property="message", type="string", example="Internal Server Error")
  993.      *     )
  994.      * )
  995.      * 
  996.      * @OA\Parameter(
  997.      *     name="id",
  998.      *     in="path",
  999.      *     description="Usuário Id",
  1000.      *     required=true,
  1001.      *     @OA\Schema(type="integer")
  1002.      * )
  1003.      * 
  1004.      * @OA\Tag(name="Usuários")
  1005.      * @Security(name="Bearer")
  1006.      * 
  1007.     */
  1008.     public function deleteUser(Request $request)
  1009.     {
  1010.         $this->requestUtil->setRequest($request)->setData();
  1011.         $userId $request->get('id');
  1012.         $user $this->repository->findOneBy([
  1013.             "id" => $userId,
  1014.             "deleted" => UserEnum::ITEM_NO_DELETED
  1015.         ]);
  1016.         if (!$user) {
  1017.             return $this->eadResponse(nullErrorEnum::NOT_FOUNDErrorEnum::MESSAGE_NOT_FOUND);
  1018.         }
  1019.         
  1020.         $this->repository->delete($usernullnullnullnullnullnullnulltrue);
  1021.         $this->userLogService->logDelete("user"$user->getId(), nullUserLogEnum::ORIGIN_CLIENT_API);
  1022.         return $this->eadResponse(nullErrorEnum::SUCCESSErrorEnum::MESSAGE_SUCCESS);
  1023.     }
  1024. }