| Conditions | 70 |
| Total Lines | 536 |
| Code Lines | 329 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 502 | public static function getUserData( |
||
| 503 | $from, |
||
| 504 | $numberOfItems, |
||
| 505 | $column, |
||
| 506 | $direction, |
||
| 507 | array $conditions = [], |
||
| 508 | bool $exerciseToCheckConfig = true, |
||
| 509 | bool $displaySessionInfo = false, |
||
| 510 | ?string $courseCode = null, |
||
| 511 | ?int $sessionId = null, |
||
| 512 | bool $exportCsv = false, |
||
| 513 | array $userIds = [] |
||
| 514 | ) { |
||
| 515 | $includeInvitedUsers = $conditions['include_invited_users'] ?? false; |
||
| 516 | $getCount = $conditions['get_count'] ?? false; |
||
| 517 | |||
| 518 | $csvContent = []; |
||
| 519 | $tblUser = Database::get_main_table(TABLE_MAIN_USER); |
||
| 520 | $tblUrlRelUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
| 521 | $accessUrlId = api_get_current_access_url_id(); |
||
| 522 | |||
| 523 | // --------------------------------------------------------------------- |
||
| 524 | // Resolve course / session context if not explicitly provided |
||
| 525 | // --------------------------------------------------------------------- |
||
| 526 | if ($sessionId === null) { |
||
| 527 | $sessionId = (int) api_get_session_id(); |
||
| 528 | } |
||
| 529 | |||
| 530 | if (empty($courseCode)) { |
||
| 531 | $courseInfo = api_get_course_info(); // current course |
||
| 532 | } else { |
||
| 533 | $courseInfo = api_get_course_info($courseCode); |
||
| 534 | } |
||
| 535 | |||
| 536 | if (empty($courseInfo)) { |
||
| 537 | // Failsafe: no course context, nothing to show |
||
| 538 | return []; |
||
| 539 | } |
||
| 540 | |||
| 541 | $courseId = (int) $courseInfo['real_id']; |
||
| 542 | $courseCode = $courseInfo['code'] ?? $courseCode; |
||
| 543 | |||
| 544 | // --------------------------------------------------------------------- |
||
| 545 | // Build user filter (single user vs list of users) |
||
| 546 | // --------------------------------------------------------------------- |
||
| 547 | if (!empty($userIds) && is_array($userIds)) { |
||
| 548 | $userIds = array_map('intval', $userIds); |
||
| 549 | $conditionUser = ' WHERE user.id IN ('.implode(',', $userIds).') '; |
||
| 550 | } else { |
||
| 551 | $conditionUser = ' WHERE user.id = '.(int) $userIds.' '; |
||
| 552 | } |
||
| 553 | |||
| 554 | // Simple keyword filter |
||
| 555 | if (!empty($_GET['user_keyword'])) { |
||
| 556 | $keyword = trim(Database::escape_string($_GET['user_keyword'])); |
||
| 557 | $conditionUser .= " AND ( |
||
| 558 | user.firstname LIKE '%".$keyword."%' OR |
||
| 559 | user.lastname LIKE '%".$keyword."%' OR |
||
| 560 | user.username LIKE '%".$keyword."%' OR |
||
| 561 | user.email LIKE '%".$keyword."%' |
||
| 562 | ) "; |
||
| 563 | } |
||
| 564 | |||
| 565 | // Multiple URL restriction |
||
| 566 | $urlTable = ''; |
||
| 567 | $urlCondition = ''; |
||
| 568 | if (api_is_multiple_url_enabled()) { |
||
| 569 | $urlTable = " INNER JOIN $tblUrlRelUser AS url_users ON (user.id = url_users.user_id)"; |
||
| 570 | $urlCondition = " AND access_url_id = '$accessUrlId'"; |
||
| 571 | } |
||
| 572 | |||
| 573 | // Exclude invited users if needed |
||
| 574 | $invitedUsersCondition = ''; |
||
| 575 | if (!$includeInvitedUsers) { |
||
| 576 | $invitedUsersCondition = ' AND user.status != '.INVITEE; |
||
| 577 | } |
||
| 578 | |||
| 579 | // --------------------------------------------------------------------- |
||
| 580 | // Base SELECT |
||
| 581 | // --------------------------------------------------------------------- |
||
| 582 | $select = ' |
||
| 583 | SELECT user.id AS user_id, |
||
| 584 | user.official_code AS col0, |
||
| 585 | user.lastname AS col1, |
||
| 586 | user.firstname AS col2, |
||
| 587 | user.username AS col3, |
||
| 588 | user.email AS col4'; |
||
| 589 | |||
| 590 | if ($getCount) { |
||
| 591 | $select = 'SELECT COUNT(DISTINCT(user.id)) AS count'; |
||
| 592 | } |
||
| 593 | |||
| 594 | // Extra joins / where from conditions (classes, extra fields, etc.) |
||
| 595 | $sqlInjectJoins = ''; |
||
| 596 | $where = 'AND 1 = 1 '; |
||
| 597 | $sqlInjectWhere = ''; |
||
| 598 | if (!empty($conditions)) { |
||
| 599 | if (isset($conditions['inject_joins'])) { |
||
| 600 | $sqlInjectJoins = $conditions['inject_joins']; |
||
| 601 | } |
||
| 602 | if (isset($conditions['where'])) { |
||
| 603 | $where = $conditions['where']; |
||
| 604 | } |
||
| 605 | if (isset($conditions['inject_where'])) { |
||
| 606 | $sqlInjectWhere = $conditions['inject_where']; |
||
| 607 | } |
||
| 608 | |||
| 609 | $injectExtraFields = $conditions['inject_extra_fields'] ?? 1; |
||
| 610 | $injectExtraFields = rtrim($injectExtraFields, ', '); |
||
| 611 | if (false === $getCount) { |
||
| 612 | $select .= " , $injectExtraFields"; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | $sql = "$select |
||
| 617 | FROM $tblUser AS user |
||
| 618 | $urlTable |
||
| 619 | $sqlInjectJoins |
||
| 620 | $conditionUser |
||
| 621 | $urlCondition |
||
| 622 | $invitedUsersCondition |
||
| 623 | $where |
||
| 624 | $sqlInjectWhere |
||
| 625 | "; |
||
| 626 | |||
| 627 | // --------------------------------------------------------------------- |
||
| 628 | // Sorting / limits |
||
| 629 | // --------------------------------------------------------------------- |
||
| 630 | $direction = strtoupper($direction); |
||
| 631 | if (!in_array($direction, ['ASC', 'DESC'], true)) { |
||
| 632 | $direction = 'ASC'; |
||
| 633 | } |
||
| 634 | |||
| 635 | $column = (int) $column; |
||
| 636 | $from = (int) $from; |
||
| 637 | $numberOfItems = (int) $numberOfItems; |
||
| 638 | |||
| 639 | if ($getCount) { |
||
| 640 | $res = Database::query($sql); |
||
| 641 | $row = Database::fetch_array($res); |
||
| 642 | |||
| 643 | return (int) $row['count']; |
||
| 644 | } |
||
| 645 | |||
| 646 | $sortByFirstName = api_sort_by_first_name(); |
||
| 647 | if ($sortByFirstName) { |
||
| 648 | // Invert columns 1/2 if we sort by firstname |
||
| 649 | if (1 === $column) { |
||
| 650 | $column = 2; |
||
| 651 | } elseif (2 === $column) { |
||
| 652 | $column = 1; |
||
| 653 | } |
||
| 654 | } |
||
| 655 | |||
| 656 | $sql .= " ORDER BY col$column $direction "; |
||
| 657 | $sql .= " LIMIT $from, $numberOfItems"; |
||
| 658 | |||
| 659 | $res = Database::query($sql); |
||
| 660 | $users = []; |
||
| 661 | |||
| 662 | // --------------------------------------------------------------------- |
||
| 663 | // Course data required for progress / scores |
||
| 664 | // --------------------------------------------------------------------- |
||
| 665 | $totalSurveys = 0; |
||
| 666 | $totalExercises = ExerciseLib::get_all_exercises( |
||
| 667 | $courseInfo, |
||
| 668 | $sessionId |
||
| 669 | ); |
||
| 670 | |||
| 671 | // Preload survey info only when we are outside a session |
||
| 672 | $surveyUserList = []; |
||
| 673 | if (empty($sessionId)) { |
||
| 674 | $courseCodeForSurvey = $courseCode; |
||
| 675 | $surveyList = []; |
||
| 676 | |||
| 677 | if (!empty($courseCodeForSurvey)) { |
||
| 678 | $surveyList = SurveyManager::get_surveys($courseCodeForSurvey); |
||
| 679 | } |
||
| 680 | |||
| 681 | if (!empty($surveyList)) { |
||
| 682 | $totalSurveys = count($surveyList); |
||
| 683 | |||
| 684 | foreach ($surveyList as $survey) { |
||
| 685 | if (!is_array($survey)) { |
||
| 686 | continue; |
||
| 687 | } |
||
| 688 | |||
| 689 | // Support both "survey_id" and "id" |
||
| 690 | $surveyId = $survey['survey_id'] ?? ($survey['id'] ?? null); |
||
| 691 | $surveyId = (int) $surveyId; |
||
| 692 | |||
| 693 | if ($surveyId <= 0) { |
||
| 694 | continue; |
||
| 695 | } |
||
| 696 | |||
| 697 | $userList = SurveyManager::get_people_who_filled_survey( |
||
| 698 | $surveyId, |
||
| 699 | false, |
||
| 700 | $courseId |
||
| 701 | ); |
||
| 702 | |||
| 703 | foreach ($userList as $userId) { |
||
| 704 | if (isset($surveyUserList[$userId])) { |
||
| 705 | $surveyUserList[$userId]++; |
||
| 706 | } else { |
||
| 707 | $surveyUserList[$userId] = 1; |
||
| 708 | } |
||
| 709 | } |
||
| 710 | } |
||
| 711 | } |
||
| 712 | } |
||
| 713 | |||
| 714 | $urlBase = api_get_path(WEB_CODE_PATH).'my_space/myStudents.php?details=true' |
||
| 715 | .'&cid='.$courseId |
||
| 716 | .'&course='.$courseCode |
||
| 717 | .'&origin=tracking_course' |
||
| 718 | .'&sid='.$sessionId; |
||
| 719 | |||
| 720 | Session::write('user_id_list', []); |
||
| 721 | $userIdList = []; |
||
| 722 | |||
| 723 | // Exercises to show as extra columns (best attempt) |
||
| 724 | $exerciseResultsToCheck = []; |
||
| 725 | if ($exerciseToCheckConfig) { |
||
| 726 | $addExerciseOption = api_get_setting('exercise.add_exercise_best_attempt_in_report', true); |
||
| 727 | if (!empty($addExerciseOption) |
||
| 728 | && isset($addExerciseOption['courses'], $addExerciseOption['courses'][$courseCode]) |
||
| 729 | ) { |
||
| 730 | foreach ($addExerciseOption['courses'][$courseCode] as $exerciseId) { |
||
| 731 | $exercise = new Exercise(); |
||
| 732 | $exercise->read($exerciseId); |
||
| 733 | if (!empty($exercise->iid)) { |
||
| 734 | $exerciseResultsToCheck[] = $exercise; |
||
| 735 | } |
||
| 736 | } |
||
| 737 | } |
||
| 738 | } |
||
| 739 | |||
| 740 | $lpShowMaxProgress = 'true' === api_get_setting('lp.lp_show_max_progress_instead_of_average'); |
||
| 741 | if ('true' === api_get_setting('lp.lp_show_max_progress_or_average_enable_course_level_redefinition')) { |
||
| 742 | $lpShowProgressCourseSetting = api_get_course_setting( |
||
| 743 | 'lp_show_max_or_average_progress', |
||
| 744 | $courseInfo, |
||
| 745 | true |
||
| 746 | ); |
||
| 747 | if (in_array($lpShowProgressCourseSetting, ['max', 'average'], true)) { |
||
| 748 | $lpShowMaxProgress = ('max' === $lpShowProgressCourseSetting); |
||
| 749 | } |
||
| 750 | } |
||
| 751 | |||
| 752 | // --------------------------------------------------------------------- |
||
| 753 | // Main per-user loop |
||
| 754 | // --------------------------------------------------------------------- |
||
| 755 | while ($user = Database::fetch_array($res, 'ASSOC')) { |
||
| 756 | $userIdList[] = $user['user_id']; |
||
| 757 | $user['official_code'] = $user['col0']; |
||
| 758 | $user['username'] = $user['col3']; |
||
| 759 | |||
| 760 | $user['time'] = api_time_to_hms( |
||
| 761 | Tracking::get_time_spent_on_the_course( |
||
| 762 | $user['user_id'], |
||
| 763 | $courseId, |
||
| 764 | $sessionId |
||
| 765 | ) |
||
| 766 | ); |
||
| 767 | |||
| 768 | $avgStudentScore = Tracking::get_avg_student_score( |
||
| 769 | $user['user_id'], |
||
| 770 | api_get_course_entity($courseId), |
||
| 771 | [], |
||
| 772 | api_get_session_entity($sessionId) |
||
| 773 | ); |
||
| 774 | |||
| 775 | $averageBestScore = Tracking::get_avg_student_score( |
||
| 776 | $user['user_id'], |
||
| 777 | api_get_course_entity($courseId), |
||
| 778 | [], |
||
| 779 | api_get_session_entity($sessionId), |
||
| 780 | false, |
||
| 781 | false, |
||
| 782 | true |
||
| 783 | ); |
||
| 784 | |||
| 785 | $avgStudentProgress = Tracking::get_avg_student_progress( |
||
| 786 | $user['user_id'], |
||
| 787 | api_get_course_entity($courseId), |
||
| 788 | [], |
||
| 789 | api_get_session_entity($sessionId) |
||
| 790 | ); |
||
| 791 | |||
| 792 | if (empty($avgStudentProgress)) { |
||
| 793 | $avgStudentProgress = 0; |
||
| 794 | } |
||
| 795 | $user['average_progress'] = $avgStudentProgress.'%'; |
||
| 796 | |||
| 797 | $totalUserExercise = Tracking::get_exercise_student_progress( |
||
| 798 | $totalExercises, |
||
| 799 | $user['user_id'], |
||
| 800 | $courseId, |
||
| 801 | $sessionId |
||
| 802 | ); |
||
| 803 | $user['exercise_progress'] = $totalUserExercise; |
||
| 804 | |||
| 805 | $totalUserExercise = Tracking::get_exercise_student_average_best_attempt( |
||
| 806 | $totalExercises, |
||
| 807 | $user['user_id'], |
||
| 808 | $courseId, |
||
| 809 | $sessionId |
||
| 810 | ); |
||
| 811 | $user['exercise_average_best_attempt'] = $totalUserExercise; |
||
| 812 | |||
| 813 | $user['student_score'] = is_numeric($avgStudentScore) |
||
| 814 | ? $avgStudentScore.'%' |
||
| 815 | : $avgStudentScore; |
||
| 816 | |||
| 817 | $user['student_score_best'] = is_numeric($averageBestScore) |
||
| 818 | ? $averageBestScore.'%' |
||
| 819 | : $averageBestScore; |
||
| 820 | |||
| 821 | // Extra specific exercises as columns |
||
| 822 | $exerciseResults = []; |
||
| 823 | if (!empty($exerciseResultsToCheck)) { |
||
| 824 | foreach ($exerciseResultsToCheck as $exercise) { |
||
| 825 | $bestExerciseResult = Event::get_best_attempt_exercise_results_per_user( |
||
| 826 | $user['user_id'], |
||
| 827 | $exercise->iid, |
||
| 828 | $courseId, |
||
| 829 | $sessionId, |
||
| 830 | false |
||
| 831 | ); |
||
| 832 | |||
| 833 | $best = null; |
||
| 834 | if ($bestExerciseResult) { |
||
| 835 | $best = $bestExerciseResult['exe_result'] / $bestExerciseResult['exe_weighting']; |
||
| 836 | $best = round($best, 2) * 100; |
||
| 837 | $best .= '%'; |
||
| 838 | } |
||
| 839 | $exerciseResults['exercise_'.$exercise->iid] = $best; |
||
| 840 | } |
||
| 841 | } |
||
| 842 | |||
| 843 | $user['first_connection'] = Tracking::get_first_connection_date_on_the_course( |
||
| 844 | $user['user_id'], |
||
| 845 | $courseId, |
||
| 846 | $sessionId, |
||
| 847 | !$exportCsv |
||
| 848 | ); |
||
| 849 | |||
| 850 | $user['last_connection'] = Tracking::get_last_connection_date_on_the_course( |
||
| 851 | $user['user_id'], |
||
| 852 | $courseInfo, |
||
| 853 | $sessionId, |
||
| 854 | !$exportCsv |
||
| 855 | ); |
||
| 856 | |||
| 857 | $user['count_assignments'] = Tracking::countStudentPublications( |
||
| 858 | $courseId, |
||
| 859 | $sessionId |
||
| 860 | ); |
||
| 861 | |||
| 862 | $user['count_messages'] = Tracking::countStudentMessages( |
||
| 863 | $courseId, |
||
| 864 | $sessionId |
||
| 865 | ); |
||
| 866 | |||
| 867 | $user['lp_finalization_date'] = Tracking::getCourseLpFinalizationDate( |
||
| 868 | $user['user_id'], |
||
| 869 | $courseId, |
||
| 870 | $sessionId, |
||
| 871 | !$exportCsv |
||
| 872 | ); |
||
| 873 | |||
| 874 | $user['quiz_finalization_date'] = Tracking::getCourseQuizLastFinalizationDate( |
||
| 875 | $user['user_id'], |
||
| 876 | $courseId, |
||
| 877 | $sessionId, |
||
| 878 | !$exportCsv |
||
| 879 | ); |
||
| 880 | |||
| 881 | if ($exportCsv) { |
||
| 882 | $user['first_connection'] = !empty($user['first_connection']) |
||
| 883 | ? api_get_local_time($user['first_connection']) |
||
| 884 | : '-'; |
||
| 885 | $user['last_connection'] = !empty($user['last_connection']) |
||
| 886 | ? api_get_local_time($user['last_connection']) |
||
| 887 | : '-'; |
||
| 888 | $user['lp_finalization_date'] = !empty($user['lp_finalization_date']) |
||
| 889 | ? api_get_local_time($user['lp_finalization_date']) |
||
| 890 | : '-'; |
||
| 891 | $user['quiz_finalization_date'] = !empty($user['quiz_finalization_date']) |
||
| 892 | ? api_get_local_time($user['quiz_finalization_date']) |
||
| 893 | : '-'; |
||
| 894 | } |
||
| 895 | |||
| 896 | if (empty($sessionId)) { |
||
| 897 | $filled = $surveyUserList[$user['user_id']] ?? 0; |
||
| 898 | $user['survey'] = $totalSurveys > 0 |
||
| 899 | ? $filled.' / '.$totalSurveys |
||
| 900 | : '0 / 0'; |
||
| 901 | } |
||
| 902 | |||
| 903 | $url = $urlBase.'&student='.$user['user_id']; |
||
| 904 | $user['link'] = '<a href="'.$url.'"> |
||
| 905 | '.Display::return_icon('2rightarrow.png', get_lang('Details')).' |
||
| 906 | </a>'; |
||
| 907 | |||
| 908 | // ------------------------------------------------------------- |
||
| 909 | // Build final row |
||
| 910 | // ------------------------------------------------------------- |
||
| 911 | $userRow = []; |
||
| 912 | if ($displaySessionInfo && !empty($sessionId)) { |
||
| 913 | $sessionInfo = api_get_session_info($sessionId); |
||
| 914 | $userRow['session_name'] = $sessionInfo['name']; |
||
| 915 | $userRow['session_startdate'] = $sessionInfo['access_start_date']; |
||
| 916 | $userRow['session_enddate'] = $sessionInfo['access_end_date']; |
||
| 917 | $userRow['course_name'] = $courseInfo['name']; |
||
| 918 | } |
||
| 919 | |||
| 920 | $userRow['official_code'] = $user['official_code']; |
||
| 921 | if ($sortByFirstName) { |
||
| 922 | $userRow['firstname'] = $user['col2']; |
||
| 923 | $userRow['lastname'] = $user['col1']; |
||
| 924 | } else { |
||
| 925 | $userRow['lastname'] = $user['col1']; |
||
| 926 | $userRow['firstname'] = $user['col2']; |
||
| 927 | } |
||
| 928 | $userRow['username'] = $user['username']; |
||
| 929 | $userRow['time'] = $user['time']; |
||
| 930 | $userRow['average_progress'] = $user['average_progress']; |
||
| 931 | $userRow['exercise_progress'] = $user['exercise_progress']; |
||
| 932 | $userRow['exercise_average_best_attempt']= $user['exercise_average_best_attempt']; |
||
| 933 | $userRow['student_score'] = $user['student_score']; |
||
| 934 | $userRow['student_score_best'] = $user['student_score_best']; |
||
| 935 | |||
| 936 | if (!empty($exerciseResults)) { |
||
| 937 | foreach ($exerciseResults as $exerciseId => $bestResult) { |
||
| 938 | $userRow[$exerciseId] = $bestResult; |
||
| 939 | } |
||
| 940 | } |
||
| 941 | |||
| 942 | $userRow['count_assignments'] = $user['count_assignments']; |
||
| 943 | $userRow['count_messages'] = $user['count_messages']; |
||
| 944 | |||
| 945 | $userGroupManager = new UserGroupModel(); |
||
| 946 | if ($exportCsv) { |
||
| 947 | $userRow['classes'] = implode( |
||
| 948 | ',', |
||
| 949 | $userGroupManager->getNameListByUser($user['user_id'], UserGroupModel::NORMAL_CLASS) |
||
| 950 | ); |
||
| 951 | } else { |
||
| 952 | $userRow['classes'] = $userGroupManager->getLabelsFromNameList( |
||
| 953 | $user['user_id'], |
||
| 954 | UserGroupModel::NORMAL_CLASS |
||
| 955 | ); |
||
| 956 | } |
||
| 957 | |||
| 958 | if (empty($sessionId)) { |
||
| 959 | $userRow['survey'] = $user['survey']; |
||
| 960 | } else { |
||
| 961 | $userSession = SessionManager::getUserSession($user['user_id'], $sessionId); |
||
| 962 | $userRow['registered_at'] = ''; |
||
| 963 | if ($userSession) { |
||
| 964 | $userRow['registered_at'] = api_get_local_time($userSession['registered_at']); |
||
| 965 | } |
||
| 966 | } |
||
| 967 | |||
| 968 | $userRow['first_connection'] = $user['first_connection']; |
||
| 969 | $userRow['last_connection'] = $user['last_connection']; |
||
| 970 | $userRow['lp_finalization_date'] = $user['lp_finalization_date']; |
||
| 971 | $userRow['quiz_finalization_date']= $user['quiz_finalization_date']; |
||
| 972 | |||
| 973 | // Extra profile fields selected by the teacher |
||
| 974 | if (isset($_GET['additional_profile_field'])) { |
||
| 975 | $data = Session::read('additional_user_profile_info'); |
||
| 976 | $extraFieldInfo = Session::read('extra_field_info'); |
||
| 977 | |||
| 978 | foreach ($_GET['additional_profile_field'] as $fieldId) { |
||
| 979 | if (isset($data[$fieldId]) && isset($data[$fieldId][$user['user_id']])) { |
||
| 980 | if (is_array($data[$fieldId][$user['user_id']])) { |
||
| 981 | $userRow[$extraFieldInfo[$fieldId]['variable']] = implode( |
||
| 982 | ', ', |
||
| 983 | $data[$fieldId][$user['user_id']] |
||
| 984 | ); |
||
| 985 | } else { |
||
| 986 | $userRow[$extraFieldInfo[$fieldId]['variable']] = $data[$fieldId][$user['user_id']]; |
||
| 987 | } |
||
| 988 | } else { |
||
| 989 | $userRow[$extraFieldInfo[$fieldId]['variable']] = ''; |
||
| 990 | } |
||
| 991 | } |
||
| 992 | } |
||
| 993 | |||
| 994 | $data = Session::read('default_additional_user_profile_info'); |
||
| 995 | $defaultExtraFieldInfo = Session::read('default_extra_field_info'); |
||
| 996 | if (!empty($defaultExtraFieldInfo) && !empty($data)) { |
||
| 997 | foreach ($data as $key => $val) { |
||
| 998 | if (isset($val[$user['user_id']])) { |
||
| 999 | if (is_array($val[$user['user_id']])) { |
||
| 1000 | $userRow[$defaultExtraFieldInfo[$key]['variable']] = implode( |
||
| 1001 | ', ', |
||
| 1002 | $val[$user['user_id']] |
||
| 1003 | ); |
||
| 1004 | } else { |
||
| 1005 | $userRow[$defaultExtraFieldInfo[$key]['variable']] = $val[$user['user_id']]; |
||
| 1006 | } |
||
| 1007 | } else { |
||
| 1008 | $userRow[$defaultExtraFieldInfo[$key]['variable']] = ''; |
||
| 1009 | } |
||
| 1010 | } |
||
| 1011 | } |
||
| 1012 | |||
| 1013 | if (api_get_setting('show_email_addresses') === 'true') { |
||
| 1014 | $userRow['email'] = $user['col4']; |
||
| 1015 | } |
||
| 1016 | |||
| 1017 | $userRow['link'] = $user['link']; |
||
| 1018 | |||
| 1019 | if ($exportCsv) { |
||
| 1020 | unset($userRow['link']); |
||
| 1021 | $csvContent[] = $userRow; |
||
| 1022 | } |
||
| 1023 | |||
| 1024 | $users[] = array_values($userRow); |
||
| 1025 | } |
||
| 1026 | |||
| 1027 | if ($exportCsv) { |
||
| 1028 | Session::write('csv_content', $csvContent); |
||
| 1029 | } |
||
| 1030 | |||
| 1031 | Session::erase('additional_user_profile_info'); |
||
| 1032 | Session::erase('extra_field_info'); |
||
| 1033 | Session::erase('default_additional_user_profile_info'); |
||
| 1034 | Session::erase('default_extra_field_info'); |
||
| 1035 | Session::write('user_id_list', $userIdList); |
||
| 1036 | |||
| 1037 | return $users; |
||
| 1038 | } |
||
| 1358 |