Get the user's list of emails.

@param string $userId
@param array  $options

@return \Google_Service_Gmail_ListMessagesResponse
355326
public function list(string $userId, array $options = []): \Google_Service_Gmail_ListMessagesResponse
    {
        return $this->googleServices->getGoogleServiceGmailForUserId($userId)->users_messages->listUsersMessages($userId, $options);
    }
395869
public function listAction($userId)
    {
        $userManager = $this->get('phlexible_user.user_manager');
        $systemUid = $userManager->getSystemUserId();

        $skipUserIds = [$userId];
        if (!in_array($systemUid, $skipUserIds)) {
            $skipUserIds[] = $systemUid;
        }

        $users = [];
        foreach ($userManager->findAll() as $user) {
            if (in_array($user->getId(), $skipUserIds)) {
                continue;
            }

            $users[$user->getDisplayName()] = [
                'uid' => $user->getId(),
                'name' => $user->getDisplayName(),
            ];
        }

        ksort($users);
        $users = array_values($users);

        return new JsonResponse($users);
    }
200004
public function GetCards($userId, & $pagination = null, $sorting = null)
    {
        return $this->GetList('users_allcards', $pagination, '\MangoPay\Card', $userId, null, $sorting);
    }
1200273
public function resolveEmailsFromUserId(string $userId, int $mode)
    {
        $gmailUser = $this->getGmailDomain()->findGmailUserById($userId);

        if (!($gmailUser instanceof GmailUserInterface)) {
            return [];
        }

        switch ($mode) {
            case self::MODE_RESOLVE_PRIMARY_ONLY:
                return [$gmailUser->getPrimaryEmailAddress()];

            case self::MODE_RESOLVE_ALIASES_ONLY:
                return $gmailUser->getEmailAliases();

            case self::MODE_RESOLVE_PRIMARY_PLUS_ALIASES:
                return $gmailUser->getAllEmailAddresses();

            default:
                throw new \InvalidArgumentException();
        }
    }
278864
public function getList(array $options)
    {
        $sql = 'SELECT ol.*, u.name AS user_name, u.email AS user_email, u.status AS user_status';

        if (!empty($options['count'])) {
            $sql = 'SELECT COUNT(ol.order_log_id)';
        }

        $sql .= ' FROM order_log ol
                  LEFT JOIN user u ON(ol.user_id=u.user_id)
                  WHERE ol.order_id=?';

        if (!empty($options['count'])) {
            return (int) $this->db->fetchColumn($sql, array($options['order_id']));
        }

        $sql .= ' ORDER BY ol.created DESC';

        if (!empty($options['limit'])) {
            $sql .= ' LIMIT ' . implode(',', array_map('intval', $options['limit']));
        }

        $fetch_options = array('unserialize' => 'data', 'index' => 'order_log_id');
        $list = $this->db->fetchAll($sql, array($options['order_id']), $fetch_options);
        $this->hook->attach('order.log.list', $list, $this);
        return (array) $list;
    }
236668
public static function legacy_messages_exist($userid) {
        global $DB;

        $sql = "SELECT id
                  FROM {message} m
                 WHERE useridfrom = ?
                    OR useridto = ?";
        $messageexists = $DB->record_exists_sql($sql, [$userid, $userid]);

        $sql = "SELECT id
                  FROM {message_read} m
                 WHERE useridfrom = ?
                    OR useridto = ?";
        $messagereadexists = $DB->record_exists_sql($sql, [$userid, $userid]);

        return $messageexists || $messagereadexists;
    }
115139
public function getGroupUsers($groupId, $options=array()){

        $data = array();
        
        $data['group_id'] = $groupId;

        $data = array_merge($data, $options);

        return $this->request($this->groupGetusersUrl, $data);
    }
1127564
public function getGoogleServiceGmailForUserId(string $userId)
    {
        $email = $this->directory->resolvePrimaryEmailFromUserId($userId);
        if (array_key_exists($email, $this->googleServiceGmails)) {
            return $this->googleServiceGmails[$email];
        }

        $googleServiceGmail = new \Google_Service_Gmail($this->serviceAccount->getGoogleClientForEmail($email));
        $this->googleServiceGmails[$email] = $googleServiceGmail;

        return $googleServiceGmail;
    }
1173892
public function listCounters($userId, $optParams = array()) {
      $params = array('userId' => $userId);
      $params = array_merge($params, $optParams);
      $data = $this->__call('list', array($params));
      if ($this->useObjects()) {
        return new Google_Counters($data);
      } else {
        return $data;
      }
    }
