Passed
Push — master ( 35dbb5...2680f7 )
by Julito
27:44
created

UserToJsonNormalizer   A

Complexity

Total Complexity 40

Size/Duplication

Total Lines 756
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 401
dl 0
loc 756
rs 9.2
c 0
b 0
f 0
wmc 40

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
F getPersonalDataToJson() 0 736 39

How to fix   Complexity   

Complex Class

Complex classes like UserToJsonNormalizer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use UserToJsonNormalizer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chamilo\CoreBundle\Serializer;
6
7
use Agenda;
8
use Chamilo\CoreBundle\Entity\GradebookCertificate;
9
use Chamilo\CoreBundle\Entity\GradebookResult;
10
use Chamilo\CoreBundle\Entity\Message;
11
use Chamilo\CoreBundle\Entity\SkillRelUserComment;
12
use Chamilo\CoreBundle\Entity\Ticket;
13
use Chamilo\CoreBundle\Entity\TicketMessage;
14
use Chamilo\CoreBundle\Entity\TrackEAccess;
15
use Chamilo\CoreBundle\Entity\TrackEAttempt;
16
use Chamilo\CoreBundle\Entity\TrackECourseAccess;
17
use Chamilo\CoreBundle\Entity\TrackEDefault;
18
use Chamilo\CoreBundle\Entity\TrackEDownloads;
19
use Chamilo\CoreBundle\Entity\TrackELastaccess;
20
use Chamilo\CoreBundle\Entity\TrackELogin;
21
use Chamilo\CoreBundle\Entity\TrackEOnline;
22
use Chamilo\CoreBundle\Entity\TrackEUploads;
23
use Chamilo\CoreBundle\Entity\TrackExercise;
24
use Chamilo\CoreBundle\Entity\User;
25
use Chamilo\CoreBundle\Entity\UserCourseCategory;
26
use Chamilo\CoreBundle\Entity\UserRelCourseVote;
27
use Chamilo\CoreBundle\Repository\Node\UserRepository;
28
use Chamilo\CourseBundle\Entity\CAttendanceResult;
29
use Chamilo\CourseBundle\Entity\CAttendanceSheet;
30
use Chamilo\CourseBundle\Entity\CDropboxFeedback;
31
use Chamilo\CourseBundle\Entity\CDropboxFile;
32
use Chamilo\CourseBundle\Entity\CDropboxPerson;
33
use Chamilo\CourseBundle\Entity\CForumPost;
34
use Chamilo\CourseBundle\Entity\CForumThread;
35
use Chamilo\CourseBundle\Entity\CGroupRelUser;
36
use Chamilo\CourseBundle\Entity\CLpView;
37
use Chamilo\CourseBundle\Entity\CNotebook;
38
use Chamilo\CourseBundle\Entity\CStudentPublication;
39
use Chamilo\CourseBundle\Entity\CStudentPublicationComment;
40
use Chamilo\CourseBundle\Entity\CSurveyAnswer;
41
use Chamilo\CourseBundle\Entity\CWiki;
42
use DateTime;
43
use DateTimeInterface;
44
use Doctrine\ORM\EntityManager;
45
use SocialManager;
46
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
47
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
48
use Symfony\Component\Serializer\SerializerInterface;
49
50
final class UserToJsonNormalizer
51
{
52
    private EntityManager $em;
53
    private UserRepository $userRepository;
54
    private SerializerInterface $serializer;
55
56
    public function __construct(EntityManager $em, UserRepository $userRepository, SerializerInterface $serializer)
57
    {
58
        $this->em = $em;
59
        $this->userRepository = $userRepository;
60
        $this->serializer = $serializer;
61
    }
62
63
    /**
64
     * Serialize the whole entity to an array.
65
     *
66
     * @param array $substitutionTerms Substitute terms for some elements
67
     *
68
     * @return string
69
     */
70
    public function getPersonalDataToJson(int $userId, array $substitutionTerms)
71
    {
72
        $em = $this->em;
73
        $dateFormat = DateTimeInterface::ATOM;
74
75
        /** @var User $user */
76
        $user = $this->userRepository->find($userId);
77
78
        $user->setPassword($substitutionTerms['password'] ?? '');
79
        $user->setSalt($substitutionTerms['salt'] ?? '');
80
81
        $noDataLabel = $substitutionTerms['empty'] ?? '';
82
83
        // Dummy content
84
        $user->setDateOfBirth(null);
85
        //$user->setBiography($noDataLabel);
86
        /*$user->setFacebookData($noDataLabel);
87
        $user->setFacebookName($noDataLabel);
88
        $user->setFacebookUid($noDataLabel);*/
89
        //$user->setImageName($noDataLabel);
90
        //$user->setTwoStepVerificationCode($noDataLabel);
91
        //$user->setGender($noDataLabel);
92
        /*$user->setGplusData($noDataLabel);
93
        $user->setGplusName($noDataLabel);
94
        $user->setGplusUid($noDataLabel);*/
95
        $user->setLocale($noDataLabel);
96
        $user->setTimezone($noDataLabel);
97
        /*$user->setTwitterData($noDataLabel);
98
        $user->setTwitterName($noDataLabel);
99
        $user->setTwitterUid($noDataLabel);*/
100
        $user->setWebsite($noDataLabel);
101
        //$user->setToken($noDataLabel);
102
103
        /*$friends = SocialManager::get_friends($userId);
104
        $friendList = [];
105
        if (!empty($friends)) {
106
            foreach ($friends as $friend) {
107
                $friendList[] = $friend['user_info']['complete_name'];
108
            }
109
        }*/
110
111
        /*$agenda = new Agenda('personal');
112
        $events = $agenda->getEvents(0, 0, 0, 0, $userId, 'array');
113
        $eventList = [];
114
        if (!empty($events)) {
115
            foreach ($events as $event) {
116
                $eventList[] = $event['title'].' '.$event['start_date_localtime'].' / '.$event['end_date_localtime'];
117
            }
118
        }*/
119
120
        // GradebookCertificate
121
        $result = $em->getRepository(GradebookCertificate::class)->findBy([
122
            'user' => $userId,
123
        ]);
124
        $gradebookCertificate = [];
125
        /** @var GradebookCertificate $item */
126
        foreach ($result as $item) {
127
            $createdAt = $item->getCreatedAt()->format($dateFormat);
128
            $list = [
129
                'Score: '.$item->getScoreCertificate(),
130
                'Path: '.$item->getPathCertificate(),
131
                'Created at: '.$createdAt,
132
            ];
133
            $gradebookCertificate[] = implode(', ', $list);
134
        }
135
136
        // TrackEExercises
137
        $criteria = [
138
            'user' => $userId,
139
        ];
140
        $result = $em->getRepository(TrackExercise::class)->findBy($criteria);
141
        $trackEExercises = [];
142
        /** @var TrackExercise $item */
143
        foreach ($result as $item) {
144
            $date = $item->getExeDate()->format($dateFormat);
145
            $list = [
146
                'IP: '.$item->getUserIp(),
147
                'Start: '.$date,
148
                'Status: '.$item->getStatus(),
149
                // 'Result: '.$item->getExeResult(),
150
                // 'Weighting: '.$item->getExeWeighting(),
151
            ];
152
            $trackEExercises[] = implode(', ', $list);
153
        }
154
155
        // TrackEAttempt
156
        $criteria = [
157
            'user' => $userId,
158
        ];
159
        $result = $em->getRepository(TrackEAttempt::class)->findBy($criteria);
160
        $trackEAttempt = [];
161
        /** @var TrackEAttempt $item */
162
        foreach ($result as $item) {
163
            $date = $item->getTms()->format($dateFormat);
164
            $list = [
165
                'Attempt #'.$item->getTrackExercise()->getExeId(),
166
                //'Answer: '.$item->getAnswer(),
167
                //'Marks: '.$item->getMarks(),
168
                'Position: '.$item->getPosition(),
169
                'Date: '.$date,
170
            ];
171
            $trackEAttempt[] = implode(', ', $list);
172
        }
173
174
        // TrackECourseAccess
175
        $criteria = [
176
            'user' => $userId,
177
        ];
178
        $result = $em->getRepository(TrackECourseAccess::class)->findBy($criteria);
179
        $trackECourseAccessList = [];
180
        /** @var TrackECourseAccess $item */
181
        foreach ($result as $item) {
182
            $startDate = $item->getLoginCourseDate()->format($dateFormat);
183
            $endDate = null !== $item->getLogoutCourseDate() ? $item->getLogoutCourseDate()->format($dateFormat) : '';
184
            $list = [
185
                'IP: '.$item->getUserIp(),
186
                'Start: '.$startDate,
187
                'End: '.$endDate,
188
            ];
189
            $trackECourseAccessList[] = implode(', ', $list);
190
        }
191
192
        $checkEntities = [
193
            TrackELogin::class => 'user',
194
            TrackEAccess::class => 'accessUserId',
195
            TrackEOnline::class => 'loginUserId',
196
            TrackEDefault::class => 'defaultUserId',
197
            TrackELastaccess::class => 'accessUserId',
198
            TrackEUploads::class => 'uploadUserId',
199
            GradebookResult::class => 'user',
200
            TrackEDownloads::class => 'downUserId',
201
        ];
202
203
        $maxResults = 1000;
204
        $trackResults = [];
205
        foreach ($checkEntities as $entity => $field) {
206
            $qb = $em->createQueryBuilder();
207
            $qb->select($qb->expr()->count('l'))
208
                ->from($entity, 'l')
209
                ->where("l.$field = :login")
210
                ->setParameter('login', $userId)
211
            ;
212
            $query = $qb->getQuery();
213
            $count = $query->getSingleScalarResult();
214
215
            if ($count > $maxResults) {
216
                $qb = $em->getRepository($entity)->createQueryBuilder('l');
217
                $qb
218
                    ->select('l')
219
                    ->where("l.$field = :login")
220
                    ->setParameter('login', $userId)
221
                ;
222
                $qb
223
                    ->setFirstResult(0)
224
                    ->setMaxResults($maxResults)
225
                ;
226
                $result = $qb->getQuery()->getResult();
227
            } else {
228
                $criteria = [
229
                    $field => $userId,
230
                ];
231
                $result = $em->getRepository($entity)->findBy($criteria);
232
            }
233
            $trackResults[$entity] = $result;
234
        }
235
236
        $trackELoginList = [];
237
        /** @var TrackELogin $item */
238
        foreach ($trackResults[TrackELogin::class] as $item) {
239
            $startDate = $item->getLoginDate()->format($dateFormat);
240
            $endDate = null !== $item->getLogoutDate() ? $item->getLogoutDate()->format($dateFormat) : '';
241
            $list = [
242
                'IP: '.$item->getUserIp(),
243
                'Start: '.$startDate,
244
                'End: '.$endDate,
245
            ];
246
            $trackELoginList[] = implode(', ', $list);
247
        }
248
249
        // TrackEAccess
250
        $trackEAccessList = [];
251
        /** @var TrackEAccess $item */
252
        foreach ($trackResults[TrackEAccess::class] as $item) {
253
            $date = $item->getAccessDate()->format($dateFormat);
254
            $list = [
255
                'IP: '.$item->getUserIp(),
256
                'Tool: '.$item->getAccessTool(),
257
                'End: '.$date,
258
            ];
259
            $trackEAccessList[] = implode(', ', $list);
260
        }
261
262
        // TrackEOnline
263
        $trackEOnlineList = [];
264
        /** @var TrackEOnline $item */
265
        foreach ($trackResults[TrackEOnline::class] as $item) {
266
            $date = $item->getLoginDate()->format($dateFormat);
267
            $list = [
268
                'IP: '.$item->getUserIp(),
269
                'Login date: '.$date,
270
                'Course # '.$item->getCId(),
271
                'Session # '.$item->getSessionId(),
272
            ];
273
            $trackEOnlineList[] = implode(', ', $list);
274
        }
275
276
        // TrackEDefault
277
        $trackEDefault = [];
278
        /** @var TrackEDefault $item */
279
        foreach ($trackResults[TrackEDefault::class] as $item) {
280
            $date = $item->getDefaultDate()->format($dateFormat);
281
            $list = [
282
                'Type: '.$item->getDefaultEventType(),
283
                'Value: '.$item->getDefaultValue(),
284
                'Value type: '.$item->getDefaultValueType(),
285
                'Date: '.$date,
286
                'Course #'.$item->getCId(),
287
                'Session # '.$item->getSessionId(),
288
            ];
289
            $trackEDefault[] = implode(', ', $list);
290
        }
291
292
        // TrackELastaccess
293
        $trackELastaccess = [];
294
        /** @var TrackELastaccess $item */
295
        foreach ($trackResults[TrackELastaccess::class] as $item) {
296
            $date = $item->getAccessDate()->format($dateFormat);
297
            $list = [
298
                'Course #'.$item->getCId(),
299
                'Session # '.$item->getAccessSessionId(),
300
                'Tool: '.$item->getAccessTool(),
301
                'Access date: '.$date,
302
            ];
303
            $trackELastaccess[] = implode(', ', $list);
304
        }
305
306
        // TrackEUploads
307
        $trackEUploads = [];
308
        /** @var TrackEUploads $item */
309
        foreach ($trackResults[TrackEUploads::class] as $item) {
310
            $date = $item->getUploadDate()->format($dateFormat);
311
            $list = [
312
                'Course #'.$item->getCId(),
313
                'Uploaded at: '.$date,
314
                'Upload id # '.$item->getUploadId(),
315
            ];
316
            $trackEUploads[] = implode(', ', $list);
317
        }
318
319
        $gradebookResult = [];
320
        /** @var GradebookResult $item */
321
        foreach ($trackResults[GradebookResult::class] as $item) {
322
            $date = $item->getCreatedAt()->format($dateFormat);
323
            $list = [
324
                'Evaluation id# '.$item->getEvaluation()->getId(),
325
                //'Score: '.$item->getScore(),
326
                'Creation date: '.$date,
327
            ];
328
            $gradebookResult[] = implode(', ', $list);
329
        }
330
331
        $trackEDownloads = [];
332
        /** @var TrackEDownloads $item */
333
        foreach ($trackResults[TrackEDownloads::class] as $item) {
334
            $date = $item->getDownDate()->format($dateFormat);
335
            $list = [
336
                'File: '.$item->getDownDocPath(),
337
                'Download at: '.$date,
338
            ];
339
            $trackEDownloads[] = implode(', ', $list);
340
        }
341
342
        // UserCourseCategory
343
        $criteria = [
344
            'user' => $userId,
345
        ];
346
        $result = $em->getRepository(UserCourseCategory::class)->findBy($criteria);
347
        $userCourseCategory = [];
348
        /** @var UserCourseCategory $item */
349
        foreach ($result as $item) {
350
            $list = [
351
                'Title: '.$item->getTitle(),
352
            ];
353
            $userCourseCategory[] = implode(', ', $list);
354
        }
355
356
        // Forum
357
        $criteria = [
358
            'user' => $userId,
359
        ];
360
        $result = $em->getRepository(CForumPost::class)->findBy($criteria);
361
        $cForumPostList = [];
362
        /** @var CForumPost $item */
363
        foreach ($result as $item) {
364
            $date = $item->getPostDate()->format($dateFormat);
365
            $list = [
366
                'Title: '.$item->getPostTitle(),
367
                'Creation date: '.$date,
368
            ];
369
            $cForumPostList[] = implode(', ', $list);
370
        }
371
372
        // CForumThread
373
        $criteria = [
374
            'user' => $userId,
375
        ];
376
        $result = $em->getRepository(CForumThread::class)->findBy($criteria);
377
        $cForumThreadList = [];
378
        /** @var CForumThread $item */
379
        foreach ($result as $item) {
380
            $date = $item->getThreadDate()->format($dateFormat);
381
            $list = [
382
                'Title: '.$item->getThreadTitle(),
383
                'Creation date: '.$date,
384
            ];
385
            $cForumThreadList[] = implode(', ', $list);
386
        }
387
        // CForumAttachment
388
        /*$criteria = [
389
            'threadPosterId' => $userId,
390
        ];
391
        $result = $em->getRepository('ChamiloCourseBundle:CForumAttachment')->findBy($criteria);
392
        $cForumThreadList = [];
393
        * @var CForumThread $item
394
        foreach ($result as $item) {
395
            $list = [
396
                'Title: '.$item->getThreadTitle(),
397
                'Creation date: '.$item->getThreadDate()->format($dateFormat),
398
            ];
399
            $cForumThreadList[] = implode(', ', $list);
400
        }*/
401
402
        // cGroupRelUser
403
        $criteria = [
404
            'user' => $userId,
405
        ];
406
        $result = $em->getRepository(CGroupRelUser::class)->findBy($criteria);
407
        $cGroupRelUser = [];
408
        /** @var CGroupRelUser $item */
409
        foreach ($result as $item) {
410
            $list = [
411
                'Course # '.$item->getCId(),
412
                'Group #'.$item->getGroup()->getIid(),
413
                'Role: '.$item->getStatus(),
414
            ];
415
            $cGroupRelUser[] = implode(', ', $list);
416
        }
417
418
        // CAttendanceSheet
419
        $criteria = [
420
            'user' => $userId,
421
        ];
422
        $result = $em->getRepository(CAttendanceSheet::class)->findBy($criteria);
423
        $cAttendanceSheetList = [];
424
        /** @var CAttendanceSheet $item */
425
        foreach ($result as $item) {
426
            $list = [
427
                'Presence: '.$item->getPresence(),
428
                'Calendar id: '.$item->getAttendanceCalendar()->getIid(),
429
            ];
430
            $cAttendanceSheetList[] = implode(', ', $list);
431
        }
432
433
        // CAttendanceResult
434
        $criteria = [
435
            'user' => $userId,
436
        ];
437
        $result = $em->getRepository(CAttendanceResult::class)->findBy($criteria);
438
        $cAttendanceResult = [];
439
        /** @var CAttendanceResult $item */
440
        foreach ($result as $item) {
441
            $list = [
442
                'Score : '.$item->getScore(),
443
                'Calendar id: '.$item->getAttendance()->getIid(),
444
            ];
445
            $cAttendanceResult[] = implode(', ', $list);
446
        }
447
448
        // Message
449
        $criteria = [
450
            'sender' => $userId,
451
        ];
452
        $result = $em->getRepository(Message::class)->findBy($criteria);
453
        $messageList = [];
454
        /** @var Message $item */
455
        foreach ($result as $item) {
456
            $date = $item->getSendDate()->format($dateFormat);
457
            $userName = '';
458
            if ($item->getReceivers()) {
459
                foreach ($item->getReceivers() as $receiver) {
460
                    $userName = ', '.$receiver->getUsername();
461
                }
462
            }
463
464
            $list = [
465
                'Title: '.$item->getTitle(),
466
                'Sent date: '.$date,
467
                'To users: '.$userName,
468
                'Type: '.$item->getMsgType(),
469
            ];
470
            $messageList[] = implode(', ', $list);
471
        }
472
473
        // CSurveyAnswer
474
        $criteria = [
475
            'user' => $userId,
476
        ];
477
        $result = $em->getRepository(CSurveyAnswer::class)->findBy($criteria);
478
        $cSurveyAnswer = [];
479
        /** @var CSurveyAnswer $item */
480
        foreach ($result as $item) {
481
            $list = [
482
                'Answer # '.$item->getIid(),
483
                'Value: '.$item->getValue(),
484
            ];
485
            $cSurveyAnswer[] = implode(', ', $list);
486
        }
487
488
        // CDropboxFile
489
        $criteria = [
490
            'uploaderId' => $userId,
491
        ];
492
        $result = $em->getRepository(CDropboxFile::class)->findBy($criteria);
493
        $cDropboxFile = [];
494
        /** @var CDropboxFile $item */
495
        foreach ($result as $item) {
496
            $date = $item->getUploadDate()->format($dateFormat);
497
            $list = [
498
                'Title: '.$item->getTitle(),
499
                'Uploaded date: '.$date,
500
                'File: '.$item->getFilename(),
501
            ];
502
            $cDropboxFile[] = implode(', ', $list);
503
        }
504
505
        // CDropboxPerson
506
        $criteria = [
507
            'userId' => $userId,
508
        ];
509
        $result = $em->getRepository(CDropboxPerson::class)->findBy($criteria);
510
        $cDropboxPerson = [];
511
        /** @var CDropboxPerson $item */
512
        foreach ($result as $item) {
513
            $list = [
514
                'File #'.$item->getFileId(),
515
                'Course #'.$item->getCId(),
516
            ];
517
            $cDropboxPerson[] = implode(', ', $list);
518
        }
519
520
        // CDropboxPerson
521
        $criteria = [
522
            'authorUserId' => $userId,
523
        ];
524
        $result = $em->getRepository(CDropboxFeedback::class)->findBy($criteria);
525
        $cDropboxFeedback = [];
526
        /** @var CDropboxFeedback $item */
527
        foreach ($result as $item) {
528
            $date = $item->getFeedbackDate()->format($dateFormat);
529
            $list = [
530
                'File #'.$item->getFileId(),
531
                'Feedback: '.$item->getFeedback(),
532
                'Date: '.$date,
533
            ];
534
            $cDropboxFeedback[] = implode(', ', $list);
535
        }
536
537
        // CNotebook
538
        $criteria = [
539
            'user' => $userId,
540
        ];
541
        $result = $em->getRepository(CNotebook::class)->findBy($criteria);
542
        $cNotebook = [];
543
        /** @var CNotebook $item */
544
        foreach ($result as $item) {
545
            $date = $item->getUpdateDate()->format($dateFormat);
546
            $list = [
547
                'Title: '.$item->getTitle(),
548
                'Date: '.$date,
549
            ];
550
            $cNotebook[] = implode(', ', $list);
551
        }
552
553
        // CLpView
554
        $criteria = [
555
            'user' => $userId,
556
        ];
557
        $result = $em->getRepository(CLpView::class)->findBy($criteria);
558
        $cLpView = [];
559
        /** @var CLpView $item */
560
        foreach ($result as $item) {
561
            $list = [
562
                //'Id #'.$item->getId(),
563
                'LP #'.$item->getLp()->getIid(),
564
                'Progress: '.$item->getProgress(),
565
                //'Course #'.$item->getCId(),
566
                //'Session #'.$item->getSessionId(),
567
            ];
568
            $cLpView[] = implode(', ', $list);
569
        }
570
571
        // CStudentPublication
572
        $criteria = [
573
            'user' => $userId,
574
        ];
575
        $result = $em->getRepository(CStudentPublication::class)->findBy($criteria);
576
        $cStudentPublication = [];
577
        /** @var CStudentPublication $item */
578
        foreach ($result as $item) {
579
            $list = [
580
                'Title: '.$item->getTitle(),
581
                //'URL: '.$item->getTitle(),
582
            ];
583
            $cStudentPublication[] = implode(', ', $list);
584
        }
585
586
        // CStudentPublicationComment
587
        $criteria = [
588
            'user' => $userId,
589
        ];
590
        $result = $em->getRepository(CStudentPublicationComment::class)->findBy($criteria);
591
        $cStudentPublicationComment = [];
592
        /** @var CStudentPublicationComment $item */
593
        foreach ($result as $item) {
594
            $date = $item->getSentAt()->format($dateFormat);
595
            $list = [
596
                'Commment: '.$item->getComment(),
597
                'File '.$item->getFile(),
598
                //'Course # '.$item->getCId(),
599
                'Date: '.$date,
600
            ];
601
            $cStudentPublicationComment[] = implode(', ', $list);
602
        }
603
604
        // CWiki
605
        $criteria = [
606
            'userId' => $userId,
607
        ];
608
        $result = $em->getRepository(CWiki::class)->findBy($criteria);
609
        $cWiki = [];
610
        /** @var CWiki $item */
611
        foreach ($result as $item) {
612
            $list = [
613
                'Title: '.$item->getTitle(),
614
                'Progress: '.$item->getProgress(),
615
                'IP: '.$item->getUserIp(),
616
            ];
617
            $cWiki[] = implode(', ', $list);
618
        }
619
620
        // Ticket
621
        $criteria = [
622
            'insertUserId' => $userId,
623
        ];
624
        $result = $em->getRepository(Ticket::class)->findBy($criteria);
625
        $ticket = [];
626
        /** @var Ticket $item */
627
        foreach ($result as $item) {
628
            $list = [
629
                'Code: '.$item->getCode(),
630
                'Subject: '.$item->getSubject(),
631
            ];
632
            $ticket[] = implode(', ', $list);
633
        }
634
635
        // Message
636
        $criteria = [
637
            'insertUserId' => $userId,
638
        ];
639
        $result = $em->getRepository(TicketMessage::class)->findBy($criteria);
640
        $ticketMessage = [];
641
        /** @var TicketMessage $item */
642
        foreach ($result as $item) {
643
            $date = $item->getInsertDateTime()->format($dateFormat);
644
            $list = [
645
                'Subject: '.$item->getSubject(),
646
                'IP: '.$item->getIpAddress(),
647
                'Status: '.$item->getStatus(),
648
                'Creation date: '.$date,
649
            ];
650
            $ticketMessage[] = implode(', ', $list);
651
        }
652
653
        // SkillRelUserComment
654
        $criteria = [
655
            'feedbackGiver' => $userId,
656
        ];
657
        $result = $em->getRepository(SkillRelUserComment::class)->findBy($criteria);
658
        $skillRelUserComment = [];
659
        /** @var SkillRelUserComment $item */
660
        foreach ($result as $item) {
661
            $date = $item->getFeedbackDateTime()->format($dateFormat);
662
            $list = [
663
                'Feedback: '.$item->getFeedbackText(),
664
                'Value: '.$item->getFeedbackValue(),
665
                'Created at: '.$date,
666
            ];
667
            $skillRelUserComment[] = implode(', ', $list);
668
        }
669
670
        // UserRelCourseVote
671
        $criteria = [
672
            'user' => $userId,
673
        ];
674
        $result = $em->getRepository(UserRelCourseVote::class)->findBy($criteria);
675
        $userRelCourseVote = [];
676
        /** @var UserRelCourseVote $item */
677
        foreach ($result as $item) {
678
            $list = [
679
                'Course #'.$item->getCourse()->getId(),
680
                //'Session #'.$item->getSession()->getId(),
681
                'Vote: '.$item->getVote(),
682
            ];
683
            $userRelCourseVote[] = implode(', ', $list);
684
        }
685
686
        /*$user->setDropBoxSentFiles(
687
            [
688
                'Friends' => $friendList,
689
                'Events' => $eventList,
690
                'GradebookCertificate' => $gradebookCertificate,
691
692
                'TrackECourseAccess' => $trackECourseAccessList,
693
                'TrackELogin' => $trackELoginList,
694
                'TrackEAccess' => $trackEAccessList,
695
                'TrackEDefault' => $trackEDefault,
696
                'TrackEOnline' => $trackEOnlineList,
697
                'TrackEUploads' => $trackEUploads,
698
                'TrackELastaccess' => $trackELastaccess,
699
                'GradebookResult' => $gradebookResult,
700
                'Downloads' => $trackEDownloads,
701
                'UserCourseCategory' => $userCourseCategory,
702
                'SkillRelUserComment' => $skillRelUserComment,
703
                'UserRelCourseVote' => $userRelCourseVote,
704
705
                // courses
706
                'AttendanceResult' => $cAttendanceResult,
707
                'Blog' => $cBlog,
708
                'DocumentsAdded' => $documents,
709
                'Chat' => $chatFiles,
710
                'ForumPost' => $cForumPostList,
711
                'ForumThread' => $cForumThreadList,
712
                'TrackEExercises' => $trackEExercises,
713
                'TrackEAttempt' => $trackEAttempt,
714
715
                'GroupRelUser' => $cGroupRelUser,
716
                'Message' => $messageList,
717
                'Survey' => $cSurveyAnswer,
718
                'StudentPublication' => $cStudentPublication,
719
                'StudentPublicationComment' => $cStudentPublicationComment,
720
                'DropboxFile' => $cDropboxFile,
721
                'DropboxPerson' => $cDropboxPerson,
722
                'DropboxFeedback' => $cDropboxFeedback,
723
724
                'LpView' => $cLpView,
725
                'Notebook' => $cNotebook,
726
727
                'Wiki' => $cWiki,
728
                // Tickets
729
730
                'Ticket' => $ticket,
731
                'TicketMessage' => $ticketMessage,
732
            ]
733
        );*/
734
735
        //$user->setDropBoxReceivedFiles([]);
736
        //$user->setGroups([]);
737
        //$user->setCurriculumItems([]);
738
739
        /*$portals = $user->getPortals();
740
        if (!empty($portals)) {
741
            $list = [];
742
            /** @var AccessUrlRelUser $portal */
743
        /*foreach ($portals as $portal) {
744
            $portalInfo = UrlManager::get_url_data_from_id($portal->getUrl()->getId());
745
            $list[] = $portalInfo['url'];
746
        }
747
        }
748
        $user->setPortals($list);*/
749
750
        /*$skillRelUserList = $user->getAchievedSkills();
751
        $list = [];
752
        foreach ($skillRelUserList as $skillRelUser) {
753
            $list[] = $skillRelUser->getSkill()->getName();
754
        }
755
        $user->setAchievedSkills($list);
756
        $user->setCommentedUserSkills([]);*/
757
758
        //$extraFieldValues = new \ExtraFieldValue('user');
759
760
        $lastLogin = $user->getLastLogin();
761
        /*if (null === $lastLogin) {
762
            $login = $this->userRepository->getLastLogin($user);
763
            if (null !== $login) {
764
                $lastLogin = $login->getLoginDate();
765
            }
766
        }*/
767
        $user->setLastLogin($lastLogin);
768
769
        $ignore = [
770
            'twoStepVerificationCode',
771
            'biography',
772
            'dateOfBirth',
773
            'gender',
774
            'facebookData',
775
            'facebookName',
776
            'facebookUid',
777
            'gplusData',
778
            'gplusName',
779
            'gplusUid',
780
            'locale',
781
            'timezone',
782
            'twitterData',
783
            'twitterName',
784
            'twitterUid',
785
            'gplusUid',
786
            'token',
787
            'website',
788
            'plainPassword',
789
            'completeNameWithUsername',
790
            'completeName',
791
            'completeNameWithClasses',
792
            'salt',
793
            'dropBoxSentFiles',
794
            'dropBoxReceivedFiles',
795
            'currentUrl',
796
            'uuid',
797
            'curriculumItems',
798
            'currentSession',
799
            'currentCourse',
800
            'resourceNode',
801
        ];
802
803
        return $this->serializer->serialize($user, 'json', [
804
            AbstractNormalizer::IGNORED_ATTRIBUTES => $ignore,
805
            'groups' => ['user_export'],
806
        ]);
807
    }
808
}
809