From 9c1596f2329af6442d4cfc13ea5849a6c8057ab8 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 29 Aug 2018 14:09:40 -0500 Subject: [PATCH] Move methods to get user complete name to UserManager --- main/admin/add_drh_to_user.php | 4 +-- main/admin/course_add.php | 2 +- main/admin/course_edit.php | 2 +- .../admin/teachers_time_by_session_report.php | 2 +- main/admin/user_information.php | 2 +- main/admin/user_linking_requests.php | 2 +- main/auth/courses_controller.php | 2 +- main/auth/hrm_courses.php | 2 +- main/badge/assign.php | 12 ++++---- main/badge/issued.php | 4 +-- main/badge/issued_all.php | 6 ++-- main/course_info/about.php | 2 +- main/cron/course_finished.php | 6 ++-- main/forum/forumfunction.inc.php | 2 +- main/inc/ajax/message.ajax.php | 2 +- main/inc/ajax/session.ajax.php | 2 +- main/inc/ajax/user_manager.ajax.php | 4 +-- main/inc/lib/CourseChatUtils.php | 6 ++-- .../lib/formvalidator/Element/UserAvatar.php | 4 +-- main/inc/lib/login.lib.php | 2 +- main/inc/lib/myspace.lib.php | 2 +- .../tool_processors/quiz_processor.class.php | 2 +- main/inc/lib/sessionmanager.lib.php | 2 +- main/inc/lib/template.lib.php | 4 +-- main/inc/lib/usermanager.lib.php | 23 ++++++++++++++- main/inc/lib/webservices/Rest.php | 6 ++-- main/mySpace/works_in_session_report.php | 2 +- main/session/about.php | 2 +- main/session/resume_session.php | 2 +- main/session/session_course_user.php | 2 +- .../gamification/my_progress.html.twig | 2 +- main/template/default/session/about.html.twig | 2 +- plugin/bbb/admin.php | 2 +- .../src/buy_course_plugin.class.php | 10 +++---- plugin/buycourses/src/buycourses.ajax.php | 2 +- plugin/buycourses/src/configure_course.php | 6 ++-- plugin/buycourses/src/service_process.php | 2 +- plugin/buycourses/src/services_add.php | 2 +- plugin/buycourses/src/services_edit.php | 2 +- plugin/ims_lti/form.php | 2 +- .../Twig/Extension/ChamiloExtension.php | 1 + src/UserBundle/Entity/User.php | 28 ++----------------- 42 files changed, 88 insertions(+), 90 deletions(-) diff --git a/main/admin/add_drh_to_user.php b/main/admin/add_drh_to_user.php index 3db1d058bc..6ddcb4e7c0 100644 --- a/main/admin/add_drh_to_user.php +++ b/main/admin/add_drh_to_user.php @@ -38,7 +38,7 @@ foreach ($subscribedUsers as $subscribedUser) { continue; } - $hrmOptions[$hrm->getId()] = $hrm->getCompleteNameWithUsername(); + $hrmOptions[$hrm->getId()] = UserManager::formatUserFullName($hrm, true); } $form = new FormValidator('assign_hrm'); @@ -89,7 +89,7 @@ if ($form->validate()) { $interbreadcrumb[] = ['name' => get_lang('PlatformAdmin'), 'url' => 'index.php']; $interbreadcrumb[] = ['name' => get_lang('UserList'), 'url' => 'user_list.php']; -$interbreadcrumb[] = ['name' => $user->getCompleteName(), 'url' => 'user_information.php?user_id='.$user->getId()]; +$interbreadcrumb[] = ['name' => UserManager::formatUserFullName($user), 'url' => 'user_information.php?user_id='.$user->getId()]; $toolName = get_lang('AssignHrmToUser'); diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 16bc00679e..c9cdf9386b 100755 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -103,7 +103,7 @@ $currentTeacher = api_get_user_entity(api_get_user_id()); $form->addSelectAjax( 'course_teachers', get_lang('CourseTeachers'), - [$currentTeacher->getId() => $currentTeacher->getCompleteNameWithUsername()], + [$currentTeacher->getId() => UserManager::formatUserFullName($currentTeacher, true)], [ 'url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=teacher_to_basis_course', 'id' => 'course_teachers', diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 2450983e9a..618d3e3929 100755 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -189,7 +189,7 @@ $courseTeacherNames = []; foreach ($course_teachers as $courseTeacherId) { /** @var User $courseTeacher */ $courseTeacher = UserManager::getRepository()->find($courseTeacherId); - $courseTeacherNames[$courseTeacher->getUserId()] = $courseTeacher->getCompleteNameWithUsername(); + $courseTeacherNames[$courseTeacher->getUserId()] = UserManager::formatUserFullName($courseTeacher, true); } $form->addSelectAjax( diff --git a/main/admin/teachers_time_by_session_report.php b/main/admin/teachers_time_by_session_report.php index 93c5b89677..14d3763f28 100644 --- a/main/admin/teachers_time_by_session_report.php +++ b/main/admin/teachers_time_by_session_report.php @@ -67,7 +67,7 @@ if ($session) { if (!array_key_exists($user->getId(), $usersInfo)) { $usersInfo[$user->getId()] = [ 'code' => $user->getOfficialCode(), - 'complete_name' => $user->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($user), 'time_in_platform' => api_time_to_hms( Tracking::get_time_spent_on_the_platform($user->getId(), 'ever') ), diff --git a/main/admin/user_information.php b/main/admin/user_information.php index c6f355b903..4c042beb31 100755 --- a/main/admin/user_information.php +++ b/main/admin/user_information.php @@ -46,7 +46,7 @@ $userId = $user['user_id']; $currentUrl = api_get_self().'?user_id='.$userId; -$tool_name = $userEntity->getCompleteName(); +$tool_name = UserManager::formatUserFullName($userEntity); $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_course = Database::get_main_table(TABLE_MAIN_COURSE); $csvContent = []; diff --git a/main/admin/user_linking_requests.php b/main/admin/user_linking_requests.php index 2316b84886..f92de9c200 100644 --- a/main/admin/user_linking_requests.php +++ b/main/admin/user_linking_requests.php @@ -147,7 +147,7 @@ $form = new FormValidator('user_linking_requests', 'get'); $form->addSelectAjax( 'hrm', get_lang('DRH'), - $hrm ? [$hrm->getId() => $hrm->getCompleteName()] : [], + $hrm ? [$hrm->getId() => UserManager::formatUserFullName($hrm)] : [], ['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=user_by_role'] ); $form->addButtonFilter(get_lang('Filter')); diff --git a/main/auth/courses_controller.php b/main/auth/courses_controller.php index c31a8f541e..86bffde84f 100755 --- a/main/auth/courses_controller.php +++ b/main/auth/courses_controller.php @@ -924,7 +924,7 @@ class CoursesController } $coachId = $session->getGeneralCoach()->getId(); - $coachName = $session->getGeneralCoach()->getCompleteName(); + $coachName = UserManager::formatUserFullName($session->getGeneralCoach()); $actions = null; if (api_is_platform_admin()) { $actions = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session->getId(); diff --git a/main/auth/hrm_courses.php b/main/auth/hrm_courses.php index 00b12735d6..bebc3d4a12 100644 --- a/main/auth/hrm_courses.php +++ b/main/auth/hrm_courses.php @@ -58,7 +58,7 @@ foreach ($assignedUsers as $assignedUserId => $assignedUserInfo) { $userInfo = [ 'username' => $assignedUser->getUsername(), - 'complete_name' => $assignedUser->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($assignedUser), 'picture_url' => UserManager::getUserPicture($assignedUserId), 'course_list' => $courseController->returnCoursesAndSessions($assignedUserId)['html'], ]; diff --git a/main/badge/assign.php b/main/badge/assign.php index 5dffbc9624..8b32d2d90b 100644 --- a/main/badge/assign.php +++ b/main/badge/assign.php @@ -278,7 +278,7 @@ if ($form->validate()) { Display::return_message( sprintf( get_lang('TheUserXHasAlreadyAchievedTheSkillY'), - $user->getCompleteName(), + UserManager::formatUserFullName($user), $skill->getName() ), 'warning' @@ -337,7 +337,7 @@ if ($form->validate()) { $subject = get_lang("StudentHadEnoughSkills"); $message = sprintf( get_lang("StudentXHadEnoughSkillsToGetSkillXToAssignClickHereX"), - $user->getCompleteName(), + UserManager::formatUserFullName($user), $parentData['name'], $link ); @@ -359,7 +359,7 @@ if ($form->validate()) { sprintf( get_lang('SkillXAssignedToUserY'), $skill->getName(), - $user->getCompleteName() + UserManager::formatUserFullName($user) ), 'success' ) @@ -369,7 +369,7 @@ if ($form->validate()) { exit; } -$form->setDefaults(['user_name' => $user->getCompleteNameWithUsername()]); +$form->setDefaults(['user_name' => UserManager::formatUserFullName($user, true)]); $form->freeze(['user_name']); if (api_is_drh()) { @@ -390,7 +390,7 @@ if (api_is_drh()) { } $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userId, - 'name' => $user->getCompleteName(), + 'name' => UserManager::formatUserFullName($user), ]; } else { $interbreadcrumb[] = [ @@ -403,7 +403,7 @@ if (api_is_drh()) { ]; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$userId, - 'name' => $user->getCompleteName(), + 'name' => UserManager::formatUserFullName($user), ]; } diff --git a/main/badge/issued.php b/main/badge/issued.php index df9962150e..a19793fc18 100644 --- a/main/badge/issued.php +++ b/main/badge/issued.php @@ -101,7 +101,7 @@ $skillIssueInfo = [ 'argumentation' => $skillIssue->getArgumentation(), 'source_name' => $skillIssue->getSourceName(), 'user_id' => $skillIssue->getUser()->getId(), - 'user_complete_name' => $skillIssue->getUser()->getCompleteName(), + 'user_complete_name' => UserManager::formatUserFullName($skillIssue->getUser()), 'skill_id' => $skillIssue->getSkill()->getId(), 'skill_badge_image' => Skill::getWebIconPath($skillIssue->getSkill()), 'skill_name' => $skillIssue->getSkill()->getName(), @@ -124,7 +124,7 @@ foreach ($skillIssueComments as $comment) { $skillIssueInfo['comments'][] = [ 'text' => $comment->getFeedbackText(), 'value' => $comment->getFeedbackValue(), - 'giver_complete_name' => $comment->getFeedbackGiver()->getCompleteName(), + 'giver_complete_name' => UserManager::formatUserFullName($comment->getFeedbackGiver()), 'datetime' => api_format_date($commentDate, DATE_TIME_FORMAT_SHORT), ]; } diff --git a/main/badge/issued_all.php b/main/badge/issued_all.php index a1e17f0bde..88f11b4560 100644 --- a/main/badge/issued_all.php +++ b/main/badge/issued_all.php @@ -49,7 +49,7 @@ $userSkills = $skillUserRepo->findBy([ $userInfo = [ 'id' => $user->getId(), - 'complete_name' => $user->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($user), ]; $skillInfo = [ @@ -87,7 +87,7 @@ foreach ($userSkills as $index => $skillIssue) { 'argumentation' => $skillIssue->getArgumentation(), 'source_name' => $skillIssue->getSourceName(), 'user_id' => $skillIssue->getUser()->getId(), - 'user_complete_name' => $skillIssue->getUser()->getCompleteName(), + 'user_complete_name' => UserManager::formatUserFullName($skillIssue->getUser()), 'skill_id' => $skillIssue->getSkill()->getId(), 'skill_badge_image' => Skill::getWebIconPath($skillIssue->getSkill()), 'skill_name' => $skillIssue->getSkill()->getName(), @@ -109,7 +109,7 @@ foreach ($userSkills as $index => $skillIssue) { $skillIssueInfo['comments'][] = [ 'text' => $comment->getFeedbackText(), 'value' => $comment->getFeedbackValue(), - 'giver_complete_name' => $comment->getFeedbackGiver()->getCompleteName(), + 'giver_complete_name' => UserManager::formatUserFullName($comment->getFeedbackGiver()), 'datetime' => api_format_date($commentDate, DATE_TIME_FORMAT_SHORT), ]; } diff --git a/main/course_info/about.php b/main/course_info/about.php index 2b3e7a32b4..e0f23720e1 100644 --- a/main/course_info/about.php +++ b/main/course_info/about.php @@ -59,7 +59,7 @@ $teachersData = []; foreach ($courseTeachers as $teacherSubscription) { $teacher = $teacherSubscription->getUser(); $userData = [ - 'complete_name' => $teacher->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($teacher), 'image' => UserManager::getUserPicture( $teacher->getId(), USER_IMAGE_SIZE_ORIGINAL diff --git a/main/cron/course_finished.php b/main/cron/course_finished.php index d471f6ba94..b55e54f4bc 100644 --- a/main/cron/course_finished.php +++ b/main/cron/course_finished.php @@ -67,7 +67,7 @@ foreach ($sessions as $session) { ); $bodyTemplate = new Template(null, false, false, false, false, false); - $bodyTemplate->assign('complete_user_name', $user->getCompleteName()); + $bodyTemplate->assign('complete_user_name', UserManager::formatUserFullName($user)); $bodyTemplate->assign('session_name', $session->getName()); $bodyLayout = $bodyTemplate->get_template( @@ -75,7 +75,7 @@ foreach ($sessions as $session) { ); api_mail_html( - $user->getCompleteName(), + UserManager::formatUserFullName($user), $user->getEmail(), $subjectTemplate->fetch($subjectLayout), $bodyTemplate->fetch($bodyLayout), @@ -84,7 +84,7 @@ foreach ($sessions as $session) { ); echo '============'.PHP_EOL; - echo "Email sent to: {$user->getCompleteName()} ({$user->getEmail()})".PHP_EOL; + echo "Email sent to: ".UserManager::formatUserFullName($user)." ({$user->getEmail()})".PHP_EOL; echo "Session: {$session->getName()}".PHP_EOL; echo "End date: {$session->getAccessEndDate()->format('Y-m-d h:i')}".PHP_EOL; } diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 8b92ddfd48..884e30a4e8 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -2142,7 +2142,7 @@ function getPosts( $postInfo['username_canonical'] = $user->getUsernameCanonical(); $postInfo['lastname'] = $user->getLastname(); $postInfo['firstname'] = $user->getFirstname(); - $postInfo['complete_name'] = $user->getCompleteName(); + $postInfo['complete_name'] = UserManager::formatUserFullName($user); } } diff --git a/main/inc/ajax/message.ajax.php b/main/inc/ajax/message.ajax.php index e9c1819392..88c67400dd 100755 --- a/main/inc/ajax/message.ajax.php +++ b/main/inc/ajax/message.ajax.php @@ -107,7 +107,7 @@ switch ($action) { /** @var User $user */ foreach ($users as $user) { - $userName = $user->getCompleteNameWithUsername(); + $userName = UserManager::formatUserFullName($user, true); if ($showEmail) { $userName .= " ({$user->getEmail()})"; diff --git a/main/inc/ajax/session.ajax.php b/main/inc/ajax/session.ajax.php index 4ddb2db5ce..8bd26b1b1f 100755 --- a/main/inc/ajax/session.ajax.php +++ b/main/inc/ajax/session.ajax.php @@ -192,7 +192,7 @@ switch ($action) { foreach ($users as $user) { $list['items'][] = [ 'id' => $user->getId(), - 'text' => $user->getCompleteName(), + 'text' => UserManager::formatUserFullName($user), ]; } diff --git a/main/inc/ajax/user_manager.ajax.php b/main/inc/ajax/user_manager.ajax.php index 92f0b7cba0..48175a6f2d 100755 --- a/main/inc/ajax/user_manager.ajax.php +++ b/main/inc/ajax/user_manager.ajax.php @@ -270,7 +270,7 @@ switch ($action) { foreach ($users as $user) { $items[] = [ 'id' => $user->getId(), - 'text' => $user->getCompleteNameWithUsername(), + 'text' => UserManager::formatUserFullName($user, true), ]; } @@ -320,7 +320,7 @@ switch ($action) { foreach ($users as $user) { $items[] = [ 'id' => $user->getId(), - 'text' => $user->getCompleteNameWithUsername(), + 'text' => UserManager::formatUserFullName($user, true), ]; } diff --git a/main/inc/lib/CourseChatUtils.php b/main/inc/lib/CourseChatUtils.php index 8127e76a16..f60d66f91a 100644 --- a/main/inc/lib/CourseChatUtils.php +++ b/main/inc/lib/CourseChatUtils.php @@ -175,7 +175,7 @@ class CourseChatUtils $fileContent = '
-
'.$user->getCompleteName().'
+
'.UserManager::formatUserFullName($user).'
'.$message.'
'.$timeNow.'
@@ -189,7 +189,7 @@ class CourseChatUtils
-
'.$user->getCompleteName().'
+
'.UserManager::formatUserFullName($user).'
'.$message.'
'.$timeNow.'
@@ -757,7 +757,7 @@ class CourseChatUtils 'status' => $status, 'image_url' => UserManager::getUserPicture($user->getId(), USER_IMAGE_SIZE_MEDIUM), 'profile_url' => api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user->getId(), - 'complete_name' => $user->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($user), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'isConnected' => $this->userIsConnected($user->getId()), diff --git a/main/inc/lib/formvalidator/Element/UserAvatar.php b/main/inc/lib/formvalidator/Element/UserAvatar.php index 247d8b1314..c3a54c3949 100644 --- a/main/inc/lib/formvalidator/Element/UserAvatar.php +++ b/main/inc/lib/formvalidator/Element/UserAvatar.php @@ -73,10 +73,10 @@ class UserAvatar extends HTML_QuickForm_input $html .= '
- '.$this->user->getCompleteName().' + '.UserManager::formatUserFullName($this->user).'
-

'.$this->user->getCompleteName().'

+

'.UserManager::formatUserFullName($this->user).'

'.$this->subTitle.'
diff --git a/main/inc/lib/login.lib.php b/main/inc/lib/login.lib.php index 216d203a25..a2befc01e4 100755 --- a/main/inc/lib/login.lib.php +++ b/main/inc/lib/login.lib.php @@ -230,7 +230,7 @@ class Login ); api_mail_html( - $user->getCompleteName(), + UserManager::formatUserFullName($user), $user->getEmail(), $mailSubject, $mailBody diff --git a/main/inc/lib/myspace.lib.php b/main/inc/lib/myspace.lib.php index 4e7b99c5ea..9cd4c6ba5b 100644 --- a/main/inc/lib/myspace.lib.php +++ b/main/inc/lib/myspace.lib.php @@ -2765,7 +2765,7 @@ class MySpace if (!empty($studentId)) { $student = api_get_user_entity($studentId); if ($student) { - $studentList[$student->getId()] = $student->getCompleteName(); + $studentList[$student->getId()] = UserManager::formatUserFullName($student); } } diff --git a/main/inc/lib/search/tool_processors/quiz_processor.class.php b/main/inc/lib/search/tool_processors/quiz_processor.class.php index 9103c87499..009e2cabd0 100755 --- a/main/inc/lib/search/tool_processors/quiz_processor.class.php +++ b/main/inc/lib/search/tool_processors/quiz_processor.class.php @@ -132,7 +132,7 @@ class quiz_processor extends search_processor ]); if ($item_result) { - $author = $item_result->getInsertUser()->getCompleteName(); + $author = UserManager::formatUserFullName($item_result->getInsertUser()); } } diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 851d3a2747..45c3a8271f 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -1965,7 +1965,7 @@ class SessionManager $tplContent->assign('session_name', $session->getName()); $tplContent->assign( 'session_coach', - $session->getGeneralCoach()->getCompleteName() + UserManager::formatUserFullName($session->getGeneralCoach()) ); $layoutContent = $tplContent->get_template( 'mail/content_subscription_to_session_confirmation.tpl' diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 7e5ce18c73..5c5c17a850 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -1332,7 +1332,7 @@ class Template /** @var User $tutor */ foreach ($tutors as $tutor) { - $names[] = $tutor->getCompleteName(); + $names[] = UserManager::formatUserFullName($tutor); } return implode(CourseManager::USER_SEPARATOR, $names); @@ -1362,7 +1362,7 @@ class Template /** @var User $teacher */ foreach ($teachers as $teacher) { - $names[] = $teacher->getCompleteName(); + $names[] = UserManager::formatUserFullName($teacher); } return implode(CourseManager::USER_SEPARATOR, $names); diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 0b7bbe1d36..3ef8ee5edf 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -6005,7 +6005,7 @@ SQL; .Display::url($url, $url); api_mail_html( - $user->getCompleteName(), + UserManager::formatUserFullName($user), $user->getEmail(), $mailSubject, $mailBody @@ -6390,4 +6390,25 @@ SQL; return $url; } + + /** + * Return the user's full name. Optionally with the username. + * + * @param User $user + * @param bool $includeUsername Optional. By default username is not included. + * + * @return string + */ + public static function formatUserFullName(User $user, $includeUsername = false) + { + $fullName = api_get_person_name($user->getFirstname(), $user->getLastname()); + + if ($includeUsername && api_get_setting('platform.hide_username_with_complete_name') === 'false') { + $username = $user->getUsername(); + + return "$fullName ($username)"; + } + + return $fullName; + } } diff --git a/main/inc/lib/webservices/Rest.php b/main/inc/lib/webservices/Rest.php index d7d8f7a85c..6ac07530f5 100644 --- a/main/inc/lib/webservices/Rest.php +++ b/main/inc/lib/webservices/Rest.php @@ -422,7 +422,7 @@ class Rest extends WebService return [ 'id' => intval($announcement['announcement']->getIid()), 'title' => $announcement['announcement']->getTitle(), - 'creatorName' => $announcement['item_property']->getInsertUser()->getCompleteName(), + 'creatorName' => UserManager::formatUserFullName($announcement['item_property']->getInsertUser()), 'date' => api_convert_and_format_date( $announcement['item_property']->getInsertDate(), DATE_TIME_FORMAT_LONG_24H @@ -682,7 +682,7 @@ class Rest extends WebService $result = [ 'pictureUri' => $pictureInfo['dir'].$pictureInfo['file'], - 'fullName' => $this->user->getCompleteName(), + 'fullName' => UserManager::formatUserFullName($this->user), 'username' => $this->user->getUsername(), 'officialCode' => $this->user->getOfficialCode(), 'phone' => $this->user->getPhone(), @@ -964,7 +964,7 @@ class Rest extends WebService /** @var User $user */ foreach ($users as $user) { - $userName = $user->getCompleteName(); + $userName = UserManager::formatUserFullName($user); if ($showEmail) { $userName .= " ({$user->getEmail()})"; diff --git a/main/mySpace/works_in_session_report.php b/main/mySpace/works_in_session_report.php index 40c3e1f55b..1c08c0af0e 100644 --- a/main/mySpace/works_in_session_report.php +++ b/main/mySpace/works_in_session_report.php @@ -62,7 +62,7 @@ if ($session) { if (!array_key_exists($user->getId(), $usersInfo)) { $usersInfo[$user->getId()] = [ 'code' => $user->getOfficialCode(), - 'complete_name' => $user->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($user), 'time_in_platform' => api_time_to_hms( Tracking::get_time_spent_on_the_platform($user->getId(), 'ever') ), diff --git a/main/session/about.php b/main/session/about.php index 13c68b9089..adda201ade 100644 --- a/main/session/about.php +++ b/main/session/about.php @@ -65,7 +65,7 @@ foreach ($sessionCourses as $sessionRelCourse) { /** @var User $courseCoach */ foreach ($courseCoaches as $courseCoach) { $coachData = [ - 'complete_name' => $courseCoach->getCompleteName(), + 'complete_name' => UserManager::formatUserFullName($courseCoach), 'image' => UserManager::getUserPicture( $courseCoach->getId(), USER_IMAGE_SIZE_ORIGINAL diff --git a/main/session/resume_session.php b/main/session/resume_session.php index a45c5f6c62..800ba5c658 100644 --- a/main/session/resume_session.php +++ b/main/session/resume_session.php @@ -173,7 +173,7 @@ if ($session->getNbrCourses() === 0) { $namesOfCoaches = []; $coachSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, Session::COACH) ->forAll(function ($index, SessionRelCourseRelUser $subscription) use (&$namesOfCoaches) { - $namesOfCoaches[] = $subscription->getUser()->getCompleteNameWithUserName(); + $namesOfCoaches[] = UserManager::formatUserFullName($subscription->getUser(), true); return true; }); diff --git a/main/session/session_course_user.php b/main/session/session_course_user.php index 265425daa2..ccd433367c 100644 --- a/main/session/session_course_user.php +++ b/main/session/session_course_user.php @@ -103,7 +103,7 @@ $interbreadcrumb[] = [ ]; Display::display_header($tool_name); -echo Display::page_header($session->getName().' - '.$user->getCompleteName()); +echo Display::page_header($session->getName().' - '.UserManager::formatUserFullName($user)); ?>
diff --git a/main/template/default/gamification/my_progress.html.twig b/main/template/default/gamification/my_progress.html.twig index a0a19060f9..aa737dffc3 100644 --- a/main/template/default/gamification/my_progress.html.twig +++ b/main/template/default/gamification/my_progress.html.twig @@ -4,7 +4,7 @@
{{ user_avatar }} -
{{ user.getCompleteName() }}
+
{{ user|format_user_full_name }}
{{ 'XPoints'|get_lang|format(gamification_points) }} diff --git a/main/template/default/session/about.html.twig b/main/template/default/session/about.html.twig index a98023b229..2fb1e78151 100644 --- a/main/template/default/session/about.html.twig +++ b/main/template/default/session/about.html.twig @@ -11,7 +11,7 @@

{% if show_tutor %}

- {{ 'SessionGeneralCoach'|get_lang }}: {{ session.generalCoach.getCompleteName() }} + {{ 'SessionGeneralCoach'|get_lang }}: {{ session.generalCoach|format_user_full_name }}

{% endif %} diff --git a/plugin/bbb/admin.php b/plugin/bbb/admin.php index 4bd39249af..c78a76fef6 100644 --- a/plugin/bbb/admin.php +++ b/plugin/bbb/admin.php @@ -50,7 +50,7 @@ foreach ($meetings as &$meeting) { foreach ($participants as $meetingParticipant) { /** @var User $participant */ $participant = $meetingParticipant['participant']; - $meeting['participants'][] = $participant->getCompleteName().' ('.$participant->getEmail().')'; + $meeting['participants'][] = UserManager::formatUserFullName($participant).' ('.$participant->getEmail().')'; } } diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index e44b9fd4a6..a7ecae20a7 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -461,7 +461,7 @@ class BuyCoursesPlugin extends Plugin } $sessionData = $this->getSessionInfo($session->getId()); - $sessionData['coach'] = $session->getGeneralCoach()->getCompleteName(); + $sessionData['coach'] = UserManager::formatUserFullName($session->getGeneralCoach()); $sessionData['enrolled'] = $this->getUserStatusForSession( api_get_user_id(), $session @@ -483,7 +483,7 @@ class BuyCoursesPlugin extends Plugin foreach ($userCourseSubscriptions as $userCourseSubscription) { $user = $userCourseSubscription->getUser(); - $sessionCourseData['coaches'][] = $user->getCompleteName(); + $sessionCourseData['coaches'][] = UserManager::formatUserFullName($user); } $sessionData['courses'][] = $sessionCourseData; @@ -536,7 +536,7 @@ class BuyCoursesPlugin extends Plugin foreach ($course->getTeachers() as $courseUser) { $teacher = $courseUser->getUser(); - $courseItem['teachers'][] = $teacher->getCompleteName(); + $courseItem['teachers'][] = UserManager::formatUserFullName($teacher); } //check images @@ -607,7 +607,7 @@ class BuyCoursesPlugin extends Plugin foreach ($courseTeachers as $teachers) { $user = $teachers->getUser(); $teacher['id'] = $user->getId(); - $teacher['name'] = $user->getCompleteName(); + $teacher['name'] = UserManager::formatUserFullName($user); $courseInfo['teachers'][] = $teacher; } @@ -697,7 +697,7 @@ class BuyCoursesPlugin extends Plugin foreach ($userCourseSubscriptions as $userCourseSubscription) { $user = $userCourseSubscription->getUser(); $coaches['id'] = $user->getUserId(); - $coaches['name'] = $user->getCompleteName(); + $coaches['name'] = UserManager::formatUserFullName($user); $sessionCourseData['coaches'][] = $coaches; } diff --git a/plugin/buycourses/src/buycourses.ajax.php b/plugin/buycourses/src/buycourses.ajax.php index 1f04390b16..a10bca6b3d 100644 --- a/plugin/buycourses/src/buycourses.ajax.php +++ b/plugin/buycourses/src/buycourses.ajax.php @@ -478,7 +478,7 @@ switch ($action) { $nodeType = get_lang('User'); /** @var User $user */ $user = UserManager::getManager()->find($serviceSale['node_id']); - $nodeName = $user ? $user->getCompleteNameWithUsername() : null; + $nodeName = $user ? UserManager::formatUserFullName($user, true) : null; } else { if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_COURSE) { $nodeType = get_lang('Course'); diff --git a/plugin/buycourses/src/configure_course.php b/plugin/buycourses/src/configure_course.php index e9157ecfdb..f3fe043603 100644 --- a/plugin/buycourses/src/configure_course.php +++ b/plugin/buycourses/src/configure_course.php @@ -57,7 +57,7 @@ if ($editingCourse) { foreach ($teachers as $courseTeacher) { $teacher = $courseTeacher->getUser(); $teachersOptions[] = [ - 'text' => $teacher->getCompleteName(), + 'text' => UserManager::formatUserFullName($teacher), 'value' => $teacher->getId(), ]; @@ -105,7 +105,7 @@ if ($editingCourse) { $sessionItem = $plugin->getSessionForConfiguration($session, $currency); $generalCoach = $session->getGeneralCoach(); $generalCoachOption = [ - 'text' => $generalCoach->getCompleteName(), + 'text' => UserManager::formatUserFullName($generalCoach), 'value' => $generalCoach->getId(), ]; $defaultBeneficiaries = [ @@ -123,7 +123,7 @@ if ($editingCourse) { } $courseCoachesOptions[] = [ - 'text' => $courseCoach->getCompleteName(), + 'text' => UserManager::formatUserFullName($courseCoach), 'value' => $courseCoach->getId(), ]; $defaultBeneficiaries[] = $courseCoach->getId(); diff --git a/plugin/buycourses/src/service_process.php b/plugin/buycourses/src/service_process.php index f53fc6f9cc..93c5c4a65f 100644 --- a/plugin/buycourses/src/service_process.php +++ b/plugin/buycourses/src/service_process.php @@ -126,7 +126,7 @@ if ($typeUser) { /** @var User $user */ foreach ($users as $user) { if (intval($userInfo['user_id']) !== intval($user->getId())) { - $selectOptions[$user->getId()] = $user->getCompleteNameWithUsername(); + $selectOptions[$user->getId()] = UserManager::formatUserFullName($user, true); } } } diff --git a/plugin/buycourses/src/services_add.php b/plugin/buycourses/src/services_add.php index 7baa13465e..802f4ceeaa 100644 --- a/plugin/buycourses/src/services_add.php +++ b/plugin/buycourses/src/services_add.php @@ -17,7 +17,7 @@ $users = UserManager::getRepository()->findAll(); $userOptions = []; if (!empty($users)) { foreach ($users as $user) { - $userOptions[$user->getId()] = $user->getCompleteNameWithUsername(); + $userOptions[$user->getId()] = UserManager::formatUserFullName($user, true); } } diff --git a/plugin/buycourses/src/services_edit.php b/plugin/buycourses/src/services_edit.php index 00b08884fa..639044a9e2 100644 --- a/plugin/buycourses/src/services_edit.php +++ b/plugin/buycourses/src/services_edit.php @@ -23,7 +23,7 @@ $users = UserManager::getRepository()->findAll(); $userOptions = []; if (!empty($users)) { foreach ($users as $user) { - $userOptions[$user->getId()] = $user->getCompleteNameWithUsername(); + $userOptions[$user->getId()] = UserManager::formatUserFullName($user, true); } } diff --git a/plugin/ims_lti/form.php b/plugin/ims_lti/form.php index ef26dba534..0861f8c78e 100644 --- a/plugin/ims_lti/form.php +++ b/plugin/ims_lti/form.php @@ -45,7 +45,7 @@ $params = [ 'lis_person_name_given' => $user->getFirstname(), 'lis_person_name_family' => $user->getLastname(), - 'lis_person_name_full' => $user->getCompleteName(), + 'lis_person_name_full' => UserManager::formatUserFullName($user), 'lis_person_contact_email_primary' => $user->getEmail(), 'context_id' => $course->getId(), diff --git a/src/CoreBundle/Twig/Extension/ChamiloExtension.php b/src/CoreBundle/Twig/Extension/ChamiloExtension.php index 31111e16f7..686b321256 100644 --- a/src/CoreBundle/Twig/Extension/ChamiloExtension.php +++ b/src/CoreBundle/Twig/Extension/ChamiloExtension.php @@ -27,6 +27,7 @@ class ChamiloExtension extends \Twig_Extension new \Twig_SimpleFilter('format_date', 'Template::format_date'), new \Twig_SimpleFilter('date_to_time_ago', 'Display::dateToStringAgoAndLongDate'), new \Twig_SimpleFilter('api_get_configuration_value', 'api_get_configuration_value'), + new \Twig_SimpleFilter('format_user_full_name', 'UserManager::formatUserFullName'), ]; } diff --git a/src/UserBundle/Entity/User.php b/src/UserBundle/Entity/User.php index 2377f98464..c06f3950c5 100644 --- a/src/UserBundle/Entity/User.php +++ b/src/UserBundle/Entity/User.php @@ -489,7 +489,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement */ public function __toString() { - return $this->getCompleteName(); + return \UserManager::formatUserFullName(); } /** @@ -773,30 +773,6 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement });*/ } - /** - * Return Complete Name with the Username. - * - * @return string - */ - public function getCompleteNameWithUsername() - { - if (api_get_setting('platform.hide_username_with_complete_name') === 'true') { - return $this->getCompleteName(); - } - - return api_get_person_name($this->firstname, $this->lastname).' ('.$this->username.')'; - } - - /** - * @todo don't use api_get_person_name - * - * @return string - */ - public function getCompleteName() - { - return api_get_person_name($this->firstname, $this->lastname); - } - /** * Returns the list of classes for the user. * @@ -813,7 +789,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement } $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null; - return $this->getCompleteName().$classString; + return \UserManager::formatUserFullName($this).$classString; } /**