302606
public function scrollUsers($scrollId, array $options = [])
    {
        $options['httpParams'] = [':scrollId' => $scrollId];

        $data = [];

        if (!$scrollId) {
            throw new InvalidArgumentException('Security.scrollUsers: scrollId is required');
        }

        if (isset($options['scroll'])) {
            $data['scroll'] = $options['scroll'];
        }

        $response = $this->kuzzle->query(
            $this->kuzzle->buildQueryArgs('security', 'scrollUsers'),
            $data,
            $options
        );

        $response['result']['hits'] = array_map(function ($document) {
            return new User($this, $document['_id'], $document['_source'], $document['_meta']);
        }, $response['result']['hits']);

        return new UsersSearchResult(
            $response['result']['total'],
            $response['result']['hits'],
            $scrollId
        );
    }
23514
public static function get_contexts_for_userid(int $userid) : contextlist {
        global $DB;

        $contextlist = new contextlist();

        // Messages are in the user context.
        // For the sake of performance, there is no need to call add_from_sql for each of the below cases.
        // It is enough to add the user's context as soon as we come to the conclusion that the user has some data.
        // Also, the order of checking is sorted by the probability of occurrence (just by guess).
        // There is no need to check the message_user_actions table, as there needs to be a message in order to be a message action.
        // There is no need to check the message_conversation_actions table, as there needs to be a conversation in order to
        // be a conversation action.
        // So, checking messages table would suffice.

        $hasdata = false;
        $hasdata = $hasdata || $DB->record_exists_select('notifications', 'useridfrom = ? OR useridto = ?', [$userid, $userid]);
        $sql = "SELECT mc.id
              FROM {message_conversations} mc
              JOIN {message_conversation_members} mcm
                ON (mcm.conversationid = mc.id AND mcm.userid = :userid)
             WHERE mc.contextid IS NULL";
        $hasdata = $hasdata || $DB->record_exists_sql($sql, ['userid' => $userid]);
        $sql = "SELECT mc.id
              FROM {message_conversations} mc
              JOIN {messages} m
                ON (m.conversationid = mc.id AND m.useridfrom = :useridfrom)
             WHERE mc.contextid IS NULL";
        $hasdata = $hasdata || $DB->record_exists_sql($sql, ['useridfrom' => $userid]);
        $hasdata = $hasdata || $DB->record_exists_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid]);
        $hasdata = $hasdata || $DB->record_exists_select('message_users_blocked', 'userid = ? OR blockeduserid = ?',
                [$userid, $userid]);
        $hasdata = $hasdata || $DB->record_exists_select('message_contact_requests', 'userid = ? OR requesteduserid = ?',
                [$userid, $userid]);

        if ($hasdata) {
            $contextlist->add_user_context($userid);
        }

        // Add favourite conversations.
        \core_favourites\privacy\provider::add_contexts_for_userid($contextlist, $userid, 'core_message', 'message_conversations');

        return $contextlist;
    }
114196
public static function search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) {
        global $DB;

        // Get the user fields we want.
        $ufields = \user_picture::fields('u', array('lastaccess'), 'userfrom_id', 'userfrom_');
        $ufields2 = \user_picture::fields('u2', array('lastaccess'), 'userto_id', 'userto_');
        // Add the uniqueid column to make each row unique and avoid SQL errors.
        $uniqueidsql = $DB->sql_concat('m.id', "'_'", 'm.useridfrom', "'_'", 'mcm.userid');

        $sql = "SELECT $uniqueidsql AS uniqueid, m.id, m.useridfrom, mcm.userid as useridto, m.subject, m.fullmessage,
                       m.fullmessagehtml, m.fullmessageformat, m.smallmessage, m.conversationid, m.timecreated, 0 as isread,
                       $ufields, mub.id as userfrom_blocked, $ufields2, mub2.id as userto_blocked
                  FROM {messages} m
            INNER JOIN {user} u
                    ON u.id = m.useridfrom
            INNER JOIN {message_conversations} mc
                    ON mc.id = m.conversationid
            INNER JOIN {message_conversation_members} mcm
                    ON mcm.conversationid = m.conversationid
            INNER JOIN {user} u2
                    ON u2.id = mcm.userid
             LEFT JOIN {message_users_blocked} mub
                    ON (mub.blockeduserid = u.id AND mub.userid = ?)
             LEFT JOIN {message_users_blocked} mub2
                    ON (mub2.blockeduserid = u2.id AND mub2.userid = ?)
             LEFT JOIN {message_user_actions} mua
                    ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                 WHERE (m.useridfrom = ? OR mcm.userid = ?)
                   AND (m.useridfrom != mcm.userid OR mc.type = ?)
                   AND u.deleted = 0
                   AND u2.deleted = 0
                   AND mua.id is NULL
                   AND " . $DB->sql_like('smallmessage', '?', false) . "
              ORDER BY timecreated DESC";

        $params = array($userid, $userid, $userid, self::MESSAGE_ACTION_DELETED, $userid, $userid,
            self::MESSAGE_CONVERSATION_TYPE_SELF, '%' . $search . '%');

        // Convert the messages into searchable contacts with their last message being the message that was searched.
        $conversations = array();
        if ($messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) {
            foreach ($messages as $message) {
                $prefix = 'userfrom_';
                if ($userid == $message->useridfrom) {
                    $prefix = 'userto_';
                    // If it from the user, then mark it as read, even if it wasn't by the receiver.
                    $message->isread = true;
                }
                $blockedcol = $prefix . 'blocked';
                $message->blocked = $message->$blockedcol ? 1 : 0;

                $message->messageid = $message->id;
                // To avoid duplicate messages, only add the message if it hasn't been added previously.
                if (!array_key_exists($message->messageid, $conversations)) {
                    $conversations[$message->messageid] = helper::create_contact($message, $prefix);
                }
            }
            // Remove the messageid keys (to preserve the expected type).
            $conversations = array_values($conversations);
        }

        return $conversations;
    }
