diff --git a/main/template/default/macro/macro.tpl b/main/template/default/macro/macro.tpl new file mode 100644 index 0000000000..c47a9926d2 --- /dev/null +++ b/main/template/default/macro/macro.tpl @@ -0,0 +1,118 @@ +{# special macros to generate repeated html code #} + +{% macro collapse(name, title, content, list = false) %} +{% autoescape false %} +
+
+ +
+
+ {% if list %} + + {% else %} + {{ content }} + {% endif %} +
+
+
+
+{% endautoescape %} +{% endmacro %} + +{% macro collapseFor(name, title, array) %} +{% autoescape false %} +
+
+ +
+
+ +
+
+
+
+{% endautoescape %} +{% endmacro %} + +{% macro collapseMenu(name, title, array) %} +{% autoescape false %} +
+
+ +
+
+
    + {% for item in array %} +
  • + {{ item.icon }} + {{ item.title }} +
  • + {% endfor %} +
+
+
+
+
+{% endautoescape %} +{% endmacro %} + +{% macro pluginSidebar(name, content) %} +{% autoescape false %} +
+ {{ content }} +
+{% endautoescape %} +{% endmacro %} + +{% macro pluginPanel(name, content) %} +{% autoescape false %} +
+
+
+ {{ content }} +
+
+
+{% endautoescape %} +{% endmacro %} + + +{% macro panel(name, content, footer = '') %} +{% autoescape false %} +
+
{{ name }}
+
+ {{ content }} +
+ {% if footer %} + + {% endif %} +
+{% endautoescape %} +{% endmacro %} \ No newline at end of file diff --git a/main/template/default/social/personal_data.html.twig b/main/template/default/social/personal_data.html.twig new file mode 100644 index 0000000000..6998c61981 --- /dev/null +++ b/main/template/default/social/personal_data.html.twig @@ -0,0 +1,57 @@ +{% extends '@ChamiloTheme/Layout/layout_one_col.html.twig' %} +{% import template ~ '/macro/macro.tpl' as display %} + +{% block content %} +{% autoescape false %} +
+
+ +
+
+ {{ display.panel('PersonalDataIntroductionTitle' | get_lang , 'PersonalDataIntroductionText' | get_lang) }} + {{ display.panel('PersonalDataKeptOnYou' | get_lang, personal_data.data) }} + + {% if personal_data.responsible %} + {{ display.panel('PersonalDataResponsibleOrganizationTitle' | get_lang , personal_data.responsible ) }} + {% endif %} + + {% if personal_data.treatment %} +
+
{{ 'PersonalDataTreatmentTitle' | get_lang }}
+
+ {% for treatment in personal_data.treatment %} + {% if treatment.content %} +
+
{{ treatment.title }}
+
{{ treatment.content }}
+
+ {% endif %} + {% endfor %} +
+
+ {% endif %} + {% if personal_data.officer_name %} +
+
{{ 'PersonalDataOfficerName' | get_lang }}
+ +
{{ 'PersonalDataOfficerRole' | get_lang }}
+
+ {{ personal_data.officer_role }} +
+
+ {% endif %} + + {% if term_link %} + {{ display.panel('TermsAndConditions'|get_lang, term_link ) }} + {% endif %} + + {{ display.panel('PersonalDataPermissionsYouGaveUs' | get_lang, permission) }} +
+
+{% endautoescape %} +{% endblock %} diff --git a/src/UserBundle/Entity/User.php b/src/UserBundle/Entity/User.php index 61d5d9248b..d4bb4046c4 100644 --- a/src/UserBundle/Entity/User.php +++ b/src/UserBundle/Entity/User.php @@ -541,6 +541,30 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this->dropBoxReceivedFiles; } + /** + * @param ArrayCollection $value + */ + public function setDropBoxSentFiles($value) + { + $this->dropBoxSentFiles = $value; + } + + /** + * @param ArrayCollection $value + */ + public function setDropBoxReceivedFiles($value) + { + $this->dropBoxReceivedFiles = $value; + } + + /** + * @param ArrayCollection $courses + */ + public function setCourses($courses) + { + $this->courses = $courses; + } + /** * @return ArrayCollection */ @@ -623,6 +647,14 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement $this->portals->add($portal); } + /** + * @param $value + */ + public function setPortals($value) + { + $this->portals = $value; + } + /** * @return ArrayCollection */ @@ -633,10 +665,14 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement /** * @param $items + * + * @return $this */ public function setCurriculumItems($items) { $this->curriculumItems = $items; + + return $this; } /** @@ -695,6 +731,18 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this->salt; } + /** + * @param ArrayCollection $classes + * + * @return $this + */ + public function setClasses($classes) + { + $this->classes = $classes; + + return $this; + } + /** * @return ArrayCollection */ @@ -1376,22 +1424,6 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this->imageFile; } - /** - * @param string $imageName - */ - public function setImageName($imageName) - { - $this->imageName = $imageName; - } - - /** - * @return string - */ - public function getImageName() - { - return $this->imageName; - } - /** * @return string */ @@ -1445,7 +1477,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement /** * {@inheritdoc} */ - public function setExtraFields($extraFields) + public function setExtraFieldList($extraFields) { $this->extraFields = new ArrayCollection(); foreach ($extraFields as $extraField) { @@ -1455,6 +1487,11 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this; } + public function setExtraFields($extraFields) + { + $this->extraFields = $extraFields; + } + /** * {@inheritdoc} */ @@ -1541,6 +1578,13 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this->sessionCourseSubscriptions; } + public function setSessionCourseSubscriptions($value) + { + $this->sessionCourseSubscriptions = $value; + + return $this; + } + /** * @return string */ @@ -1767,6 +1811,18 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this->achievedSkills; } + /** + * @param $value + * + * @return $this + */ + public function setAchievedSkills($value) + { + $this->achievedSkills = $value; + + return $this; + } + /** * Check if the user has the skill. * @@ -1846,6 +1902,41 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement return $this->sessionAsGeneralCoach; } + /** + * Get sessionAsGeneralCoach. + * + * @param ArrayCollection $value + * + * @return $this + */ + public function setSessionAsGeneralCoach($value) + { + $this->sessionAsGeneralCoach = $value; + + return $this; + } + + /** + * @return mixed + */ + public function getCommentedUserSkills() + { + return $this->commentedUserSkills; + } + + /** + * @param mixed $commentedUserSkills + * + * @return User + */ + public function setCommentedUserSkills($commentedUserSkills) + { + $this->commentedUserSkills = $commentedUserSkills; + + return $this; + } + + /** * @param UserInterface $user * diff --git a/src/UserBundle/Repository/UserRepository.php b/src/UserBundle/Repository/UserRepository.php index 41af396c1a..64ad69d472 100644 --- a/src/UserBundle/Repository/UserRepository.php +++ b/src/UserBundle/Repository/UserRepository.php @@ -3,13 +3,53 @@ namespace Chamilo\UserBundle\Repository; -use Chamilo\CoreBundle\Entity\AccessUrl; +use Chamilo\CoreBundle\Entity\AccessUrlRelUser; use Chamilo\CoreBundle\Entity\Course; +use Chamilo\CoreBundle\Entity\CourseRelUser; +use Chamilo\CoreBundle\Entity\GradebookCertificate; +use Chamilo\CoreBundle\Entity\GradebookResult; +use Chamilo\CoreBundle\Entity\Message; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; +use Chamilo\CoreBundle\Entity\SkillRelUser; +use Chamilo\CoreBundle\Entity\SkillRelUserComment; +use Chamilo\CoreBundle\Entity\TrackEAccess; +use Chamilo\CoreBundle\Entity\TrackEAttempt; +use Chamilo\CoreBundle\Entity\TrackECourseAccess; +use Chamilo\CoreBundle\Entity\TrackEDefault; +use Chamilo\CoreBundle\Entity\TrackEDownloads; +use Chamilo\CoreBundle\Entity\TrackEExercises; +use Chamilo\CoreBundle\Entity\TrackELastaccess; +use Chamilo\CoreBundle\Entity\TrackELogin; +use Chamilo\CoreBundle\Entity\TrackEOnline; +use Chamilo\CoreBundle\Entity\TrackEUploads; +use Chamilo\CoreBundle\Entity\UserApiKey; +use Chamilo\CoreBundle\Entity\UserCourseCategory; +use Chamilo\CoreBundle\Entity\UsergroupRelUser; +use Chamilo\CoreBundle\Entity\UserRelCourseVote; +use Chamilo\CourseBundle\Entity\CAttendanceResult; +use Chamilo\CourseBundle\Entity\CAttendanceSheet; +use Chamilo\CourseBundle\Entity\CBlogPost; +use Chamilo\CourseBundle\Entity\CDropboxFeedback; +use Chamilo\CourseBundle\Entity\CDropboxFile; +use Chamilo\CourseBundle\Entity\CDropboxPerson; +use Chamilo\CourseBundle\Entity\CForumPost; +use Chamilo\CourseBundle\Entity\CForumThread; +use Chamilo\CourseBundle\Entity\CGroupRelUser; +use Chamilo\CourseBundle\Entity\CLpView; +use Chamilo\CourseBundle\Entity\CNotebook; +use Chamilo\CourseBundle\Entity\CStudentPublication; +use Chamilo\CourseBundle\Entity\CStudentPublicationComment; +use Chamilo\CourseBundle\Entity\CSurveyAnswer; +use Chamilo\CourseBundle\Entity\CWiki; +use Chamilo\TicketBundle\Entity\Ticket; use Chamilo\UserBundle\Entity\User; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query\Expr\Join; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Serializer\Encoder\JsonEncoder; +use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; +use Symfony\Component\Serializer\Serializer; //use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; //use Symfony\Component\Security\Core\Exception\UnsupportedUserException; @@ -442,4 +482,844 @@ class UserRepository extends EntityRepository ->setParameters(['search' => "%$search%"]) ->getResult(); } + + /** + * Serialize the whole entity to an array. + * + * @param int $userId + * @param array $substitutionTerms Substitute terms for some elements + * + * @return string + */ + public function getPersonalDataToJson($userId, array $substitutionTerms) + { + $em = $this->getEntityManager(); + $dateFormat = \Datetime::ATOM; + + /** @var User $user */ + $user = $this->find($userId); + + $user->setPassword($substitutionTerms['password']); + $user->setSalt($substitutionTerms['salt']); + $noDataLabel = $substitutionTerms['empty']; + + // Dummy content + $user->setDateOfBirth(null); + //$user->setBiography($noDataLabel); + $user->setFacebookData($noDataLabel); + $user->setFacebookName($noDataLabel); + $user->setFacebookUid($noDataLabel); + //$user->setImageName($noDataLabel); + //$user->setTwoStepVerificationCode($noDataLabel); + $user->setGender($noDataLabel); + $user->setGplusData($noDataLabel); + $user->setGplusName($noDataLabel); + $user->setGplusUid($noDataLabel); + $user->setLocale($noDataLabel); + $user->setTimezone($noDataLabel); + $user->setTwitterData($noDataLabel); + $user->setTwitterName($noDataLabel); + $user->setTwitterUid($noDataLabel); + $user->setWebsite($noDataLabel); + $user->setToken($noDataLabel); + + $courses = $user->getCourses(); + $list = []; + $chatFiles = []; + /** @var CourseRelUser $course */ + foreach ($courses as $course) { + $list[] = $course->getCourse()->getCode(); + $courseDir = api_get_path(SYS_COURSE_PATH).$course->getCourse()->getDirectory(); + $documentDir = $courseDir.'/document/chat_files/'; + if (is_dir($documentDir)) { + $fs = new Finder(); + $fs->files()->in($documentDir); + foreach ($fs as $file) { + $chatFiles[] = + $course->getCourse()->getDirectory().'/document/chat_files/'.$file->getFilename().' - '. + get_lang('ContentNotAccessibleRequestFromDataPrivacyOfficer'); + } + } + } + + $user->setCourses($list); + + $classes = $user->getClasses(); + $list = []; + /** @var UsergroupRelUser $class */ + foreach ($classes as $class) { + $name = $class->getUsergroup()->getName(); + $list[$class->getUsergroup()->getGroupType()][] = $name.' - Status: '.$class->getRelationType(); + } + $user->setClasses($list); + + $collection = $user->getSessionCourseSubscriptions(); + $list = []; + /** @var SessionRelCourseRelUser $item */ + foreach ($collection as $item) { + $list[$item->getSession()->getName()][] = $item->getCourse()->getCode(); + } + $user->setSessionCourseSubscriptions($list); + + $documents = \DocumentManager::getAllDocumentsCreatedByUser($userId); + + $friends = \SocialManager::get_friends($userId); + $friendList = []; + if (!empty($friends)) { + foreach ($friends as $friend) { + $friendList[] = $friend['user_info']['complete_name']; + } + } + + $agenda = new \Agenda('personal'); + $events = $agenda->getEvents('', '', null, null, $userId, 'array'); + $eventList = []; + if (!empty($events)) { + foreach ($events as $event) { + $eventList[] = $event['title'].' '.$event['start_date_localtime'].' / '.$event['end_date_localtime']; + } + } + + // GradebookCertificate + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:GradebookCertificate')->findBy($criteria); + $gradebookCertificate = []; + /** @var GradebookCertificate $item */ + foreach ($result as $item) { + $list = [ + 'Score: '.$item->getScoreCertificate(), + 'Path: '.$item->getPathCertificate(), + 'Created at: '.$item->getCreatedAt()->format($dateFormat), + ]; + $gradebookCertificate[] = implode(', ', $list); + } + + // TrackEExercises + $criteria = [ + 'exeUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->findBy($criteria); + $trackEExercises = []; + /** @var TrackEExercises $item */ + foreach ($result as $item) { + $list = [ + 'IP: '.$item->getUserIp(), + 'Start: '.$item->getExeDate()->format($dateFormat), + 'Status: '.$item->getStatus(), + // 'Result: '.$item->getExeResult(), + // 'Weighting: '.$item->getExeWeighting(), + ]; + $trackEExercises[] = implode(', ', $list); + } + + // TrackEAttempt + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEAttempt')->findBy($criteria); + $trackEAttempt = []; + /** @var TrackEAttempt $item */ + foreach ($result as $item) { + $list = [ + 'Attempt #'.$item->getExeId(), + 'Course # '.$item->getCId(), + //'Answer: '.$item->getAnswer(), + 'Session #'.$item->getSessionId(), + //'Marks: '.$item->getMarks(), + 'Position: '.$item->getPosition(), + 'Date: '.$item->getTms()->format($dateFormat), + ]; + $trackEAttempt[] = implode(', ', $list); + } + + // TrackECourseAccess + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackECourseAccess')->findBy($criteria); + $trackECourseAccessList = []; + /** @var TrackECourseAccess $item */ + foreach ($result as $item) { + $list = [ + 'IP: '.$item->getUserIp(), + 'Start: '.$item->getLoginCourseDate()->format($dateFormat), + 'End: '.$item->getLogoutCourseDate()->format($dateFormat), + ]; + $trackECourseAccessList[] = implode(', ', $list); + } + + // TrackELogin + $criteria = [ + 'loginUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackELogin')->findBy($criteria); + $trackELoginList = []; + /** @var TrackELogin $item */ + foreach ($result as $item) { + $list = [ + 'IP: '.$item->getUserIp(), + 'Start: '.$item->getLoginDate()->format($dateFormat), + 'End: '.$item->getLogoutDate()->format($dateFormat), + ]; + $trackELoginList[] = implode(', ', $list); + } + + // TrackEAccess + $criteria = [ + 'accessUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEAccess')->findBy($criteria); + $trackEAccessList = []; + /** @var TrackEAccess $item */ + foreach ($result as $item) { + $list = [ + 'IP: '.$item->getUserIp(), + 'Tool: '.$item->getAccessTool(), + 'End: '.$item->getAccessDate()->format($dateFormat), + ]; + $trackEAccessList[] = implode(', ', $list); + } + + // TrackEOnline + $criteria = [ + 'loginUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEOnline')->findBy($criteria); + $trackEOnlineList = []; + /** @var TrackEOnline $item */ + foreach ($result as $item) { + $list = [ + 'IP: '.$item->getUserIp(), + 'Login date: '.$item->getLoginDate()->format($dateFormat), + 'Course # '.$item->getCId(), + 'Session # '.$item->getSessionId(), + ]; + $trackEOnlineList[] = implode(', ', $list); + } + + // TrackEDefault + $criteria = [ + 'defaultUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEDefault')->findBy($criteria); + $trackEDefault = []; + /** @var TrackEDefault $item */ + foreach ($result as $item) { + $list = [ + 'Type: '.$item->getDefaultEventType(), + 'Value: '.$item->getDefaultValue(), + 'Value type: '.$item->getDefaultValueType(), + 'Date: '.$item->getDefaultDate()->format($dateFormat), + 'Course #'.$item->getCId(), + 'Session # '.$item->getSessionId(), + ]; + $trackEDefault[] = implode(', ', $list); + } + + // TrackELastaccess + $criteria = [ + 'accessUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackELastaccess')->findBy($criteria); + $trackELastaccess = []; + /** @var TrackELastaccess $item */ + foreach ($result as $item) { + $list = [ + 'Course #'.$item->getCId(), + 'Session # '.$item->getAccessSessionId(), + 'Tool: '.$item->getAccessTool(), + 'Access date: '.$item->getAccessDate()->format($dateFormat), + ]; + $trackELastaccess[] = implode(', ', $list); + } + + // TrackEUploads + $criteria = [ + 'uploadUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEUploads')->findBy($criteria); + $trackEUploads = []; + /** @var TrackEUploads $item */ + foreach ($result as $item) { + $list = [ + 'Course #'.$item->getCId(), + 'Uploaded at: '.$item->getUploadDate()->format($dateFormat), + 'Upload id # '.$item->getUploadId(), + ]; + $trackEUploads[] = implode(', ', $list); + } + + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:GradebookResult')->findBy($criteria); + $gradebookResult = []; + /** @var GradebookResult $item */ + foreach ($result as $item) { + $list = [ + 'Evaluation id# '.$item->getEvaluationId(), + //'Score: '.$item->getScore(), + 'Creation date: '.$item->getCreatedAt()->format($dateFormat), + ]; + $gradebookResult[] = implode(', ', $list); + } + + $criteria = [ + 'downUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:TrackEDownloads')->findBy($criteria); + $trackEDownloads = []; + /** @var TrackEDownloads $item */ + foreach ($result as $item) { + $list = [ + 'File: '.$item->getDownDocPath(), + 'Download at: '.$item->getDownDate()->format($dateFormat), + ]; + $trackEDownloads[] = implode(', ', $list); + } + + // UserCourseCategory + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:UserCourseCategory')->findBy($criteria); + $userCourseCategory = []; + /** @var UserCourseCategory $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + ]; + $userCourseCategory[] = implode(', ', $list); + } + + // Forum + $criteria = [ + 'posterId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CForumPost')->findBy($criteria); + $cForumPostList = []; + /** @var CForumPost $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getPostTitle(), + 'Creation date: '.$item->getPostDate()->format($dateFormat), + ]; + $cForumPostList[] = implode(', ', $list); + } + + // CForumThread + $criteria = [ + 'threadPosterId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CForumThread')->findBy($criteria); + $cForumThreadList = []; + /** @var CForumThread $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getThreadTitle(), + 'Creation date: '.$item->getThreadDate()->format($dateFormat), + ]; + $cForumThreadList[] = implode(', ', $list); + } + + // CForumAttachment + /*$criteria = [ + 'threadPosterId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CForumAttachment')->findBy($criteria); + $cForumThreadList = []; + * @var CForumThread $item + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getThreadTitle(), + 'Creation date: '.$item->getThreadDate()->format($dateFormat), + ]; + $cForumThreadList[] = implode(', ', $list); + }*/ + + // cGroupRelUser + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CGroupRelUser')->findBy($criteria); + $cGroupRelUser = []; + /** @var CGroupRelUser $item */ + foreach ($result as $item) { + $list = [ + 'Course # '.$item->getCId(), + 'Group #'.$item->getGroupId(), + 'Role: '.$item->getStatus(), + ]; + $cGroupRelUser[] = implode(', ', $list); + } + + // CAttendanceSheet + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CAttendanceSheet')->findBy($criteria); + $cAttendanceSheetList = []; + /** @var CAttendanceSheet $item */ + foreach ($result as $item) { + $list = [ + 'Presence: '.$item->getPresence(), + 'Calendar id: '.$item->getAttendanceCalendarId(), + ]; + $cAttendanceSheetList[] = implode(', ', $list); + } + + // CBlogPost + $criteria = [ + 'authorId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CBlogPost')->findBy($criteria); + $cBlog = []; + /** @var CBlogPost $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + 'Date: '.$item->getDateCreation()->format($dateFormat), + ]; + $cBlog[] = implode(', ', $list); + } + + // CAttendanceResult + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CAttendanceResult')->findBy($criteria); + $cAttendanceResult = []; + /** @var CAttendanceResult $item */ + foreach ($result as $item) { + $list = [ + 'Score : '.$item->getScore(), + 'Calendar id: '.$item->getAttendanceId(), + ]; + $cAttendanceResult[] = implode(', ', $list); + } + + // Message + $criteria = [ + 'userSenderId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:Message')->findBy($criteria); + $messageList = []; + /** @var Message $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + 'Sent date: '.$item->getSendDate()->format($dateFormat), + 'To user # '.$item->getUserReceiverId(), + 'Status'.$item->getMsgStatus(), + ]; + $messageList[] = implode(', ', $list); + } + + // CSurveyAnswer + $criteria = [ + 'user' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CSurveyAnswer')->findBy($criteria); + $cSurveyAnswer = []; + /** @var CSurveyAnswer $item */ + foreach ($result as $item) { + $list = [ + 'Answer # '.$item->getAnswerId(), + 'Value: '.$item->getValue(), + ]; + $cSurveyAnswer[] = implode(', ', $list); + } + + // CDropboxFile + $criteria = [ + 'uploaderId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CDropboxFile')->findBy($criteria); + $cDropboxFile = []; + /** @var CDropboxFile $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + 'Uploaded date: '.$item->getUploadDate()->format($dateFormat), + 'File: '.$item->getFilename(), + ]; + $cDropboxFile[] = implode(', ', $list); + } + + // CDropboxPerson + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CDropboxPerson')->findBy($criteria); + $cDropboxPerson = []; + /** @var CDropboxPerson $item */ + foreach ($result as $item) { + $list = [ + 'File #'.$item->getFileId(), + 'Course #'.$item->getCId(), + ]; + $cDropboxPerson[] = implode(', ', $list); + } + + // CDropboxPerson + $criteria = [ + 'authorUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CDropboxFeedback')->findBy($criteria); + $cDropboxFeedback = []; + /** @var CDropboxFeedback $item */ + foreach ($result as $item) { + $list = [ + 'File #'.$item->getFileId(), + 'Feedback: '.$item->getFeedback(), + 'Date: '.$item->getFeedbackDate()->format($dateFormat), + ]; + $cDropboxFeedback[] = implode(', ', $list); + } + + // CNotebook + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CNotebook')->findBy($criteria); + $cNotebook = []; + /** @var CNotebook $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + 'Date: '.$item->getUpdateDate()->format($dateFormat), + ]; + $cNotebook[] = implode(', ', $list); + } + + // CLpView + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CLpView')->findBy($criteria); + $cLpView = []; + /** @var CLpView $item */ + foreach ($result as $item) { + $list = [ + //'Id #'.$item->getId(), + 'LP #'.$item->getLpId(), + 'Progress: '.$item->getProgress(), + 'Course #'.$item->getCId(), + 'Session #'.$item->getSessionId(), + ]; + $cLpView[] = implode(', ', $list); + } + + // CStudentPublication + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CStudentPublication')->findBy($criteria); + $cStudentPublication = []; + /** @var CStudentPublication $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + 'URL: '.$item->getUrl(), + ]; + $cStudentPublication[] = implode(', ', $list); + } + + // CStudentPublicationComment + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CStudentPublicationComment')->findBy($criteria); + $cStudentPublicationComment = []; + /** @var CStudentPublicationComment $item */ + foreach ($result as $item) { + $list = [ + 'Commment: '.$item->getComment(), + 'File '.$item->getFile(), + 'Course # '.$item->getCId(), + 'Date: '.$item->getSentAt()->format($dateFormat), + ]; + $cStudentPublicationComment[] = implode(', ', $list); + } + + // CWiki + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCourseBundle:CWiki')->findBy($criteria); + $cWiki = []; + /** @var CWiki $item */ + foreach ($result as $item) { + $list = [ + 'Title: '.$item->getTitle(), + 'Progress: '.$item->getProgress(), + 'IP: '.$item->getUserIp(), + ]; + $cWiki[] = implode(', ', $list); + } + + // Ticket + $criteria = [ + 'insertUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloTicketBundle:Ticket')->findBy($criteria); + $ticket = []; + /** @var Ticket $item */ + foreach ($result as $item) { + $list = [ + 'Code: '.$item->getCode(), + 'Subject: '.$item->getSubject(), + ]; + $ticket[] = implode(', ', $list); + } + + // Message + $criteria = [ + 'insertUserId' => $userId, + ]; + $result = $em->getRepository('ChamiloTicketBundle:Message')->findBy($criteria); + $ticketMessage = []; + /** @var \Chamilo\TicketBundle\Entity\Message $item */ + foreach ($result as $item) { + $list = [ + 'Subject: '.$item->getSubject(), + 'IP: '.$item->getIpAddress(), + 'Status: '.$item->getStatus(), + 'Creation date: '.$item->getInsertDateTime()->format($dateFormat), + ]; + $ticketMessage[] = implode(', ', $list); + } + + // SkillRelUserComment + $criteria = [ + 'feedbackGiver' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:SkillRelUserComment')->findBy($criteria); + $skillRelUserComment = []; + /** @var SkillRelUserComment $item */ + foreach ($result as $item) { + $list = [ + 'Feedback: '.$item->getFeedbackText(), + 'Value: '.$item->getFeedbackValue(), + 'Created at: '.$item->getFeedbackDateTime()->format($dateFormat), + ]; + $skillRelUserComment[] = implode(', ', $list); + } + + // UserRelCourseVote + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:UserRelCourseVote')->findBy($criteria); + $userRelCourseVote = []; + /** @var UserRelCourseVote $item */ + foreach ($result as $item) { + $list = [ + 'Course #'.$item->getCId(), + 'Session #'.$item->getSessionId(), + 'Vote: '.$item->getVote(), + ]; + $userRelCourseVote[] = implode(', ', $list); + } + + // UserApiKey + $criteria = [ + 'userId' => $userId, + ]; + $result = $em->getRepository('ChamiloCoreBundle:UserApiKey')->findBy($criteria); + $userApiKey = []; + /** @var UserApiKey $item */ + foreach ($result as $item) { + $list = [ + 'ApiKey #'.$item->getApiKey(), + 'Service: '.$item->getApiService(), + 'EndPoint: '.$item->getApiEndPoint(), + 'Validity start date: '.$item->getValidityEndDate()->format($dateFormat), + 'Validity enddate: '.$item->getValidityStartDate()->format($dateFormat), + 'Created at: '.$item->getCreatedDate()->format($dateFormat), + ]; + $userApiKey[] = implode(', ', $list); + } + + $user->setDropBoxSentFiles( + [ + 'Friends' => $friendList, + 'Events' => $eventList, + 'GradebookCertificate' => $gradebookCertificate, + + 'TrackECourseAccess' => $trackECourseAccessList, + 'TrackELogin' => $trackELoginList, + 'TrackEAccess' => $trackEAccessList, + 'TrackEDefault' => $trackEDefault, + 'TrackEOnline' => $trackEOnlineList, + 'TrackEUploads' => $trackEUploads, + 'TrackELastaccess' => $trackELastaccess, + 'GradebookResult' => $gradebookResult, + 'Downloads' => $trackEDownloads, + 'UserCourseCategory' => $userCourseCategory, + 'SkillRelUserComment' => $skillRelUserComment, + 'UserRelCourseVote' => $userRelCourseVote, + 'UserApiKey' => $userApiKey, + + // courses + 'AttendanceResult' => $cAttendanceResult, + 'Blog' => $cBlog, + 'DocumentsAdded' => $documents, + 'Chat' => $chatFiles, + 'ForumPost' => $cForumPostList, + 'ForumThread' => $cForumThreadList, + 'TrackEExercises' => $trackEExercises, + 'TrackEAttempt' => $trackEAttempt, + + 'GroupRelUser' => $cGroupRelUser, + 'Message' => $messageList, + 'Survey' => $cSurveyAnswer, + 'StudentPublication' => $cStudentPublication, + 'StudentPublicationComment' => $cStudentPublicationComment, + 'DropboxFile' => $cDropboxFile, + 'DropboxPerson' => $cDropboxPerson, + 'DropboxFeedback' => $cDropboxFeedback, + + 'LpView' => $cLpView, + 'Notebook' => $cNotebook, + + 'Wiki' => $cWiki, + // Tickets + + 'Ticket' => $ticket, + 'TicketMessage' => $ticketMessage, + ] + ); + + $user->setDropBoxReceivedFiles([]); + //$user->setGroups([]); + $user->setCurriculumItems([]); + + $portals = $user->getPortals(); + if (!empty($portals)) { + $list = []; + /** @var AccessUrlRelUser $portal */ + foreach ($portals as $portal) { + $portalInfo = \UrlManager::get_url_data_from_id($portal->getAccessUrlId()); + $list[] = $portalInfo['url']; + } + $user->setPortals($list); + } + + $coachList = $user->getSessionAsGeneralCoach(); + $list = []; + /** @var Session $session */ + foreach ($coachList as $session) { + $list[] = $session->getName(); + } + $user->setSessionAsGeneralCoach($list); + + $skillRelUserList = $user->getAchievedSkills(); + $list = []; + /** @var SkillRelUser $skillRelUser */ + foreach ($skillRelUserList as $skillRelUser) { + $list[] = $skillRelUser->getSkill()->getName(); + } + $user->setAchievedSkills($list); + $user->setCommentedUserSkills([]); + + $extraFieldValues = new \ExtraFieldValue('user'); + $items = $extraFieldValues->getAllValuesByItem($userId); + $user->setExtraFields($items); + + $lastLogin = $user->getLastLogin(); + if (empty($lastLogin)) { + $login = $this->getLastLogin($user); + if ($login) { + $lastLogin = $login->getLoginDate(); + } + } + $user->setLastLogin($lastLogin); + + $dateNormalizer = new GetSetMethodNormalizer(); + $dateNormalizer->setCircularReferenceHandler(function ($object) { + return get_class($object); + }); + + $ignore = [ + 'twoStepVerificationCode', + 'biography', + 'dateOfBirth', + 'gender', + 'facebookData', + 'facebookName', + 'facebookUid', + 'gplusData', + 'gplusName', + 'gplusUid', + 'locale', + 'timezone', + 'twitterData', + 'twitterName', + 'twitterUid', + 'gplusUid', + 'token', + 'website', + 'plainPassword', + 'completeNameWithUsername', + 'completeName', + 'completeNameWithClasses', + 'salt', + ]; + + $dateNormalizer->setIgnoredAttributes($ignore); + + $callback = function ($dateTime) { + return $dateTime instanceof \DateTime + ? $dateTime->format(\DateTime::ISO8601) + : ''; + }; + $dateNormalizer->setCallbacks( + [ + 'createdAt' => $callback, + 'lastLogin' => $callback, + 'registrationDate' => $callback, + 'memberSince' => $callback, + ] + ); + + $normalizers = [$dateNormalizer]; + $serializer = new Serializer($normalizers, [new JsonEncoder()]); + + $jsonContent = $serializer->serialize($user, 'json'); + + return $jsonContent; + } + + /** + * Get the last login from the track_e_login table. + * This might be different from user.last_login in the case of legacy users + * as user.last_login was only implemented in 1.10 version with a default + * value of NULL (not the last record from track_e_login). + * + * @param User $user + * + * @throws \Exception + * + * @return null|TrackELogin + */ + public function getLastLogin(User $user) + { + $repo = $this->getEntityManager()->getRepository('ChamiloCoreBundle:TrackELogin'); + $qb = $repo->createQueryBuilder('l'); + + $login = $qb + ->select('l') + ->where( + $qb->expr()->eq('l.loginUserId', $user->getId()) + ) + ->setMaxResults(1) + ->orderBy('l.loginDate', 'DESC') + ->getQuery() + ->getOneOrNullResult(); + + return $login; + } }