| Conditions | 81 |
| Total Lines | 841 |
| Code Lines | 544 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 553 | public function getPersonalDataToJson($userId, array $substitutionTerms) |
||
| 554 | { |
||
| 555 | $em = $this->getEntityManager(); |
||
| 556 | $dateFormat = \Datetime::ATOM; |
||
| 557 | |||
| 558 | /** @var User $user */ |
||
| 559 | $user = $this->find($userId); |
||
| 560 | |||
| 561 | $user->setPassword($substitutionTerms['password']); |
||
| 562 | $user->setSalt($substitutionTerms['salt']); |
||
| 563 | $noDataLabel = $substitutionTerms['empty']; |
||
| 564 | |||
| 565 | // Dummy content |
||
| 566 | $user->setDateOfBirth(null); |
||
| 567 | //$user->setBiography($noDataLabel); |
||
| 568 | $user->setFacebookData($noDataLabel); |
||
| 569 | $user->setFacebookName($noDataLabel); |
||
| 570 | $user->setFacebookUid($noDataLabel); |
||
| 571 | //$user->setImageName($noDataLabel); |
||
| 572 | //$user->setTwoStepVerificationCode($noDataLabel); |
||
| 573 | $user->setGender($noDataLabel); |
||
| 574 | $user->setGplusData($noDataLabel); |
||
| 575 | $user->setGplusName($noDataLabel); |
||
| 576 | $user->setGplusUid($noDataLabel); |
||
| 577 | $user->setLocale($noDataLabel); |
||
| 578 | $user->setTimezone($noDataLabel); |
||
| 579 | $user->setTwitterData($noDataLabel); |
||
| 580 | $user->setTwitterName($noDataLabel); |
||
| 581 | $user->setTwitterUid($noDataLabel); |
||
| 582 | $user->setWebsite($noDataLabel); |
||
| 583 | $user->setToken($noDataLabel); |
||
| 584 | |||
| 585 | $courses = $user->getCourses(); |
||
| 586 | $list = []; |
||
| 587 | $chatFiles = []; |
||
| 588 | /** @var CourseRelUser $course */ |
||
| 589 | foreach ($courses as $course) { |
||
| 590 | $list[] = $course->getCourse()->getCode(); |
||
| 591 | $courseDir = api_get_path(SYS_COURSE_PATH).$course->getCourse()->getDirectory(); |
||
| 592 | $documentDir = $courseDir.'/document/chat_files/'; |
||
| 593 | if (is_dir($documentDir)) { |
||
| 594 | $fs = new Finder(); |
||
| 595 | $fs->files()->in($documentDir); |
||
| 596 | foreach ($fs as $file) { |
||
| 597 | $chatFiles[] = |
||
| 598 | $course->getCourse()->getDirectory().'/document/chat_files/'.$file->getFilename().' - '. |
||
| 599 | get_lang('This content is not accessible to you directly because of course-related access rules. If you require access to that data, please contact the Data Privacy Officer as defined in our privacy terms.'); |
||
| 600 | } |
||
| 601 | } |
||
| 602 | } |
||
| 603 | |||
| 604 | $user->setCourses($list); |
||
| 605 | |||
| 606 | $classes = $user->getClasses(); |
||
| 607 | $list = []; |
||
| 608 | /** @var UsergroupRelUser $class */ |
||
| 609 | foreach ($classes as $class) { |
||
| 610 | $name = $class->getUsergroup()->getName(); |
||
| 611 | $list[$class->getUsergroup()->getGroupType()][] = $name.' - Status: '.$class->getRelationType(); |
||
| 612 | } |
||
| 613 | $user->setClasses($list); |
||
| 614 | |||
| 615 | $collection = $user->getSessionCourseSubscriptions(); |
||
| 616 | $list = []; |
||
| 617 | /** @var SessionRelCourseRelUser $item */ |
||
| 618 | foreach ($collection as $item) { |
||
| 619 | $list[$item->getSession()->getName()][] = $item->getCourse()->getCode(); |
||
| 620 | } |
||
| 621 | $user->setSessionCourseSubscriptions($list); |
||
| 622 | |||
| 623 | $documents = \DocumentManager::getAllDocumentsCreatedByUser($userId); |
||
| 624 | |||
| 625 | $friends = \SocialManager::get_friends($userId); |
||
| 626 | $friendList = []; |
||
| 627 | if (!empty($friends)) { |
||
| 628 | foreach ($friends as $friend) { |
||
| 629 | $friendList[] = $friend['user_info']['complete_name']; |
||
| 630 | } |
||
| 631 | } |
||
| 632 | |||
| 633 | $agenda = new \Agenda('personal'); |
||
| 634 | $events = $agenda->getEvents('', '', null, null, $userId, 'array'); |
||
| 635 | $eventList = []; |
||
| 636 | if (!empty($events)) { |
||
| 637 | foreach ($events as $event) { |
||
| 638 | $eventList[] = $event['title'].' '.$event['start_date_localtime'].' / '.$event['end_date_localtime']; |
||
| 639 | } |
||
| 640 | } |
||
| 641 | |||
| 642 | // GradebookCertificate |
||
| 643 | $criteria = [ |
||
| 644 | 'userId' => $userId, |
||
| 645 | ]; |
||
| 646 | $result = $em->getRepository('ChamiloCoreBundle:GradebookCertificate')->findBy($criteria); |
||
| 647 | $gradebookCertificate = []; |
||
| 648 | /** @var GradebookCertificate $item */ |
||
| 649 | foreach ($result as $item) { |
||
| 650 | $createdAt = $item->getCreatedAt() ? $item->getCreatedAt()->format($dateFormat) : ''; |
||
| 651 | $list = [ |
||
| 652 | 'Score: '.$item->getScoreCertificate(), |
||
| 653 | 'Path: '.$item->getPathCertificate(), |
||
| 654 | 'Created at: '.$createdAt, |
||
| 655 | ]; |
||
| 656 | $gradebookCertificate[] = implode(', ', $list); |
||
| 657 | } |
||
| 658 | |||
| 659 | // TrackEExercises |
||
| 660 | $criteria = [ |
||
| 661 | 'exeUserId' => $userId, |
||
| 662 | ]; |
||
| 663 | $result = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->findBy($criteria); |
||
| 664 | $trackEExercises = []; |
||
| 665 | /** @var TrackEExercises $item */ |
||
| 666 | foreach ($result as $item) { |
||
| 667 | $date = $item->getExeDate() ? $item->getExeDate()->format($dateFormat) : ''; |
||
| 668 | $list = [ |
||
| 669 | 'IP: '.$item->getUserIp(), |
||
| 670 | 'Start: '.$date, |
||
| 671 | 'Status: '.$item->getStatus(), |
||
| 672 | // 'Result: '.$item->getExeResult(), |
||
| 673 | // 'Weighting: '.$item->getExeWeighting(), |
||
| 674 | ]; |
||
| 675 | $trackEExercises[] = implode(', ', $list); |
||
| 676 | } |
||
| 677 | |||
| 678 | // TrackEAttempt |
||
| 679 | $criteria = [ |
||
| 680 | 'userId' => $userId, |
||
| 681 | ]; |
||
| 682 | $result = $em->getRepository('ChamiloCoreBundle:TrackEAttempt')->findBy($criteria); |
||
| 683 | $trackEAttempt = []; |
||
| 684 | /** @var TrackEAttempt $item */ |
||
| 685 | foreach ($result as $item) { |
||
| 686 | $date = $item->getTms() ? $item->getTms()->format($dateFormat) : ''; |
||
| 687 | $list = [ |
||
| 688 | 'Attempt #'.$item->getExeId(), |
||
| 689 | 'Course # '.$item->getCourse()->getCode(), |
||
| 690 | //'Answer: '.$item->getAnswer(), |
||
| 691 | 'Session #'.$item->getSessionId(), |
||
| 692 | //'Marks: '.$item->getMarks(), |
||
| 693 | 'Position: '.$item->getPosition(), |
||
| 694 | 'Date: '.$date, |
||
| 695 | ]; |
||
| 696 | $trackEAttempt[] = implode(', ', $list); |
||
| 697 | } |
||
| 698 | |||
| 699 | // TrackECourseAccess |
||
| 700 | $criteria = [ |
||
| 701 | 'userId' => $userId, |
||
| 702 | ]; |
||
| 703 | $result = $em->getRepository('ChamiloCoreBundle:TrackECourseAccess')->findBy($criteria); |
||
| 704 | $trackECourseAccessList = []; |
||
| 705 | /** @var TrackECourseAccess $item */ |
||
| 706 | foreach ($result as $item) { |
||
| 707 | $startDate = $item->getLoginCourseDate() ? $item->getLoginCourseDate()->format($dateFormat) : ''; |
||
| 708 | $endDate = $item->getLogoutCourseDate() ? $item->getLogoutCourseDate()->format($dateFormat) : ''; |
||
| 709 | $list = [ |
||
| 710 | 'IP: '.$item->getUserIp(), |
||
| 711 | 'Start: '.$startDate, |
||
| 712 | 'End: '.$endDate, |
||
| 713 | ]; |
||
| 714 | $trackECourseAccessList[] = implode(', ', $list); |
||
| 715 | } |
||
| 716 | |||
| 717 | $checkEntities = [ |
||
| 718 | 'ChamiloCoreBundle:TrackELogin' => 'loginUserId', |
||
| 719 | 'ChamiloCoreBundle:TrackEAccess' => 'accessUserId', |
||
| 720 | 'ChamiloCoreBundle:TrackEOnline' => 'loginUserId', |
||
| 721 | 'ChamiloCoreBundle:TrackEDefault' => 'defaultUserId', |
||
| 722 | 'ChamiloCoreBundle:TrackELastaccess' => 'accessUserId', |
||
| 723 | 'ChamiloCoreBundle:TrackEUploads' => 'uploadUserId', |
||
| 724 | 'ChamiloCoreBundle:GradebookResult' => 'userId', |
||
| 725 | 'ChamiloCoreBundle:TrackEDownloads' => 'downUserId', |
||
| 726 | ]; |
||
| 727 | |||
| 728 | $maxResults = 1000; |
||
| 729 | $trackResults = []; |
||
| 730 | foreach ($checkEntities as $entity => $field) { |
||
| 731 | $qb = $em->createQueryBuilder(); |
||
| 732 | $qb->select($qb->expr()->count('l')) |
||
| 733 | ->from($entity, 'l') |
||
| 734 | ->where("l.$field = :login") |
||
| 735 | ->setParameter('login', $userId); |
||
| 736 | $query = $qb->getQuery(); |
||
| 737 | $count = $query->getSingleScalarResult(); |
||
| 738 | |||
| 739 | if ($count > $maxResults) { |
||
| 740 | $qb = $em->getRepository($entity)->createQueryBuilder('l'); |
||
| 741 | $qb |
||
| 742 | ->select('l') |
||
| 743 | ->where("l.$field = :login") |
||
| 744 | ->setParameter('login', $userId); |
||
| 745 | $qb |
||
| 746 | ->setFirstResult(0) |
||
| 747 | ->setMaxResults($maxResults) |
||
| 748 | ; |
||
| 749 | $result = $qb->getQuery()->getResult(); |
||
| 750 | } else { |
||
| 751 | $criteria = [ |
||
| 752 | $field => $userId, |
||
| 753 | ]; |
||
| 754 | $result = $em->getRepository($entity)->findBy($criteria); |
||
| 755 | } |
||
| 756 | $trackResults[$entity] = $result; |
||
| 757 | } |
||
| 758 | |||
| 759 | $trackELoginList = []; |
||
| 760 | /** @var TrackELogin $item */ |
||
| 761 | foreach ($trackResults['ChamiloCoreBundle:TrackELogin'] as $item) { |
||
| 762 | $startDate = $item->getLoginDate() ? $item->getLoginDate()->format($dateFormat) : ''; |
||
| 763 | $endDate = $item->getLogoutDate() ? $item->getLogoutDate()->format($dateFormat) : ''; |
||
| 764 | $list = [ |
||
| 765 | 'IP: '.$item->getUserIp(), |
||
| 766 | 'Start: '.$startDate, |
||
| 767 | 'End: '.$endDate, |
||
| 768 | ]; |
||
| 769 | $trackELoginList[] = implode(', ', $list); |
||
| 770 | } |
||
| 771 | |||
| 772 | // TrackEAccess |
||
| 773 | $trackEAccessList = []; |
||
| 774 | /** @var TrackEAccess $item */ |
||
| 775 | foreach ($trackResults['ChamiloCoreBundle:TrackEAccess'] as $item) { |
||
| 776 | $date = $item->getAccessDate() ? $item->getAccessDate()->format($dateFormat) : ''; |
||
| 777 | $list = [ |
||
| 778 | 'IP: '.$item->getUserIp(), |
||
| 779 | 'Tool: '.$item->getAccessTool(), |
||
| 780 | 'End: '.$date, |
||
| 781 | ]; |
||
| 782 | $trackEAccessList[] = implode(', ', $list); |
||
| 783 | } |
||
| 784 | |||
| 785 | // TrackEOnline |
||
| 786 | $trackEOnlineList = []; |
||
| 787 | /** @var TrackEOnline $item */ |
||
| 788 | foreach ($trackResults['ChamiloCoreBundle:TrackEOnline'] as $item) { |
||
| 789 | $date = $item->getLoginDate() ? $item->getLoginDate()->format($dateFormat) : ''; |
||
| 790 | $list = [ |
||
| 791 | 'IP: '.$item->getUserIp(), |
||
| 792 | 'Login date: '.$date, |
||
| 793 | 'Course # '.$item->getCId(), |
||
| 794 | 'Session # '.$item->getSessionId(), |
||
| 795 | ]; |
||
| 796 | $trackEOnlineList[] = implode(', ', $list); |
||
| 797 | } |
||
| 798 | |||
| 799 | // TrackEDefault |
||
| 800 | $trackEDefault = []; |
||
| 801 | /** @var TrackEDefault $item */ |
||
| 802 | foreach ($trackResults['ChamiloCoreBundle:TrackEDefault'] as $item) { |
||
| 803 | $date = $item->getDefaultDate() ? $item->getDefaultDate()->format($dateFormat) : ''; |
||
| 804 | $list = [ |
||
| 805 | 'Type: '.$item->getDefaultEventType(), |
||
| 806 | 'Value: '.$item->getDefaultValue(), |
||
| 807 | 'Value type: '.$item->getDefaultValueType(), |
||
| 808 | 'Date: '.$date, |
||
| 809 | 'Course #'.$item->getCId(), |
||
| 810 | 'Session # '.$item->getSessionId(), |
||
| 811 | ]; |
||
| 812 | $trackEDefault[] = implode(', ', $list); |
||
| 813 | } |
||
| 814 | |||
| 815 | // TrackELastaccess |
||
| 816 | $trackELastaccess = []; |
||
| 817 | /** @var TrackELastaccess $item */ |
||
| 818 | foreach ($trackResults['ChamiloCoreBundle:TrackELastaccess'] as $item) { |
||
| 819 | $date = $item->getAccessDate() ? $item->getAccessDate()->format($dateFormat) : ''; |
||
| 820 | $list = [ |
||
| 821 | 'Course #'.$item->getCId(), |
||
| 822 | 'Session # '.$item->getAccessSessionId(), |
||
| 823 | 'Tool: '.$item->getAccessTool(), |
||
| 824 | 'Access date: '.$date, |
||
| 825 | ]; |
||
| 826 | $trackELastaccess[] = implode(', ', $list); |
||
| 827 | } |
||
| 828 | |||
| 829 | // TrackEUploads |
||
| 830 | $trackEUploads = []; |
||
| 831 | /** @var TrackEUploads $item */ |
||
| 832 | foreach ($trackResults['ChamiloCoreBundle:TrackEUploads'] as $item) { |
||
| 833 | $date = $item->getUploadDate() ? $item->getUploadDate()->format($dateFormat) : ''; |
||
| 834 | $list = [ |
||
| 835 | 'Course #'.$item->getCId(), |
||
| 836 | 'Uploaded at: '.$date, |
||
| 837 | 'Upload id # '.$item->getUploadId(), |
||
| 838 | ]; |
||
| 839 | $trackEUploads[] = implode(', ', $list); |
||
| 840 | } |
||
| 841 | |||
| 842 | $gradebookResult = []; |
||
| 843 | /** @var GradebookResult $item */ |
||
| 844 | foreach ($trackResults['ChamiloCoreBundle:GradebookResult'] as $item) { |
||
| 845 | $date = $item->getCreatedAt() ? $item->getCreatedAt()->format($dateFormat) : ''; |
||
| 846 | $list = [ |
||
| 847 | 'Evaluation id# '.$item->getEvaluationId(), |
||
| 848 | //'Score: '.$item->getScore(), |
||
| 849 | 'Creation date: '.$date, |
||
| 850 | ]; |
||
| 851 | $gradebookResult[] = implode(', ', $list); |
||
| 852 | } |
||
| 853 | |||
| 854 | $trackEDownloads = []; |
||
| 855 | /** @var TrackEDownloads $item */ |
||
| 856 | foreach ($trackResults['ChamiloCoreBundle:TrackEDownloads'] as $item) { |
||
| 857 | $date = $item->getDownDate() ? $item->getDownDate()->format($dateFormat) : ''; |
||
| 858 | $list = [ |
||
| 859 | 'File: '.$item->getDownDocPath(), |
||
| 860 | 'Download at: '.$date, |
||
| 861 | ]; |
||
| 862 | $trackEDownloads[] = implode(', ', $list); |
||
| 863 | } |
||
| 864 | |||
| 865 | // UserCourseCategory |
||
| 866 | $criteria = [ |
||
| 867 | 'userId' => $userId, |
||
| 868 | ]; |
||
| 869 | $result = $em->getRepository('ChamiloCoreBundle:UserCourseCategory')->findBy($criteria); |
||
| 870 | $userCourseCategory = []; |
||
| 871 | /** @var UserCourseCategory $item */ |
||
| 872 | foreach ($result as $item) { |
||
| 873 | $list = [ |
||
| 874 | 'Title: '.$item->getTitle(), |
||
| 875 | ]; |
||
| 876 | $userCourseCategory[] = implode(', ', $list); |
||
| 877 | } |
||
| 878 | |||
| 879 | // Forum |
||
| 880 | $criteria = [ |
||
| 881 | 'posterId' => $userId, |
||
| 882 | ]; |
||
| 883 | $result = $em->getRepository('ChamiloCourseBundle:CForumPost')->findBy($criteria); |
||
| 884 | $cForumPostList = []; |
||
| 885 | /** @var CForumPost $item */ |
||
| 886 | foreach ($result as $item) { |
||
| 887 | $date = $item->getPostDate() ? $item->getPostDate()->format($dateFormat) : ''; |
||
| 888 | $list = [ |
||
| 889 | 'Title: '.$item->getPostTitle(), |
||
| 890 | 'Creation date: '.$date, |
||
| 891 | ]; |
||
| 892 | $cForumPostList[] = implode(', ', $list); |
||
| 893 | } |
||
| 894 | |||
| 895 | // CForumThread |
||
| 896 | $criteria = [ |
||
| 897 | 'threadPosterId' => $userId, |
||
| 898 | ]; |
||
| 899 | $result = $em->getRepository('ChamiloCourseBundle:CForumThread')->findBy($criteria); |
||
| 900 | $cForumThreadList = []; |
||
| 901 | /** @var CForumThread $item */ |
||
| 902 | foreach ($result as $item) { |
||
| 903 | $date = $item->getThreadDate() ? $item->getThreadDate()->format($dateFormat) : ''; |
||
| 904 | $list = [ |
||
| 905 | 'Title: '.$item->getThreadTitle(), |
||
| 906 | 'Creation date: '.$date, |
||
| 907 | ]; |
||
| 908 | $cForumThreadList[] = implode(', ', $list); |
||
| 909 | } |
||
| 910 | |||
| 911 | // CForumAttachment |
||
| 912 | /*$criteria = [ |
||
| 913 | 'threadPosterId' => $userId, |
||
| 914 | ]; |
||
| 915 | $result = $em->getRepository('ChamiloCourseBundle:CForumAttachment')->findBy($criteria); |
||
| 916 | $cForumThreadList = []; |
||
| 917 | * @var CForumThread $item |
||
| 918 | foreach ($result as $item) { |
||
| 919 | $list = [ |
||
| 920 | 'Title: '.$item->getThreadTitle(), |
||
| 921 | 'Creation date: '.$item->getThreadDate()->format($dateFormat), |
||
| 922 | ]; |
||
| 923 | $cForumThreadList[] = implode(', ', $list); |
||
| 924 | }*/ |
||
| 925 | |||
| 926 | // cGroupRelUser |
||
| 927 | $criteria = [ |
||
| 928 | 'user' => $userId, |
||
| 929 | ]; |
||
| 930 | $result = $em->getRepository('ChamiloCourseBundle:CGroupRelUser')->findBy($criteria); |
||
| 931 | $cGroupRelUser = []; |
||
| 932 | /** @var CGroupRelUser $item */ |
||
| 933 | foreach ($result as $item) { |
||
| 934 | $list = [ |
||
| 935 | 'Course # '.$item->getCId(), |
||
| 936 | 'Group #'.$item->getGroup()->getId(), |
||
| 937 | 'Role: '.$item->getStatus(), |
||
| 938 | ]; |
||
| 939 | $cGroupRelUser[] = implode(', ', $list); |
||
| 940 | } |
||
| 941 | |||
| 942 | // CAttendanceSheet |
||
| 943 | $criteria = [ |
||
| 944 | 'userId' => $userId, |
||
| 945 | ]; |
||
| 946 | $result = $em->getRepository('ChamiloCourseBundle:CAttendanceSheet')->findBy($criteria); |
||
| 947 | $cAttendanceSheetList = []; |
||
| 948 | /** @var CAttendanceSheet $item */ |
||
| 949 | foreach ($result as $item) { |
||
| 950 | $list = [ |
||
| 951 | 'Presence: '.$item->getPresence(), |
||
| 952 | 'Calendar id: '.$item->getAttendanceCalendarId(), |
||
| 953 | ]; |
||
| 954 | $cAttendanceSheetList[] = implode(', ', $list); |
||
| 955 | } |
||
| 956 | |||
| 957 | // CBlogPost |
||
| 958 | $criteria = [ |
||
| 959 | 'authorId' => $userId, |
||
| 960 | ]; |
||
| 961 | $result = $em->getRepository('ChamiloCourseBundle:CBlogPost')->findBy($criteria); |
||
| 962 | $cBlog = []; |
||
| 963 | /** @var CBlogPost $item */ |
||
| 964 | foreach ($result as $item) { |
||
| 965 | $date = $item->getDateCreation() ? $item->getDateCreation()->format($dateFormat) : ''; |
||
| 966 | $list = [ |
||
| 967 | 'Title: '.$item->getTitle(), |
||
| 968 | 'Date: '.$date, |
||
| 969 | ]; |
||
| 970 | $cBlog[] = implode(', ', $list); |
||
| 971 | } |
||
| 972 | |||
| 973 | // CAttendanceResult |
||
| 974 | $criteria = [ |
||
| 975 | 'userId' => $userId, |
||
| 976 | ]; |
||
| 977 | $result = $em->getRepository('ChamiloCourseBundle:CAttendanceResult')->findBy($criteria); |
||
| 978 | $cAttendanceResult = []; |
||
| 979 | /** @var CAttendanceResult $item */ |
||
| 980 | foreach ($result as $item) { |
||
| 981 | $list = [ |
||
| 982 | 'Score : '.$item->getScore(), |
||
| 983 | 'Calendar id: '.$item->getAttendanceId(), |
||
| 984 | ]; |
||
| 985 | $cAttendanceResult[] = implode(', ', $list); |
||
| 986 | } |
||
| 987 | |||
| 988 | // Message |
||
| 989 | $criteria = [ |
||
| 990 | 'userSender' => $userId, |
||
| 991 | ]; |
||
| 992 | $result = $em->getRepository('ChamiloCoreBundle:Message')->findBy($criteria); |
||
| 993 | $messageList = []; |
||
| 994 | /** @var Message $item */ |
||
| 995 | foreach ($result as $item) { |
||
| 996 | $date = $item->getSendDate() ? $item->getSendDate()->format($dateFormat) : ''; |
||
| 997 | $userName = ''; |
||
| 998 | if ($item->getUserReceiver()) { |
||
| 999 | $userName = $item->getUserReceiver()->getUsername(); |
||
| 1000 | } |
||
| 1001 | $list = [ |
||
| 1002 | 'Title: '.$item->getTitle(), |
||
| 1003 | 'Sent date: '.$date, |
||
| 1004 | 'To user: '.$userName, |
||
| 1005 | 'Status'.$item->getMsgStatus(), |
||
| 1006 | ]; |
||
| 1007 | $messageList[] = implode(', ', $list); |
||
| 1008 | } |
||
| 1009 | |||
| 1010 | // CSurveyAnswer |
||
| 1011 | $criteria = [ |
||
| 1012 | 'user' => $userId, |
||
| 1013 | ]; |
||
| 1014 | $result = $em->getRepository('ChamiloCourseBundle:CSurveyAnswer')->findBy($criteria); |
||
| 1015 | $cSurveyAnswer = []; |
||
| 1016 | /** @var CSurveyAnswer $item */ |
||
| 1017 | foreach ($result as $item) { |
||
| 1018 | $list = [ |
||
| 1019 | 'Answer # '.$item->getAnswerId(), |
||
| 1020 | 'Value: '.$item->getValue(), |
||
| 1021 | ]; |
||
| 1022 | $cSurveyAnswer[] = implode(', ', $list); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | // CDropboxFile |
||
| 1026 | $criteria = [ |
||
| 1027 | 'uploaderId' => $userId, |
||
| 1028 | ]; |
||
| 1029 | $result = $em->getRepository('ChamiloCourseBundle:CDropboxFile')->findBy($criteria); |
||
| 1030 | $cDropboxFile = []; |
||
| 1031 | /** @var CDropboxFile $item */ |
||
| 1032 | foreach ($result as $item) { |
||
| 1033 | $date = $item->getUploadDate() ? $item->getUploadDate()->format($dateFormat) : ''; |
||
| 1034 | $list = [ |
||
| 1035 | 'Title: '.$item->getTitle(), |
||
| 1036 | 'Uploaded date: '.$date, |
||
| 1037 | 'File: '.$item->getFilename(), |
||
| 1038 | ]; |
||
| 1039 | $cDropboxFile[] = implode(', ', $list); |
||
| 1040 | } |
||
| 1041 | |||
| 1042 | // CDropboxPerson |
||
| 1043 | $criteria = [ |
||
| 1044 | 'userId' => $userId, |
||
| 1045 | ]; |
||
| 1046 | $result = $em->getRepository('ChamiloCourseBundle:CDropboxPerson')->findBy($criteria); |
||
| 1047 | $cDropboxPerson = []; |
||
| 1048 | /** @var CDropboxPerson $item */ |
||
| 1049 | foreach ($result as $item) { |
||
| 1050 | $list = [ |
||
| 1051 | 'File #'.$item->getFileId(), |
||
| 1052 | 'Course #'.$item->getCId(), |
||
| 1053 | ]; |
||
| 1054 | $cDropboxPerson[] = implode(', ', $list); |
||
| 1055 | } |
||
| 1056 | |||
| 1057 | // CDropboxPerson |
||
| 1058 | $criteria = [ |
||
| 1059 | 'authorUserId' => $userId, |
||
| 1060 | ]; |
||
| 1061 | $result = $em->getRepository('ChamiloCourseBundle:CDropboxFeedback')->findBy($criteria); |
||
| 1062 | $cDropboxFeedback = []; |
||
| 1063 | /** @var CDropboxFeedback $item */ |
||
| 1064 | foreach ($result as $item) { |
||
| 1065 | $date = $item->getFeedbackDate() ? $item->getFeedbackDate()->format($dateFormat) : ''; |
||
| 1066 | $list = [ |
||
| 1067 | 'File #'.$item->getFileId(), |
||
| 1068 | 'Feedback: '.$item->getFeedback(), |
||
| 1069 | 'Date: '.$date, |
||
| 1070 | ]; |
||
| 1071 | $cDropboxFeedback[] = implode(', ', $list); |
||
| 1072 | } |
||
| 1073 | |||
| 1074 | // CNotebook |
||
| 1075 | $criteria = [ |
||
| 1076 | 'userId' => $userId, |
||
| 1077 | ]; |
||
| 1078 | $result = $em->getRepository('ChamiloCourseBundle:CNotebook')->findBy($criteria); |
||
| 1079 | $cNotebook = []; |
||
| 1080 | /** @var CNotebook $item */ |
||
| 1081 | foreach ($result as $item) { |
||
| 1082 | $date = $item->getUpdateDate() ? $item->getUpdateDate()->format($dateFormat) : ''; |
||
| 1083 | $list = [ |
||
| 1084 | 'Title: '.$item->getTitle(), |
||
| 1085 | 'Date: '.$date, |
||
| 1086 | ]; |
||
| 1087 | $cNotebook[] = implode(', ', $list); |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | // CLpView |
||
| 1091 | $criteria = [ |
||
| 1092 | 'userId' => $userId, |
||
| 1093 | ]; |
||
| 1094 | $result = $em->getRepository('ChamiloCourseBundle:CLpView')->findBy($criteria); |
||
| 1095 | $cLpView = []; |
||
| 1096 | /** @var CLpView $item */ |
||
| 1097 | foreach ($result as $item) { |
||
| 1098 | $list = [ |
||
| 1099 | //'Id #'.$item->getId(), |
||
| 1100 | 'LP #'.$item->getLpId(), |
||
| 1101 | 'Progress: '.$item->getProgress(), |
||
| 1102 | 'Course #'.$item->getCId(), |
||
| 1103 | 'Session #'.$item->getSessionId(), |
||
| 1104 | ]; |
||
| 1105 | $cLpView[] = implode(', ', $list); |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | // CStudentPublication |
||
| 1109 | $criteria = [ |
||
| 1110 | 'userId' => $userId, |
||
| 1111 | ]; |
||
| 1112 | $result = $em->getRepository('ChamiloCourseBundle:CStudentPublication')->findBy($criteria); |
||
| 1113 | $cStudentPublication = []; |
||
| 1114 | /** @var CStudentPublication $item */ |
||
| 1115 | foreach ($result as $item) { |
||
| 1116 | $list = [ |
||
| 1117 | 'Title: '.$item->getTitle(), |
||
| 1118 | 'URL: '.$item->getUrl(), |
||
| 1119 | ]; |
||
| 1120 | $cStudentPublication[] = implode(', ', $list); |
||
| 1121 | } |
||
| 1122 | |||
| 1123 | // CStudentPublicationComment |
||
| 1124 | $criteria = [ |
||
| 1125 | 'userId' => $userId, |
||
| 1126 | ]; |
||
| 1127 | $result = $em->getRepository('ChamiloCourseBundle:CStudentPublicationComment')->findBy($criteria); |
||
| 1128 | $cStudentPublicationComment = []; |
||
| 1129 | /** @var CStudentPublicationComment $item */ |
||
| 1130 | foreach ($result as $item) { |
||
| 1131 | $date = $item->getSentAt() ? $item->getSentAt()->format($dateFormat) : ''; |
||
| 1132 | $list = [ |
||
| 1133 | 'Commment: '.$item->getComment(), |
||
| 1134 | 'File '.$item->getFile(), |
||
| 1135 | 'Course # '.$item->getCId(), |
||
| 1136 | 'Date: '.$date, |
||
| 1137 | ]; |
||
| 1138 | $cStudentPublicationComment[] = implode(', ', $list); |
||
| 1139 | } |
||
| 1140 | |||
| 1141 | // CWiki |
||
| 1142 | $criteria = [ |
||
| 1143 | 'userId' => $userId, |
||
| 1144 | ]; |
||
| 1145 | $result = $em->getRepository('ChamiloCourseBundle:CWiki')->findBy($criteria); |
||
| 1146 | $cWiki = []; |
||
| 1147 | /** @var CWiki $item */ |
||
| 1148 | foreach ($result as $item) { |
||
| 1149 | $list = [ |
||
| 1150 | 'Title: '.$item->getTitle(), |
||
| 1151 | 'Progress: '.$item->getProgress(), |
||
| 1152 | 'IP: '.$item->getUserIp(), |
||
| 1153 | ]; |
||
| 1154 | $cWiki[] = implode(', ', $list); |
||
| 1155 | } |
||
| 1156 | |||
| 1157 | // Ticket |
||
| 1158 | $criteria = [ |
||
| 1159 | 'insertUserId' => $userId, |
||
| 1160 | ]; |
||
| 1161 | $result = $em->getRepository('ChamiloTicketBundle:Ticket')->findBy($criteria); |
||
| 1162 | $ticket = []; |
||
| 1163 | /** @var Ticket $item */ |
||
| 1164 | foreach ($result as $item) { |
||
| 1165 | $list = [ |
||
| 1166 | 'Code: '.$item->getCode(), |
||
| 1167 | 'Subject: '.$item->getSubject(), |
||
| 1168 | ]; |
||
| 1169 | $ticket[] = implode(', ', $list); |
||
| 1170 | } |
||
| 1171 | |||
| 1172 | // Message |
||
| 1173 | $criteria = [ |
||
| 1174 | 'insertUserId' => $userId, |
||
| 1175 | ]; |
||
| 1176 | $result = $em->getRepository('ChamiloTicketBundle:Message')->findBy($criteria); |
||
| 1177 | $ticketMessage = []; |
||
| 1178 | /** @var \Chamilo\TicketBundle\Entity\Message $item */ |
||
| 1179 | foreach ($result as $item) { |
||
| 1180 | $date = $item->getInsertDateTime() ? $item->getInsertDateTime()->format($dateFormat) : ''; |
||
| 1181 | $list = [ |
||
| 1182 | 'Subject: '.$item->getSubject(), |
||
| 1183 | 'IP: '.$item->getIpAddress(), |
||
| 1184 | 'Status: '.$item->getStatus(), |
||
| 1185 | 'Creation date: '.$date, |
||
| 1186 | ]; |
||
| 1187 | $ticketMessage[] = implode(', ', $list); |
||
| 1188 | } |
||
| 1189 | |||
| 1190 | // SkillRelUserComment |
||
| 1191 | $criteria = [ |
||
| 1192 | 'feedbackGiver' => $userId, |
||
| 1193 | ]; |
||
| 1194 | $result = $em->getRepository('ChamiloCoreBundle:SkillRelUserComment')->findBy($criteria); |
||
| 1195 | $skillRelUserComment = []; |
||
| 1196 | /** @var SkillRelUserComment $item */ |
||
| 1197 | foreach ($result as $item) { |
||
| 1198 | $date = $item->getFeedbackDateTime() ? $item->getFeedbackDateTime()->format($dateFormat) : ''; |
||
| 1199 | $list = [ |
||
| 1200 | 'Feedback: '.$item->getFeedbackText(), |
||
| 1201 | 'Value: '.$item->getFeedbackValue(), |
||
| 1202 | 'Created at: '.$date, |
||
| 1203 | ]; |
||
| 1204 | $skillRelUserComment[] = implode(', ', $list); |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | // UserRelCourseVote |
||
| 1208 | $criteria = [ |
||
| 1209 | 'userId' => $userId, |
||
| 1210 | ]; |
||
| 1211 | $result = $em->getRepository('ChamiloCoreBundle:UserRelCourseVote')->findBy($criteria); |
||
| 1212 | $userRelCourseVote = []; |
||
| 1213 | /** @var UserRelCourseVote $item */ |
||
| 1214 | foreach ($result as $item) { |
||
| 1215 | $list = [ |
||
| 1216 | 'Course #'.$item->getCId(), |
||
| 1217 | 'Session #'.$item->getSessionId(), |
||
| 1218 | 'Vote: '.$item->getVote(), |
||
| 1219 | ]; |
||
| 1220 | $userRelCourseVote[] = implode(', ', $list); |
||
| 1221 | } |
||
| 1222 | |||
| 1223 | // UserApiKey |
||
| 1224 | $criteria = [ |
||
| 1225 | 'userId' => $userId, |
||
| 1226 | ]; |
||
| 1227 | $result = $em->getRepository('ChamiloCoreBundle:UserApiKey')->findBy($criteria); |
||
| 1228 | $userApiKey = []; |
||
| 1229 | /** @var UserApiKey $item */ |
||
| 1230 | foreach ($result as $item) { |
||
| 1231 | $validityStart = $item->getValidityStartDate() ? $item->getValidityStartDate()->format($dateFormat) : ''; |
||
| 1232 | $validityEnd = $item->getValidityEndDate() ? $item->getValidityEndDate()->format($dateFormat) : ''; |
||
| 1233 | $created = $item->getCreatedDate() ? $item->getCreatedDate()->format($dateFormat) : ''; |
||
| 1234 | |||
| 1235 | $list = [ |
||
| 1236 | 'ApiKey #'.$item->getApiKey(), |
||
| 1237 | 'Service: '.$item->getApiService(), |
||
| 1238 | 'EndPoint: '.$item->getApiEndPoint(), |
||
| 1239 | 'Validity start date: '.$validityStart, |
||
| 1240 | 'Validity enddate: '.$validityEnd, |
||
| 1241 | 'Created at: '.$created, |
||
| 1242 | ]; |
||
| 1243 | $userApiKey[] = implode(', ', $list); |
||
| 1244 | } |
||
| 1245 | |||
| 1246 | $user->setDropBoxSentFiles( |
||
| 1247 | [ |
||
| 1248 | 'Friends' => $friendList, |
||
| 1249 | 'Events' => $eventList, |
||
| 1250 | 'GradebookCertificate' => $gradebookCertificate, |
||
| 1251 | |||
| 1252 | 'TrackECourseAccess' => $trackECourseAccessList, |
||
| 1253 | 'TrackELogin' => $trackELoginList, |
||
| 1254 | 'TrackEAccess' => $trackEAccessList, |
||
| 1255 | 'TrackEDefault' => $trackEDefault, |
||
| 1256 | 'TrackEOnline' => $trackEOnlineList, |
||
| 1257 | 'TrackEUploads' => $trackEUploads, |
||
| 1258 | 'TrackELastaccess' => $trackELastaccess, |
||
| 1259 | 'GradebookResult' => $gradebookResult, |
||
| 1260 | 'Downloads' => $trackEDownloads, |
||
| 1261 | 'UserCourseCategory' => $userCourseCategory, |
||
| 1262 | 'SkillRelUserComment' => $skillRelUserComment, |
||
| 1263 | 'UserRelCourseVote' => $userRelCourseVote, |
||
| 1264 | 'UserApiKey' => $userApiKey, |
||
| 1265 | |||
| 1266 | // courses |
||
| 1267 | 'AttendanceResult' => $cAttendanceResult, |
||
| 1268 | 'Blog' => $cBlog, |
||
| 1269 | 'DocumentsAdded' => $documents, |
||
| 1270 | 'Chat' => $chatFiles, |
||
| 1271 | 'ForumPost' => $cForumPostList, |
||
| 1272 | 'ForumThread' => $cForumThreadList, |
||
| 1273 | 'TrackEExercises' => $trackEExercises, |
||
| 1274 | 'TrackEAttempt' => $trackEAttempt, |
||
| 1275 | |||
| 1276 | 'GroupRelUser' => $cGroupRelUser, |
||
| 1277 | 'Message' => $messageList, |
||
| 1278 | 'Survey' => $cSurveyAnswer, |
||
| 1279 | 'StudentPublication' => $cStudentPublication, |
||
| 1280 | 'StudentPublicationComment' => $cStudentPublicationComment, |
||
| 1281 | 'DropboxFile' => $cDropboxFile, |
||
| 1282 | 'DropboxPerson' => $cDropboxPerson, |
||
| 1283 | 'DropboxFeedback' => $cDropboxFeedback, |
||
| 1284 | |||
| 1285 | 'LpView' => $cLpView, |
||
| 1286 | 'Notebook' => $cNotebook, |
||
| 1287 | |||
| 1288 | 'Wiki' => $cWiki, |
||
| 1289 | // Tickets |
||
| 1290 | |||
| 1291 | 'Ticket' => $ticket, |
||
| 1292 | 'TicketMessage' => $ticketMessage, |
||
| 1293 | ] |
||
| 1294 | ); |
||
| 1295 | |||
| 1296 | $user->setDropBoxReceivedFiles([]); |
||
| 1297 | //$user->setGroups([]); |
||
| 1298 | $user->setCurriculumItems([]); |
||
| 1299 | |||
| 1300 | $portals = $user->getPortals(); |
||
| 1301 | if (!empty($portals)) { |
||
| 1302 | $list = []; |
||
| 1303 | /** @var AccessUrlRelUser $portal */ |
||
| 1304 | foreach ($portals as $portal) { |
||
| 1305 | $portalInfo = \UrlManager::get_url_data_from_id($portal->getUrl()->getId()); |
||
| 1306 | $list[] = $portalInfo['url']; |
||
| 1307 | } |
||
| 1308 | } |
||
| 1309 | $user->setPortals($list); |
||
| 1310 | |||
| 1311 | $coachList = $user->getSessionAsGeneralCoach(); |
||
| 1312 | $list = []; |
||
| 1313 | /** @var Session $session */ |
||
| 1314 | foreach ($coachList as $session) { |
||
| 1315 | $list[] = $session->getName(); |
||
| 1316 | } |
||
| 1317 | $user->setSessionAsGeneralCoach($list); |
||
| 1318 | |||
| 1319 | $skillRelUserList = $user->getAchievedSkills(); |
||
| 1320 | $list = []; |
||
| 1321 | /** @var SkillRelUser $skillRelUser */ |
||
| 1322 | foreach ($skillRelUserList as $skillRelUser) { |
||
| 1323 | $list[] = $skillRelUser->getSkill()->getName(); |
||
| 1324 | } |
||
| 1325 | $user->setAchievedSkills($list); |
||
| 1326 | $user->setCommentedUserSkills([]); |
||
| 1327 | |||
| 1328 | $extraFieldValues = new \ExtraFieldValue('user'); |
||
| 1329 | $items = $extraFieldValues->getAllValuesByItem($userId); |
||
| 1330 | //$user->setExtraFields($items); |
||
| 1331 | //$user->setExtraFields([]); |
||
| 1332 | |||
| 1333 | $lastLogin = $user->getLastLogin(); |
||
| 1334 | if (empty($lastLogin)) { |
||
| 1335 | $login = $this->getLastLogin($user); |
||
| 1336 | if ($login) { |
||
| 1337 | $lastLogin = $login->getLoginDate(); |
||
| 1338 | } |
||
| 1339 | } |
||
| 1340 | $user->setLastLogin($lastLogin); |
||
| 1341 | |||
| 1342 | $dateNormalizer = new GetSetMethodNormalizer(); |
||
| 1343 | $dateNormalizer->setCircularReferenceHandler(function ($object) { |
||
| 1344 | return get_class($object); |
||
| 1345 | }); |
||
| 1346 | |||
| 1347 | $ignore = [ |
||
| 1348 | 'twoStepVerificationCode', |
||
| 1349 | 'biography', |
||
| 1350 | 'dateOfBirth', |
||
| 1351 | 'gender', |
||
| 1352 | 'facebookData', |
||
| 1353 | 'facebookName', |
||
| 1354 | 'facebookUid', |
||
| 1355 | 'gplusData', |
||
| 1356 | 'gplusName', |
||
| 1357 | 'gplusUid', |
||
| 1358 | 'locale', |
||
| 1359 | 'timezone', |
||
| 1360 | 'twitterData', |
||
| 1361 | 'twitterName', |
||
| 1362 | 'twitterUid', |
||
| 1363 | 'gplusUid', |
||
| 1364 | 'token', |
||
| 1365 | 'website', |
||
| 1366 | 'plainPassword', |
||
| 1367 | 'completeNameWithUsername', |
||
| 1368 | 'completeName', |
||
| 1369 | 'completeNameWithClasses', |
||
| 1370 | 'salt', |
||
| 1371 | ]; |
||
| 1372 | |||
| 1373 | $dateNormalizer->setIgnoredAttributes($ignore); |
||
| 1374 | |||
| 1375 | $callback = function ($dateTime) { |
||
| 1376 | return $dateTime instanceof \DateTime ? $dateTime->format(\DateTime::ATOM) : ''; |
||
| 1377 | }; |
||
| 1378 | |||
| 1379 | $dateNormalizer->setCallbacks( |
||
| 1380 | [ |
||
| 1381 | 'createdAt' => $callback, |
||
| 1382 | 'lastLogin' => $callback, |
||
| 1383 | 'registrationDate' => $callback, |
||
| 1384 | 'memberSince' => $callback, |
||
| 1385 | ] |
||
| 1386 | ); |
||
| 1387 | |||
| 1388 | $normalizers = [$dateNormalizer]; |
||
| 1389 | $serializer = new Serializer($normalizers, [new JsonEncoder()]); |
||
| 1390 | |||
| 1391 | $jsonContent = $serializer->serialize($user, 'json'); |
||
| 1392 | |||
| 1393 | return $jsonContent; |
||
| 1394 | } |
||
| 1424 |