Browse Source

Don't show inactive users, add username see BT#13417

jmontoyaa 7 years ago
parent
commit
dfefc69b5f

+ 2 - 3
main/inc/ajax/message.ajax.php

@@ -77,8 +77,7 @@ switch ($action) {
         }
 
         /** @var UserRepository $repo */
-        $repo = Database::getManager()
-            ->getRepository('ChamiloUserBundle:User');
+        $repo = Database::getManager()->getRepository('ChamiloUserBundle:User');
 
         $users = $repo->findUsersToSendMessage(
             api_get_user_id(),
@@ -91,7 +90,7 @@ switch ($action) {
 
         /** @var User $user */
         foreach ($users as $user) {
-            $userName = $user->getCompleteName();
+            $userName = $user->getCompleteNameWithUsername();
 
             if ($showEmail) {
                 $userName .= " ({$user->getEmail()})";

+ 24 - 11
src/Chamilo/UserBundle/Entity/Repository/UserRepository.php

@@ -233,7 +233,7 @@ class UserRepository extends EntityRepository
     }
 
     /**
-     * Find potencial users to send a message
+     * Find potential users to send a message
      * @param int $currentUserId The current user ID
      * @param string $search The search text to filter the user list
      * @param int $limit Optional. Sets the maximum number of results to retrieve
@@ -241,23 +241,30 @@ class UserRepository extends EntityRepository
      */
     public function findUsersToSendMessage($currentUserId, $search, $limit = 10)
     {
+        $allowSendMessageToAllUsers = api_get_setting('allow_send_message_to_all_platform_users');
         $accessUrlId = api_get_multiple_access_url() ? api_get_current_access_url_id() : 1;
 
-        if (api_get_setting('allow_social_tool') === 'true' && api_get_setting('allow_message_tool') === 'true') {
+        if (api_get_setting('allow_social_tool') === 'true' &&
+            api_get_setting('allow_message_tool') === 'true'
+        ) {
             // All users
-            if (api_get_setting('allow_send_message_to_all_platform_users') === 'true' || api_is_platform_admin()) {
+            if ($allowSendMessageToAllUsers === 'true' || api_is_platform_admin()) {
                 $dql = "SELECT DISTINCT U
                         FROM ChamiloUserBundle:User U
-                        LEFT JOIN ChamiloCoreBundle:AccessUrlRelUser R WITH U = R.user
+                        LEFT JOIN ChamiloCoreBundle:AccessUrlRelUser R
+                        WITH U = R.user
                         WHERE
+                            U.active = 1 AND
                             U.status != 6  AND
                             U.id != $currentUserId AND
                             R.portal = $accessUrlId";
             } else {
                 $dql = "SELECT DISTINCT U
                         FROM ChamiloCoreBundle:AccessUrlRelUser R, ChamiloCoreBundle:UserRelUser UF
-                        INNER JOIN ChamiloUserBundle:User AS U WITH UF.friendUserId = U
+                        INNER JOIN ChamiloUserBundle:User AS U 
+                        WITH UF.friendUserId = U
                         WHERE
+                            U.active = 1 AND
                             U.status != 6 AND
                             UF.relationType NOT IN(" . USER_RELATION_TYPE_DELETED.", ".USER_RELATION_TYPE_RRHH.") AND
                             UF.userId = $currentUserId AND
@@ -266,13 +273,16 @@ class UserRepository extends EntityRepository
                             R.portal = $accessUrlId";
             }
         } elseif (
-            api_get_setting('allow_social_tool') === 'false' && api_get_setting('allow_message_tool') === 'true'
+            api_get_setting('allow_social_tool') === 'false' &&
+            api_get_setting('allow_message_tool') === 'true'
         ) {
-            if (api_get_setting('allow_send_message_to_all_platform_users') === 'true') {
+            if ($allowSendMessageToAllUsers === 'true') {
                 $dql = "SELECT DISTINCT U
                         FROM ChamiloUserBundle:User U
-                        LEFT JOIN ChamiloCoreBundle:AccessUrlRelUser R WITH U = R.user
+                        LEFT JOIN ChamiloCoreBundle:AccessUrlRelUser R 
+                        WITH U = R.user
                         WHERE
+                            U.active = 1 AND
                             U.status != 6  AND
                             U.id != $currentUserId AND
                             R.portal = $accessUrlId";
@@ -282,12 +292,15 @@ class UserRepository extends EntityRepository
                 $limit_date = api_get_utc_datetime($online_time);
                 $dql = "SELECT DISTINCT U
                         FROM ChamiloUserBundle:User U
-                        INNER JOIN ChamiloCoreBundle:TrackEOnline T WITH U.id = T.loginUserId
-                        WHERE T.loginDate >= '" . $limit_date."'";
+                        INNER JOIN ChamiloCoreBundle:TrackEOnline T 
+                        WITH U.id = T.loginUserId
+                        WHERE 
+                          U.active = 1 AND 
+                          T.loginDate >= '" . $limit_date."'";
             }
         }
 
-        $dql .= ' AND (U.firstname LIKE :search OR U.lastname LIKE :search OR U.email LIKE :search)';
+        $dql .= ' AND (U.firstname LIKE :search OR U.lastname LIKE :search OR U.email LIKE :search OR U.username LIKE :search)';
 
         return $this->getEntityManager()
             ->createQuery($dql)