Specify recipients.
@param string|array $users the guid of recipient if string, or guid array
of recipients if array.
@return static $this
776782
public function recipients($users = [])
    {
        if (empty($users)) {
            return $this;
        }
        $model = $this->noInitModel;
        return $this->andWhere([$model->otherGuidAttribute => BaseMongoEntityModel::compositeGUIDs($users)]);
    }
1212180
public function setSmsRecipients($recipients)
    {
        $this->params['sms_recipients'] =
          is_array($recipients) ? implode(',', $recipients) : $recipients;
        return $this;
    }
1013412
public function removeUsers($users)
    {
        if (is_array($users)) {
            foreach ($users as $id) {
                $this->users()->detach($id);
            }

            return $this;
        }

        $this->users()->detach($users);

        return $this;
    }
376545
public function setHeaders(array $headers)
    {
        foreach ($headers as $key => $value) {
            $this->headers[$key] = $value;
        }

        return $this;
    }
1291631
protected function setHeaders(array $headers)
    {
        foreach ($headers as $header) {

            if (isset($header['name']) && isset($header['value'])) {
                $this->headers[$header['name']] = $header['value'];
            }
        }

        return $this;
    }
284823
public function setActiveUsers(\WobbleCode\UserBundle\Document\User $activeUsers)
    {
        $this->activeUsers = $activeUsers;
        return $this;
    }
862431
protected function setUserPassword(array & $users)
    {
        if (!empty($users)) {
            if (Arr::isAssoc($users)) {
                $users = [$users];
            }

            foreach ($users as $i => $user) {
                /** @noinspection PhpUndefinedMethodInspection */
                $model = User::find($user['id']);
                if (!empty($model)) {
                    $users[$i]['password'] = $model->password;
                }
            }
        }
    }
1365124
public function grant($rid, $user = [])
    {
        $params = ['rid' => $rid];

        if (!empty($user['uid'])) {
            $params['uid'] = $user['uid'];
        }

        if (!empty($user['emails'])) {
            $params['emails'] = $user['emails'];
        }

        return $this->client->call('/publisher/user/access/grant', $params);
    }
658691
public function setCc(array $addresses): Email
    {
        $addresses = $this->transformAddressesToArray($addresses);
        $this->message->setCc($addresses);

        return $this;
    }
749437
public function to($users)
    {
        $this->to = $users;

        if (! $this->locale && $users instanceof HasLocalePreference) {
            $this->locale($users->preferredLocale());
        }

        return $this;
    }
1160088
public function addUsers(User ...$users)
    {
        foreach ($users as $user) {
            $this->getUsers()->add($user);
        }

        return $this;
    }
377596
public function setUser(string $user)
    {
        $this->user = $user;

        $this->raw = array_merge($this->raw, ['User' => $user]);

        return $this;
    }
327655
public static function update_users($users) {
        global $CFG, $DB, $USER;
        require_once($CFG->dirroot."/user/lib.php");
        require_once($CFG->dirroot."/user/profile/lib.php"); // Required for customfields related function.
        require_once($CFG->dirroot.'/user/editlib.php');

        // Ensure the current user is allowed to run this function.
        $context = context_system::instance();
        require_capability('moodle/user:update', $context);
        self::validate_context($context);

        $params = self::validate_parameters(self::update_users_parameters(), array('users' => $users));

        $filemanageroptions = array('maxbytes' => $CFG->maxbytes,
                'subdirs'        => 0,
                'maxfiles'       => 1,
                'accepted_types' => 'web_image');

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['users'] as $user) {
            // First check the user exists.
            if (!$existinguser = core_user::get_user($user['id'])) {
                continue;
            }
            // Check if we are trying to update an admin.
            if ($existinguser->id != $USER->id and is_siteadmin($existinguser) and !is_siteadmin($USER)) {
                continue;
            }
            // Other checks (deleted, remote or guest users).
            if ($existinguser->deleted or is_mnet_remote_user($existinguser) or isguestuser($existinguser->id)) {
                continue;
            }
            // Check duplicated emails.
            if (isset($user['email']) && $user['email'] !== $existinguser->email) {
                if (!validate_email($user['email'])) {
                    continue;
                } else if (empty($CFG->allowaccountssameemail)) {
                    // Make a case-insensitive query for the given email address and make sure to exclude the user being updated.
                    $select = $DB->sql_equal('email', ':email', false) . ' AND mnethostid = :mnethostid AND id <> :userid';
                    $params = array(
                        'email' => $user['email'],
                        'mnethostid' => $CFG->mnet_localhost_id,
                        'userid' => $user['id']
                    );
                    // Skip if there are other user(s) that already have the same email.
                    if ($DB->record_exists_select('user', $select, $params)) {
                        continue;
                    }
                }
            }

            user_update_user($user, true, false);

            $userobject = (object)$user;

            // Update user picture if it was specified for this user.
            if (empty($CFG->disableuserimages) && isset($user['userpicture'])) {
                $userobject->deletepicture = null;

                if ($user['userpicture'] == 0) {
                    $userobject->deletepicture = true;
                } else {
                    $userobject->imagefile = $user['userpicture'];
                }

                core_user::update_picture($userobject, $filemanageroptions);
            }

            // Update user interests.
            if (!empty($user['interests'])) {
                $trimmedinterests = array_map('trim', explode(',', $user['interests']));
                $interests = array_filter($trimmedinterests, function($value) {
                    return !empty($value);
                });
                useredit_update_interests($userobject, $interests);
            }

            // Update user custom fields.
            if (!empty($user['customfields'])) {

                foreach ($user['customfields'] as $customfield) {
                    // Profile_save_data() saves profile file it's expecting a user with the correct id,
                    // and custom field to be named profile_field_"shortname".
                    $user["profile_field_".$customfield['type']] = $customfield['value'];
                }
                profile_save_data((object) $user);
            }

            // Trigger event.
            \core\event\user_updated::create_from_userid($user['id'])->trigger();

            // Preferences.
            if (!empty($user['preferences'])) {
                $userpref = clone($existinguser);
                foreach ($user['preferences'] as $preference) {
                    $userpref->{'preference_'.$preference['type']} = $preference['value'];
                }
                useredit_update_user_preference($userpref);
            }
            if (isset($user['suspended']) and $user['suspended']) {
                \core\session\manager::kill_user_sessions($user['id']);
            }
        }

        $transaction->allow_commit();

        return null;
    }
1020934
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];
        $referral = Referral::create($payload['referral']);

        return new static($senderId, $recipientId, $timestamp, $referral);
    }
158221
public function setUserFields(array $fields) {
        $clean = array();

        foreach ($fields as $base => $field) {
            if (is_numeric($base)) {
                $base = $field;
            }

            $clean[$base] = $field;
        }

        $this->userFields = $clean;

        return $this;
    }
1184579
protected function unassignUserFromUserGroups(User $user, array $userGroups)
    {
        $existingUserGroups = $this->userService->loadUserGroupsOfUser($user);
        foreach ($existingUserGroups as $existingUserGroup) {
            if (!array_key_exists($existingUserGroup->id, $userGroups)) {
                $this->userService->unAssignUserFromUserGroup($user, $existingUserGroup);
            }
        }
    }
822433
public function setReadReceiptTo($addresses)
    {
        if (!$this->setHeaderFieldModel('Disposition-Notification-To', $addresses)) {
            $this->getHeaders()
                ->addMailboxHeader('Disposition-Notification-To', $addresses);
        }

        return $this;
    }