| Total Complexity | 111 |
| Total Lines | 1400 |
| Duplicated Lines | 0 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 1 |
Complex classes like UserRepository 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 UserRepository, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 65 | class UserRepository extends ResourceRepository |
||
| 66 | { |
||
| 67 | public function getRootUser(): User |
||
| 68 | { |
||
| 69 | $qb = $this->getRepository()->createQueryBuilder('u'); |
||
| 70 | $qb |
||
| 71 | ->innerJoin( |
||
| 72 | 'u.resourceNode', |
||
| 73 | 'r' |
||
| 74 | ); |
||
| 75 | $qb->where('r.creator = u'); |
||
| 76 | $qb->andWhere('r.parent IS NULL'); |
||
| 77 | $qb->getFirstResult(); |
||
| 78 | |||
| 79 | return $qb->getQuery()->getSingleResult(); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function deleteUser(User $user) |
||
| 83 | { |
||
| 84 | $em = $this->getEntityManager(); |
||
| 85 | $type = $user->getResourceNode()->getResourceType(); |
||
| 86 | |||
| 87 | $rootUser = $this->getRootUser(); |
||
| 88 | |||
| 89 | if (null === $rootUser) { |
||
| 90 | throw new UsernameNotFoundException('Root user not found'); |
||
| 91 | } |
||
| 92 | |||
| 93 | // User children will be set to the root user. |
||
| 94 | $criteria = Criteria::create()->where(Criteria::expr()->eq('resourceType', $type)); |
||
| 95 | $userNodeCreatedList = $user->getResourceNodes()->matching($criteria); |
||
| 96 | /** @var ResourceNode $userCreated */ |
||
| 97 | foreach ($userNodeCreatedList as $userCreated) { |
||
| 98 | $userCreated->setCreator($rootUser); |
||
| 99 | } |
||
| 100 | |||
| 101 | $em->remove($user->getResourceNode()); |
||
| 102 | |||
| 103 | foreach ($user->getGroups() as $group) { |
||
| 104 | $user->removeGroup($group); |
||
| 105 | } |
||
| 106 | |||
| 107 | $em->remove($user); |
||
| 108 | $em->flush(); |
||
| 109 | } |
||
| 110 | |||
| 111 | public function addUserToResourceNode(int $userId, int $creatorId): ResourceNode |
||
| 112 | { |
||
| 113 | /** @var User $user */ |
||
| 114 | $user = $this->find($userId); |
||
| 115 | $creator = $this->find($creatorId); |
||
| 116 | |||
| 117 | $resourceNode = new ResourceNode(); |
||
| 118 | $resourceNode |
||
| 119 | ->setSlug($user->getUsername()) |
||
| 120 | ->setCreator($creator) |
||
| 121 | ->setResourceType($this->getResourceType()) |
||
| 122 | // ->setParent($url->getResourceNode()) |
||
| 123 | ; |
||
| 124 | $this->getEntityManager()->persist($resourceNode); |
||
| 125 | $user->setResourceNode($resourceNode); |
||
| 126 | $this->getEntityManager()->persist($user); |
||
| 127 | |||
| 128 | return $resourceNode; |
||
| 129 | } |
||
| 130 | |||
| 131 | public function findByUsername(string $username): ?User |
||
| 132 | { |
||
| 133 | $user = $this->repository->findOneBy(['username' => $username]); |
||
| 134 | |||
| 135 | if (null === $user) { |
||
| 136 | throw new UsernameNotFoundException(sprintf("User with id '%s' not found.", $username)); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $user; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param string $role |
||
| 144 | * |
||
| 145 | * @return array |
||
| 146 | */ |
||
| 147 | public function findByRole($role) |
||
| 148 | { |
||
| 149 | $em = $this->repository->getEntityManager(); |
||
| 150 | $qb = $em->createQueryBuilder(); |
||
| 151 | |||
| 152 | $qb->select('u') |
||
| 153 | ->from($this->_entityName, 'u') |
||
| 154 | ->where('u.roles LIKE :roles') |
||
| 155 | ->setParameter('roles', '%"'.$role.'"%'); |
||
| 156 | |||
| 157 | return $qb->getQuery()->getResult(); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param string $keyword |
||
| 162 | * |
||
| 163 | * @return mixed |
||
| 164 | */ |
||
| 165 | public function searchUserByKeyword($keyword) |
||
| 166 | { |
||
| 167 | $qb = $this->repository->createQueryBuilder('a'); |
||
| 168 | |||
| 169 | // Selecting user info |
||
| 170 | $qb->select('DISTINCT b'); |
||
| 171 | |||
| 172 | $qb->from('Chamilo\UserBundle\Entity\User', 'b'); |
||
| 173 | |||
| 174 | // Selecting courses for users |
||
| 175 | //$qb->innerJoin('u.courses', 'c'); |
||
| 176 | |||
| 177 | //@todo check app settings |
||
| 178 | $qb->add('orderBy', 'b.firstname ASC'); |
||
| 179 | $qb->where('b.firstname LIKE :keyword OR b.lastname LIKE :keyword '); |
||
| 180 | $qb->setParameter('keyword', "%$keyword%"); |
||
| 181 | $query = $qb->getQuery(); |
||
| 182 | |||
| 183 | return $query->execute(); |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Get course user relationship based in the course_rel_user table. |
||
| 188 | * |
||
| 189 | * @return array |
||
| 190 | */ |
||
| 191 | /*public function getCourses(User $user) |
||
| 192 | { |
||
| 193 | $queryBuilder = $this->createQueryBuilder('user'); |
||
| 194 | |||
| 195 | // Selecting course info. |
||
| 196 | $queryBuilder->select('c'); |
||
| 197 | |||
| 198 | // Loading User. |
||
| 199 | //$qb->from('Chamilo\UserBundle\Entity\User', 'u'); |
||
| 200 | |||
| 201 | // Selecting course |
||
| 202 | $queryBuilder->innerJoin('Chamilo\CoreBundle\Entity\Course', 'c'); |
||
| 203 | |||
| 204 | //@todo check app settings |
||
| 205 | //$qb->add('orderBy', 'u.lastname ASC'); |
||
| 206 | |||
| 207 | $wherePart = $queryBuilder->expr()->andx(); |
||
| 208 | |||
| 209 | // Get only users subscribed to this course |
||
| 210 | $wherePart->add($queryBuilder->expr()->eq('user.userId', $user->getUserId())); |
||
| 211 | |||
| 212 | $queryBuilder->where($wherePart); |
||
| 213 | $query = $queryBuilder->getQuery(); |
||
| 214 | |||
| 215 | return $query->execute(); |
||
| 216 | } |
||
| 217 | |||
| 218 | public function getTeachers() |
||
| 219 | { |
||
| 220 | $queryBuilder = $this->createQueryBuilder('u'); |
||
| 221 | |||
| 222 | // Selecting course info. |
||
| 223 | $queryBuilder |
||
| 224 | ->select('u') |
||
| 225 | ->where('u.groups.id = :groupId') |
||
| 226 | ->setParameter('groupId', 1); |
||
| 227 | |||
| 228 | $query = $queryBuilder->getQuery(); |
||
| 229 | |||
| 230 | return $query->execute(); |
||
| 231 | }*/ |
||
| 232 | |||
| 233 | /*public function getUsers($group) |
||
| 234 | { |
||
| 235 | $queryBuilder = $this->createQueryBuilder('u'); |
||
| 236 | |||
| 237 | // Selecting course info. |
||
| 238 | $queryBuilder |
||
| 239 | ->select('u') |
||
| 240 | ->where('u.groups = :groupId') |
||
| 241 | ->setParameter('groupId', $group); |
||
| 242 | |||
| 243 | $query = $queryBuilder->getQuery(); |
||
| 244 | |||
| 245 | return $query->execute(); |
||
| 246 | }*/ |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Get a filtered list of user by status and (optionally) access url. |
||
| 250 | * |
||
| 251 | * @todo not use status |
||
| 252 | * |
||
| 253 | * @param string $query The query to filter |
||
| 254 | * @param int $status The status |
||
| 255 | * @param int $accessUrlId The access URL ID |
||
| 256 | * |
||
| 257 | * @return array |
||
| 258 | */ |
||
| 259 | public function findByStatus($query, $status, $accessUrlId = null) |
||
| 260 | { |
||
| 261 | $accessUrlId = (int) $accessUrlId; |
||
| 262 | $queryBuilder = $this->repository->createQueryBuilder('u'); |
||
| 263 | |||
| 264 | if ($accessUrlId > 0) { |
||
| 265 | $queryBuilder->innerJoin( |
||
| 266 | 'ChamiloCoreBundle:AccessUrlRelUser', |
||
| 267 | 'auru', |
||
| 268 | Join::WITH, |
||
| 269 | 'u.id = auru.user' |
||
| 270 | ); |
||
| 271 | } |
||
| 272 | |||
| 273 | $queryBuilder->where('u.status = :status') |
||
| 274 | ->andWhere('u.username LIKE :query OR u.firstname LIKE :query OR u.lastname LIKE :query') |
||
| 275 | ->setParameter('status', $status) |
||
| 276 | ->setParameter('query', "$query%"); |
||
| 277 | |||
| 278 | if ($accessUrlId > 0) { |
||
| 279 | $queryBuilder->andWhere('auru.url = :url') |
||
| 280 | ->setParameter(':url', $accessUrlId); |
||
| 281 | } |
||
| 282 | |||
| 283 | return $queryBuilder->getQuery()->getResult(); |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Get the coaches for a course within a session. |
||
| 288 | * |
||
| 289 | * @param Session $session The session |
||
| 290 | * @param Course $course The course |
||
| 291 | * |
||
| 292 | * @return \Doctrine\ORM\QueryBuilder |
||
| 293 | */ |
||
| 294 | public function getCoachesForSessionCourse(Session $session, Course $course) |
||
| 295 | { |
||
| 296 | $queryBuilder = $this->repository->createQueryBuilder('u'); |
||
| 297 | |||
| 298 | $queryBuilder->select('u') |
||
| 299 | ->innerJoin( |
||
| 300 | 'ChamiloCoreBundle:SessionRelCourseRelUser', |
||
| 301 | 'scu', |
||
| 302 | Join::WITH, |
||
| 303 | 'scu.user = u' |
||
| 304 | ) |
||
| 305 | ->where( |
||
| 306 | $queryBuilder->expr()->andX( |
||
| 307 | $queryBuilder->expr()->eq('scu.session', $session->getId()), |
||
| 308 | $queryBuilder->expr()->eq('scu.course', $course->getId()), |
||
| 309 | $queryBuilder->expr()->eq('scu.status', SessionRelCourseRelUser::STATUS_COURSE_COACH) |
||
| 310 | ) |
||
| 311 | ); |
||
| 312 | |||
| 313 | return $queryBuilder->getQuery()->getResult(); |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Get course user relationship based in the course_rel_user table. |
||
| 318 | * |
||
| 319 | * @return array |
||
| 320 | */ |
||
| 321 | /*public function getCourses(User $user) |
||
| 322 | { |
||
| 323 | $queryBuilder = $this->createQueryBuilder('user'); |
||
| 324 | |||
| 325 | // Selecting course info. |
||
| 326 | $queryBuilder->select('c'); |
||
| 327 | |||
| 328 | // Loading User. |
||
| 329 | //$qb->from('Chamilo\UserBundle\Entity\User', 'u'); |
||
| 330 | |||
| 331 | // Selecting course |
||
| 332 | $queryBuilder->innerJoin('Chamilo\CoreBundle\Entity\Course', 'c'); |
||
| 333 | |||
| 334 | //@todo check app settings |
||
| 335 | //$qb->add('orderBy', 'u.lastname ASC'); |
||
| 336 | |||
| 337 | $wherePart = $queryBuilder->expr()->andx(); |
||
| 338 | |||
| 339 | // Get only users subscribed to this course |
||
| 340 | $wherePart->add($queryBuilder->expr()->eq('user.userId', $user->getUserId())); |
||
| 341 | |||
| 342 | $queryBuilder->where($wherePart); |
||
| 343 | $query = $queryBuilder->getQuery(); |
||
| 344 | |||
| 345 | return $query->execute(); |
||
| 346 | } |
||
| 347 | |||
| 348 | public function getTeachers() |
||
| 349 | { |
||
| 350 | $queryBuilder = $this->createQueryBuilder('u'); |
||
| 351 | |||
| 352 | // Selecting course info. |
||
| 353 | $queryBuilder |
||
| 354 | ->select('u') |
||
| 355 | ->where('u.groups.id = :groupId') |
||
| 356 | ->setParameter('groupId', 1); |
||
| 357 | |||
| 358 | $query = $queryBuilder->getQuery(); |
||
| 359 | |||
| 360 | return $query->execute(); |
||
| 361 | }*/ |
||
| 362 | |||
| 363 | /*public function getUsers($group) |
||
| 364 | { |
||
| 365 | $queryBuilder = $this->createQueryBuilder('u'); |
||
| 366 | |||
| 367 | // Selecting course info. |
||
| 368 | $queryBuilder |
||
| 369 | ->select('u') |
||
| 370 | ->where('u.groups = :groupId') |
||
| 371 | ->setParameter('groupId', $group); |
||
| 372 | |||
| 373 | $query = $queryBuilder->getQuery(); |
||
| 374 | |||
| 375 | return $query->execute(); |
||
| 376 | }*/ |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Get the sessions admins for a user. |
||
| 380 | * |
||
| 381 | * @return array |
||
| 382 | */ |
||
| 383 | public function getSessionAdmins(User $user) |
||
| 384 | { |
||
| 385 | $queryBuilder = $this->repository->createQueryBuilder('u'); |
||
| 386 | $queryBuilder |
||
| 387 | ->distinct() |
||
| 388 | ->innerJoin( |
||
| 389 | 'ChamiloCoreBundle:SessionRelUser', |
||
| 390 | 'su', |
||
| 391 | Join::WITH, |
||
| 392 | $queryBuilder->expr()->eq('u', 'su.user') |
||
| 393 | ) |
||
| 394 | ->innerJoin( |
||
| 395 | 'ChamiloCoreBundle:SessionRelCourseRelUser', |
||
| 396 | 'scu', |
||
| 397 | Join::WITH, |
||
| 398 | $queryBuilder->expr()->eq('su.session', 'scu.session') |
||
| 399 | ) |
||
| 400 | ->where( |
||
| 401 | $queryBuilder->expr()->eq('scu.user', $user->getId()) |
||
| 402 | ) |
||
| 403 | ->andWhere( |
||
| 404 | $queryBuilder->expr()->eq('su.relationType', SESSION_RELATION_TYPE_RRHH) |
||
| 405 | ) |
||
| 406 | ; |
||
| 407 | |||
| 408 | return $queryBuilder->getQuery()->getResult(); |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Get the student bosses for a user. |
||
| 413 | * |
||
| 414 | * @return array |
||
| 415 | */ |
||
| 416 | public function getStudentBosses(User $user) |
||
| 417 | { |
||
| 418 | $queryBuilder = $this->repository->createQueryBuilder('u'); |
||
| 419 | $queryBuilder |
||
| 420 | ->distinct() |
||
| 421 | ->innerJoin( |
||
| 422 | 'ChamiloCoreBundle:UserRelUser', |
||
| 423 | 'uu', |
||
| 424 | Join::WITH, |
||
| 425 | $queryBuilder->expr()->eq('u.id', 'uu.friendUserId') |
||
| 426 | ) |
||
| 427 | ->where( |
||
| 428 | $queryBuilder->expr()->eq('uu.relationType', USER_RELATION_TYPE_BOSS) |
||
| 429 | ) |
||
| 430 | ->andWhere( |
||
| 431 | $queryBuilder->expr()->eq('uu.userId', $user->getId()) |
||
| 432 | ); |
||
| 433 | |||
| 434 | return $queryBuilder->getQuery()->getResult(); |
||
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Get number of users in URL. |
||
| 439 | * |
||
| 440 | * @return int |
||
| 441 | */ |
||
| 442 | public function getCountUsersByUrl(AccessUrl $url) |
||
| 443 | { |
||
| 444 | return $this->repository->createQueryBuilder('a') |
||
| 445 | ->select('COUNT(a)') |
||
| 446 | ->innerJoin('a.portals', 'u') |
||
| 447 | ->where('u.portal = :u') |
||
| 448 | ->setParameters(['u' => $url]) |
||
| 449 | ->getQuery() |
||
| 450 | ->getSingleScalarResult(); |
||
| 451 | } |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Get number of users in URL. |
||
| 455 | * |
||
| 456 | * @return int |
||
| 457 | */ |
||
| 458 | public function getCountTeachersByUrl(AccessUrl $url) |
||
| 470 | ; |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Find potential users to send a message. |
||
| 475 | * |
||
| 476 | * @param int $currentUserId The current user ID |
||
| 477 | * @param string $searchFilter Optional. The search text to filter the user list |
||
| 478 | * @param int $limit Optional. Sets the maximum number of results to retrieve |
||
| 479 | * |
||
| 480 | * @return mixed |
||
| 481 | */ |
||
| 482 | public function findUsersToSendMessage($currentUserId, $searchFilter = null, $limit = 10) |
||
| 483 | { |
||
| 484 | $allowSendMessageToAllUsers = api_get_setting('allow_send_message_to_all_platform_users'); |
||
| 485 | $accessUrlId = api_get_multiple_access_url() ? api_get_current_access_url_id() : 1; |
||
| 486 | |||
| 487 | if (api_get_setting('allow_social_tool') === 'true' && |
||
| 488 | api_get_setting('allow_message_tool') === 'true' |
||
| 489 | ) { |
||
| 490 | // All users |
||
| 491 | if ($allowSendMessageToAllUsers === 'true' || api_is_platform_admin()) { |
||
| 492 | $dql = "SELECT DISTINCT U |
||
| 493 | FROM ChamiloUserBundle:User U |
||
| 494 | LEFT JOIN ChamiloCoreBundle:AccessUrlRelUser R |
||
| 495 | WITH U = R.user |
||
| 496 | WHERE |
||
| 497 | U.active = 1 AND |
||
| 498 | U.status != 6 AND |
||
| 499 | U.id != $currentUserId AND |
||
| 500 | R.url = $accessUrlId"; |
||
| 501 | } else { |
||
| 502 | $dql = "SELECT DISTINCT U |
||
| 503 | FROM ChamiloCoreBundle:AccessUrlRelUser R, ChamiloCoreBundle:UserRelUser UF |
||
| 504 | INNER JOIN ChamiloUserBundle:User AS U |
||
| 505 | WITH UF.friendUserId = U |
||
| 506 | WHERE |
||
| 507 | U.active = 1 AND |
||
| 508 | U.status != 6 AND |
||
| 509 | UF.relationType NOT IN(".USER_RELATION_TYPE_DELETED.", ".USER_RELATION_TYPE_RRHH.") AND |
||
| 510 | UF.userId = $currentUserId AND |
||
| 511 | UF.friendUserId != $currentUserId AND |
||
| 512 | U = R.user AND |
||
| 513 | R.url = $accessUrlId"; |
||
| 514 | } |
||
| 515 | } elseif ( |
||
| 516 | api_get_setting('allow_social_tool') === 'false' && |
||
| 517 | api_get_setting('allow_message_tool') === 'true' |
||
| 518 | ) { |
||
| 519 | if ($allowSendMessageToAllUsers === 'true') { |
||
| 520 | $dql = "SELECT DISTINCT U |
||
| 521 | FROM ChamiloUserBundle:User U |
||
| 522 | LEFT JOIN ChamiloCoreBundle:AccessUrlRelUser R |
||
| 523 | WITH U = R.user |
||
| 524 | WHERE |
||
| 525 | U.active = 1 AND |
||
| 526 | U.status != 6 AND |
||
| 527 | U.id != $currentUserId AND |
||
| 528 | R.url = $accessUrlId"; |
||
| 529 | } else { |
||
| 530 | $time_limit = api_get_setting('time_limit_whosonline'); |
||
| 531 | $online_time = time() - $time_limit * 60; |
||
| 532 | $limit_date = api_get_utc_datetime($online_time); |
||
| 533 | $dql = "SELECT DISTINCT U |
||
| 534 | FROM ChamiloUserBundle:User U |
||
| 535 | INNER JOIN ChamiloCoreBundle:TrackEOnline T |
||
| 536 | WITH U.id = T.loginUserId |
||
| 537 | WHERE |
||
| 538 | U.active = 1 AND |
||
| 539 | T.loginDate >= '".$limit_date."'"; |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | $parameters = []; |
||
| 544 | |||
| 545 | if (!empty($searchFilter)) { |
||
| 546 | $dql .= ' AND (U.firstname LIKE :search OR U.lastname LIKE :search OR U.email LIKE :search OR U.username LIKE :search)'; |
||
| 547 | $parameters['search'] = "%$searchFilter%"; |
||
| 548 | } |
||
| 549 | |||
| 550 | return $this->getEntityManager() |
||
| 551 | ->createQuery($dql) |
||
| 552 | ->setMaxResults($limit) |
||
| 553 | ->setParameters($parameters) |
||
| 554 | ->getResult(); |
||
| 555 | } |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Get the list of HRM who have assigned this user. |
||
| 559 | * |
||
| 560 | * @param int $userId |
||
| 561 | * @param int $urlId |
||
| 562 | * |
||
| 563 | * @return array |
||
| 564 | */ |
||
| 565 | public function getAssignedHrmUserList($userId, $urlId) |
||
| 566 | { |
||
| 567 | $qb = $this->repository->createQueryBuilder('user'); |
||
| 568 | |||
| 569 | $hrmList = $qb |
||
| 570 | ->select('uru') |
||
| 571 | ->innerJoin('ChamiloCoreBundle:UserRelUser', 'uru', Join::WITH, 'uru.userId = user.id') |
||
| 572 | ->innerJoin('ChamiloCoreBundle:AccessUrlRelUser', 'auru', Join::WITH, 'auru.user = uru.friendUserId') |
||
| 573 | ->where( |
||
| 574 | $qb->expr()->eq('auru.url', $urlId) |
||
| 575 | ) |
||
| 576 | ->andWhere( |
||
| 577 | $qb->expr()->eq('uru.userId', $userId) |
||
| 578 | ) |
||
| 579 | ->andWhere( |
||
| 580 | $qb->expr()->eq('uru.relationType', USER_RELATION_TYPE_RRHH) |
||
| 581 | ) |
||
| 582 | ->getQuery() |
||
| 583 | ->getResult(); |
||
| 584 | |||
| 585 | return $hrmList; |
||
| 586 | } |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Serialize the whole entity to an array. |
||
| 590 | * |
||
| 591 | * @param int $userId |
||
| 592 | * @param array $substitutionTerms Substitute terms for some elements |
||
| 593 | * |
||
| 594 | * @return string |
||
| 595 | */ |
||
| 596 | public function getPersonalDataToJson($userId, array $substitutionTerms) |
||
| 597 | { |
||
| 598 | $em = $this->getEntityManager(); |
||
| 599 | $dateFormat = \Datetime::ATOM; |
||
| 600 | |||
| 601 | /** @var User $user */ |
||
| 602 | $user = $this->find($userId); |
||
| 603 | |||
| 604 | $user->setPassword($substitutionTerms['password']); |
||
| 605 | $user->setSalt($substitutionTerms['salt']); |
||
| 606 | $noDataLabel = $substitutionTerms['empty']; |
||
| 607 | |||
| 608 | // Dummy content |
||
| 609 | $user->setDateOfBirth(null); |
||
| 610 | //$user->setBiography($noDataLabel); |
||
| 611 | $user->setFacebookData($noDataLabel); |
||
| 612 | $user->setFacebookName($noDataLabel); |
||
| 613 | $user->setFacebookUid($noDataLabel); |
||
| 614 | //$user->setImageName($noDataLabel); |
||
| 615 | //$user->setTwoStepVerificationCode($noDataLabel); |
||
| 616 | $user->setGender($noDataLabel); |
||
| 617 | $user->setGplusData($noDataLabel); |
||
| 618 | $user->setGplusName($noDataLabel); |
||
| 619 | $user->setGplusUid($noDataLabel); |
||
| 620 | $user->setLocale($noDataLabel); |
||
| 621 | $user->setTimezone($noDataLabel); |
||
| 622 | $user->setTwitterData($noDataLabel); |
||
| 623 | $user->setTwitterName($noDataLabel); |
||
| 624 | $user->setTwitterUid($noDataLabel); |
||
| 625 | $user->setWebsite($noDataLabel); |
||
| 626 | $user->setToken($noDataLabel); |
||
| 627 | |||
| 628 | $courses = $user->getCourses(); |
||
| 629 | $list = []; |
||
| 630 | $chatFiles = []; |
||
| 631 | /** @var CourseRelUser $course */ |
||
| 632 | foreach ($courses as $course) { |
||
| 633 | $list[] = $course->getCourse()->getCode(); |
||
| 634 | $courseDir = api_get_path(SYS_COURSE_PATH).$course->getCourse()->getDirectory(); |
||
| 635 | $documentDir = $courseDir.'/document/chat_files/'; |
||
| 636 | if (is_dir($documentDir)) { |
||
| 637 | $fs = new Finder(); |
||
| 638 | $fs->files()->in($documentDir); |
||
| 639 | foreach ($fs as $file) { |
||
| 640 | $chatFiles[] = |
||
| 641 | $course->getCourse()->getDirectory().'/document/chat_files/'.$file->getFilename().' - '. |
||
| 642 | get_lang('This content is not accessible to you directly because of course-related access rules. If you require access to that data, please contact the Data Privacy Officer as defined in our privacy terms.'); |
||
| 643 | } |
||
| 644 | } |
||
| 645 | } |
||
| 646 | |||
| 647 | $user->setCourses($list); |
||
| 648 | |||
| 649 | $classes = $user->getClasses(); |
||
| 650 | $list = []; |
||
| 651 | /** @var UsergroupRelUser $class */ |
||
| 652 | foreach ($classes as $class) { |
||
| 653 | $name = $class->getUsergroup()->getName(); |
||
| 654 | $list[$class->getUsergroup()->getGroupType()][] = $name.' - Status: '.$class->getRelationType(); |
||
| 655 | } |
||
| 656 | $user->setClasses($list); |
||
| 657 | |||
| 658 | $collection = $user->getSessionCourseSubscriptions(); |
||
| 659 | $list = []; |
||
| 660 | /** @var SessionRelCourseRelUser $item */ |
||
| 661 | foreach ($collection as $item) { |
||
| 662 | $list[$item->getSession()->getName()][] = $item->getCourse()->getCode(); |
||
| 663 | } |
||
| 664 | $user->setSessionCourseSubscriptions($list); |
||
| 665 | |||
| 666 | $documents = \DocumentManager::getAllDocumentsCreatedByUser($userId); |
||
| 667 | |||
| 668 | $friends = \SocialManager::get_friends($userId); |
||
| 669 | $friendList = []; |
||
| 670 | if (!empty($friends)) { |
||
| 671 | foreach ($friends as $friend) { |
||
| 672 | $friendList[] = $friend['user_info']['complete_name']; |
||
| 673 | } |
||
| 674 | } |
||
| 675 | |||
| 676 | $agenda = new \Agenda('personal'); |
||
| 677 | $events = $agenda->getEvents('', '', null, null, $userId, 'array'); |
||
| 678 | $eventList = []; |
||
| 679 | if (!empty($events)) { |
||
| 680 | foreach ($events as $event) { |
||
| 681 | $eventList[] = $event['title'].' '.$event['start_date_localtime'].' / '.$event['end_date_localtime']; |
||
| 682 | } |
||
| 683 | } |
||
| 684 | |||
| 685 | // GradebookCertificate |
||
| 686 | $criteria = [ |
||
| 687 | 'userId' => $userId, |
||
| 688 | ]; |
||
| 689 | $result = $em->getRepository('ChamiloCoreBundle:GradebookCertificate')->findBy($criteria); |
||
| 690 | $gradebookCertificate = []; |
||
| 691 | /** @var GradebookCertificate $item */ |
||
| 692 | foreach ($result as $item) { |
||
| 693 | $createdAt = $item->getCreatedAt() ? $item->getCreatedAt()->format($dateFormat) : ''; |
||
| 694 | $list = [ |
||
| 695 | 'Score: '.$item->getScoreCertificate(), |
||
| 696 | 'Path: '.$item->getPathCertificate(), |
||
| 697 | 'Created at: '.$createdAt, |
||
| 698 | ]; |
||
| 699 | $gradebookCertificate[] = implode(', ', $list); |
||
| 700 | } |
||
| 701 | |||
| 702 | // TrackEExercises |
||
| 703 | $criteria = [ |
||
| 704 | 'exeUserId' => $userId, |
||
| 705 | ]; |
||
| 706 | $result = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->findBy($criteria); |
||
| 707 | $trackEExercises = []; |
||
| 708 | /** @var TrackEExercises $item */ |
||
| 709 | foreach ($result as $item) { |
||
| 710 | $date = $item->getExeDate() ? $item->getExeDate()->format($dateFormat) : ''; |
||
| 711 | $list = [ |
||
| 712 | 'IP: '.$item->getUserIp(), |
||
| 713 | 'Start: '.$date, |
||
| 714 | 'Status: '.$item->getStatus(), |
||
| 715 | // 'Result: '.$item->getExeResult(), |
||
| 716 | // 'Weighting: '.$item->getExeWeighting(), |
||
| 717 | ]; |
||
| 718 | $trackEExercises[] = implode(', ', $list); |
||
| 719 | } |
||
| 720 | |||
| 721 | // TrackEAttempt |
||
| 722 | $criteria = [ |
||
| 723 | 'userId' => $userId, |
||
| 724 | ]; |
||
| 725 | $result = $em->getRepository('ChamiloCoreBundle:TrackEAttempt')->findBy($criteria); |
||
| 726 | $trackEAttempt = []; |
||
| 727 | /** @var TrackEAttempt $item */ |
||
| 728 | foreach ($result as $item) { |
||
| 729 | $date = $item->getTms() ? $item->getTms()->format($dateFormat) : ''; |
||
| 730 | $list = [ |
||
| 731 | 'Attempt #'.$item->getExeId(), |
||
| 732 | 'Course # '.$item->getCourse()->getCode(), |
||
| 733 | //'Answer: '.$item->getAnswer(), |
||
| 734 | 'Session #'.$item->getSessionId(), |
||
| 735 | //'Marks: '.$item->getMarks(), |
||
| 736 | 'Position: '.$item->getPosition(), |
||
| 737 | 'Date: '.$date, |
||
| 738 | ]; |
||
| 739 | $trackEAttempt[] = implode(', ', $list); |
||
| 740 | } |
||
| 741 | |||
| 742 | // TrackECourseAccess |
||
| 743 | $criteria = [ |
||
| 744 | 'userId' => $userId, |
||
| 745 | ]; |
||
| 746 | $result = $em->getRepository('ChamiloCoreBundle:TrackECourseAccess')->findBy($criteria); |
||
| 747 | $trackECourseAccessList = []; |
||
| 748 | /** @var TrackECourseAccess $item */ |
||
| 749 | foreach ($result as $item) { |
||
| 750 | $startDate = $item->getLoginCourseDate() ? $item->getLoginCourseDate()->format($dateFormat) : ''; |
||
| 751 | $endDate = $item->getLogoutCourseDate() ? $item->getLogoutCourseDate()->format($dateFormat) : ''; |
||
| 752 | $list = [ |
||
| 753 | 'IP: '.$item->getUserIp(), |
||
| 754 | 'Start: '.$startDate, |
||
| 755 | 'End: '.$endDate, |
||
| 756 | ]; |
||
| 757 | $trackECourseAccessList[] = implode(', ', $list); |
||
| 758 | } |
||
| 759 | |||
| 760 | $checkEntities = [ |
||
| 761 | 'ChamiloCoreBundle:TrackELogin' => 'loginUserId', |
||
| 762 | 'ChamiloCoreBundle:TrackEAccess' => 'accessUserId', |
||
| 763 | 'ChamiloCoreBundle:TrackEOnline' => 'loginUserId', |
||
| 764 | 'ChamiloCoreBundle:TrackEDefault' => 'defaultUserId', |
||
| 765 | 'ChamiloCoreBundle:TrackELastaccess' => 'accessUserId', |
||
| 766 | 'ChamiloCoreBundle:TrackEUploads' => 'uploadUserId', |
||
| 767 | 'ChamiloCoreBundle:GradebookResult' => 'userId', |
||
| 768 | 'ChamiloCoreBundle:TrackEDownloads' => 'downUserId', |
||
| 769 | ]; |
||
| 770 | |||
| 771 | $maxResults = 1000; |
||
| 772 | $trackResults = []; |
||
| 773 | foreach ($checkEntities as $entity => $field) { |
||
| 774 | $qb = $em->createQueryBuilder(); |
||
| 775 | $qb->select($qb->expr()->count('l')) |
||
| 776 | ->from($entity, 'l') |
||
| 777 | ->where("l.$field = :login") |
||
| 778 | ->setParameter('login', $userId); |
||
| 779 | $query = $qb->getQuery(); |
||
| 780 | $count = $query->getSingleScalarResult(); |
||
| 781 | |||
| 782 | if ($count > $maxResults) { |
||
| 783 | $qb = $em->getRepository($entity)->createQueryBuilder('l'); |
||
| 784 | $qb |
||
| 785 | ->select('l') |
||
| 786 | ->where("l.$field = :login") |
||
| 787 | ->setParameter('login', $userId); |
||
| 788 | $qb |
||
| 789 | ->setFirstResult(0) |
||
| 790 | ->setMaxResults($maxResults) |
||
| 791 | ; |
||
| 792 | $result = $qb->getQuery()->getResult(); |
||
| 793 | } else { |
||
| 794 | $criteria = [ |
||
| 795 | $field => $userId, |
||
| 796 | ]; |
||
| 797 | $result = $em->getRepository($entity)->findBy($criteria); |
||
| 798 | } |
||
| 799 | $trackResults[$entity] = $result; |
||
| 800 | } |
||
| 801 | |||
| 802 | $trackELoginList = []; |
||
| 803 | /** @var TrackELogin $item */ |
||
| 804 | foreach ($trackResults['ChamiloCoreBundle:TrackELogin'] as $item) { |
||
| 805 | $startDate = $item->getLoginDate() ? $item->getLoginDate()->format($dateFormat) : ''; |
||
| 806 | $endDate = $item->getLogoutDate() ? $item->getLogoutDate()->format($dateFormat) : ''; |
||
| 807 | $list = [ |
||
| 808 | 'IP: '.$item->getUserIp(), |
||
| 809 | 'Start: '.$startDate, |
||
| 810 | 'End: '.$endDate, |
||
| 811 | ]; |
||
| 812 | $trackELoginList[] = implode(', ', $list); |
||
| 813 | } |
||
| 814 | |||
| 815 | // TrackEAccess |
||
| 816 | $trackEAccessList = []; |
||
| 817 | /** @var TrackEAccess $item */ |
||
| 818 | foreach ($trackResults['ChamiloCoreBundle:TrackEAccess'] as $item) { |
||
| 819 | $date = $item->getAccessDate() ? $item->getAccessDate()->format($dateFormat) : ''; |
||
| 820 | $list = [ |
||
| 821 | 'IP: '.$item->getUserIp(), |
||
| 822 | 'Tool: '.$item->getAccessTool(), |
||
| 823 | 'End: '.$date, |
||
| 824 | ]; |
||
| 825 | $trackEAccessList[] = implode(', ', $list); |
||
| 826 | } |
||
| 827 | |||
| 828 | // TrackEOnline |
||
| 829 | $trackEOnlineList = []; |
||
| 830 | /** @var TrackEOnline $item */ |
||
| 831 | foreach ($trackResults['ChamiloCoreBundle:TrackEOnline'] as $item) { |
||
| 832 | $date = $item->getLoginDate() ? $item->getLoginDate()->format($dateFormat) : ''; |
||
| 833 | $list = [ |
||
| 834 | 'IP: '.$item->getUserIp(), |
||
| 835 | 'Login date: '.$date, |
||
| 836 | 'Course # '.$item->getCId(), |
||
| 837 | 'Session # '.$item->getSessionId(), |
||
| 838 | ]; |
||
| 839 | $trackEOnlineList[] = implode(', ', $list); |
||
| 840 | } |
||
| 841 | |||
| 842 | // TrackEDefault |
||
| 843 | $trackEDefault = []; |
||
| 844 | /** @var TrackEDefault $item */ |
||
| 845 | foreach ($trackResults['ChamiloCoreBundle:TrackEDefault'] as $item) { |
||
| 846 | $date = $item->getDefaultDate() ? $item->getDefaultDate()->format($dateFormat) : ''; |
||
| 847 | $list = [ |
||
| 848 | 'Type: '.$item->getDefaultEventType(), |
||
| 849 | 'Value: '.$item->getDefaultValue(), |
||
| 850 | 'Value type: '.$item->getDefaultValueType(), |
||
| 851 | 'Date: '.$date, |
||
| 852 | 'Course #'.$item->getCId(), |
||
| 853 | 'Session # '.$item->getSessionId(), |
||
| 854 | ]; |
||
| 855 | $trackEDefault[] = implode(', ', $list); |
||
| 856 | } |
||
| 857 | |||
| 858 | // TrackELastaccess |
||
| 859 | $trackELastaccess = []; |
||
| 860 | /** @var TrackELastaccess $item */ |
||
| 861 | foreach ($trackResults['ChamiloCoreBundle:TrackELastaccess'] as $item) { |
||
| 862 | $date = $item->getAccessDate() ? $item->getAccessDate()->format($dateFormat) : ''; |
||
| 863 | $list = [ |
||
| 864 | 'Course #'.$item->getCId(), |
||
| 865 | 'Session # '.$item->getAccessSessionId(), |
||
| 866 | 'Tool: '.$item->getAccessTool(), |
||
| 867 | 'Access date: '.$date, |
||
| 868 | ]; |
||
| 869 | $trackELastaccess[] = implode(', ', $list); |
||
| 870 | } |
||
| 871 | |||
| 872 | // TrackEUploads |
||
| 873 | $trackEUploads = []; |
||
| 874 | /** @var TrackEUploads $item */ |
||
| 875 | foreach ($trackResults['ChamiloCoreBundle:TrackEUploads'] as $item) { |
||
| 876 | $date = $item->getUploadDate() ? $item->getUploadDate()->format($dateFormat) : ''; |
||
| 877 | $list = [ |
||
| 878 | 'Course #'.$item->getCId(), |
||
| 879 | 'Uploaded at: '.$date, |
||
| 880 | 'Upload id # '.$item->getUploadId(), |
||
| 881 | ]; |
||
| 882 | $trackEUploads[] = implode(', ', $list); |
||
| 883 | } |
||
| 884 | |||
| 885 | $gradebookResult = []; |
||
| 886 | /** @var GradebookResult $item */ |
||
| 887 | foreach ($trackResults['ChamiloCoreBundle:GradebookResult'] as $item) { |
||
| 888 | $date = $item->getCreatedAt() ? $item->getCreatedAt()->format($dateFormat) : ''; |
||
| 889 | $list = [ |
||
| 890 | 'Evaluation id# '.$item->getEvaluationId(), |
||
| 891 | //'Score: '.$item->getScore(), |
||
| 892 | 'Creation date: '.$date, |
||
| 893 | ]; |
||
| 894 | $gradebookResult[] = implode(', ', $list); |
||
| 895 | } |
||
| 896 | |||
| 897 | $trackEDownloads = []; |
||
| 898 | /** @var TrackEDownloads $item */ |
||
| 899 | foreach ($trackResults['ChamiloCoreBundle:TrackEDownloads'] as $item) { |
||
| 900 | $date = $item->getDownDate() ? $item->getDownDate()->format($dateFormat) : ''; |
||
| 901 | $list = [ |
||
| 902 | 'File: '.$item->getDownDocPath(), |
||
| 903 | 'Download at: '.$date, |
||
| 904 | ]; |
||
| 905 | $trackEDownloads[] = implode(', ', $list); |
||
| 906 | } |
||
| 907 | |||
| 908 | // UserCourseCategory |
||
| 909 | $criteria = [ |
||
| 910 | 'userId' => $userId, |
||
| 911 | ]; |
||
| 912 | $result = $em->getRepository('ChamiloCoreBundle:UserCourseCategory')->findBy($criteria); |
||
| 913 | $userCourseCategory = []; |
||
| 914 | /** @var UserCourseCategory $item */ |
||
| 915 | foreach ($result as $item) { |
||
| 916 | $list = [ |
||
| 917 | 'Title: '.$item->getTitle(), |
||
| 918 | ]; |
||
| 919 | $userCourseCategory[] = implode(', ', $list); |
||
| 920 | } |
||
| 921 | |||
| 922 | // Forum |
||
| 923 | $criteria = [ |
||
| 924 | 'posterId' => $userId, |
||
| 925 | ]; |
||
| 926 | $result = $em->getRepository('ChamiloCourseBundle:CForumPost')->findBy($criteria); |
||
| 927 | $cForumPostList = []; |
||
| 928 | /** @var CForumPost $item */ |
||
| 929 | foreach ($result as $item) { |
||
| 930 | $date = $item->getPostDate() ? $item->getPostDate()->format($dateFormat) : ''; |
||
| 931 | $list = [ |
||
| 932 | 'Title: '.$item->getPostTitle(), |
||
| 933 | 'Creation date: '.$date, |
||
| 934 | ]; |
||
| 935 | $cForumPostList[] = implode(', ', $list); |
||
| 936 | } |
||
| 937 | |||
| 938 | // CForumThread |
||
| 939 | $criteria = [ |
||
| 940 | 'threadPosterId' => $userId, |
||
| 941 | ]; |
||
| 942 | $result = $em->getRepository('ChamiloCourseBundle:CForumThread')->findBy($criteria); |
||
| 943 | $cForumThreadList = []; |
||
| 944 | /** @var CForumThread $item */ |
||
| 945 | foreach ($result as $item) { |
||
| 946 | $date = $item->getThreadDate() ? $item->getThreadDate()->format($dateFormat) : ''; |
||
| 947 | $list = [ |
||
| 948 | 'Title: '.$item->getThreadTitle(), |
||
| 949 | 'Creation date: '.$date, |
||
| 950 | ]; |
||
| 951 | $cForumThreadList[] = implode(', ', $list); |
||
| 952 | } |
||
| 953 | |||
| 954 | // CForumAttachment |
||
| 955 | /*$criteria = [ |
||
| 956 | 'threadPosterId' => $userId, |
||
| 957 | ]; |
||
| 958 | $result = $em->getRepository('ChamiloCourseBundle:CForumAttachment')->findBy($criteria); |
||
| 959 | $cForumThreadList = []; |
||
| 960 | * @var CForumThread $item |
||
| 961 | foreach ($result as $item) { |
||
| 962 | $list = [ |
||
| 963 | 'Title: '.$item->getThreadTitle(), |
||
| 964 | 'Creation date: '.$item->getThreadDate()->format($dateFormat), |
||
| 965 | ]; |
||
| 966 | $cForumThreadList[] = implode(', ', $list); |
||
| 967 | }*/ |
||
| 968 | |||
| 969 | // cGroupRelUser |
||
| 970 | $criteria = [ |
||
| 971 | 'user' => $userId, |
||
| 972 | ]; |
||
| 973 | $result = $em->getRepository('ChamiloCourseBundle:CGroupRelUser')->findBy($criteria); |
||
| 974 | $cGroupRelUser = []; |
||
| 975 | /** @var CGroupRelUser $item */ |
||
| 976 | foreach ($result as $item) { |
||
| 977 | $list = [ |
||
| 978 | 'Course # '.$item->getCId(), |
||
| 979 | 'Group #'.$item->getGroup()->getId(), |
||
| 980 | 'Role: '.$item->getStatus(), |
||
| 981 | ]; |
||
| 982 | $cGroupRelUser[] = implode(', ', $list); |
||
| 983 | } |
||
| 984 | |||
| 985 | // CAttendanceSheet |
||
| 986 | $criteria = [ |
||
| 987 | 'userId' => $userId, |
||
| 988 | ]; |
||
| 989 | $result = $em->getRepository('ChamiloCourseBundle:CAttendanceSheet')->findBy($criteria); |
||
| 990 | $cAttendanceSheetList = []; |
||
| 991 | /** @var CAttendanceSheet $item */ |
||
| 992 | foreach ($result as $item) { |
||
| 993 | $list = [ |
||
| 994 | 'Presence: '.$item->getPresence(), |
||
| 995 | 'Calendar id: '.$item->getAttendanceCalendarId(), |
||
| 996 | ]; |
||
| 997 | $cAttendanceSheetList[] = implode(', ', $list); |
||
| 998 | } |
||
| 999 | |||
| 1000 | // CBlogPost |
||
| 1001 | $criteria = [ |
||
| 1002 | 'authorId' => $userId, |
||
| 1003 | ]; |
||
| 1004 | $result = $em->getRepository('ChamiloCourseBundle:CBlogPost')->findBy($criteria); |
||
| 1005 | $cBlog = []; |
||
| 1006 | /** @var CBlogPost $item */ |
||
| 1007 | foreach ($result as $item) { |
||
| 1008 | $date = $item->getDateCreation() ? $item->getDateCreation()->format($dateFormat) : ''; |
||
| 1009 | $list = [ |
||
| 1010 | 'Title: '.$item->getTitle(), |
||
| 1011 | 'Date: '.$date, |
||
| 1012 | ]; |
||
| 1013 | $cBlog[] = implode(', ', $list); |
||
| 1014 | } |
||
| 1015 | |||
| 1016 | // CAttendanceResult |
||
| 1017 | $criteria = [ |
||
| 1018 | 'userId' => $userId, |
||
| 1019 | ]; |
||
| 1020 | $result = $em->getRepository('ChamiloCourseBundle:CAttendanceResult')->findBy($criteria); |
||
| 1021 | $cAttendanceResult = []; |
||
| 1022 | /** @var CAttendanceResult $item */ |
||
| 1023 | foreach ($result as $item) { |
||
| 1024 | $list = [ |
||
| 1025 | 'Score : '.$item->getScore(), |
||
| 1026 | 'Calendar id: '.$item->getAttendanceId(), |
||
| 1027 | ]; |
||
| 1028 | $cAttendanceResult[] = implode(', ', $list); |
||
| 1029 | } |
||
| 1030 | |||
| 1031 | // Message |
||
| 1032 | $criteria = [ |
||
| 1033 | 'userSender' => $userId, |
||
| 1034 | ]; |
||
| 1035 | $result = $em->getRepository('ChamiloCoreBundle:Message')->findBy($criteria); |
||
| 1036 | $messageList = []; |
||
| 1037 | /** @var Message $item */ |
||
| 1038 | foreach ($result as $item) { |
||
| 1039 | $date = $item->getSendDate() ? $item->getSendDate()->format($dateFormat) : ''; |
||
| 1040 | $userName = ''; |
||
| 1041 | if ($item->getUserReceiver()) { |
||
| 1042 | $userName = $item->getUserReceiver()->getUsername(); |
||
| 1043 | } |
||
| 1044 | $list = [ |
||
| 1045 | 'Title: '.$item->getTitle(), |
||
| 1046 | 'Sent date: '.$date, |
||
| 1047 | 'To user: '.$userName, |
||
| 1048 | 'Status'.$item->getMsgStatus(), |
||
| 1049 | ]; |
||
| 1050 | $messageList[] = implode(', ', $list); |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | // CSurveyAnswer |
||
| 1054 | $criteria = [ |
||
| 1055 | 'user' => $userId, |
||
| 1056 | ]; |
||
| 1057 | $result = $em->getRepository('ChamiloCourseBundle:CSurveyAnswer')->findBy($criteria); |
||
| 1058 | $cSurveyAnswer = []; |
||
| 1059 | /** @var CSurveyAnswer $item */ |
||
| 1060 | foreach ($result as $item) { |
||
| 1061 | $list = [ |
||
| 1062 | 'Answer # '.$item->getAnswerId(), |
||
| 1063 | 'Value: '.$item->getValue(), |
||
| 1064 | ]; |
||
| 1065 | $cSurveyAnswer[] = implode(', ', $list); |
||
| 1066 | } |
||
| 1067 | |||
| 1068 | // CDropboxFile |
||
| 1069 | $criteria = [ |
||
| 1070 | 'uploaderId' => $userId, |
||
| 1071 | ]; |
||
| 1072 | $result = $em->getRepository('ChamiloCourseBundle:CDropboxFile')->findBy($criteria); |
||
| 1073 | $cDropboxFile = []; |
||
| 1074 | /** @var CDropboxFile $item */ |
||
| 1075 | foreach ($result as $item) { |
||
| 1076 | $date = $item->getUploadDate() ? $item->getUploadDate()->format($dateFormat) : ''; |
||
| 1077 | $list = [ |
||
| 1078 | 'Title: '.$item->getTitle(), |
||
| 1079 | 'Uploaded date: '.$date, |
||
| 1080 | 'File: '.$item->getFilename(), |
||
| 1081 | ]; |
||
| 1082 | $cDropboxFile[] = implode(', ', $list); |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | // CDropboxPerson |
||
| 1086 | $criteria = [ |
||
| 1087 | 'userId' => $userId, |
||
| 1088 | ]; |
||
| 1089 | $result = $em->getRepository('ChamiloCourseBundle:CDropboxPerson')->findBy($criteria); |
||
| 1090 | $cDropboxPerson = []; |
||
| 1091 | /** @var CDropboxPerson $item */ |
||
| 1092 | foreach ($result as $item) { |
||
| 1093 | $list = [ |
||
| 1094 | 'File #'.$item->getFileId(), |
||
| 1095 | 'Course #'.$item->getCId(), |
||
| 1096 | ]; |
||
| 1097 | $cDropboxPerson[] = implode(', ', $list); |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | // CDropboxPerson |
||
| 1101 | $criteria = [ |
||
| 1102 | 'authorUserId' => $userId, |
||
| 1103 | ]; |
||
| 1104 | $result = $em->getRepository('ChamiloCourseBundle:CDropboxFeedback')->findBy($criteria); |
||
| 1105 | $cDropboxFeedback = []; |
||
| 1106 | /** @var CDropboxFeedback $item */ |
||
| 1107 | foreach ($result as $item) { |
||
| 1108 | $date = $item->getFeedbackDate() ? $item->getFeedbackDate()->format($dateFormat) : ''; |
||
| 1109 | $list = [ |
||
| 1110 | 'File #'.$item->getFileId(), |
||
| 1111 | 'Feedback: '.$item->getFeedback(), |
||
| 1112 | 'Date: '.$date, |
||
| 1113 | ]; |
||
| 1114 | $cDropboxFeedback[] = implode(', ', $list); |
||
| 1115 | } |
||
| 1116 | |||
| 1117 | // CNotebook |
||
| 1118 | $criteria = [ |
||
| 1119 | 'userId' => $userId, |
||
| 1120 | ]; |
||
| 1121 | $result = $em->getRepository('ChamiloCourseBundle:CNotebook')->findBy($criteria); |
||
| 1122 | $cNotebook = []; |
||
| 1123 | /** @var CNotebook $item */ |
||
| 1124 | foreach ($result as $item) { |
||
| 1125 | $date = $item->getUpdateDate() ? $item->getUpdateDate()->format($dateFormat) : ''; |
||
| 1126 | $list = [ |
||
| 1127 | 'Title: '.$item->getTitle(), |
||
| 1128 | 'Date: '.$date, |
||
| 1129 | ]; |
||
| 1130 | $cNotebook[] = implode(', ', $list); |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | // CLpView |
||
| 1134 | $criteria = [ |
||
| 1135 | 'userId' => $userId, |
||
| 1136 | ]; |
||
| 1137 | $result = $em->getRepository('ChamiloCourseBundle:CLpView')->findBy($criteria); |
||
| 1138 | $cLpView = []; |
||
| 1139 | /** @var CLpView $item */ |
||
| 1140 | foreach ($result as $item) { |
||
| 1141 | $list = [ |
||
| 1142 | //'Id #'.$item->getId(), |
||
| 1143 | 'LP #'.$item->getLpId(), |
||
| 1144 | 'Progress: '.$item->getProgress(), |
||
| 1145 | 'Course #'.$item->getCId(), |
||
| 1146 | 'Session #'.$item->getSessionId(), |
||
| 1147 | ]; |
||
| 1148 | $cLpView[] = implode(', ', $list); |
||
| 1149 | } |
||
| 1150 | |||
| 1151 | // CStudentPublication |
||
| 1152 | $criteria = [ |
||
| 1153 | 'userId' => $userId, |
||
| 1154 | ]; |
||
| 1155 | $result = $em->getRepository('ChamiloCourseBundle:CStudentPublication')->findBy($criteria); |
||
| 1156 | $cStudentPublication = []; |
||
| 1157 | /** @var CStudentPublication $item */ |
||
| 1158 | foreach ($result as $item) { |
||
| 1159 | $list = [ |
||
| 1160 | 'Title: '.$item->getTitle(), |
||
| 1161 | 'URL: '.$item->getUrl(), |
||
| 1162 | ]; |
||
| 1163 | $cStudentPublication[] = implode(', ', $list); |
||
| 1164 | } |
||
| 1165 | |||
| 1166 | // CStudentPublicationComment |
||
| 1167 | $criteria = [ |
||
| 1168 | 'userId' => $userId, |
||
| 1169 | ]; |
||
| 1170 | $result = $em->getRepository('ChamiloCourseBundle:CStudentPublicationComment')->findBy($criteria); |
||
| 1171 | $cStudentPublicationComment = []; |
||
| 1172 | /** @var CStudentPublicationComment $item */ |
||
| 1173 | foreach ($result as $item) { |
||
| 1174 | $date = $item->getSentAt() ? $item->getSentAt()->format($dateFormat) : ''; |
||
| 1175 | $list = [ |
||
| 1176 | 'Commment: '.$item->getComment(), |
||
| 1177 | 'File '.$item->getFile(), |
||
| 1178 | 'Course # '.$item->getCId(), |
||
| 1179 | 'Date: '.$date, |
||
| 1180 | ]; |
||
| 1181 | $cStudentPublicationComment[] = implode(', ', $list); |
||
| 1182 | } |
||
| 1183 | |||
| 1184 | // CWiki |
||
| 1185 | $criteria = [ |
||
| 1186 | 'userId' => $userId, |
||
| 1187 | ]; |
||
| 1188 | $result = $em->getRepository('ChamiloCourseBundle:CWiki')->findBy($criteria); |
||
| 1189 | $cWiki = []; |
||
| 1190 | /** @var CWiki $item */ |
||
| 1191 | foreach ($result as $item) { |
||
| 1192 | $list = [ |
||
| 1193 | 'Title: '.$item->getTitle(), |
||
| 1194 | 'Progress: '.$item->getProgress(), |
||
| 1195 | 'IP: '.$item->getUserIp(), |
||
| 1196 | ]; |
||
| 1197 | $cWiki[] = implode(', ', $list); |
||
| 1198 | } |
||
| 1199 | |||
| 1200 | // Ticket |
||
| 1201 | $criteria = [ |
||
| 1202 | 'insertUserId' => $userId, |
||
| 1203 | ]; |
||
| 1204 | $result = $em->getRepository('ChamiloTicketBundle:Ticket')->findBy($criteria); |
||
| 1205 | $ticket = []; |
||
| 1206 | /** @var Ticket $item */ |
||
| 1207 | foreach ($result as $item) { |
||
| 1208 | $list = [ |
||
| 1209 | 'Code: '.$item->getCode(), |
||
| 1210 | 'Subject: '.$item->getSubject(), |
||
| 1211 | ]; |
||
| 1212 | $ticket[] = implode(', ', $list); |
||
| 1213 | } |
||
| 1214 | |||
| 1215 | // Message |
||
| 1216 | $criteria = [ |
||
| 1217 | 'insertUserId' => $userId, |
||
| 1218 | ]; |
||
| 1219 | $result = $em->getRepository('ChamiloTicketBundle:Message')->findBy($criteria); |
||
| 1220 | $ticketMessage = []; |
||
| 1221 | /** @var \Chamilo\TicketBundle\Entity\Message $item */ |
||
| 1222 | foreach ($result as $item) { |
||
| 1223 | $date = $item->getInsertDateTime() ? $item->getInsertDateTime()->format($dateFormat) : ''; |
||
| 1224 | $list = [ |
||
| 1225 | 'Subject: '.$item->getSubject(), |
||
| 1226 | 'IP: '.$item->getIpAddress(), |
||
| 1227 | 'Status: '.$item->getStatus(), |
||
| 1228 | 'Creation date: '.$date, |
||
| 1229 | ]; |
||
| 1230 | $ticketMessage[] = implode(', ', $list); |
||
| 1231 | } |
||
| 1232 | |||
| 1233 | // SkillRelUserComment |
||
| 1234 | $criteria = [ |
||
| 1235 | 'feedbackGiver' => $userId, |
||
| 1236 | ]; |
||
| 1237 | $result = $em->getRepository('ChamiloCoreBundle:SkillRelUserComment')->findBy($criteria); |
||
| 1238 | $skillRelUserComment = []; |
||
| 1239 | /** @var SkillRelUserComment $item */ |
||
| 1240 | foreach ($result as $item) { |
||
| 1241 | $date = $item->getFeedbackDateTime() ? $item->getFeedbackDateTime()->format($dateFormat) : ''; |
||
| 1242 | $list = [ |
||
| 1243 | 'Feedback: '.$item->getFeedbackText(), |
||
| 1244 | 'Value: '.$item->getFeedbackValue(), |
||
| 1245 | 'Created at: '.$date, |
||
| 1246 | ]; |
||
| 1247 | $skillRelUserComment[] = implode(', ', $list); |
||
| 1248 | } |
||
| 1249 | |||
| 1250 | // UserRelCourseVote |
||
| 1251 | $criteria = [ |
||
| 1252 | 'userId' => $userId, |
||
| 1253 | ]; |
||
| 1254 | $result = $em->getRepository('ChamiloCoreBundle:UserRelCourseVote')->findBy($criteria); |
||
| 1255 | $userRelCourseVote = []; |
||
| 1256 | /** @var UserRelCourseVote $item */ |
||
| 1257 | foreach ($result as $item) { |
||
| 1258 | $list = [ |
||
| 1259 | 'Course #'.$item->getCId(), |
||
| 1260 | 'Session #'.$item->getSessionId(), |
||
| 1261 | 'Vote: '.$item->getVote(), |
||
| 1262 | ]; |
||
| 1263 | $userRelCourseVote[] = implode(', ', $list); |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | // UserApiKey |
||
| 1267 | $criteria = [ |
||
| 1268 | 'userId' => $userId, |
||
| 1269 | ]; |
||
| 1270 | $result = $em->getRepository('ChamiloCoreBundle:UserApiKey')->findBy($criteria); |
||
| 1271 | $userApiKey = []; |
||
| 1272 | /** @var UserApiKey $item */ |
||
| 1273 | foreach ($result as $item) { |
||
| 1274 | $validityStart = $item->getValidityStartDate() ? $item->getValidityStartDate()->format($dateFormat) : ''; |
||
| 1275 | $validityEnd = $item->getValidityEndDate() ? $item->getValidityEndDate()->format($dateFormat) : ''; |
||
| 1276 | $created = $item->getCreatedDate() ? $item->getCreatedDate()->format($dateFormat) : ''; |
||
| 1277 | |||
| 1278 | $list = [ |
||
| 1279 | 'ApiKey #'.$item->getApiKey(), |
||
| 1280 | 'Service: '.$item->getApiService(), |
||
| 1281 | 'EndPoint: '.$item->getApiEndPoint(), |
||
| 1282 | 'Validity start date: '.$validityStart, |
||
| 1283 | 'Validity enddate: '.$validityEnd, |
||
| 1284 | 'Created at: '.$created, |
||
| 1285 | ]; |
||
| 1286 | $userApiKey[] = implode(', ', $list); |
||
| 1287 | } |
||
| 1288 | |||
| 1289 | $user->setDropBoxSentFiles( |
||
| 1290 | [ |
||
| 1291 | 'Friends' => $friendList, |
||
| 1292 | 'Events' => $eventList, |
||
| 1293 | 'GradebookCertificate' => $gradebookCertificate, |
||
| 1294 | |||
| 1295 | 'TrackECourseAccess' => $trackECourseAccessList, |
||
| 1296 | 'TrackELogin' => $trackELoginList, |
||
| 1297 | 'TrackEAccess' => $trackEAccessList, |
||
| 1298 | 'TrackEDefault' => $trackEDefault, |
||
| 1299 | 'TrackEOnline' => $trackEOnlineList, |
||
| 1300 | 'TrackEUploads' => $trackEUploads, |
||
| 1301 | 'TrackELastaccess' => $trackELastaccess, |
||
| 1302 | 'GradebookResult' => $gradebookResult, |
||
| 1303 | 'Downloads' => $trackEDownloads, |
||
| 1304 | 'UserCourseCategory' => $userCourseCategory, |
||
| 1305 | 'SkillRelUserComment' => $skillRelUserComment, |
||
| 1306 | 'UserRelCourseVote' => $userRelCourseVote, |
||
| 1307 | 'UserApiKey' => $userApiKey, |
||
| 1308 | |||
| 1309 | // courses |
||
| 1310 | 'AttendanceResult' => $cAttendanceResult, |
||
| 1311 | 'Blog' => $cBlog, |
||
| 1312 | 'DocumentsAdded' => $documents, |
||
| 1313 | 'Chat' => $chatFiles, |
||
| 1314 | 'ForumPost' => $cForumPostList, |
||
| 1315 | 'ForumThread' => $cForumThreadList, |
||
| 1316 | 'TrackEExercises' => $trackEExercises, |
||
| 1317 | 'TrackEAttempt' => $trackEAttempt, |
||
| 1318 | |||
| 1319 | 'GroupRelUser' => $cGroupRelUser, |
||
| 1320 | 'Message' => $messageList, |
||
| 1321 | 'Survey' => $cSurveyAnswer, |
||
| 1322 | 'StudentPublication' => $cStudentPublication, |
||
| 1323 | 'StudentPublicationComment' => $cStudentPublicationComment, |
||
| 1324 | 'DropboxFile' => $cDropboxFile, |
||
| 1325 | 'DropboxPerson' => $cDropboxPerson, |
||
| 1326 | 'DropboxFeedback' => $cDropboxFeedback, |
||
| 1327 | |||
| 1328 | 'LpView' => $cLpView, |
||
| 1329 | 'Notebook' => $cNotebook, |
||
| 1330 | |||
| 1331 | 'Wiki' => $cWiki, |
||
| 1332 | // Tickets |
||
| 1333 | |||
| 1334 | 'Ticket' => $ticket, |
||
| 1335 | 'TicketMessage' => $ticketMessage, |
||
| 1336 | ] |
||
| 1337 | ); |
||
| 1338 | |||
| 1339 | $user->setDropBoxReceivedFiles([]); |
||
| 1340 | //$user->setGroups([]); |
||
| 1341 | $user->setCurriculumItems([]); |
||
| 1342 | |||
| 1343 | $portals = $user->getPortals(); |
||
| 1344 | if (!empty($portals)) { |
||
| 1345 | $list = []; |
||
| 1346 | /** @var AccessUrlRelUser $portal */ |
||
| 1347 | foreach ($portals as $portal) { |
||
| 1348 | $portalInfo = \UrlManager::get_url_data_from_id($portal->getUrl()->getId()); |
||
| 1349 | $list[] = $portalInfo['url']; |
||
| 1350 | } |
||
| 1351 | } |
||
| 1352 | $user->setPortals($list); |
||
| 1353 | |||
| 1354 | $coachList = $user->getSessionAsGeneralCoach(); |
||
| 1355 | $list = []; |
||
| 1356 | /** @var Session $session */ |
||
| 1357 | foreach ($coachList as $session) { |
||
| 1358 | $list[] = $session->getName(); |
||
| 1359 | } |
||
| 1360 | $user->setSessionAsGeneralCoach($list); |
||
| 1361 | |||
| 1362 | $skillRelUserList = $user->getAchievedSkills(); |
||
| 1363 | $list = []; |
||
| 1364 | /** @var SkillRelUser $skillRelUser */ |
||
| 1365 | foreach ($skillRelUserList as $skillRelUser) { |
||
| 1366 | $list[] = $skillRelUser->getSkill()->getName(); |
||
| 1367 | } |
||
| 1368 | $user->setAchievedSkills($list); |
||
| 1369 | $user->setCommentedUserSkills([]); |
||
| 1370 | |||
| 1371 | $extraFieldValues = new \ExtraFieldValue('user'); |
||
| 1372 | $items = $extraFieldValues->getAllValuesByItem($userId); |
||
| 1373 | //$user->setExtraFields($items); |
||
| 1374 | //$user->setExtraFields([]); |
||
| 1375 | |||
| 1376 | $lastLogin = $user->getLastLogin(); |
||
| 1377 | if (empty($lastLogin)) { |
||
| 1378 | $login = $this->getLastLogin($user); |
||
| 1379 | if ($login) { |
||
| 1380 | $lastLogin = $login->getLoginDate(); |
||
| 1381 | } |
||
| 1382 | } |
||
| 1383 | $user->setLastLogin($lastLogin); |
||
| 1384 | |||
| 1385 | $dateNormalizer = new GetSetMethodNormalizer(); |
||
| 1386 | $dateNormalizer->setCircularReferenceHandler(function ($object) { |
||
| 1387 | return get_class($object); |
||
| 1388 | }); |
||
| 1389 | |||
| 1390 | $ignore = [ |
||
| 1391 | 'twoStepVerificationCode', |
||
| 1392 | 'biography', |
||
| 1393 | 'dateOfBirth', |
||
| 1394 | 'gender', |
||
| 1395 | 'facebookData', |
||
| 1396 | 'facebookName', |
||
| 1397 | 'facebookUid', |
||
| 1398 | 'gplusData', |
||
| 1399 | 'gplusName', |
||
| 1400 | 'gplusUid', |
||
| 1401 | 'locale', |
||
| 1402 | 'timezone', |
||
| 1403 | 'twitterData', |
||
| 1404 | 'twitterName', |
||
| 1405 | 'twitterUid', |
||
| 1406 | 'gplusUid', |
||
| 1407 | 'token', |
||
| 1408 | 'website', |
||
| 1409 | 'plainPassword', |
||
| 1410 | 'completeNameWithUsername', |
||
| 1411 | 'completeName', |
||
| 1412 | 'completeNameWithClasses', |
||
| 1413 | 'salt', |
||
| 1414 | ]; |
||
| 1415 | |||
| 1416 | $dateNormalizer->setIgnoredAttributes($ignore); |
||
| 1417 | |||
| 1418 | $callback = function ($dateTime) { |
||
| 1419 | return $dateTime instanceof \DateTime ? $dateTime->format(\DateTime::ATOM) : ''; |
||
| 1420 | }; |
||
| 1421 | |||
| 1422 | $dateNormalizer->setCallbacks( |
||
| 1423 | [ |
||
| 1424 | 'createdAt' => $callback, |
||
| 1425 | 'lastLogin' => $callback, |
||
| 1426 | 'registrationDate' => $callback, |
||
| 1427 | 'memberSince' => $callback, |
||
| 1428 | ] |
||
| 1429 | ); |
||
| 1430 | |||
| 1431 | $normalizers = [$dateNormalizer]; |
||
| 1432 | $serializer = new Serializer($normalizers, [new JsonEncoder()]); |
||
| 1433 | |||
| 1434 | $jsonContent = $serializer->serialize($user, 'json'); |
||
| 1435 | |||
| 1436 | return $jsonContent; |
||
| 1437 | } |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Get the last login from the track_e_login table. |
||
| 1441 | * This might be different from user.last_login in the case of legacy users |
||
| 1442 | * as user.last_login was only implemented in 1.10 version with a default |
||
| 1443 | * value of NULL (not the last record from track_e_login). |
||
| 1444 | * |
||
| 1445 | * @throws \Exception |
||
| 1446 | * |
||
| 1447 | * @return TrackELogin|null |
||
| 1448 | */ |
||
| 1449 | public function getLastLogin(User $user) |
||
| 1465 | } |
||
| 1466 | } |
||
| 1467 |