Minor - fix personal data from 1.11.x

pull/2635/head
Julio Montoya 7 years ago
parent 36a780bd07
commit b97ae56cd9
  1. 118
      main/template/default/macro/macro.tpl
  2. 57
      main/template/default/social/personal_data.html.twig
  3. 125
      src/UserBundle/Entity/User.php
  4. 882
      src/UserBundle/Repository/UserRepository.php

@ -0,0 +1,118 @@
{# special macros to generate repeated html code #}
{% macro collapse(name, title, content, list = false) %}
{% autoescape false %}
<div class="panel-group" id="{{ name }}" role="tablist" aria-multiselectable="true">
<div class="panel panel-default" id="{{ name }}_block">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#{{ name }}" href="#{{ name }}Collapse" aria-expanded="true" aria-controls="{{ name }}Collapse">
{{ title }}
</a>
</h4>
</div>
<div style="" aria-expanded="true" id="{{ name }}Collapse" class="panel-collapse collapse in" role="tabpanel">
<div class="panel-body">
{% if list %}
<ul class="nav nav-pills nav-stacked">
{{ content }}
</ul>
{% else %}
{{ content }}
{% endif %}
</div>
</div>
</div>
</div>
{% endautoescape %}
{% endmacro %}
{% macro collapseFor(name, title, array) %}
{% autoescape false %}
<div class="panel-group" id="{{ name }}" role="tablist" aria-multiselectable="true">
<div class="panel panel-default" id="{{ name }}_block">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#{{ name }}" href="#{{ name }}Collapse" aria-expanded="true" aria-controls="{{ name }}Collapse">
{{ title }}
</a>
</h4>
</div>
<div style="" aria-expanded="true" id="{{ name }}Collapse" class="panel-collapse collapse in" role="tabpanel">
<div class="panel-body">
<ul class="nav nav-pills nav-stacked">
{% for item in array %}
<li>
<a href="{{ item.link }}">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endautoescape %}
{% endmacro %}
{% macro collapseMenu(name, title, array) %}
{% autoescape false %}
<div class="panel-group" id="{{ name }}" role="tablist" aria-multiselectable="true">
<div class="panel panel-default" id="{{ name }}_block">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#{{ name }}" href="#{{ name }}Collapse" aria-expanded="true" aria-controls="{{ name }}Collapse">
{{ title }}
</a>
</h4>
</div>
<div aria-expanded="true" id="{{ name }}Collapse" class="panel-collapse collapse in" role="tabpanel">
<div class="panel-body">
<ul class="list-group">
{% for item in array %}
<li class="list-group-item {{ item.class }}">
<span class="item-icon">{{ item.icon }}</span>
<a href="{{ item.link }}">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endautoescape %}
{% endmacro %}
{% macro pluginSidebar(name, content) %}
{% autoescape false %}
<div id="{{ name }}" class="plugin plugin_{{ name }}">
{{ content }}
</div>
{% endautoescape %}
{% endmacro %}
{% macro pluginPanel(name, content) %}
{% autoescape false %}
<div id="{{ name }}" class="plugin plugin_{{ name }}">
<div class="row">
<div class="col-md-12">
{{ content }}
</div>
</div>
</div>
{% endautoescape %}
{% endmacro %}
{% macro panel(name, content, footer = '') %}
{% autoescape false %}
<div class="panel panel-default">
<div class="panel-heading"> {{ name }}</div>
<div class="panel-body">
{{ content }}
</div>
{% if footer %}
<div class="panel-footer">{{ footer }}</div>
{% endif %}
</div>
{% endautoescape %}
{% endmacro %}

@ -0,0 +1,57 @@
{% extends '@ChamiloTheme/Layout/layout_one_col.html.twig' %}
{% import template ~ '/macro/macro.tpl' as display %}
{% block content %}
{% autoescape false %}
<div class="row">
<div class="col-md-3">
<div class="social-network-menu">
{{ social_avatar_block }}
{{ social_menu_block }}
</div>
</div>
<div class="col-md-9">
{{ 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 %}
<div class="panel personal-data-treatment">
<div class="panel-title">{{ 'PersonalDataTreatmentTitle' | get_lang }}</div>
<div class="personal-data-treatment-description">
{% for treatment in personal_data.treatment %}
{% if treatment.content %}
<div class="sub-section">
<div class="panel-sub-title">{{ treatment.title }}</div>
<div class="panel-body">{{ treatment.content }}</div>
</div>
{% endif %}
{% endfor %}
</div>
</div>
{% endif %}
{% if personal_data.officer_name %}
<div class="panel personal-data-responsible">
<div class="panel-title">{{ 'PersonalDataOfficerName' | get_lang }}</div>
<div class="personal-data-responsible-description">
<a href="mailto:{{ personal_data.officer_email }}">{{ personal_data.officer_name }}</a>
</div>
<div class="panel-title">{{ 'PersonalDataOfficerRole' | get_lang }}</div>
<div class="personal-data-responsible-description">
{{ personal_data.officer_role }}
</div>
</div>
{% endif %}
{% if term_link %}
{{ display.panel('TermsAndConditions'|get_lang, term_link ) }}
{% endif %}
{{ display.panel('PersonalDataPermissionsYouGaveUs' | get_lang, permission) }}
</div>
</div>
{% endautoescape %}
{% endblock %}

@ -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
*

@ -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;
}
}

Loading…
Cancel
Save