46235
public function listLog ( $options, $user_id )
    {
        $where = array();
        $args  = array();
        if (empty($options))
        {
            $where[] = 'olg_usa_id_ref = \'%d\'';
            $args[]  = $user_id;
        }
        else
        {
            foreach ($options as $option => $value)
            {
                if (strlen($value) > 0)
                {
                    switch ($option)
                    {
                    case 'osr_consumer_key':
                    case 'ocr_consumer_key':
                    case 'ost_token':
                    case 'oct_token':
                        $where[] = 'olg_'.$option.' = \'%s\'';
                        $args[]  = $value;
                        break;
                    }
                }
            }

            $where[] = '(olg_usa_id_ref IS NULL OR olg_usa_id_ref = \'%d\')';
            $args[]  = $user_id;
        }

        $rs = $this->query_all_assoc('
                    SELECT olg_id,
                            olg_osr_consumer_key     AS osr_consumer_key,
                            olg_ost_token            AS ost_token,
                            olg_ocr_consumer_key    AS ocr_consumer_key,
                            olg_oct_token            AS oct_token,
                            olg_usa_id_ref            AS user_id,
                            olg_received            AS received,
                            olg_sent                AS sent,
                            olg_base_string            AS base_string,
                            olg_notes                AS notes,
                            olg_timestamp            AS timestamp,
                            olg_remote_ip           AS remote_ip
                    FROM oauth_log
                    WHERE '.implode(' AND ', $where).'
                    ORDER BY olg_id DESC
                    LIMIT 0,100', $args);

        return $rs;
    }
181552
public static function get_children_of_user($userid) {
        global $DB;

        // Get users that the user has role assignments to.
        $allusernames = get_all_user_name_fields(true, 'u');
        $sql = "SELECT u.id, $allusernames
                  FROM {role_assignments} ra, {context} c, {user} u
                 WHERE ra.userid = :userid
                       AND ra.contextid = c.id
                       AND c.instanceid = u.id
                       AND c.contextlevel = :contextlevel";
        $params = [
            'userid' => $userid,
            'contextlevel' => CONTEXT_USER
        ];

        // The final list of users that we will return.
        $finalresults = [];

        // Our prospective list of users.
        if ($candidates = $DB->get_records_sql($sql, $params)) {
            foreach ($candidates as $key => $child) {
                $childcontext = \context_user::instance($child->id);
                if (has_capability('tool/dataprivacy:makedatarequestsforchildren', $childcontext, $userid)) {
                    $finalresults[$key] = $child;
                }
            }
        }
        return $finalresults;
    }
990270
public function getImap($userId, $optParams = array())
  {
    $params = array('userId' => $userId);
    $params = array_merge($params, $optParams);
    return $this->call('getImap', array($params), "Google_Service_Gmail_ImapSettings");
  }
714988
public static function create($userId, $params = null, $options = null)
    {
        return self::_userBasedCreate($userId, $params, $options);
    }
1362078
public static function get_providers_preferences($providers, $userid) {
        $preferences = new \stdClass();

        // Get providers preferences.
        foreach ($providers as $provider) {
            foreach (array('loggedin', 'loggedoff') as $state) {
                $linepref = get_user_preferences('message_provider_' . $provider->component . '_' . $provider->name
                    . '_' . $state, '', $userid);
                if ($linepref == '') {
                    continue;
                }
                $lineprefarray = explode(',', $linepref);
                $preferences->{$provider->component.'_'.$provider->name.'_'.$state} = array();
                foreach ($lineprefarray as $pref) {
                    $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$pref] = 1;
                }
            }
        }

        return $preferences;
    }