src/Controller/Website/UserController.php line 126

Open in your IDE?
  1. <?php
  2. namespace EADPlataforma\Controller\Website;
  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\Country;
  8. use EADPlataforma\Entity\UserCard;
  9. use EADPlataforma\Entity\UserCustomField;
  10. use EADPlataforma\Entity\UserCheckoutInfo;
  11. use EADPlataforma\Entity\CourseCertificate;
  12. use EADPlataforma\Entity\Enrollment;
  13. use EADPlataforma\Entity\Forum;
  14. use EADPlataforma\Entity\LikeControl;
  15. use EADPlataforma\Entity\Receiver;
  16. use EADPlataforma\Enum\ReceiverEnum;
  17. use EADPlataforma\Enum\ForumEnum;
  18. use EADPlataforma\Enum\LikeControlEnum;
  19. use EADPlataforma\Enum\UserEnum;
  20. use EADPlataforma\Enum\GeoDataEnum;
  21. use EADPlataforma\Enum\UserCardEnum;
  22. use EADPlataforma\Enum\UserCustomFieldEnum;
  23. use EADPlataforma\Enum\UserCheckoutInfoEnum;
  24. use EADPlataforma\Enum\CourseCertificateEnum;
  25. use EADPlataforma\Enum\EnrollmentEnum;
  26. /**
  27.  * @Route(
  28.  *      schemes         = {"http|https"}
  29.  * )
  30.  * @Cache(
  31.  *      maxage          = "0",
  32.  *      smaxage         = "0",
  33.  *      expires         = "now",
  34.  *      public          = false
  35.  * )
  36.  */
  37. class UserController extends AbstractWebsiteController {
  38.     /**
  39.      * @Route(
  40.      *      path          = "/profile/",
  41.      *      name          = "userProfile",
  42.      *      methods       = {"GET"}
  43.      * )
  44.      */
  45.     public function getUserProfile(Request $request) {
  46.         $this->checkUserSession($request);
  47.         $cardTotal $this->em->getRepository(UserCard::class)->count([
  48.             "user" => $this->user->getId(),
  49.             "deleted" => UserCardEnum::ITEM_NO_DELETED
  50.         ]);
  51.         $userCheckoutTotal $this->em->getRepository(UserCheckoutInfo::class)->count([
  52.             "user" => $this->user->getId(),
  53.             "deleted" => UserCheckoutInfoEnum::ITEM_NO_DELETED
  54.         ]);
  55.         $fields = [];
  56.         if($this->configuration->checkModuleIsAbleOnPlan('customFormModule')){
  57.             $fields $this->em->getRepository(UserCustomField::class)->findBy([
  58.                 "deleted" => UserCustomFieldEnum::ITEM_NO_DELETED,
  59.                 "status" => UserCustomFieldEnum::PUBLISHED,
  60.             ],
  61.             [ "order" => "ASC" ]);
  62.             $fieldsValues json_decode($this->user->getCustomField());
  63.             foreach ($fields as $key => $field) {
  64.                 
  65.                 $field->value null;
  66.                 $field->optionsObj null;
  67.                 
  68.                 $options $field->getOptions();
  69.                 if(!empty($options)){
  70.                     $field->optionsObj json_decode($options);
  71.                 }
  72.                 if(!empty($fieldsValues->{$field->getId()})){
  73.                     $objSave $fieldsValues->{$field->getId()};
  74.                     if(!empty($objSave->value)){
  75.                         $field->value $objSave->value;
  76.                     }
  77.                 }
  78.                 if($field->getType() == UserCustomFieldEnum::FIELD_MULTIPLE){
  79.                     foreach ($field->optionsObj as $keyOp => $option) {
  80.                         $option->checked false;
  81.                         if(!empty($field->value)){
  82.                             foreach ($field->value as $keyVal => $valueOp) {
  83.                                 if($option->value == $valueOp){
  84.                                     $option->checked true;
  85.                                 }
  86.                             }
  87.                         }
  88.                         $field->optionsObj[$keyOp] = $option;
  89.                     }
  90.                 }
  91.                 $fields[$key] = $field;
  92.             }
  93.         }
  94.         $receiverRepository $this->em->getRepository(Receiver::class);
  95.         $pagarMeBankAccount $this->generalService->getService(
  96.             'PagarMe\\PagarMeBankAccount'
  97.         );
  98.         $banks $pagarMeBankAccount->getBanks();
  99.         $banksData = [];
  100.         foreach ($banks as $key => $bank) {
  101.             $banksData[] = (object)[
  102.                 "id" => (string)$key,
  103.                 "name" => $bank
  104.             ];
  105.         }
  106.         if($this->user){
  107.             $googleAuthenticatorService $this->generalService->getService('GoogleAuthenticatorService');
  108.             $googleAuthenticatorService->setEmail($this->user->getEmail());
  109.             $dataAuthentication $googleAuthenticatorService->generateQrCodeAuthentication();
  110.             $this->data['secretKey'] = $dataAuthentication['secretKey'];
  111.             $this->data['qrCode'] = $dataAuthentication['qrCode'];
  112.         }
  113.         $this->data['banksData'] = $banksData;
  114.         
  115.         $this->data['totalReceiver'] = $receiverRepository->countByType(
  116.             ReceiverEnum::EAD_CHECKOUT
  117.             $this->user->getId()
  118.         );
  119.         $this->data['cardTotal'] = $cardTotal;
  120.         $this->data['userCheckoutTotal'] = $userCheckoutTotal;
  121.         $this->data['fields'] = $fields;
  122.         return $this->renderEAD('user/profile/user-profile-board.html.twig');
  123.     }
  124.     /**
  125.      * @Route(
  126.      *      path          = "/p/{username}",
  127.      *      name          = "userProfilePublic",
  128.      *      methods       = {"GET"}
  129.      * )
  130.      */
  131.     public function getUserProfilePublic(Request $request) {
  132.         $this->checkUserSession($request);
  133.         
  134.         $username $request->get('username');
  135.         $userRepository $this->em->getRepository(User::class);
  136.         $user $userRepository->findOneBy([
  137.             "deleted" => UserEnum::ITEM_NO_DELETED,
  138.             "username" => $username,
  139.         ]);
  140.         if(!$user){
  141.             return $this->redirectToRoute('notFound');
  142.         }
  143.         $forumRepository $this->em->getRepository(Forum::class);
  144.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  145.         $likeControlRepository $this->em->getRepository(LikeControl::class);
  146.         $certificateRepository $this->em->getRepository(CourseCertificate::class);
  147.         $enrollments $enrollmentRepository->getResumeEnrollment(
  148.             $user->getId()
  149.         );
  150.         $totalCoursesCompleted $enrollmentRepository->countResumeEnrollment(
  151.             $user->getId(), 
  152.             [ EnrollmentEnum::SITUATION_COMPLETED ]
  153.         );
  154.         $lastCertificate $certificateRepository->findOneBy(
  155.             [
  156.                 "user" => $user->getId(),
  157.                 "deleted" => CourseCertificateEnum::ITEM_NO_DELETED,
  158.             ], 
  159.             [ "id" => "DESC"]
  160.         );
  161.         
  162.         $totalForum $forumRepository->count([
  163.             "user" => $user->getId(),
  164.             "forum" => null,
  165.             "deleted" => ForumEnum::ITEM_NO_DELETED,
  166.         ]);
  167.         
  168.         $totalLike $likeControlRepository->count([
  169.             "userFrom" => $user->getId(),
  170.         ]);
  171.         $this->data['pUser'] = $user;
  172.         $this->data['enrollments'] = $enrollments;
  173.         $this->data['lastCertificate'] = $lastCertificate;
  174.         $this->data['totalCoursesCompleted'] = $totalCoursesCompleted;
  175.         $this->data['totalForum'] = $totalForum;
  176.         $this->data['totalLike'] = $totalLike;
  177.         return $this->renderEAD('user/profile/user-profile.html.twig');
  178.     }
  179.     /**
  180.      * @Route(
  181.      *      path          = "/p/{userId}/courses",
  182.      *      name          = "userProfileCourses",
  183.      *      methods       = {"GET"}
  184.      * )
  185.      */
  186.     public function getUserProfileCourses(Request $request) {
  187.         $userId $request->get('userId');
  188.         $userRepository $this->em->getRepository(User::class);
  189.         $user $userRepository->findOneBy([
  190.             "deleted" => UserEnum::ITEM_NO_DELETED,
  191.             "id" => $userId,
  192.         ]);
  193.         if(!$user){
  194.             return $this->redirectToRoute('notFound');
  195.         }
  196.         $enrollmentRepository $this->em->getRepository(Enrollment::class);
  197.         $enrollments $enrollmentRepository->getResumeEnrollment(
  198.             $this->user->getId(),
  199.             [],
  200.             null,
  201.             null,
  202.             null,
  203.             null,
  204.             2
  205.         );
  206.         $this->data['enrollments'] = $enrollments;
  207.         return $this->renderEAD('user/profile/user-profile-courses.html.twig');
  208.     }
  209. }