src/Controller/Admin/UserController.php line 636

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Admin;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use EADPlataforma\Entity\User;
  7. use EADPlataforma\Entity\UserProfile;
  8. use EADPlataforma\Entity\Country;
  9. use EADPlataforma\Entity\State;
  10. use EADPlataforma\Entity\City;
  11. use EADPlataforma\Entity\UserCustomField;
  12. use EADPlataforma\Entity\UserCheckoutInfo;
  13. use EADPlataforma\Entity\Group;
  14. use EADPlataforma\Entity\Session;
  15. use EADPlataforma\Entity\Receiver;
  16. use EADPlataforma\Entity\Enrollment;
  17. use EADPlataforma\Entity\Cart;
  18. use EADPlataforma\Entity\Configuration;
  19. use EADPlataforma\DataTransferObject\UserDTO;
  20. use EADPlataforma\Enum\UserEnum;
  21. use EADPlataforma\Enum\ConfigurationEnum;
  22. use EADPlataforma\Enum\SessionEnum;
  23. use EADPlataforma\Enum\ReceiverEnum;
  24. use EADPlataforma\Enum\UserCustomFieldEnum;
  25. use EADPlataforma\Enum\UserPermissionEnum;
  26. use EADPlataforma\Enum\UserCheckoutInfoEnum;
  27. use EADPlataforma\Enum\TagsMarketingEnum;
  28. use EADPlataforma\Enum\ErrorEnum;
  29. use EADPlataforma\Util\StringUtil;
  30. /**
  31.  * @Route(
  32.  *      schemes         = {"http|https"}
  33.  * )
  34.  * @Cache(
  35.  *      maxage          = "0",
  36.  *      smaxage         = "0",
  37.  *      expires         = "now",
  38.  *      public          = false
  39.  * )
  40.  */
  41. class UserController extends AbstractController {
  42.     public function getEntityClass(){
  43.         return User::class;
  44.     }
  45.     /**
  46.      * @Route(
  47.      *      path          = "/admin/user/list/paginate",
  48.      *      name          = "userPaginate",
  49.      *      methods       = {"GET"},
  50.      * )
  51.      */
  52.     public function getUserPaginate(Request $request) {
  53.         $permission $this->userPermissionUtil->getPermission("user""see");
  54.         if(!$this->userPermissionUtil->isHigh($permission)){
  55.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  56.         }
  57.         $this->requestUtil->setRequest($request)->setData();
  58.         $columns =  [ 
  59.             "u.id"
  60.             "u.name"
  61.             "u.email"
  62.             "up.name AS profile"
  63.             "u.type",
  64.             "DATE_FORMAT(u.dateRegister, '%Y-%m-%d %H:%i:%s') AS dateRegister",
  65.             "DATE_FORMAT(u.dateLastAccess, '%Y-%m-%d %H:%i:%s') AS dateLastAccess",
  66.             "u.status"
  67.             "u.validEmail"
  68.             "u.document"
  69.             "u.photo"
  70.             "u.occupation"
  71.             "u.biography"
  72.             "u.resume"
  73.             "u.custom"
  74.             "u.notes"
  75.             "DATE_FORMAT(u.birthDate, '%Y-%m-%d') AS birthDate"
  76.             "u.phone"
  77.             "u.zipCode"
  78.             "u.address"
  79.             "u.addressNumber"
  80.             "u.addressComplement"
  81.             "u.addressNeighborhood"
  82.             "u.customField",
  83.             "DATE_FORMAT(u.dateDelete, '%Y-%m-%d %H:%i:%s') AS dateDelete",
  84.             "ud.name AS userDelete" 
  85.         ];
  86.         
  87.         $profileClass UserProfile::class;
  88.         $userClass User::class;
  89.         $enrollmentClass Enrollment::class;
  90.         
  91.         $joins = [
  92.             "{$profileClass} AS up" => "up.id = u.userProfile",
  93.             "{$userClass} AS ud" => ["LEFT""ud.id = u.userDelete"]
  94.         ];
  95.         $type $this->requestUtil->getField('type');
  96.         $status $this->requestUtil->getField('status');
  97.         $userProfile $this->requestUtil->getField('userProfile');
  98.         $validEmail $this->requestUtil->getField('validEmail');
  99.         $searchText $this->requestUtil->getField('searchText');
  100.         $orderParam $this->requestUtil->getField('order');
  101.         $limit $this->requestUtil->getField('limit');
  102.         $offset $this->requestUtil->getField('offset');
  103.         $dateStart $this->requestUtil->getField('dateStart');
  104.         $dateEnd $this->requestUtil->getField('dateEnd');
  105.         $recover = (int)$this->requestUtil->getField('recover');
  106.         $course = (int)$this->requestUtil->getField('course');
  107.         $filter = [];
  108.         $filterDelete $this->requestUtil->getDeletedParam();
  109.         $filter = [
  110.             "u.id" => [ "!="]
  111.         ];
  112.         if(!empty($type)){
  113.             $filter["u.type"] = $type;
  114.         }
  115.         if(!is_null($status)){
  116.             $filter["u.status"] = $status;
  117.         }
  118.         if(!empty($course)){
  119.             $filter["whereText"] = " u.id IN ( 
  120.                 SELECT
  121.                    IDENTITY(e.user)
  122.                 FROM {$enrollmentClass} AS e 
  123.                 WHERE e.deleted = 0 
  124.                 AND e.course = {$course}
  125.             ) ";
  126.         }
  127.         if($recover == UserEnum::YES){
  128.             $today date('Y-m-d');
  129.             $filter["u.status"] = UserEnum::WAITING;
  130.             $filter["whereText"] = "
  131.                 (DATE_FORMAT(u.recoverDate, '%Y-%m-%d') != '{$today}' OR u.recoverDate IS NULL)
  132.             ";
  133.         }
  134.         if(!empty($userProfile)){
  135.             $filter["u.userProfile"] = $userProfile;
  136.         }
  137.         if(!is_null($validEmail)){
  138.             $filter["u.validEmail"] = $validEmail;
  139.         }
  140.         if(!empty($dateStart) && !empty($dateEnd)){
  141.             $filter["whereText"] = "
  142.                 DATE_FORMAT(u.dateRegister, '%Y-%m-%d') BETWEEN '{$dateStart}' AND '{$dateEnd}'
  143.             ";
  144.         }
  145.         
  146.         $order = [ "u.id" => "DESC" ];
  147.         if(!empty($orderParam)){
  148.             $orderJson json_decode($orderParamtrue);
  149.             $order = (!empty($orderJson) && is_array($orderJson) ? $orderJson $order);
  150.         }
  151.         $data $this->repository->paginate(
  152.             "u"
  153.             $searchText
  154.             $columns
  155.             $joins
  156.             $filter
  157.             $order
  158.             $limit
  159.             $offset
  160.             $filterDelete
  161.         );
  162.         return $this->eadResponse($data);
  163.     }
  164.     /**
  165.      * @Route(
  166.      *      path          = "/admin/user/list/paginate/all",
  167.      *      name          = "userPaginateAll",
  168.      *      methods       = {"GET"},
  169.      * )
  170.      */
  171.     public function getUserPaginateAll(Request $request) {
  172.         $this->requestUtil->setRequest($request)->setData();
  173.         $columns =  [ 
  174.             "u.id"
  175.             "u.name"
  176.             "u.email"
  177.             "up.name AS profile"
  178.             "u.type",
  179.             "DATE_FORMAT(u.dateRegister, '%Y-%m-%d %H:%i:%s') AS dateRegister",
  180.             "DATE_FORMAT(u.dateLastAccess, '%Y-%m-%d %H:%i:%s') AS dateLastAccess",
  181.             "u.status",
  182.             "u.validEmail",  
  183.             "u.document"
  184.             "u.photo"
  185.             "u.occupation"
  186.             "u.biography"
  187.             "u.resume"
  188.             "u.custom"
  189.             "u.notes"
  190.             "DATE_FORMAT(u.birthDate, '%Y-%m-%d') AS birthDate",
  191.             "u.phone"
  192.             "u.zipCode"
  193.             "u.address"
  194.             "u.addressNumber"
  195.             "u.addressComplement"
  196.             "u.addressNeighborhood"
  197.             "u.customField",
  198.             "DATE_FORMAT(u.dateDelete, '%Y-%m-%d %H:%i:%s') AS dateDelete",
  199.             "ud.name AS userDelete" 
  200.         ];
  201.         
  202.         $profileClass UserProfile::class;
  203.         $userClass User::class;
  204.         $enrollmentClass Enrollment::class;
  205.         
  206.         $joins = [
  207.             "{$profileClass} AS up" => "up.id = u.userProfile",
  208.             "{$userClass} AS ud" => ["LEFT""ud.id = u.userDelete"]
  209.         ];
  210.         $type = (int)$this->requestUtil->getField('type');
  211.         $status $this->requestUtil->getField('status');
  212.         $userProfile = (int)$this->requestUtil->getField('userProfile');
  213.         $enrollment = (int)$this->requestUtil->getField('enrollment');
  214.         $validEmail $this->requestUtil->getField('validEmail');
  215.         $orderParam $this->requestUtil->getField('order');
  216.         $searchText $this->requestUtil->getField('searchText');
  217.         $limit = (int)$this->requestUtil->getField('limit');
  218.         $offset = (int)$this->requestUtil->getField('offset');
  219.         $dateStart $this->requestUtil->getField('dateStart');
  220.         $dateEnd $this->requestUtil->getField('dateEnd');
  221.         $filter = [];
  222.         $filterDelete $this->requestUtil->getDeletedParam();
  223.         $filter = [
  224.             "u.id" => [ "!="],
  225.         ];
  226.         if($enrollment == UserEnum::YES){
  227.             $filter["whereText"] = " u.id IN ( 
  228.                 SELECT
  229.                    IDENTITY(e.user)
  230.                 FROM {$enrollmentClass} AS e 
  231.                 WHERE e.deleted = 0 
  232.                 AND e.user != 1
  233.             ) ";
  234.         }
  235.         if(!empty($type)){
  236.             $filter["u.type"] = $type;
  237.         }
  238.         if(!is_null($status)){
  239.             $filter["u.status"] = $status;
  240.         }
  241.         if(!empty($userProfile)){
  242.             $filter["u.userProfile"] = $userProfile;
  243.         }
  244.         if(!is_null($validEmail)){
  245.             $filter["u.validEmail"] = $validEmail;
  246.         }
  247.         if(!empty($dateStart) && !empty($dateEnd)){
  248.             $filter["whereText"] = "DATE_FORMAT(u.dateRegister, '%Y-%m-%d') BETWEEN '{$dateStart}' AND '{$dateEnd}'";
  249.         }
  250.         $order = [ "u.id" => "DESC" ];
  251.         if(!empty($orderParam)){
  252.             $order json_decode($orderParamtrue);
  253.         }
  254.         
  255.         $data $this->repository->paginate(
  256.             "u"
  257.             $searchText
  258.             $columns
  259.             $joins
  260.             $filter
  261.             $order
  262.             $limit
  263.             $offset
  264.             $filterDelete
  265.         );
  266.         return $this->eadResponse($data);
  267.     }
  268.     /**
  269.      * @Route(
  270.      *      path          = "/admin/user/list/all/trash",
  271.      *      name          = "userAllTrash",
  272.      *      methods       = {"GET"},
  273.      * )
  274.      */
  275.     public function getUserAllTrash(Request $request) {
  276.         $this->requestUtil->setRequest($request)->setData();
  277.         $data $this->repository->getAllTrash();
  278.         return $this->eadResponse($data);
  279.     }
  280.     /**
  281.      * @Route(
  282.      *      path          = "/admin/user/new/number",
  283.      *      name          = "userNewNumber",
  284.      *      methods       = {"GET"},
  285.      * )
  286.      */
  287.     public function getUserNewNumber(Request $request) {
  288.         $permission $this->userPermissionUtil->getPermission("user""see");
  289.         if(!$this->userPermissionUtil->isHigh($permission)){
  290.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  291.         }
  292.         $period $request->get('period');
  293.         $dateStart $request->get('dateStart');
  294.         $dateEnd $request->get('dateEnd');
  295.         if($period == UserEnum::FILTER_PERIOD_All){
  296.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  297.         }
  298.         $dateTimeUtil $this->generalService->getUtil('DateTimeUtil');
  299.         $dates $dateTimeUtil->periodDate($period$dateStart$dateEnd);
  300.         $dateStart $dates->dateStart;
  301.         $dateEnd $dates->dateEnd;
  302.         $numberTotal $this->repository->getNewUsersNumber($dateStart$dateEnd);
  303.         return $this->eadResponse([ "total" => $numberTotal ]);
  304.     }
  305.     /**
  306.      * @Route(
  307.      *      path          = "/admin/user/active/number",
  308.      *      name          = "userActiveNumber",
  309.      *      methods       = {"GET"},
  310.      * )
  311.      */
  312.     public function getActiveUsersNumber(Request $request) {
  313.         $permission $this->userPermissionUtil->getPermission("user""see");
  314.         if(!$this->userPermissionUtil->isHigh($permission)){
  315.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  316.         }
  317.         $period $request->get('period');
  318.         $dateStart $request->get('dateStart');
  319.         $dateEnd $request->get('dateEnd');
  320.         if($period == UserEnum::FILTER_PERIOD_All){
  321.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  322.         }
  323.         $dateTimeUtil $this->generalService->getUtil('DateTimeUtil');
  324.         $dates $dateTimeUtil->periodDate($period$dateStart$dateEnd);
  325.         $dateStart $dates->dateStart;
  326.         $dateEnd $dates->dateEnd;
  327.         $numberTotal $this->repository->getActiveUsersNumber($dateStart$dateEnd);
  328.         return $this->eadResponse([ "total" => $numberTotal ]);
  329.     }
  330.     /**
  331.      * @Route(
  332.      *      path          = "/admin/user/list/admin",
  333.      *      name          = "userListAdmin",
  334.      *      methods       = {"GET"},
  335.      * )
  336.      */
  337.     public function getUserAdmin(Request $request) {
  338.         $product = (int)$request->get('product');
  339.         $course = (int)$request->get('course');
  340.         $data $this->repository->getUserAdminSimply($product$course);
  341.         return $this->eadResponse($data);
  342.     }
  343.     /**
  344.      * @Route(
  345.      *      path          = "/admin/user/list/receiver",
  346.      *      name          = "getUserReceiverList",
  347.      *      methods       = {"GET"}
  348.      * )
  349.      */
  350.     public function getUserReceiverList(Request $request) {
  351.         $permission $this->userPermissionUtil->getPermission(
  352.             "financial"
  353.             "receiver"
  354.             "create"
  355.         );
  356.         
  357.         $data = [];
  358.         if($this->userPermissionUtil->isLow($permission)){
  359.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  360.         }else if(
  361.             $this->userPermissionUtil->isMiddle($permission) &&
  362.             $this->user->getAllowReceiver() == UserEnum::YES
  363.         ){
  364.             $data[] = (object)[
  365.                 "id" => $this->user->getId(),
  366.                 "name" => $this->user->getName(),
  367.                 "email" => $this->user->getEmail(),
  368.             ];
  369.         }else if($this->userPermissionUtil->isHigh($permission)){
  370.             $data $this->repository->getUserAllowReceiver();
  371.         }
  372.         $accountType ReceiverEnum::EAD_CHECKOUT;
  373.         $receiverRepository $this->em->getRepository(Receiver::class);
  374.         $aux = [];
  375.         foreach ($data as $key => $item) {
  376.             $item = (object)$item;
  377.             $numberReceiver $receiverRepository->countByType(
  378.                 $accountType
  379.                 $item->id
  380.             );
  381.             if($numberReceiver 2){
  382.                 $aux[] = $item;
  383.             }
  384.         }
  385.         return $this->eadResponse($aux);
  386.     }
  387.     /**
  388.      * @Route(
  389.      *      path          = "/admin/user/list/manager",
  390.      *      name          = "userListCourseManager",
  391.      *      methods       = {"GET"},
  392.      * )
  393.      */
  394.     public function getUserCourseManager(Request $request) {
  395.         $product = (int)$request->get('product');
  396.         $course = (int)$request->get('course');
  397.         
  398.         $data $this->repository->getUserCourseManager($product$course);
  399.         return $this->eadResponse($data);
  400.     }
  401.     /**
  402.      * @Route(
  403.      *      path          = "/admin/user/list/group/manager",
  404.      *      name          = "userListGroupManager",
  405.      *      methods       = {"GET"},
  406.      * )
  407.      */
  408.     public function userListGroupManager(Request $request) {
  409.         $data $this->repository->getUserAdminToGroupPermission();
  410.         return $this->eadResponse($data);
  411.     }
  412.     /**
  413.      * @Route(
  414.      *      path          = "/admin/user/profile/{username}",
  415.      *      name          = "userProfile",
  416.      *      methods       = {"GET"},
  417.      * )
  418.      */
  419.     public function getUserProfileByUsername(Request $request) {
  420.         $username $request->get('username');
  421.         $user $this->repository->findOneBy([
  422.             "deleted" => UserEnum::ITEM_NO_DELETED,
  423.             "username" => $username,
  424.         ]);
  425.         if (!$user) {
  426.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  427.         }
  428.         
  429.         return $this->eadResponse($user->toReturn(true));
  430.     }
  431.     /**
  432.      * @Route(
  433.      *      path          = "/admin/user/profile",
  434.      *      name          = "userProfileOn",
  435.      *      methods       = {"GET"},
  436.      * )
  437.      */
  438.     public function getUserProfile(Request $request) {
  439.         $user $this->user;
  440.         if (!$user) {
  441.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  442.         }
  443.         return $this->eadResponse($user->toReturn(true));
  444.     }
  445.     /**
  446.      * @Route(
  447.      *      path          = "/admin/user/permissions",
  448.      *      name          = "userPermissions",
  449.      *      methods       = {"GET"},
  450.      * )
  451.      */
  452.     public function getUserPermissions(Request $request) {
  453.         if(!$this->user){
  454.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  455.         }
  456.         
  457.         $permissions json_decode($this->user->getPermission());
  458.         if($this->user->getId() == 1){
  459.             $permissions $this->userPermissionUtil->getAdminPermissionTemplate();
  460.         }
  461.         $permissions->menu = (object)[];
  462.         $permissions->menu->dashboardModule $this->userPermissionUtil->canAccessDashboardModule();
  463.         $permissions->menu->productModule $this->userPermissionUtil->canAccessProductModule();
  464.         $permissions->menu->courseModule $this->userPermissionUtil->canAccessCourseModule();
  465.         $permissions->menu->userModule $this->userPermissionUtil->canAccessUserModule();
  466.         $permissions->menu->financialModule $this->userPermissionUtil->canAccessFinancialModule();
  467.         $permissions->menu->websiteModule $this->userPermissionUtil->canAccessWebsiteModule();
  468.         $permissions->menu->appStoreModule $this->userPermissionUtil->canAccessAppStore();
  469.         $permissions->menu->trashModule $this->userPermissionUtil->canAccessTrashModule();
  470.         $permissions->menu->planModule $this->userPermissionUtil->canAccessPlanModule();
  471.         
  472.         return $this->eadResponse($permissionsnullfalse);
  473.     }
  474.     /**
  475.      * @Route(
  476.      *      path          = "/admin/user/permissions/front/clean",
  477.      *      name          = "userPermissionsFrontClean",
  478.      *      methods       = {"GET"},
  479.      * )
  480.      */
  481.     public function getUserPermissionsFrontClean(Request $request) {
  482.         if(!$this->configuration->checkModuleIsAbleOnPlan('permissionFunction')){
  483.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  484.         }
  485.         if(!$this->user){
  486.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  487.         }
  488.         
  489.         $data $this->userPermissionUtil->getPermissionToFrontClean();
  490.         return $this->eadResponse($datanullfalse);
  491.     }
  492.     /**
  493.      * @Route(
  494.      *      path          = "/admin/user/permissions/front/template",
  495.      *      name          = "userPermissionsFrontTemplate",
  496.      *      methods       = {"GET"},
  497.      * )
  498.      */
  499.     public function getUserPermissionsFrontTemplate(Request $request) {
  500.         if(!$this->configuration->checkModuleIsAbleOnPlan('permissionFunction')){
  501.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  502.         }
  503.         if(!$this->user){
  504.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  505.         }
  506.         
  507.         $data $this->userPermissionUtil->getStudentPermissionTemplate();
  508.         return $this->eadResponse($datanullfalse);
  509.     }
  510.     /**
  511.      * @Route(
  512.      *      path          = "/admin/user/detail/{id}",
  513.      *      name          = "userDetail",
  514.      *      methods       = {"GET"},
  515.      *      requirements  = { "id" = "\d+" }
  516.      * )
  517.      */
  518.     public function getUserDetail(Request $request) {
  519.         $permission $this->userPermissionUtil->getPermission("user""see");
  520.         if(!$this->userPermissionUtil->isHigh($permission)){
  521.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  522.         }
  523.         $this->requestUtil->setRequest($request)->setData();
  524.         $ignoreOption $this->requestUtil->getField('ignoreOption');
  525.         $userId $request->get('id');
  526.         if($ignoreOption == UserEnum::ITEM_ON_TRASH){
  527.             $user $this->repository->findOneBy([
  528.                 "id" => $userId
  529.             ]);
  530.         }
  531.         if($ignoreOption == UserEnum::ITEM_NO_DELETED || !$ignoreOption){
  532.             $user $this->repository->findOneBy([
  533.                 "id" => $userId,
  534.                 "deleted" => UserEnum::ITEM_NO_DELETED
  535.             ]);
  536.         }
  537.         if (!$user) {
  538.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  539.         }
  540.         if($user->getId() == UserEnum::FIRST_ADMIN && $user->getType() == UserEnum::ADMIN){
  541.             $user->setPermission(
  542.                 json_encode($this->userPermissionUtil->getAdminPermissionTemplate())
  543.             );
  544.             $this->em->flush();
  545.         }
  546.         $data $user->toReturn();
  547.         $data['urlProfile'] = $this->generalService->generateUrl(
  548.             'userProfilePublic'
  549.             [ 'username' => $user->getUsername() ]
  550.         );
  551.         
  552.         return $this->eadResponse($data);
  553.     }
  554.     /**
  555.      * @Route(
  556.      *      path          = "/user/download/custom/file/{id}/{fieldId}",
  557.      *      name          = "userDownloadCustom",
  558.      *      methods       = {"GET"},
  559.      *      requirements  = { "id" = "\d+", "fieldId" = "\d+" }
  560.      * )
  561.      */
  562.     public function downloadCustomFieldFile(Request $request) {
  563.         if(!$this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  564.             return $this->redirectToRoute('notFound');
  565.         }
  566.         $userId $request->get('id');
  567.         $user $this->repository->findOneBy([
  568.             "deleted" => UserEnum::ITEM_NO_DELETED,
  569.             "id" => $userId
  570.         ]);
  571.         if (!$user) {
  572.             return $this->redirectToRoute('notFound');
  573.         }
  574.         if($userId != $this->user->getId()){
  575.             $permission $this->userPermissionUtil->getPermission("user""see");
  576.             if(!$this->userPermissionUtil->isHigh($permission)){
  577.                 return $this->redirectToRoute('notFound');
  578.             }
  579.         }
  580.         $fieldId $request->get('fieldId');
  581.         $fields json_decode($user->getCustomField());
  582.         
  583.         $url null;
  584.         if(!empty($fields->{$fieldId})){
  585.             if(!empty($fields->{$fieldId}->value)){
  586.                 $file $fields->{$fieldId}->value->path;
  587.                 $othersPath UserEnum::PATH_OTHERS_PROFILES;
  588.                 $this->fileService->setFile("{$othersPath}/{$file}");
  589.                 $url $this->fileService->getFileUrlTemp();
  590.             }
  591.         }
  592.         if($url){
  593.             return $this->redirect($url301);
  594.         }
  595.         return $this->redirectToRoute('notFound');
  596.     }
  597.     
  598.     /**
  599.      * @Route(
  600.      *      path          = "/admin/user/merge",
  601.      *      name          = "userMerge",
  602.      *      methods       = {"POST"},
  603.      * )
  604.      */
  605.     public function mergeUser(Request $request) {
  606.         if($this->user->getId() != UserEnum::YES){
  607.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  608.         }
  609.         $this->requestUtil->setRequest($request)->setData();
  610.         $userIdOld $this->requestUtil->getField('userOld');
  611.         $userIdNew $this->requestUtil->getField('userNew');
  612.         $userOld $this->repository->findOneBy([ 
  613.             "deleted" => UserEnum::ITEM_NO_DELETED
  614.             "id" => $userIdOld 
  615.         ]);
  616.         $userNew $this->repository->findOneBy([ 
  617.             "deleted" => UserEnum::ITEM_NO_DELETED
  618.             "id" => $userIdNew 
  619.         ]);
  620.         if (!$userOld) {
  621.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  622.         }
  623.         if (!$userNew) {
  624.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  625.         }
  626.         $this->repository->mergeUser($userOld$userNew);
  627.         return $this->eadResponse([ "success" => ]);
  628.     }
  629.     /**
  630.      * @Route(
  631.      *      path          = "/admin/user/register",
  632.      *      name          = "userRegister",
  633.      *      methods       = {"POST"},
  634.      * )
  635.      */
  636.     public function registerUser(Request $request) {
  637.         $permission $this->userPermissionUtil->getPermission("user""create");
  638.         if(!$this->userPermissionUtil->isHigh($permission)){
  639.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  640.         }
  641.         $this->requestUtil->setRequest($request)->setData();
  642.         $name $this->requestUtil->getField('name');
  643.         $email $this->requestUtil->getField('email');
  644.         $password $this->requestUtil->getField('password');
  645.         $userProfileId $this->requestUtil->getField('userProfile');
  646.         $groupId $this->requestUtil->getField('group');
  647.         $totalEmail $this->repository->countByEmail($email);
  648.         if(!empty($totalEmail)){
  649.             return $this->eadResponse([ 'email' ], ErrorEnum::FIELD_EMPTY);
  650.         }
  651.         $allowPermissions = [
  652.             UserEnum::STUDENT
  653.         ];
  654.         $permission $this->userPermissionUtil->getPermission("user""permissions");
  655.         if($this->userPermissionUtil->isHigh($permission)){
  656.             $maxAllowID $this->user->getUserProfile()->getId();
  657.             $allowPermissions[] = $maxAllowID;
  658.             if($maxAllowID == UserEnum::ADMIN){
  659.                 $allowPermissions[] = UserEnum::TUTOR;
  660.                 $allowPermissions[] = UserEnum::TEACHER;
  661.                 $allowPermissions[] = $userProfileId;
  662.             }else if($maxAllowID == UserEnum::TEACHER){
  663.                 $allowPermissions[] = UserEnum::TUTOR;
  664.             }
  665.         }
  666.         if(!in_array($userProfileId$allowPermissions)){
  667.             $userProfileId null;
  668.         }
  669.         $dataUser = [
  670.             "name" => $name,
  671.             "email" => $email,
  672.             "password" => $password,
  673.             "userProfileId" => $userProfileId,
  674.             "groupId" => $groupId,
  675.             "notify" => UserEnum::YES,
  676.             "invited" => UserEnum::YES
  677.         ];
  678.     
  679.         $userDTO = new UserDTO($dataUser);
  680.         $data $this->repository->newUser($userDTO);
  681.         if($data->errors){
  682.             return $this->eadResponse($data->errorsErrorEnum::FIELD_EMPTY);
  683.         }
  684.         $user $data->user;
  685.         $data $user->toReturn();
  686.         $this->userLogService->logInsert("user"$user->getId(), $data);
  687.         return $this->eadResponse($data);
  688.     }
  689.     /**
  690.      * @Route(
  691.      *      path          = "/admin/user/edit/info/cart/{id}",
  692.      *      name          = "userEditInfoCart",
  693.      *      methods       = {"PUT"},
  694.      *      requirements  = { "id" = "\d+" }
  695.      * )
  696.      */
  697.     public function editUserInfoCart(Request $request) {
  698.         $userId $request->get('id');
  699.         $user $this->repository->findOneBy([
  700.             "deleted" => UserEnum::ITEM_NO_DELETED,
  701.             "id" => $userId
  702.         ]);
  703.         if (!$user) {
  704.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  705.         }
  706.         if($userId != $this->user->getId()){
  707.            return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  708.         }
  709.         $this->requestUtil->setRequest($request)->setData();
  710.         
  711.         if($this->requestUtil->issetField('document')){
  712.             $user->setDocument($this->requestUtil->getField('document'));
  713.         }
  714.         if($this->requestUtil->issetField('country')){
  715.             $countryId $this->requestUtil->getField('country');
  716.             $country $this->em->getRepository(Country::class)->findOneBy([
  717.                 "id" => $countryId,
  718.                 "deleted" => UserEnum::ITEM_NO_DELETED
  719.             ]);
  720.             if($country){
  721.                 $user->setCountry($country);
  722.             }else{
  723.                 $user->setCountry(null);
  724.             }
  725.         }
  726.         if($this->requestUtil->issetField('state')){
  727.             $stateId $this->requestUtil->getField('state');
  728.             $state $this->em->getRepository(State::class)->findOneBy([
  729.                 "id" => $stateId,
  730.                 "deleted" => UserEnum::ITEM_NO_DELETED
  731.             ]);
  732.             if($state){
  733.                 $user->setState($state);
  734.             }else{
  735.                 $user->setState(null);
  736.             }
  737.         }
  738.         if($this->requestUtil->issetField('city')){
  739.             $cityId $this->requestUtil->getField('city');
  740.             $city $this->em->getRepository(City::class)->findOneBy([
  741.                 "id" => $cityId,
  742.                 "deleted" => UserEnum::ITEM_NO_DELETED
  743.             ]);
  744.             if($city){
  745.                 $user->setCity($city);
  746.             }else{
  747.                 $user->setCity(null);
  748.             }
  749.         }
  750.         if($this->requestUtil->issetField('zipCode')){
  751.             $user->setZipCode($this->requestUtil->getField('zipCode'));
  752.         }
  753.         if($this->requestUtil->issetField('address')){
  754.             $user->setAddress($this->requestUtil->getField('address'));
  755.         }
  756.         if($this->requestUtil->issetField('addressNumber')){
  757.             $user->setAddressNumber($this->requestUtil->getField('addressNumber'));
  758.         }
  759.         if($this->requestUtil->issetField('addressComplement')){
  760.             $user->setAddressComplement($this->requestUtil->getField('addressComplement'));
  761.         }
  762.         if($this->requestUtil->issetField('addressNeighborhood')){
  763.             $user->setAddressNeighborhood(
  764.                 $this->requestUtil->getField('addressNeighborhood')
  765.             );
  766.         }
  767.         $errors $this->validateEntity($user);
  768.         if($errors){
  769.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  770.         }
  771.         $userCheckoutInfoRepository $this->em->getRepository(UserCheckoutInfo::class);
  772.         $userCheckoutInfoId null;
  773.         $userCheckoutInfo $userCheckoutInfoRepository->findOneBy([
  774.             "user" => $user->getId(),
  775.             "default" => UserCheckoutInfoEnum::YES,
  776.             "deleted" => UserCheckoutInfoEnum::ITEM_NO_DELETED
  777.         ]);
  778.         $new false;
  779.         if(!$userCheckoutInfo){
  780.             $new true;
  781.             $userCheckoutInfo = new UserCheckoutInfo();
  782.         }
  783.         $userCheckoutInfo->setName($user->getName());
  784.         $userCheckoutInfo->setEmail($user->getEmail());
  785.         $userCheckoutInfo->setDocument($user->getDocument());
  786.         $userCheckoutInfo->setPhone($user->getPhone());
  787.         $userCheckoutInfo->setZipCode($user->getZipCode());
  788.         $userCheckoutInfo->setAddress($user->getAddress());
  789.         $userCheckoutInfo->setAddressNumber($user->getAddressNumber());
  790.         $userCheckoutInfo->setAddressComplement($user->getAddressComplement());
  791.         $userCheckoutInfo->setAddressNeighborhood($user->getAddressNeighborhood());
  792.         $userCheckoutInfo->setCity($user->getCity());
  793.         $userCheckoutInfo->setState($user->getState());
  794.         $userCheckoutInfo->setCountry($user->getCountry());
  795.         $userCheckoutInfo->setUser($user);
  796.         $userCheckoutInfo->setReceiveEmail(UserCheckoutInfoEnum::NO);
  797.         if($new){
  798.             $userCheckoutInfo->setDefault(UserCheckoutInfoEnum::YES);
  799.             $this->em->persist($userCheckoutInfo);
  800.         }
  801.         $userCheckoutInfoId $userCheckoutInfo->getId();
  802.         $this->em->flush();
  803.         $this->repository->sendWebhook($user);
  804.         $crmService $this->generalService->getService('CRM\\CrmService');
  805.         $crmService->savePerson($user);
  806.         $data $user->toReturn();
  807.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  808.         $data['userCheckoutInfoId'] = $userCheckoutInfoId;
  809.         return $this->eadResponse($data);
  810.     }
  811.     /**
  812.      * @Route(
  813.      *      path          = "/admin/user/edit/info/profile",
  814.      *      name          = "userEditInfoProfile",
  815.      *      methods       = {"POST"}
  816.      * )
  817.      */
  818.     public function userEditInfoProfile(Request $request) {
  819.         if (!$this->user) {
  820.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  821.         }
  822.         $this->requestUtil->setRequest($request)->setData();
  823.         $files $this->requestUtil->getFile('files');
  824.         $filePhoto $this->requestUtil->getFile('photo');
  825.         $fileCover $this->requestUtil->getFile('cover');
  826.         $emailService $this->generalService->getService('EmailService');
  827.         $emailService->setToEmail($this->user->getEmail());
  828.         $emailService->setToName($this->user->getName());
  829.         if($filePhoto){
  830.             if($filePhoto->getSize() > UserEnum::MAX_SIZE_USER_IMAGES){
  831.                 return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  832.             }
  833.         }
  834.         if($fileCover){
  835.             if($fileCover->getSize() > UserEnum::MAX_SIZE_USER_IMAGES){
  836.                 return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  837.             }
  838.         }
  839.         if($this->requestUtil->issetField('name')){
  840.             $this->user->setName($this->requestUtil->getField('name'));
  841.         }
  842.         if($this->requestUtil->issetField('username')){
  843.             if($this->user->getUsername() != $this->requestUtil->getField('username'))
  844.             {
  845.                 $totalUsername $this->repository->countByUsername($this->requestUtil->getField('username'));
  846.                 if(!empty($totalUsername))
  847.                 {
  848.                     return $this->eadResponse([ 'username' ], ErrorEnum::FIELD_EMPTY);
  849.                 }
  850.                 $this->user->setUsername($this->requestUtil->getField('username'));
  851.             }
  852.         }
  853.         $password "******";
  854.         if($this->requestUtil->issetField('password')){
  855.             $newPassword $this->requestUtil->getField('password');
  856.             if(
  857.                 $this->user->getPassword() != $newPassword && 
  858.                 $this->user->getPassword() != md5($newPassword)
  859.             ){
  860.                 $oldPassword $this->user->getPassword();
  861.                 $this->user->setPassword($newPassword);
  862.                 $oldPass $this->user->getOldPassword(true);
  863.                 if(in_array($this->user->getPassword(), $oldPass)){
  864.                     return $this->eadResponse([ 
  865.                         "message" => "Nova senha precisa ser diferente da anterior!"
  866.                     ], ErrorEnum::ACTION_INVALID);
  867.                 }
  868.                 if($oldPassword != UserEnum::PASSWORD_RESET){
  869.                     $this->user->setOldPassword($oldPassword);
  870.                 }
  871.                 if(
  872.                     $emailService->checkUserToSend($this->userfalse) ||
  873.                     $this->configuration->get("allow_send_email_user") == UserEnum::YES
  874.                 ){
  875.                     $subText $this->configuration->getLanguage(
  876.                         'change_password.subject''email'
  877.                     );
  878.                     $subject "{$subText} - {$this->client->getBrand()}";
  879.                     $emailService->setSubject($subject);
  880.                     $emailService->setData([
  881.                         "userName" => $this->user->getName(),
  882.                         "btnLink" => 'https://'.$this->client->getDomainPrimary()."/profile",
  883.                     ]);
  884.                     $emailService->setTemplateBody("change_password");
  885.                     $emailService->send();
  886.                 }
  887.             }
  888.         }
  889.         if($this->requestUtil->issetField('document')){
  890.             $this->user->setDocument($this->requestUtil->getField('document'));
  891.         }
  892.         if($this->requestUtil->issetField('phone')){
  893.             $this->user->setPhone($this->requestUtil->getField('phone'));
  894.         }
  895.         if($this->requestUtil->issetField('birthDate')){
  896.             $birthDate $this->requestUtil->getField('birthDate');
  897.             $birthDate implode('-'array_reverse(explode('/'$birthDate)));
  898.             $this->user->setBirthDate($birthDate);
  899.         }
  900.         if($this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  901.             if($this->requestUtil->issetField('customField')){
  902.                 $this->user->setCustomField($this->requestUtil->getField('customField'));
  903.             }
  904.         }
  905.         if($this->requestUtil->issetField('occupation')){
  906.             $this->user->setOccupation($this->requestUtil->getField('occupation'));
  907.         }
  908.         if($this->requestUtil->issetField('biography')){
  909.             $this->user->setBiography($this->requestUtil->getField('biography'));
  910.         }
  911.         if($this->requestUtil->issetField('resume')){
  912.             $this->user->setResume($this->requestUtil->getField('resume'));
  913.         }
  914.         if($this->requestUtil->issetField('custom')){
  915.             $this->user->setCustom($this->requestUtil->getField('custom'));
  916.         }
  917.         if($this->requestUtil->issetField('notes')){
  918.             $this->user->setNotes($this->requestUtil->getField('notes'));
  919.         }
  920.         
  921.         if($this->requestUtil->issetField('country')){
  922.             $countryId $this->requestUtil->getField('country');
  923.             $country $this->em->getRepository(Country::class)->findOneBy([
  924.                 "id" => $countryId,
  925.                 "deleted" => UserEnum::ITEM_NO_DELETED
  926.             ]);
  927.             if($country){
  928.                 $this->user->setCountry($country);
  929.             }else{
  930.                 $this->user->setCountry(null);
  931.             }
  932.         }
  933.         if($this->requestUtil->issetField('state')){
  934.             $stateId $this->requestUtil->getField('state');
  935.             $state $this->em->getRepository(State::class)->findOneBy([
  936.                 "id" => $stateId,
  937.                 "deleted" => UserEnum::ITEM_NO_DELETED
  938.             ]);
  939.             if($state){
  940.                 $this->user->setState($state);
  941.             }else{
  942.                 $this->user->setState(null);
  943.             }
  944.         }
  945.         if($this->requestUtil->issetField('city')){
  946.             $cityId $this->requestUtil->getField('city');
  947.             $city $this->em->getRepository(City::class)->findOneBy([
  948.                 "id" => $cityId,
  949.                 "deleted" => UserEnum::ITEM_NO_DELETED
  950.             ]);
  951.             if($city){
  952.                 $this->user->setCity($city);
  953.             }else{
  954.                 $this->user->setCity(null);
  955.             }
  956.         }
  957.         if($this->requestUtil->issetField('zipCode')){
  958.             $this->user->setZipCode($this->requestUtil->getField('zipCode'));
  959.         }
  960.         if($this->requestUtil->issetField('address')){
  961.             $this->user->setAddress($this->requestUtil->getField('address'));
  962.         }
  963.         if($this->requestUtil->issetField('addressNumber')){
  964.             $this->user->setAddressNumber($this->requestUtil->getField('addressNumber'));
  965.         }
  966.         if($this->requestUtil->issetField('addressComplement')){
  967.             $this->user->setAddressComplement(
  968.                 $this->requestUtil->getField('addressComplement')
  969.             );
  970.         }
  971.         if($this->requestUtil->issetField('addressNeighborhood')){
  972.             $this->user->setAddressNeighborhood(
  973.                 $this->requestUtil->getField('addressNeighborhood')
  974.             );
  975.         }
  976.         if($this->requestUtil->issetField('website')){
  977.             $this->user->setWebsite($this->requestUtil->getField('website'));
  978.         }
  979.         if($this->requestUtil->issetField('twitter')){
  980.             $this->user->setTwitter($this->requestUtil->getField('twitter'));
  981.         }
  982.         if($this->requestUtil->issetField('facebook')){
  983.             $this->user->setFacebook($this->requestUtil->getField('facebook'));
  984.         }
  985.         if($this->requestUtil->issetField('linkedin')){
  986.             $this->user->setLinkedin($this->requestUtil->getField('linkedin'));
  987.         }
  988.         if($this->requestUtil->issetField('youtube')){
  989.             $this->user->setYoutube($this->requestUtil->getField('youtube'));
  990.         }
  991.         if($this->requestUtil->issetField('instagram')){
  992.             $this->user->setInstagram($this->requestUtil->getField('instagram'));
  993.         }
  994.         if($this->requestUtil->issetField('tiktok')){
  995.             $this->user->setTiktok($this->requestUtil->getField('tiktok'));
  996.         }
  997.         $errors $this->validateEntity($this->user);
  998.         if($errors){
  999.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1000.         }
  1001.         if($filePhoto){
  1002.             $filePhoto $this->fileService->setFile($filePhoto);
  1003.             if($filePhoto){
  1004.                 $this->fileService->moveFile(UserEnum::PATH_PROFILES);
  1005.                 $this->user->setPhoto($this->fileService->getFileName());
  1006.             }
  1007.         }
  1008.         if($fileCover){
  1009.             $fileCover $this->fileService->setFile($fileCover);
  1010.             if($fileCover){
  1011.                 $this->fileService->moveFile(UserEnum::PATH_COVERS_PROFILE);
  1012.                 $this->user->setCover($this->fileService->getFileName());
  1013.             }
  1014.         }
  1015.         if($this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  1016.             $customField json_decode($this->user->getCustomField());
  1017.             if($customField){
  1018.                 foreach ($customField as $key => $field) {
  1019.                     if(!empty($field->fieldId)){
  1020.                         if(isset($files[$field->fieldId])){
  1021.                             $file $files[$field->fieldId];
  1022.                             if(
  1023.                                 $field->type == UserCustomFieldEnum::FIELD_FILE 
  1024.                                 && $file->getError() == UserCustomFieldEnum::NO
  1025.                             ){
  1026.                                 $file $this->fileService->setFile($file);
  1027.                                 if($file){
  1028.                                     $this->fileService->moveFile(
  1029.                                         UserEnum::PATH_OTHERS_PROFILES
  1030.                                     );
  1031.                                     $filePath $this->fileService->getFileName();
  1032.                                     $extension $this->fileService->getFileExtension();
  1033.                                     if(!empty($field->value)){
  1034.                                         $field->value->path $filePath;
  1035.                                         $field->value->extension $extension;
  1036.                                     }
  1037.                                     $customField->{$key} = $field;
  1038.                                 }
  1039.                             }
  1040.                         }
  1041.                     }
  1042.                 }
  1043.                 
  1044.                 $customField json_encode($customField);
  1045.                 $this->user->setCustomField($customField);
  1046.             }
  1047.         }
  1048.         $this->em->flush();
  1049.         $this->repository->sendWebhook($this->user);
  1050.         $crmService $this->generalService->getService('CRM\\CrmService');
  1051.         $crmService->savePerson($this->user);
  1052.         
  1053.         $data $this->user->toReturn();
  1054.         $this->userLogService->logUpdate("user"$this->user->getId(), $data);
  1055.         return $this->eadResponse($data);
  1056.     }
  1057.     /**
  1058.      * @Route(
  1059.      *      path          = "/admin/user/edit/lesson/config",
  1060.      *      name          = "userEditLessonConfig",
  1061.      *      methods       = {"PUT"}
  1062.      * )
  1063.      */
  1064.     public function userEditLessonConfig(Request $request) {
  1065.         if (!$this->user) {
  1066.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1067.         }
  1068.         $this->requestUtil->setRequest($request)->setData();
  1069.         if($this->requestUtil->issetField('screenSize')){
  1070.             $this->user->setScreenSize((int)$this->requestUtil->getField('screenSize'));
  1071.         }
  1072.         if($this->requestUtil->issetField('autoplay')){
  1073.             $this->user->setAutoplay((int)$this->requestUtil->getField('autoplay'));
  1074.         }
  1075.         $errors $this->validateEntity($this->user);
  1076.         if($errors){
  1077.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1078.         }
  1079.         $this->em->flush();
  1080.         
  1081.         $data $this->user->toReturn();
  1082.         $this->userLogService->logUpdate("user"$this->user->getId(), $data);
  1083.         return $this->eadResponse([ "success" => ]);
  1084.     }
  1085.     /**
  1086.      * @Route(
  1087.      *      path          = "/admin/user/edit/payment/config",
  1088.      *      name          = "userEditPaymentConfig",
  1089.      *      methods       = {"PUT"}
  1090.      * )
  1091.      */
  1092.     public function userEditPaymentConfig(Request $request) {
  1093.         if (!$this->user) {
  1094.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1095.         }
  1096.         $this->requestUtil->setRequest($request)->setData();
  1097.         if($this->requestUtil->issetField('allowOneClickBuy')){
  1098.             $this->user->setAllowOneClickBuy(
  1099.                 (int)$this->requestUtil->getField('allowOneClickBuy')
  1100.             );
  1101.         }
  1102.         $errors $this->validateEntity($this->user);
  1103.         if($errors){
  1104.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1105.         }
  1106.         $this->em->flush();
  1107.         
  1108.         $data $this->user->toReturn();
  1109.         $this->userLogService->logUpdate("user"$this->user->getId(), $data);
  1110.         return $this->eadResponse([ "success" => ]);
  1111.     }
  1112.     /**
  1113.      * @Route(
  1114.      *      path          = "/admin/user/edit/info/{id}",
  1115.      *      name          = "userEditInfo",
  1116.      *      methods       = {"PUT"},
  1117.      *      requirements  = { "id" = "\d+" }
  1118.      * )
  1119.      */
  1120.     public function editUserInfo(Request $request) {
  1121.         $userId $request->get('id');
  1122.         $user $this->repository->findOneBy([
  1123.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1124.             "id" => $userId
  1125.         ]);
  1126.     
  1127.         if (!$user) {
  1128.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1129.         }
  1130.         if($userId != $this->user->getId()){
  1131.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1132.             if(!$this->userPermissionUtil->isHigh($permission)){
  1133.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1134.             }
  1135.         }
  1136.         $emailService $this->generalService->getService('EmailService');
  1137.         $emailService->setToEmail($user->getEmail());
  1138.         $emailService->setToName($user->getName());
  1139.         $this->requestUtil->setRequest($request)->setData();
  1140.         $userProfileSave $user->getUserProfile();
  1141.         $userOldStatus $user->getOldStatus();
  1142.         $userTypeSave $user->getType();
  1143.         $userAllowReceiverSave $user->getAllowReceiver();
  1144.         if($this->requestUtil->issetField('email'))
  1145.         {
  1146.             if($user->getEmail() != $this->requestUtil->getField('email'))
  1147.             {
  1148.                 $totalEmail $this->repository->countByEmail($this->requestUtil->getField('email'));
  1149.                 if(!empty($totalEmail))
  1150.                 {
  1151.                     return $this->eadResponse([ 'email' ], ErrorEnum::FIELD_EMPTY);
  1152.                 }
  1153.                 $user->setEmail(strtolower($this->requestUtil->getField('email')));
  1154.                 $user->setValidEmail(UserEnum::UNKNOWN);
  1155.             }
  1156.         }
  1157.         if($this->requestUtil->issetField('name')){
  1158.             $user->setName($this->requestUtil->getField('name'));
  1159.         }
  1160.         if($this->requestUtil->issetField('username')){
  1161.             if($user->getUsername() != $this->requestUtil->getField('username'))
  1162.             {
  1163.                 $totalUsername $this->repository->countByUsername(
  1164.                     $this->requestUtil->getField('username')
  1165.                 );
  1166.                 
  1167.                 if(!empty($totalUsername))
  1168.                 {
  1169.                     return $this->eadResponse([ 'username' ], ErrorEnum::FIELD_EMPTY);
  1170.                 }
  1171.                 $user->setUsername($this->requestUtil->getField('username'));
  1172.             }
  1173.         }
  1174.         if($this->requestUtil->issetField('teacherSpotlight')){
  1175.             $user->setTeacherSpotlight((int)$this->requestUtil->getField('teacherSpotlight'));
  1176.             $this->em->getRepository(Configuration::class)->resetTeacherNumber();
  1177.         }
  1178.         $updatePassword false;
  1179.         $password "******";
  1180.         if($this->requestUtil->issetField('password')){
  1181.             $newPassword $this->requestUtil->getField('password');
  1182.             if(
  1183.                 $user->getPassword() != $newPassword && 
  1184.                 $user->getPassword() != md5($newPassword)
  1185.             ){
  1186.                 $oldPassword $user->getPassword();
  1187.                 $user->setPassword($newPassword);
  1188.                 $oldPass $user->getOldPassword(true);
  1189.                 if(in_array($user->getPassword(), $oldPass)){
  1190.                     return $this->eadResponse([ 
  1191.                         "message" => "Nova senha precisa ser diferente da anterior!"
  1192.                     ], ErrorEnum::ACTION_INVALID);
  1193.                 }
  1194.                 $updatePassword true;
  1195.                 if($oldPassword != UserEnum::PASSWORD_RESET){
  1196.                     $user->setOldPassword($oldPassword);
  1197.                 }
  1198.             }
  1199.         }
  1200.         if($this->requestUtil->issetField('allowReceiver')){
  1201.             $user->setAllowReceiver((int)$this->requestUtil->getField('allowReceiver'));
  1202.         }
  1203.         
  1204.         if($this->requestUtil->issetField('document')){
  1205.             $user->setDocument($this->requestUtil->getField('document'));
  1206.         }
  1207.         if($this->requestUtil->issetField('birthDate')){
  1208.             $user->setBirthDate($this->requestUtil->getField('birthDate'));
  1209.         }
  1210.         if($this->requestUtil->issetField('phone')){
  1211.             $user->setPhone($this->requestUtil->getField('phone'));
  1212.         }
  1213.         if($this->requestUtil->issetField('userProfile')){
  1214.             $userProfileId $this->requestUtil->getField('userProfile');
  1215.             $maxAllowID $this->user->getUserProfile()->getId();
  1216.             $saveAllowID $user->getUserProfile()->getId();
  1217.             $allowEditPermissions = (
  1218.                 $maxAllowID == $saveAllowID ||
  1219.                 $maxAllowID == UserEnum::ADMIN || 
  1220.                 $saveAllowID == UserEnum::STUDENT
  1221.             );
  1222.             if($saveAllowID == UserEnum::ADMIN){
  1223.                 $allowEditPermissions = ($maxAllowID == $saveAllowID);
  1224.             }else if($saveAllowID == UserEnum::TEACHER){
  1225.                 $allowEditPermissions = ($maxAllowID == UserEnum::ADMIN);
  1226.             }else if($saveAllowID == UserEnum::TUTOR){
  1227.                 $allowEditPermissions = (
  1228.                     $maxAllowID == UserEnum::TEACHER || $maxAllowID == UserEnum::ADMIN
  1229.                 );
  1230.             }
  1231.             if($userProfileSave->getId() != $userProfileId && $allowEditPermissions){
  1232.                 $allowPermissions = [
  1233.                     $maxAllowID,
  1234.                     UserEnum::STUDENT
  1235.                 ];
  1236.                 
  1237.                 if($maxAllowID == UserEnum::ADMIN){
  1238.                     $allowPermissions[] = UserEnum::TUTOR;
  1239.                     $allowPermissions[] = UserEnum::TEACHER;
  1240.                     $allowPermissions[] = $userProfileId;
  1241.                 }else if($maxAllowID == UserEnum::TEACHER){
  1242.                     $allowPermissions[] = UserEnum::TUTOR;
  1243.                 }
  1244.                 $permission $this->userPermissionUtil->getPermission("user""permissions");
  1245.                 if(!$this->userPermissionUtil->isHigh($permission)){
  1246.                     if(!in_array($userProfileId$allowPermissions)){
  1247.                         $userProfileId null;
  1248.                     }
  1249.                 }
  1250.                 $userProfile $this->em->getRepository(UserProfile::class)->findOneBy([
  1251.                     "id" => $userProfileId,
  1252.                     "deleted" => UserEnum::ITEM_NO_DELETED
  1253.                 ]);
  1254.                 $user->setUserProfile($userProfile);
  1255.                 
  1256.                 if($userProfile){
  1257.                     $user->setPermission($userProfile->getPermission());
  1258.                 }
  1259.             }
  1260.         }
  1261.         if($this->requestUtil->issetField('type')){
  1262.             $type = (int)$this->requestUtil->getField('type');
  1263.             $user->setType($type);
  1264.             if($userTypeSave == UserEnum::ADMIN && $userTypeSave != $type){
  1265.                 $adminsNumber $this->repository->countAdmins();
  1266.                 if($adminsNumber 1){
  1267.                     $user->setType(null);
  1268.                 }
  1269.             }
  1270.         }
  1271.         if($this->requestUtil->issetField('status')){
  1272.             $user->setStatus((int)$this->requestUtil->getField('status'));
  1273.             if($user->getStatus() == UserEnum::ACTIVE){
  1274.                 $user->setConfirmationDate(date('Y-m-d H:i:s'));
  1275.             }
  1276.         }
  1277.         if($this->requestUtil->issetField('validEmail')){
  1278.             $user->setValidEmail($this->requestUtil->getField('validEmail'));
  1279.         }        
  1280.         if($user->getUserProfile()){
  1281.             $types = [
  1282.                 UserEnum::STUDENT,
  1283.                 UserEnum::TUTOR,
  1284.                 UserEnum::TEACHER,
  1285.                 UserEnum::ADMIN,
  1286.             ];
  1287.             if(in_array($user->getUserProfile()->getId(), $types)){
  1288.                 $user->setType($user->getUserProfile()->getId());
  1289.             }
  1290.         }
  1291.         $errors $this->validateEntity($user);
  1292.         if($errors){
  1293.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1294.         }
  1295.         if($updatePassword){
  1296.             $this->em->getRepository(Session::class)->resetSessions($user);
  1297.             if(
  1298.                 $emailService->checkUserToSend($userfalse) ||
  1299.                 $this->configuration->get("allow_send_email_user") == UserEnum::YES
  1300.             ){
  1301.                 $subText $this->configuration->getLanguage(
  1302.                     'change_password.subject''email'
  1303.                 );
  1304.                 $subject "{$subText} - {$this->client->getBrand()}";
  1305.                 $emailService->setSubject($subject);
  1306.                 $emailService->setData([
  1307.                     "userName" => $user->getName(),
  1308.                     "btnLink" => "https://{$this->client->getDomainPrimary()}/profile",
  1309.                 ]);
  1310.                 $emailService->setTemplateBody("change_password");
  1311.                 $emailService->send();
  1312.             }
  1313.         }
  1314.         $this->em->flush();
  1315.         $crmService $this->generalService->getService('CRM\\CrmService');
  1316.         $crmService->savePerson($user);
  1317.         $marketingService $this->generalService->getService(
  1318.             'Marketing\\MarketingService'
  1319.         );
  1320.         if($user->getStatus() == UserEnum::ACTIVE && $userOldStatus == UserEnum::WAITING){
  1321.             
  1322.             $marketingService->setTag(TagsMarketingEnum::TAG_CONFIRM_REGISTER);
  1323.             $marketingService->setUser($user);
  1324.             $marketingService->send();
  1325.         }
  1326.         $userPermission json_decode($user->getPermission());
  1327.         if($userAllowReceiverSave != $user->getAllowReceiver()){
  1328.             if($user->getAllowReceiver() == UserEnum::NO){
  1329.                 if(!isset($userPermission->financial)){
  1330.                     $userPermission->financial = (object)[];
  1331.                 }
  1332.                 if(!isset($userPermission->financial->receiver)){
  1333.                     $userPermission->financial->receiver = (object)[];
  1334.                 }
  1335.                 if(empty($userPermission->financial->receiver->see)){
  1336.                     $userPermission->financial->receiver->see UserPermissionEnum::LOW;
  1337.                 }
  1338.                 if(empty($userPermission->financial->receiver->enable)){
  1339.                     $userPermission->financial->receiver->enable UserPermissionEnum::LOW;
  1340.                 }
  1341.                 if(empty($userPermission->financial->receiver->disable)){
  1342.                     $userPermission->financial->receiver->disable UserPermissionEnum::LOW;
  1343.                 }
  1344.                 if(empty($userPermission->financial->receiver->create)){
  1345.                     $userPermission->financial->receiver->create UserPermissionEnum::LOW;
  1346.                 }
  1347.                 if(empty($userPermission->financial->receiver->edit)){
  1348.                     $userPermission->financial->receiver->edit UserPermissionEnum::LOW;
  1349.                 }
  1350.                 if(empty($userPermission->financial->receiver->delete)){
  1351.                     $userPermission->financial->receiver->delete UserPermissionEnum::LOW;
  1352.                 }
  1353.                 $receiver $this->em->getRepository(Receiver::class)->findOneBy([ 
  1354.                     "user" => $user
  1355.                     "deleted" => UserEnum::ITEM_NO_DELETED 
  1356.                 ]);
  1357.                 if($receiver){
  1358.                     $receiver->setStatus(ReceiverEnum::INACTIVE);
  1359.                 }
  1360.             }else if($user->getAllowReceiver() == UserEnum::YES){
  1361.                 if(!isset($userPermission->financial)){
  1362.                     $userPermission->financial = (object)[];
  1363.                 }
  1364.                 if(!isset($userPermission->financial->receiver)){
  1365.                     $userPermission->financial->receiver = (object)[];
  1366.                 }
  1367.                 if(empty($userPermission->financial->receiver->see)){
  1368.                     $userPermission->financial->receiver->see UserPermissionEnum::MIDDLE;
  1369.                 }
  1370.                 if(empty($userPermission->financial->receiver->enable)){
  1371.                     $userPermission->financial->receiver->enable UserPermissionEnum::MIDDLE;
  1372.                 }
  1373.                 if(empty($userPermission->financial->receiver->disable)){
  1374.                     $userPermission->financial->receiver->disable UserPermissionEnum::MIDDLE;
  1375.                 }
  1376.                 if(empty($userPermission->financial->receiver->create)){
  1377.                     $userPermission->financial->receiver->create UserPermissionEnum::MIDDLE;
  1378.                 }
  1379.                 if(empty($userPermission->financial->receiver->edit)){
  1380.                     $userPermission->financial->receiver->edit UserPermissionEnum::MIDDLE;
  1381.                 }
  1382.                 if(empty($userPermission->financial->receiver->delete)){
  1383.                     $userPermission->financial->receiver->delete UserPermissionEnum::MIDDLE;
  1384.                 }
  1385.                 if($emailService->checkUserToSend($user)){
  1386.                     //send email allow receiver
  1387.                     $subText $this->configuration->getLanguage(
  1388.                         'receiver_register.subject''email'
  1389.                     );
  1390.                     $subject "{$subText} - {$this->client->getBrand()}";
  1391.                     $emailService->setSubject($subject);
  1392.                     $emailService->setData([
  1393.                         "userName" => $user->getName(),
  1394.                         "btnLink" => "https://{$this->client->getDomainPrimary()}/profile#table-receivers",
  1395.                     ]);
  1396.                     $emailService->setTemplateBody("receiver_register");
  1397.                     $emailService->send();
  1398.                 }
  1399.             }
  1400.         }
  1401.         $user->setPermission(json_encode($userPermission));
  1402.         $this->em->flush();
  1403.         $this->repository->sendWebhook($user);
  1404.         $data $user->toReturn();
  1405.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1406.         return $this->eadResponse($data);
  1407.     }
  1408.     /**
  1409.      * @Route(
  1410.      *      path          = "/admin/user/enable/authentication",
  1411.      *      name          = "userEnableAuthentication",
  1412.      *      methods       = {"PUT"}
  1413.      * )
  1414.      */
  1415.     public function userEnableAuthentication(Request $request) {
  1416.         if (!$this->user) {
  1417.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1418.         }
  1419.         $this->requestUtil->setRequest($request)->setData();
  1420.         $secretKey $this->requestUtil->getField('secretKey');
  1421.         $code $this->requestUtil->getField('code');
  1422.         $googleAuthenticatorService $this->generalService->getService('GoogleAuthenticatorService');
  1423.         $googleAuthenticatorService->setSecretKey($secretKey);
  1424.         $googleAuthenticatorService->setCode($code);
  1425.         $checkCode $googleAuthenticatorService->checkCodeAuthentication();
  1426.         $this->user->setAuthenticationSecretKey($secretKey);
  1427.         $this->user->setAuthenticationAllow(UserEnum::YES);
  1428.         $errors $this->validateEntity($this->user);
  1429.         if($errors){
  1430.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1431.         }
  1432.         if(!$checkCode){
  1433.             return $this->eadResponse($errorsErrorEnum::AUTH_INVALID);
  1434.         }
  1435.         $this->em->flush();
  1436.         
  1437.         $data $this->user->toReturn();
  1438.         $this->userLogService->logUpdate("user"$this->user->getId(), $data);
  1439.         return $this->eadResponse([ "success" => ]);
  1440.     }
  1441.     /**
  1442.      * @Route(
  1443.      *      path          = "/admin/user/disable/authentication",
  1444.      *      name          = "userDisableAuthentication",
  1445.      *      methods       = {"PUT"}
  1446.      * )
  1447.      */
  1448.     public function userDisableAuthentication(Request $request) {
  1449.         if (!$this->user) {
  1450.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1451.         }
  1452.         $this->requestUtil->setRequest($request)->setData();
  1453.         $this->user->setAuthenticationSecretKey(null);
  1454.         $this->user->setAuthenticationCodeEmail(null);
  1455.         $this->user->setAuthenticationEmailDateExpire(null);
  1456.         $this->user->setAuthenticationAllow(UserEnum::NO);
  1457.         $errors $this->validateEntity($this->user);
  1458.         if($errors){
  1459.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1460.         }
  1461.         $this->em->flush();
  1462.         
  1463.         $data $this->user->toReturn();
  1464.         $this->userLogService->logUpdate("user"$this->user->getId(), $data);
  1465.         return $this->eadResponse([ "success" => ]);
  1466.     }
  1467.     /**
  1468.      * @Route(
  1469.      *      path          = "/admin/user/edit/permission/{id}",
  1470.      *      name          = "userEditPermission",
  1471.      *      methods       = {"PUT"},
  1472.      *      requirements  = { "id" = "\d+" }
  1473.      * )
  1474.      */
  1475.     public function editUserPermission(Request $request) {
  1476.         if(!$this->configuration->checkModuleIsAbleOnPlan('permissionFunction')){
  1477.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  1478.         }
  1479.         
  1480.         $userId $request->get('id');
  1481.         $user $this->repository->findOneBy([
  1482.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1483.             "id" => $userId
  1484.         ]);
  1485.         if (!$user) {
  1486.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1487.         }
  1488.         $permission $this->userPermissionUtil->getPermission("user""permissions");
  1489.         if(!$this->userPermissionUtil->isHigh($permission)){
  1490.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  1491.         }
  1492.         $this->requestUtil->setRequest($request)->setData();
  1493.         if($this->requestUtil->issetField('permission')){
  1494.             $user->setPermission($this->requestUtil->getField('permission'));
  1495.         }
  1496.         
  1497.         $errors $this->validateEntity($user);
  1498.         if($errors){
  1499.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1500.         }
  1501.         $this->em->flush();
  1502.         $data $user->toReturn();
  1503.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1504.         return $this->eadResponse($data);
  1505.     }
  1506.     /**
  1507.      * @Route(
  1508.      *      path          = "/admin/user/edit/custom/{id}",
  1509.      *      name          = "userEditCustom",
  1510.      *      methods       = {"POST"},
  1511.      *      requirements  = { "id" = "\d+" }
  1512.      * )
  1513.      */
  1514.     public function editUserCustomFields(Request $request) {
  1515.         $userId $request->get('id');
  1516.         $user $this->repository->findOneBy([
  1517.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1518.             "id" => $userId
  1519.         ]);
  1520.         if (!$user) {
  1521.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1522.         }
  1523.         if($userId != $this->user->getId()){
  1524.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1525.             if(!$this->userPermissionUtil->isHigh($permission)){
  1526.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1527.             }
  1528.         }
  1529.         $this->requestUtil->setRequest($request)->setData();
  1530.         $files $this->requestUtil->getFile('file');
  1531.         if($this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  1532.             if($this->requestUtil->issetField('customField')){
  1533.                 $user->setCustomField($this->requestUtil->getField('customField'));
  1534.             }
  1535.         }
  1536.         if($this->requestUtil->issetField('occupation')){
  1537.             $user->setOccupation($this->requestUtil->getField('occupation'));
  1538.         }
  1539.         if($this->requestUtil->issetField('biography')){
  1540.             $user->setBiography($this->requestUtil->getField('biography'));
  1541.         }
  1542.         if($this->requestUtil->issetField('resume')){
  1543.             $user->setResume($this->requestUtil->getField('resume'));
  1544.         }
  1545.         if($this->requestUtil->issetField('custom')){
  1546.             $user->setCustom($this->requestUtil->getField('custom'));
  1547.         }
  1548.         if($this->requestUtil->issetField('notes')){
  1549.             $user->setNotes($this->requestUtil->getField('notes'));
  1550.         }
  1551.         
  1552.         $errors $this->validateEntity($user);
  1553.         if($errors){
  1554.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1555.         }
  1556.         if($this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  1557.             $customField json_decode($user->getCustomField());
  1558.             if($customField){
  1559.                 foreach ($customField as $key => $field) {
  1560.                     if(!empty($field->fieldId)){
  1561.                         if(isset($files[$field->fieldId])){
  1562.                             $file $files[$field->fieldId];
  1563.                             if(
  1564.                                 $field->type == UserCustomFieldEnum::FIELD_FILE && 
  1565.                                 $file->getError() == UserCustomFieldEnum::NO
  1566.                             ){
  1567.                                 $file $this->fileService->setFile($file);
  1568.                                 if($file){
  1569.                                     $this->fileService->moveFile(
  1570.                                         UserEnum::PATH_OTHERS_PROFILES
  1571.                                     );
  1572.                                     $filePath $this->fileService->getFileName();
  1573.                                     $extension $this->fileService->getFileExtension();
  1574.                                     if(!empty($field->value)){
  1575.                                         $field->value->path $filePath;
  1576.                                         $field->value->extension $extension;
  1577.                                     }
  1578.                                     $customField->{$key} = $field;
  1579.                                 }
  1580.                             }
  1581.                         }
  1582.                     }
  1583.                 }
  1584.                 $customField json_encode($customField);
  1585.                 $user->setCustomField($customField);
  1586.             }
  1587.         }
  1588.         $this->em->flush();
  1589.         $this->repository->sendWebhook($user);
  1590.         $data $user->toReturn();
  1591.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1592.         return $this->eadResponse($data);
  1593.     }
  1594.     /**
  1595.      * @Route(
  1596.      *      path          = "/admin/user/edit/address/{id}",
  1597.      *      name          = "userEditAddress",
  1598.      *      methods       = {"PUT"},
  1599.      *      requirements  = { "id" = "\d+" }
  1600.      * )
  1601.      */
  1602.     public function editUserAddress(Request $request) {
  1603.         $userId $request->get('id');
  1604.         $user $this->repository->findOneBy([
  1605.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1606.             "id" => $userId
  1607.         ]);
  1608.         if (!$user) {
  1609.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1610.         }
  1611.         if($userId != $this->user->getId()){
  1612.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1613.             if(!$this->userPermissionUtil->isHigh($permission)){
  1614.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1615.             }
  1616.         }
  1617.         $this->requestUtil->setRequest($request)->setData();
  1618.         if($this->requestUtil->issetField('country')){
  1619.             $countryId $this->requestUtil->getField('country');
  1620.             $country $this->em->getRepository(Country::class)->findOneBy([
  1621.                 "id" => $countryId,
  1622.                 "deleted" => UserEnum::ITEM_NO_DELETED
  1623.             ]);
  1624.             $user->setCountry($country);
  1625.         }
  1626.         if($this->requestUtil->issetField('state')){
  1627.             $stateId $this->requestUtil->getField('state');
  1628.             $state $this->em->getRepository(State::class)->findOneBy([
  1629.                 "id" => $stateId,
  1630.                 "deleted" => UserEnum::ITEM_NO_DELETED
  1631.             ]);
  1632.             $user->setState($state);
  1633.         }
  1634.         if($this->requestUtil->issetField('city')){
  1635.             $cityId $this->requestUtil->getField('city');
  1636.             $city $this->em->getRepository(City::class)->findOneBy([
  1637.                 "id" => $cityId,
  1638.                 "deleted" => UserEnum::ITEM_NO_DELETED
  1639.             ]);
  1640.             $user->setCity($city);
  1641.         }
  1642.         if($this->requestUtil->issetField('zipCode')){
  1643.             $user->setZipCode($this->requestUtil->getField('zipCode'));
  1644.         }
  1645.         if($this->requestUtil->issetField('address')){
  1646.             $user->setAddress($this->requestUtil->getField('address'));
  1647.         }
  1648.         if($this->requestUtil->issetField('addressNumber')){
  1649.             $user->setAddressNumber($this->requestUtil->getField('addressNumber'));
  1650.         }
  1651.         if($this->requestUtil->issetField('addressComplement')){
  1652.             $user->setAddressComplement($this->requestUtil->getField('addressComplement'));
  1653.         }
  1654.         if($this->requestUtil->issetField('addressNeighborhood')){
  1655.             $user->setAddressNeighborhood(
  1656.                 $this->requestUtil->getField('addressNeighborhood')
  1657.             );
  1658.         }
  1659.         
  1660.         $errors $this->validateEntity($user);
  1661.         if($errors){
  1662.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1663.         }
  1664.         $this->em->flush();
  1665.         $this->repository->sendWebhook($user);
  1666.         $data $user->toReturn();
  1667.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1668.         return $this->eadResponse($data);
  1669.     }
  1670.     /**
  1671.      * @Route(
  1672.      *      path          = "/admin/user/edit/social/{id}",
  1673.      *      name          = "userEditSocial",
  1674.      *      methods       = {"PUT"},
  1675.      *      requirements  = { "id" = "\d+" }
  1676.      * )
  1677.      */
  1678.     public function editUserSocial(Request $request) {
  1679.         $userId $request->get('id');
  1680.         $user $this->repository->findOneBy([
  1681.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1682.             "id" => $userId
  1683.         ]);
  1684.         if (!$user) {
  1685.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1686.         }
  1687.         if($userId != $this->user->getId()){
  1688.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1689.             if(!$this->userPermissionUtil->isHigh($permission)){
  1690.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1691.             }
  1692.         }
  1693.         $this->requestUtil->setRequest($request)->setData();
  1694.         if($this->requestUtil->issetField('website')){
  1695.             $user->setWebsite($this->requestUtil->getField('website'));
  1696.         }
  1697.         if($this->requestUtil->issetField('twitter')){
  1698.             $user->setTwitter($this->requestUtil->getField('twitter'));
  1699.         }
  1700.         if($this->requestUtil->issetField('facebook')){
  1701.             $user->setFacebook($this->requestUtil->getField('facebook'));
  1702.         }
  1703.         if($this->requestUtil->issetField('linkedin')){
  1704.             $user->setLinkedin($this->requestUtil->getField('linkedin'));
  1705.         }
  1706.         if($this->requestUtil->issetField('youtube')){
  1707.             $user->setYoutube($this->requestUtil->getField('youtube'));
  1708.         }
  1709.         if($this->requestUtil->issetField('instagram')){
  1710.             $user->setInstagram($this->requestUtil->getField('instagram'));
  1711.         }
  1712.         if($this->requestUtil->issetField('tiktok')){
  1713.             $this->user->setTiktok($this->requestUtil->getField('tiktok'));
  1714.         }
  1715.         
  1716.         $errors $this->validateEntity($user);
  1717.         if($errors){
  1718.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1719.         }
  1720.         $this->em->flush();
  1721.         $this->repository->sendWebhook($user);
  1722.         $data $user->toReturn();
  1723.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1724.         return $this->eadResponse($data);
  1725.     }
  1726.     /**
  1727.      * @Route(
  1728.      *      path          = "/admin/user/edit/theme/{id}",
  1729.      *      name          = "userEditTheme",
  1730.      *      methods       = {"POST"},
  1731.      *      requirements  = { "id" = "\d+" }
  1732.      * )
  1733.      */
  1734.     public function editUserTheme(Request $request) {
  1735.         $userId $request->get('id');
  1736.         $user $this->repository->findOneBy([
  1737.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1738.             "id" => $userId
  1739.         ]);
  1740.         if (!$user) {
  1741.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1742.         }
  1743.         if($userId != $this->user->getId()){
  1744.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1745.             if(!$this->userPermissionUtil->isHigh($permission)){
  1746.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1747.             }
  1748.         }
  1749.         $this->requestUtil->setRequest($request)->setData();
  1750.         $filePhoto $this->requestUtil->getFile('photo');
  1751.         $fileCover $this->requestUtil->getFile('cover');
  1752.         if($filePhoto){
  1753.             if($filePhoto->getSize() > UserEnum::MAX_SIZE_USER_IMAGES){
  1754.                 return $this->eadResponse([ 
  1755.                     "message" => "Photo Size"
  1756.                 ], ErrorEnum::ACTION_INVALID);
  1757.             }
  1758.             $filePhoto $this->fileService->setFile($filePhoto);
  1759.             if($filePhoto){
  1760.                 $this->fileService->moveFile(UserEnum::PATH_PROFILES);
  1761.                 $user->setPhoto($this->fileService->getFileName());
  1762.             }
  1763.         }
  1764.         if($fileCover){
  1765.             if($fileCover->getSize() > UserEnum::MAX_SIZE_USER_IMAGES){
  1766.                 return $this->eadResponse([ 
  1767.                     "message" => "Cover Size"
  1768.                 ], ErrorEnum::ACTION_INVALID);
  1769.             }
  1770.             $fileCover $this->fileService->setFile($fileCover);
  1771.             if($fileCover){
  1772.                 $this->fileService->moveFile(UserEnum::PATH_COVERS_PROFILE);
  1773.                 $user->setCover($this->fileService->getFileName());
  1774.             }
  1775.         }
  1776.         $errors $this->validateEntity($user);
  1777.         if($errors){
  1778.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  1779.         }
  1780.         
  1781.         $this->em->flush();
  1782.         $data $user->toReturn();
  1783.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1784.         return $this->eadResponse($data);
  1785.     }
  1786.     /**
  1787.      * @Route(
  1788.      *      path          = "/admin/user/edit/notification/{id}",
  1789.      *      name          = "userEditNotification",
  1790.      *      methods       = {"PUT"},
  1791.      *      requirements  = { "id" = "\d+" }
  1792.      * )
  1793.      */
  1794.     public function editUserNotification(Request $request) {
  1795.         $userId $request->get('id');
  1796.         $user $this->repository->findOneBy([
  1797.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1798.             "id" => $userId
  1799.         ]);
  1800.         if (!$user) {
  1801.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1802.         }
  1803.         if($userId != $this->user->getId()){
  1804.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1805.             if(!$this->userPermissionUtil->isHigh($permission)){
  1806.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1807.             }
  1808.         }
  1809.         $this->requestUtil->setRequest($request)->setData();
  1810.         if($this->requestUtil->issetField('allowNotifyNewLesson')){
  1811.             $user->setAllowNotifyNewLesson($this->requestUtil->getField('allowNotifyNewLesson'));
  1812.         }
  1813.         if($this->requestUtil->issetField('allowNotifyNewExam')){
  1814.             $user->setAllowNotifyNewExam(
  1815.                 $this->requestUtil->getField('allowNotifyNewExam')
  1816.             );
  1817.         }
  1818.         if($this->requestUtil->issetField('allowNotifyNewSupportMessage')){
  1819.             $user->setAllowNotifyNewSupportMessage(
  1820.                 $this->requestUtil->getField('allowNotifyNewSupportMessage')
  1821.             );
  1822.         }
  1823.         if($this->requestUtil->issetField('allowNotifyNewSupportAnswer')){
  1824.             $user->setAllowNotifyNewSupportAnswer(
  1825.                 $this->requestUtil->getField('allowNotifyNewSupportAnswer')
  1826.             );
  1827.         }
  1828.         if($this->requestUtil->issetField('allowNotifyNewMessage')){
  1829.             $user->setAllowNotifyNewMessage(
  1830.                 $this->requestUtil->getField('allowNotifyNewMessage')
  1831.             );
  1832.         }
  1833.         if($this->requestUtil->issetField('allowNotifyNewGroupMessage')){
  1834.             $user->setAllowNotifyNewGroupMessage(
  1835.                 $this->requestUtil->getField('allowNotifyNewGroupMessage')
  1836.             );
  1837.         }
  1838.         if($this->requestUtil->issetField('allowNotifyCart')){
  1839.             $user->setAllowNotifyCart($this->requestUtil->getField('allowNotifyCart'));
  1840.         }
  1841.         $this->em->flush();
  1842.         $data $user->toReturn();
  1843.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1844.         return $this->eadResponse($data);
  1845.     }
  1846.     /**
  1847.      * @Route(
  1848.      *      path          = "/admin/user/edit/status/email/{id}",
  1849.      *      name          = "userEditStatusEmail",
  1850.      *      methods       = {"PUT"},
  1851.      *      requirements  = { "id" = "\d+" }
  1852.      * )
  1853.      */
  1854.     public function editUserStatusEmail(Request $request) {
  1855.         $userId $request->get('id');
  1856.         $user $this->repository->findOneBy([
  1857.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1858.             "id" => $userId
  1859.         ]);
  1860.         if (!$user) {
  1861.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1862.         }
  1863.         if($userId != $this->user->getId()){
  1864.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1865.             if(!$this->userPermissionUtil->isHigh($permission)){
  1866.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1867.             }
  1868.         }
  1869.         $this->requestUtil->setRequest($request)->setData();
  1870.         if($this->requestUtil->issetField('validEmail')){
  1871.             $user->setValidEmail($this->requestUtil->getField('validEmail'));
  1872.         }
  1873.         $this->em->flush();
  1874.         $data $user->toReturn();
  1875.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1876.         return $this->eadResponse($data);
  1877.     }
  1878.     /**
  1879.      * @Route(
  1880.      *      path          = "/admin/user/edit/many/status/email",
  1881.      *      name          = "userEditManyStatusEmail",
  1882.      *      methods       = {"PUT"}
  1883.      * )
  1884.      */
  1885.     public function editManyUserStatusEmail(Request $request) {
  1886.         $permission $this->userPermissionUtil->getPermission("user""edit");
  1887.         $this->requestUtil->setRequest($request)->setData();
  1888.         $userId $this->requestUtil->getField('users');
  1889.         if(empty($userId)){
  1890.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  1891.         };
  1892.         $userId json_decode($userId);
  1893.         foreach ($userId as $key => $id) {
  1894.             $user $this->repository->findOneBy([
  1895.                 "id" => $id,
  1896.                 "deleted" => UserEnum::ITEM_NO_DELETED
  1897.             ]);
  1898.             if($user) {
  1899.                 if($this->userPermissionUtil->isHigh($permission)){
  1900.                     if($this->requestUtil->issetField('validEmail')){
  1901.                         $user->setValidEmail((int)$this->requestUtil->getField('validEmail'));
  1902.                     }
  1903.                     $errors $this->validateEntity($user);
  1904.                     if(!$errors){
  1905.                         $this->em->flush();
  1906.                     
  1907.                         $data $user->toReturn();
  1908.                         $this->userLogService->logUpdate(
  1909.                             "user"
  1910.                             $user->getId(), 
  1911.                             $data
  1912.                         );
  1913.                     }
  1914.                 }
  1915.             }
  1916.         }
  1917.         return $this->eadResponse([ "message" => "Success" ]);
  1918.     }
  1919.     /**
  1920.      * @Route(
  1921.      *      path          = "/admin/user/delete/custom/file/{id}/{fieldId}",
  1922.      *      name          = "userDeleteCustomFile",
  1923.      *      methods       = {"DELETE"},
  1924.      *      requirements  = { "id" = "\d+", "fieldId" = "\d+" }
  1925.      * )
  1926.      */
  1927.     public function deleteCustomFieldFile(Request $request) {
  1928.         if(!$this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  1929.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  1930.         }
  1931.         
  1932.         $userId $request->get('id');
  1933.         $user $this->repository->findOneBy([
  1934.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1935.             "id" => $userId
  1936.         ]);
  1937.         if (!$user) {
  1938.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1939.         }
  1940.         if($userId != $this->user->getId()){
  1941.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1942.             if(!$this->userPermissionUtil->isHigh($permission)){
  1943.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1944.             }
  1945.         }
  1946.         $fieldId $request->get('fieldId');
  1947.         $fields json_decode($user->getCustomField());
  1948.         
  1949.         if(!empty($fields->{$fieldId})){
  1950.             if(!empty($fields->{$fieldId}->value)){
  1951.                 $file $fields->{$fieldId}->value->path;
  1952.                 $pathComplete $this->fileService->getFilePathComplete(
  1953.                     $file
  1954.                     UserEnum::PATH_OTHERS_PROFILES
  1955.                 );
  1956.                 $this->fileService->setFile($pathComplete);
  1957.                 $this->fileService->deleteFile();
  1958.                 $fields->{$fieldId}->value null;
  1959.             }
  1960.             //unset($fields->{$fieldId});
  1961.             $user->setCustomField(json_encode($fields));
  1962.         }
  1963.         $this->em->flush();
  1964.         $data $user->toReturn();
  1965.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  1966.         return $this->eadResponse([ "success" => ]);
  1967.     }
  1968.     /**
  1969.      * @Route(
  1970.      *      path          = "/admin/user/delete/cover/{id}",
  1971.      *      name          = "userDeleteCover",
  1972.      *      methods       = {"DELETE"},
  1973.      *      requirements  = { "id" = "\d+" }
  1974.      * )
  1975.      */
  1976.     public function deleteUserCover(Request $request) {
  1977.         $userId $request->get('id');
  1978.         $user $this->repository->findOneBy([
  1979.             "deleted" => UserEnum::ITEM_NO_DELETED,
  1980.             "id" => $userId
  1981.         ]);
  1982.         if (!$user) {
  1983.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  1984.         }
  1985.         if($userId != $this->user->getId()){
  1986.             $permission $this->userPermissionUtil->getPermission("user""edit");
  1987.             if(!$this->userPermissionUtil->isHigh($permission)){
  1988.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  1989.             }
  1990.         }
  1991.         
  1992.         if($user->getCover()){
  1993.             $pathComplete $this->fileService->getFilePathComplete(
  1994.                 $user->getCover(), 
  1995.                 UserEnum::PATH_COVERS_PROFILE
  1996.             );
  1997.             $this->fileService->setFile($pathComplete);
  1998.             $this->fileService->deleteFile();
  1999.             $user->setCover(null);
  2000.         }
  2001.         $this->em->flush();
  2002.         $return $user->toReturn();
  2003.         $this->userLogService->logUpdate("user"$user->getId(), $return);
  2004.         return $this->eadResponse($return);
  2005.     }
  2006.     /**
  2007.      * @Route(
  2008.      *      path          = "/admin/user/delete/photo/{id}",
  2009.      *      name          = "userDeletePhoto",
  2010.      *      methods       = {"DELETE"},
  2011.      *      requirements  = { "id" = "\d+" }
  2012.      * )
  2013.      */
  2014.     public function deleteUserPhoto(Request $request) {
  2015.         $userId $request->get('id');
  2016.         $user $this->repository->findOneBy([
  2017.             "deleted" => UserEnum::ITEM_NO_DELETED,
  2018.             "id" => $userId
  2019.         ]);
  2020.         if (!$user) {
  2021.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2022.         }
  2023.         if($userId != $this->user->getId()){
  2024.             $permission $this->userPermissionUtil->getPermission("user""edit");
  2025.             if(!$this->userPermissionUtil->isHigh($permission)){
  2026.                 return $this->eadResponse(nullErrorEnum::PERMISSION);
  2027.             }
  2028.         }
  2029.         
  2030.         if($user->getPhoto()){
  2031.             $pathComplete $this->fileService->getFilePathComplete(
  2032.                 $user->getPhoto(), 
  2033.                 UserEnum::PATH_PROFILES
  2034.             );
  2035.             
  2036.             $this->fileService->setFile($pathComplete);
  2037.             $this->fileService->deleteFile();
  2038.             $user->setPhoto(null);
  2039.         }
  2040.         $this->em->flush();
  2041.         $data $user->toReturn();
  2042.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  2043.         return $this->eadResponse($data);
  2044.     }
  2045.     /**
  2046.      * @Route(
  2047.      *      path          = "/admin/user/recover/data",
  2048.      *      name          = "getDataToRecover",
  2049.      *      methods       = {"GET"}
  2050.      * )
  2051.      */
  2052.     public function getDataToRecover(Request $request) {
  2053.         $permission $this->userPermissionUtil->getPermission("user""recover");
  2054.         if(!$this->userPermissionUtil->isHigh($permission)){
  2055.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2056.         }
  2057.         $data = [
  2058.             "notConfirmNumber" => $this->repository->countNotConfirmed(),
  2059.             "confirmationSendNumber" => $this->repository->countRecoverSendToday(),
  2060.             "recoverNumber" => $this->repository->countRecoverToday(),
  2061.         ];
  2062.         return $this->eadResponse($data);
  2063.     }
  2064.     /**
  2065.      * @Route(
  2066.      *      path          = "/admin/user/recover",
  2067.      *      name          = "userRecover",
  2068.      *      methods       = {"GET"}
  2069.      * )
  2070.      */
  2071.     public function recoverUser(Request $request) {
  2072.         $permission $this->userPermissionUtil->getPermission("user""recover");
  2073.         if(!$this->userPermissionUtil->isHigh($permission)){
  2074.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2075.         }
  2076.         $user $this->repository->getUserToRecover();
  2077.         if(!$user){
  2078.             return $this->eadResponse([ "continue" => false ], ErrorEnum::NOT_FOUND);
  2079.         }
  2080.         if($user->getRecoverAttempt() >= 4){
  2081.             return $this->eadResponse([ "continue" => false ], ErrorEnum::ACTION_INVALID);
  2082.         }
  2083.         $emailService $this->generalService->getService('EmailService');
  2084.         $password "******";
  2085.         if($user->getInvited() == UserEnum::YES){
  2086.             $password $this->stringUtil->randomText(6);
  2087.             $user->setPassword($password);
  2088.             $user->setOldPassword($user->getPassword());
  2089.         }
  2090.         $user->setRecoverDate(date('Y-m-d'));
  2091.         $send false;
  2092.         if(
  2093.             $emailService->checkUserToSend($userfalse) ||
  2094.             $this->configuration->get("allow_send_email_user") == UserEnum::YES
  2095.         ){
  2096.             $emailService->setToEmail($user->getEmail());
  2097.             $emailService->setToName($user->getName());
  2098.             $subText $this->configuration->getLanguage('recover_user.subject''email');
  2099.             $subject "{$subText} - {$this->client->getBrand()}";
  2100.             $emailService->setSubject($subject);
  2101.             
  2102.             $domain $this->client->getDomainPrimary();
  2103.             $emailService->setData([
  2104.                 "userName" => $user->getName(),
  2105.                 "invited" => $user->getInvited(),
  2106.                 "userDateRegister" => $user->getDateRegister(),
  2107.                 "userEmail" => $user->getEmail(),
  2108.                 "userPassword" => $password,
  2109.                 "btnConfirm" => "https://{$domain}/confirm/{$user->getHashIdentify()}",
  2110.                 "btnDelete" => "https://{$domain}/stopEmail/{$user->getHashIdentify()}",
  2111.             ]);
  2112.             $emailService->setTemplateBody("recover_user");
  2113.             $send $emailService->send();
  2114.         }
  2115.         if($send){
  2116.             $user->setRecoverAttempt($user->getRecoverAttempt() + 1);
  2117.         }
  2118.         $this->em->flush();
  2119.         return $this->eadResponse([
  2120.             "continue" => true,
  2121.             "send" => $send,
  2122.             "email" => $user->getEmail(),
  2123.             "dateRecover" => date('Y-m-d'),
  2124.         ]);
  2125.     }
  2126.     /**
  2127.      * @Route(
  2128.      *      path          = "/admin/user/send/confirmation/{id}",
  2129.      *      name          = "userConfirm",
  2130.      *      methods       = {"GET"},
  2131.      *      requirements  = { "id" = "\d+" }
  2132.      * )
  2133.      */
  2134.     public function sendUserConfirmation(Request $request) {
  2135.         $permission $this->userPermissionUtil->getPermission(
  2136.             "user"
  2137.             "send_confirmation"
  2138.         );
  2139.         if(!$this->userPermissionUtil->isHigh($permission)){
  2140.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2141.         }
  2142.         $send null;
  2143.         $userId $request->get('id');
  2144.         $user $this->repository->findOneBy([
  2145.             "id" => $userId,
  2146.             "deleted" => UserEnum::ITEM_NO_DELETED
  2147.         ]);
  2148.         if(!$user){
  2149.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2150.         }
  2151.         $emailService $this->generalService->getService('EmailService');
  2152.         $password "******";
  2153.         if($user->getInvited() == UserEnum::YES){
  2154.             $password $this->stringUtil->randomText(6);
  2155.             $user->setPassword($password);
  2156.             $user->setOldPassword($user->getPassword());
  2157.         }
  2158.         if(
  2159.             $emailService->checkUserToSend($userfalse) ||
  2160.             $this->configuration->get("allow_send_email_user") == UserEnum::YES
  2161.         ){
  2162.             $emailService->setToEmail($user->getEmail());
  2163.             $emailService->setToName($user->getName());
  2164.             $subText $this->configuration->getLanguage('user_confirmation.subject''email');
  2165.             $subject "{$subText} - {$this->client->getBrand()}";
  2166.             $emailService->setSubject($subject);
  2167.             
  2168.             $domain $this->client->getDomainPrimary();
  2169.             $emailService->setData([
  2170.                 "userName" => $user->getName(),
  2171.                 "userEmail" => $user->getEmail(),
  2172.                 "invited" => $user->getInvited(),
  2173.                 "userDateRegister" => $user->getDateRegister("d/m/Y"),
  2174.                 "userPassword" => $password,
  2175.                 "btnLink" => "https://{$domain}/confirm/{$user->getHashIdentify()}",
  2176.                 "isCart" => UserEnum::NO
  2177.             ]);
  2178.             $emailService->setTemplateBody("user_confirmation");
  2179.             $send $emailService->send();
  2180.         }
  2181.         $this->em->flush();
  2182.         return $this->eadResponse([ "send" => $send ]);
  2183.     }
  2184.     /**
  2185.      * @Route(
  2186.      *      path          = "/admin/user/login/{id}",
  2187.      *      name          = "userLogin",
  2188.      *      methods       = {"GET"},
  2189.      *      requirements  = { "id" = "\d+" }
  2190.      * )
  2191.      */
  2192.     public function loginUser(Request $request) {
  2193.         $permission $this->userPermissionUtil->getPermission("user""login");
  2194.         if(!$this->userPermissionUtil->isHigh($permission)){
  2195.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2196.         }
  2197.         $userId $request->get('id');
  2198.         $user $this->repository->findOneBy([
  2199.             "id" => $userId,
  2200.             "deleted" => UserEnum::ITEM_NO_DELETED
  2201.         ]);
  2202.         if (!$user) {
  2203.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2204.         }
  2205.         if($user->getStatus() == UserEnum::INACTIVE){
  2206.             return $this->eadResponse([ 
  2207.                 "message" => "User Inactive" 
  2208.             ], ErrorEnum::ACTION_INVALID);
  2209.         }
  2210.         if($user->getStatus() == UserEnum::BLOCK){
  2211.             return $this->eadResponse([ 
  2212.                 "message" => "User Blocked" 
  2213.             ], ErrorEnum::ACTION_INVALID);
  2214.         }
  2215.         $maxAllowID $this->user->getUserProfile()->getId();
  2216.         $allowPermissions = [
  2217.             UserEnum::STUDENT
  2218.         ];
  2219.         $userProfileId $user->getUserProfile()->getId();
  2220.         
  2221.         if($maxAllowID == UserEnum::ADMIN && $userProfileId != UserEnum::ADMIN){
  2222.             $allowPermissions[] = $userProfileId;
  2223.         }else if($maxAllowID == UserEnum::TEACHER){
  2224.             $allowPermissions[] = UserEnum::TUTOR;
  2225.         }
  2226.         if(!in_array($userProfileId$allowPermissions) && $this->user->getId() != UserEnum::YES){
  2227.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2228.         }
  2229.         $session = new Session();
  2230.         $ipApi $this->generalService->getService('IpApiService');
  2231.         $ipApi->setRequest($request);
  2232.         
  2233.         $userAgent $request->headers->get('User-Agent');
  2234.         $session->setUser($user);
  2235.         $session->setIp($ipApi->getIp());
  2236.         $session->setIspName($ipApi->getIsp());
  2237.         $session->setCoordinate($ipApi->getCoordinate());
  2238.         $session->setTimeZone($ipApi->getTimeZone());
  2239.         $session->setCity($ipApi->getCity());
  2240.         $session->setState($ipApi->getState());
  2241.         $session->setCountry($ipApi->getCountry());
  2242.         $session->setIsAdmin(UserEnum::YES);
  2243.         $session->setUserOrigin($this->user);
  2244.         $session->setUserAgent($userAgent);
  2245.         
  2246.         $errors $this->validateEntity($session);
  2247.         
  2248.         if($errors){
  2249.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  2250.         }
  2251.         $this->configuration->alertLogin(
  2252.             (string)$user->getEmail(),
  2253.             (string)'LOGOU PELO ADMIN',
  2254.             (string)$this->clientConfig->getId(),
  2255.             (
  2256.                 in_array($request->getHost(), ConfigurationEnum::DOMAIN_DEV) ? 
  2257.                 ConfigurationEnum::IP_LOCAL 
  2258.                 $request->getClientIp()
  2259.             ),
  2260.             $userAgent,
  2261.             $request->getHost(),
  2262.             $user->getId(),
  2263.             $this->user
  2264.         );
  2265.         //$this->sessionSym->set('session', $session);
  2266.         //$this->em->getRepository(Cart::class)->updateCartHashToUser($user);
  2267.         $time time() + (24 60 60);
  2268.         $this->generalService->setCookie('sessiontoken'$session->getToken(), $time);
  2269.         $this->em->persist($session);
  2270.         $this->em->flush();
  2271.         $crmService $this->generalService->getService('CRM\\CrmService');
  2272.         $crmService->savePerson($user);
  2273.         return $this->eadResponse([ 
  2274.             "token" => $session->getToken(), 
  2275.             "userId" => $userId 
  2276.         ]);
  2277.     }
  2278.     /**
  2279.      * @Route(
  2280.      *      path          = "/admin/user/block/{id}",
  2281.      *      name          = "userBlock",
  2282.      *      methods       = {"PUT"},
  2283.      *      requirements  = { "id" = "\d+" }
  2284.      * )
  2285.      */
  2286.     public function blockUser(Request $request) {
  2287.         $permission $this->userPermissionUtil->getPermission("user""block");
  2288.         if(!$this->userPermissionUtil->isHigh($permission)){
  2289.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2290.         }
  2291.         $userId $request->get('id');
  2292.         $user $this->repository->findOneBy([
  2293.             "id" => $userId,
  2294.             "deleted" => UserEnum::ITEM_NO_DELETED
  2295.         ]);
  2296.         if (!$user) {
  2297.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2298.         }
  2299.         $user->setStatus(UserEnum::BLOCK);
  2300.         $sessions $this->em->getRepository(Session::class)->findBy([ 
  2301.             "user" => $user
  2302.             "deleted" => UserEnum::ITEM_NO_DELETED 
  2303.         ]);
  2304.         foreach ($sessions as $key => $session) {
  2305.             $session->delete();
  2306.         }
  2307.         $receivers $this->em->getRepository(Receiver::class)->findBy([ 
  2308.             "user" => $user
  2309.             "deleted" => UserEnum::ITEM_NO_DELETED 
  2310.         ]);
  2311.         foreach ($receivers as $key => $receiver) {
  2312.             $receiver->setStatus(ReceiverEnum::INACTIVE);
  2313.         }
  2314.         $errors $this->validateEntity($user);
  2315.         if($errors){
  2316.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  2317.         }
  2318.         
  2319.         $this->em->flush();
  2320.         $this->repository->sendWebhook($user);
  2321.         $data $user->toReturn();
  2322.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  2323.         return $this->eadResponse($data);
  2324.     }
  2325.     /**
  2326.      * @Route(
  2327.      *      path          = "/admin/user/block/many",
  2328.      *      name          = "userBlockMany",
  2329.      *      methods       = {"PUT"}
  2330.      * )
  2331.      */
  2332.     public function blockUserMany(Request $request) {
  2333.         $permission $this->userPermissionUtil->getPermission("user""block");
  2334.         if(!$this->userPermissionUtil->isHigh($permission)){
  2335.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2336.         }
  2337.         $this->requestUtil->setRequest($request)->setData();
  2338.         $userId $this->requestUtil->getField('ids');
  2339.         if(empty($userId)){
  2340.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  2341.         };
  2342.         $userId json_decode($userId);
  2343.         foreach ($userId as $key => $id) {
  2344.             $user $this->repository->findOneBy([
  2345.                 "id" => $id,
  2346.                 "deleted" => UserEnum::ITEM_NO_DELETED
  2347.             ]);
  2348.         
  2349.             if($user) {
  2350.                 $user->setStatus(UserEnum::BLOCK);
  2351.                 $sessions $this->em->getRepository(Session::class)->findBy([ 
  2352.                     "user" => $user
  2353.                     "deleted" => UserEnum::ITEM_NO_DELETED 
  2354.                 ]);
  2355.         
  2356.                 foreach ($sessions as $key => $session) {
  2357.                     $session->delete();
  2358.                 }
  2359.         
  2360.                 $receivers $this->em->getRepository(Receiver::class)->findBy([ 
  2361.                     "user" => $user
  2362.                     "deleted" => UserEnum::ITEM_NO_DELETED 
  2363.                 ]);
  2364.         
  2365.                 foreach ($receivers as $key => $receiver) {
  2366.                     $receiver->setStatus(ReceiverEnum::INACTIVE);
  2367.                 }
  2368.                 $errors $this->validateEntity($user);
  2369.                 if(!$errors){
  2370.                     $this->em->flush();
  2371.                     $this->repository->sendWebhook($user);
  2372.                 
  2373.                     $data $user->toReturn();
  2374.                     $this->userLogService->logUpdate(
  2375.                         "user"
  2376.                         $user->getId(), 
  2377.                         $data
  2378.                     );
  2379.                 }
  2380.             }
  2381.         }
  2382.         return $this->eadResponse([ "message" => "Success" ]);
  2383.     }
  2384.     
  2385.     /**
  2386.      * @Route(
  2387.      *      path          = "/admin/user/unblock/{id}",
  2388.      *      name          = "userUnblock",
  2389.      *      methods       = {"PUT"},
  2390.      *      requirements  = { "id" = "\d+" }
  2391.      * )
  2392.      */
  2393.     public function unblockUser(Request $request) {
  2394.         $permission $this->userPermissionUtil->getPermission("user""unblock");
  2395.         if(!$this->userPermissionUtil->isHigh($permission)){
  2396.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2397.         }
  2398.         $userId $request->get('id');
  2399.         $user $this->repository->findOneBy([
  2400.             "id" => $userId,
  2401.             "deleted" => UserEnum::ITEM_NO_DELETED
  2402.         ]);
  2403.         
  2404.         if (!$user) {
  2405.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2406.         }
  2407.         $userOldStatus $user->getOldStatus();
  2408.         $user->setStatus($userOldStatus);
  2409.         $errors $this->validateEntity($user);
  2410.         if($errors){
  2411.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  2412.         }
  2413.         
  2414.         $this->em->flush();
  2415.         $this->repository->sendWebhook($user);
  2416.         $data $user->toReturn();
  2417.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  2418.         return $this->eadResponse($data);
  2419.     }
  2420.     /**
  2421.      * @Route(
  2422.      *      path          = "/admin/user/unblock/many",
  2423.      *      name          = "userUnblockMany",
  2424.      *      methods       = {"PUT"}
  2425.      * )
  2426.      */
  2427.     public function unblockUserMany(Request $request) {
  2428.         $permission $this->userPermissionUtil->getPermission("user""unblock");
  2429.         if(!$this->userPermissionUtil->isHigh($permission)){
  2430.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2431.         }
  2432.         $this->requestUtil->setRequest($request)->setData();
  2433.         $userId $this->requestUtil->getField('ids');
  2434.         if(empty($userId)){
  2435.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  2436.         };
  2437.         $userId json_decode($userId);
  2438.         foreach ($userId as $key => $id) {
  2439.             $user $this->repository->findOneBy([
  2440.                 "id" => $id,
  2441.                 "deleted" => UserEnum::ITEM_NO_DELETED
  2442.             ]);
  2443.         
  2444.             if($user) {
  2445.                 $userOldStatus $user->getOldStatus();
  2446.                 $user->setStatus($userOldStatus);
  2447.                 $errors $this->validateEntity($user);
  2448.                 if(!$errors){
  2449.                     $this->em->flush();
  2450.                     $this->repository->sendWebhook($user);
  2451.                 
  2452.                     $data $user->toReturn();
  2453.                     $this->userLogService->logUpdate(
  2454.                         "user"
  2455.                         $user->getId(), 
  2456.                         $data
  2457.                     );
  2458.                 }
  2459.             }
  2460.         }
  2461.         return $this->eadResponse([ "message" => "Success" ]);
  2462.     }
  2463.     /**
  2464.      * @Route(
  2465.      *      path          = "/admin/user/activate/{id}",
  2466.      *      name          = "userActivate",
  2467.      *      methods       = {"PUT"},
  2468.      *      requirements  = { "id" = "\d+" }
  2469.      * )
  2470.      */
  2471.     public function activateUser(Request $request) {
  2472.         $permission $this->userPermissionUtil->getPermission("user""enable");
  2473.         if(!$this->userPermissionUtil->isHigh($permission)){
  2474.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2475.         }
  2476.         $this->requestUtil->setRequest($request)->setData();
  2477.         $userId $request->get('id');
  2478.         $user $this->repository->findOneBy([
  2479.             "id" => $userId,
  2480.             "deleted" => UserEnum::ITEM_NO_DELETED
  2481.         ]);
  2482.         
  2483.         if (!$user) {
  2484.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2485.         }
  2486.         if($user->getStatus() == UserEnum::BLOCK){
  2487.             return $this->eadResponse([ 
  2488.                 "message" => "Action invalid" 
  2489.             ], ErrorEnum::ACTION_INVALID);
  2490.         }
  2491.         if($user->getStatus() == UserEnum::INACTIVE){
  2492.             $userOldStatus $user->getOldStatus();
  2493.             $user->setStatus($userOldStatus);
  2494.         }else{
  2495.             $user->setStatus(UserEnum::ACTIVE);
  2496.         }
  2497.         
  2498.         $errors $this->validateEntity($user);
  2499.         if($errors){
  2500.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  2501.         }
  2502.         
  2503.         $this->em->flush();
  2504.         $this->repository->sendWebhook($user);
  2505.         $data $user->toReturn();
  2506.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  2507.         return $this->eadResponse($data);
  2508.     }
  2509.     /**
  2510.      * @Route(
  2511.      *      path          = "/admin/user/activate/many",
  2512.      *      name          = "userActivateMany",
  2513.      *      methods       = {"PUT"}
  2514.      * )
  2515.      */
  2516.     public function activateUserMany(Request $request) {
  2517.         $permission $this->userPermissionUtil->getPermission("user""enable");
  2518.         if(!$this->userPermissionUtil->isHigh($permission)){
  2519.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2520.         }
  2521.         $this->requestUtil->setRequest($request)->setData();
  2522.         $userId $this->requestUtil->getField('ids');
  2523.         if(empty($userId)){
  2524.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  2525.         };
  2526.         $userId json_decode($userId);
  2527.         foreach ($userId as $key => $id) {
  2528.             $user $this->repository->findOneBy([
  2529.                 "id" => $id,
  2530.                 "deleted" => UserEnum::ITEM_NO_DELETED
  2531.             ]);
  2532.         
  2533.             if($user) {
  2534.                 if($user->getStatus() != UserEnum::BLOCK){
  2535.                     if($user->getStatus() == UserEnum::INACTIVE){
  2536.                         $userOldStatus $user->getOldStatus();
  2537.                         $user->setStatus($userOldStatus);
  2538.                     }else{
  2539.                         $user->setStatus(UserEnum::ACTIVE);
  2540.                     }
  2541.                 }
  2542.                 $errors $this->validateEntity($user);
  2543.                 if(!$errors){
  2544.                     $this->em->flush();
  2545.                     $this->repository->sendWebhook($user);
  2546.                 
  2547.                     $data $user->toReturn();
  2548.                     $this->userLogService->logUpdate(
  2549.                         "user"
  2550.                         $user->getId(), 
  2551.                         $data
  2552.                     );
  2553.                 }
  2554.             }
  2555.         }
  2556.         return $this->eadResponse([ "message" => "Success" ]);
  2557.     }
  2558.     /**
  2559.      * @Route(
  2560.      *      path          = "/admin/user/disable/{id}",
  2561.      *      name          = "userDisable",
  2562.      *      methods       = {"PUT"},
  2563.      *      requirements  = { "id" = "\d+" }
  2564.      * )
  2565.      */
  2566.     public function disableUser(Request $request) {
  2567.         $permission $this->userPermissionUtil->getPermission("user""disable");
  2568.         if(!$this->userPermissionUtil->isHigh($permission)){
  2569.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2570.         }
  2571.         $this->requestUtil->setRequest($request)->setData();
  2572.         $userId $request->get('id');
  2573.         $user $this->repository->findOneBy([
  2574.             "id" => $userId,
  2575.             "deleted" => UserEnum::ITEM_NO_DELETED
  2576.         ]);
  2577.         
  2578.         if (!$user) {
  2579.             return $this->eadResponse(nullErrorEnum::NOT_FOUND);
  2580.         }
  2581.         if($user->getStatus() == UserEnum::BLOCK){
  2582.             return $this->eadResponse([ 
  2583.                 "message" => "Action invalid" 
  2584.             ], ErrorEnum::ACTION_INVALID);
  2585.         }
  2586.         $user->setStatus(UserEnum::INACTIVE);
  2587.         $errors $this->validateEntity($user);
  2588.         if($errors){
  2589.             return $this->eadResponse($errorsErrorEnum::FIELD_EMPTY);
  2590.         }
  2591.         
  2592.         $this->em->flush();
  2593.         $this->repository->sendWebhook($user);
  2594.         $data $user->toReturn();
  2595.         $this->userLogService->logUpdate("user"$user->getId(), $data);
  2596.         return $this->eadResponse($data);
  2597.     }
  2598.     /**
  2599.      * @Route(
  2600.      *      path          = "/admin/user/disable/many",
  2601.      *      name          = "userDisableMany",
  2602.      *      methods       = {"PUT"}
  2603.      * )
  2604.      */
  2605.     public function disableUserMany(Request $request) {
  2606.         $permission $this->userPermissionUtil->getPermission("user""disable");
  2607.         if(!$this->userPermissionUtil->isHigh($permission)){
  2608.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2609.         }
  2610.         $this->requestUtil->setRequest($request)->setData();
  2611.         $userId $this->requestUtil->getField('ids');
  2612.         if(empty($userId)){
  2613.             return $this->eadResponse(nullErrorEnum::ACTION_INVALID);
  2614.         };
  2615.         $userId json_decode($userId);
  2616.         foreach ($userId as $key => $id) {
  2617.             $user $this->repository->findOneBy([
  2618.                 "id" => $id,
  2619.                 "deleted" => UserEnum::ITEM_NO_DELETED
  2620.             ]);
  2621.         
  2622.             if($user) {
  2623.                 if($user->getStatus() != UserEnum::BLOCK){
  2624.                     $user->setStatus(UserEnum::INACTIVE);
  2625.                 }
  2626.                 $errors $this->validateEntity($user);
  2627.                 if(!$errors){
  2628.                     $this->em->flush();
  2629.                     $this->repository->sendWebhook($user);
  2630.                 
  2631.                     $data $user->toReturn();
  2632.                     $this->userLogService->logUpdate(
  2633.                         "user"
  2634.                         $user->getId(), 
  2635.                         $data
  2636.                     );
  2637.                 }
  2638.             }
  2639.         }
  2640.         return $this->eadResponse([ "message" => "Success" ]);
  2641.     }
  2642.     /**
  2643.      * @Route(
  2644.      *      path          = "/admin/user/import",
  2645.      *      name          = "userImport",
  2646.      *      methods       = {"POST"},
  2647.      * )
  2648.      */
  2649.     public function importUser(Request $request) {
  2650.         $permission $this->userPermissionUtil->getPermission("user""import");
  2651.         if(!$this->userPermissionUtil->isHigh($permission)){
  2652.             return $this->eadResponse(nullErrorEnum::PERMISSION);
  2653.         }
  2654.         $this->requestUtil->setRequest($request)->setData();
  2655.         $file $this->requestUtil->getFile('file');
  2656.         if(empty($file)){
  2657.             return $this->eadResponse([ "file" ], ErrorEnum::FIELD_EMPTY);
  2658.         }
  2659.         $spreadSheetUtil $this->generalService->getUtil('SpreadSheetUtil');
  2660.         $data $spreadSheetUtil->import($file);
  2661.         $groupsValidation = [];
  2662.         $userProfileRepository $this->em->getRepository(UserProfile::class);
  2663.         $groupRepository $this->em->getRepository(Group::class);
  2664.         
  2665.         $groupId $this->requestUtil->getField('group');
  2666.         
  2667.         $groupRepository $this->em->getRepository(Group::class);
  2668.         $group null;
  2669.         if($groupId 0){
  2670.             $group $groupRepository->findOneBy([
  2671.                 "id" => $groupId,
  2672.                 "deleted" => UserEnum::ITEM_NO_DELETED
  2673.             ]);
  2674.         }
  2675.         $allowPermissions = [
  2676.             UserEnum::STUDENT
  2677.         ];
  2678.         $permission $this->userPermissionUtil->getPermission("user""permissions");
  2679.         if($this->userPermissionUtil->isHigh($permission)){
  2680.             $maxAllowID $this->user->getUserProfile()->getId();
  2681.             $allowPermissions[] = $maxAllowID;
  2682.             if($maxAllowID == UserEnum::ADMIN){
  2683.                 $allowPermissions[] = UserEnum::TUTOR;
  2684.                 $allowPermissions[] = UserEnum::TEACHER;
  2685.             }else if($maxAllowID == UserEnum::TEACHER){
  2686.                 $allowPermissions[] = UserEnum::TUTOR;
  2687.             }
  2688.         }
  2689.         foreach ($data as $key => $value) {
  2690.             $name trim($value['A']);
  2691.             $document = !empty($value['G']) ? trim($value['G']) : null;
  2692.             $email trim($value['B']);
  2693.             $password trim($value['F']);
  2694.             $custom = !empty($value['C']) ? trim($value['C']) : null;
  2695.             $notes = !empty($value['D']) ? trim($value['D']) : null;
  2696.             $userProfileId = !empty($value['E']) ? (int)$value['E'] : null;
  2697.             if(!in_array($userProfileId$allowPermissions)){
  2698.                 $userProfileId null;
  2699.             }
  2700.             if(!empty($name) && !empty($email)){
  2701.                 $dataUser = [
  2702.                     "name" => $name,
  2703.                     "document" => $document,
  2704.                     "email" => $email,
  2705.                     "password" => $password,
  2706.                     "custom" => $custom,
  2707.                     "notes" => $notes,
  2708.                     "userProfileId" => $userProfileId,
  2709.                     "groupId" => $groupId,
  2710.                     "notify" => UserEnum::YES,
  2711.                     "invited" => UserEnum::YES
  2712.                 ];
  2713.                 $userDTO = new UserDTO($dataUser);
  2714.                 $user $this->repository->findOneBy([
  2715.                     "email" => $email
  2716.                 ], [ "id" => "DESC" ]);
  2717.                 if(!$user || $user->isDeleted()){
  2718.                     $data $this->repository->newUser($userDTO);
  2719.                     if($data->user){
  2720.                         $user $data->user;
  2721.                     }
  2722.                 }
  2723.                 if($group && $user){
  2724.                     $user->addGroup($group);
  2725.                     $groupRepository->enrollOneUser($group$user);
  2726.                     $clientDomain $this->configuration->getActiveDomain(true);
  2727.                     $subText $this->configuration->getLanguage(
  2728.                         'user_in_group.subject1''email'
  2729.                     );
  2730.                     $subText2 $this->configuration->getLanguage(
  2731.                         'user_in_group.subject2''email'
  2732.                     );
  2733.                     $emailTitle $subText $group->getName() . $subText2;
  2734.                     $emailService $this->generalService->getService('EmailService');
  2735.                     if($emailService->checkUserToSend($user)){
  2736.                         $emailService->setToEmail($user->getEmail());
  2737.                         $emailService->setToName($user->getName());
  2738.                         $emailService->setSubject($emailTitle);
  2739.                         $emailService->setData([
  2740.                             "userName" => $user->getName(),
  2741.                             "btnLink" => "https:{$clientDomain}",
  2742.                             "groupName" => $group->getName()
  2743.                         ]);
  2744.                         $emailService->setTemplateBody("user_in_group");
  2745.                         $emailService->send();
  2746.                     }
  2747.                 }  
  2748.             }
  2749.         }
  2750.         $this->em->flush();
  2751.         return $this->eadResponse([ "message" => "Successfully imported!" ]);
  2752.     }
  2753. }