Handles adding a contact.

@param int $userid The id of the user who requested to be a contact
@param int $contactid The id of the contact
357
public static function add_contact(int $userid, int $contactid) {
        global $DB;

        $messagecontact = new \stdClass();
        $messagecontact->userid = $userid;
        $messagecontact->contactid = $contactid;
        $messagecontact->timecreated = time();
        $messagecontact->id = $DB->insert_record('message_contacts', $messagecontact);

        $eventparams = [
            'objectid' => $messagecontact->id,
            'userid' => $userid,
            'relateduserid' => $contactid,
            'context' => \context_user::instance($userid)
        ];
        $event = \core\event\message_contact_added::create($eventparams);
        $event->add_record_snapshot('message_contacts', $messagecontact);
        $event->trigger();
    }
863115
public function create($data, $contactId = null)
    {
        if (isset($contactId)) {
            return $this->client()->put($data, 'contacts/{contactId}', ['contactId' => $contactId]);
        }

        return $this->client()->post($data, 'contacts');
    }
1336005
public function setPreferencesForContact($contactId, $preferences)
    {
        $url = $this->getApiEndpoint() . "/v2/contact/" . $contactId . "/preferences";
        $this->setUrl($url)
            ->setVerb('PUT')
            ->buildPostBody($preferences);

        $response = $this->execute();

        if (isset($response->message)) {
            $this->helper->log('SET PREFERENCES FOR CONTACT: ' . $response->message);
        }

        return $response;
    }
850147
public function addContact(Contact $contact): Contact
    {
        @trigger_error(sprintf('The %s() method is deprecated since version 0.8. Use create() instead.', __METHOD__), E_USER_DEPRECATED);

        return $this->create($contact);
    }
1356962
public function loadByCustomerId($customerId)
    {
        $contact = $this->getCollection()
            ->loadByCustomerId($customerId);

        if ($contact) {
            return $contact;
        }

        return $this;
    }
1343810
public function removeByUserId($userId): void
    {
        $results = $this->findBy(['userId' => $userId]);

        foreach ($results as $result) {
            $this->getEntityManager()->remove($result);
        }

        $this->getEntityManager()->flush();
    }
70503
public function UpdateUser($UserID) {
      // Retrieve a draft count
      $CountDrafts = $this->GetCount($UserID);
      
      // Update CountDrafts column of user table fot this user
      Gdn::UserModel()->SetField($UserID, 'CountDrafts', $CountDrafts);
   }
929441
public static function create_from_userid($userid) {
        $data = array(
            'objectid' => $userid,
            'relateduserid' => $userid,
            'context' => \context_user::instance($userid)
        );

        // Create user_updated event.
        $event = self::create($data);
        return $event;
    }
60404
public function createUser($accountID, $contactID, $username, $password)
    {
        try
        {
            return $this->httpHelper->patch("accounts/" . intval($accountID) . "/contacts/" . intval($contactID),[
                'username' => $username,
                'password' => $password
            ]);
        }
        catch (ApiException $e)
        {
            throw new InvalidArgumentException($e->getMessage());
        }
    }
1060505
protected function add_userids(array $userids) : userlist_base {
        $this->set_userids(array_merge($this->get_userids(), $userids));

        return $this;
    }
694361
public static function get_user_contacts(int $userid, int $limitfrom = 0, int $limitnum = 0) {
        global $CFG, $USER;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $systemcontext = context_system::instance();

        $params = array(
            'userid' => $userid,
            'limitfrom' => $limitfrom,
            'limitnum' => $limitnum
        );
        $params = self::validate_parameters(self::get_user_contacts_parameters(), $params);
        self::validate_context($systemcontext);

        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
            throw new moodle_exception('You do not have permission to perform this action.');
        }

        return \core_message\api::get_user_contacts($params['userid'], $params['limitfrom'], $params['limitnum']);
    }
636432
protected function attachPermissionToUser($permission, $userId)
    {
        // Check if user exists
        if ($user = $this->userRepository->findById($userId)) {
            $user->attachPermission($permission);
            $this->info('Permission attached successfully to user');
        } else {
            $this->error('Not possible to attach permission. User not found');
        }
    }
677197
protected static function delete_user_data(int $userid) {
        global $DB;

        // Delete individual conversations information for this user.
        self::delete_user_data_conversations($userid, [], '', '');

        // Delete contacts, requests, users blocked and notifications.
        $DB->delete_records_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid]);
        $DB->delete_records_select('message_contact_requests', 'userid = ? OR requesteduserid = ?', [$userid, $userid]);
        $DB->delete_records_select('message_users_blocked', 'userid = ? OR blockeduserid = ?', [$userid, $userid]);
        $DB->delete_records_select('notifications', 'useridfrom = ? OR useridto = ?', [$userid, $userid]);
    }
851280
public function updateContactPoint(ContactPoint $contactPoint)
    {
        if (is_null($this->contactPoint) || !$this->contactPoint->sameAs($contactPoint)) {
            $this->apply(
                $this->createContactPointUpdatedEvent($contactPoint)
            );
        }
    }
978474
public function addContact($databaseID, $updateIfFound, $columns, $contactListID = false, $sendAutoReply = false, $allowHTML = false, $createdFrom = 1, $visitorKey = '', $syncFields = []) {
        $data["Envelope"] = array(
            "Body" => array(
                "AddRecipient" => array(
                    "LIST_ID" => $databaseID,
                    "CREATED_FROM" => $createdFrom,
                    "SEND_AUTOREPLY"  => ($sendAutoReply ? 'true' : 'false'),
                    "UPDATE_IF_FOUND" => ($updateIfFound ? 'true' : 'false'),
                    "ALLOW_HTML" => ($allowHTML ? 'true' : 'false'),
                    "VISITOR_KEY" => $visitorKey,
                    "CONTACT_LISTS" => ($contactListID) ? array("CONTACT_LIST_ID" => $contactListID) : '',
                    "COLUMN" => array(),
                ),
            ),
        );
        foreach ($columns as $name => $value) {
            $data["Envelope"]["Body"]["AddRecipient"]["COLUMN"][] = array("NAME" => $name, "VALUE" => $value);
        }
        foreach ($syncFields as $name => $value) {
            $data["Envelope"]["Body"]["AddRecipient"]["SYNC_FIELDS"]["SYNC_FIELD"][] = array("NAME" => $name, "VALUE" => $value);
        }
        $response = $this->_request($data);
        $result = $response["Envelope"]["Body"]["RESULT"];
        if ($this->_isSuccess($result)) {
            if (isset($result['RecipientId']))
                return $result['RecipientId'];
            else {
                throw new \Exception('Recipient added but no recipient ID was returned from the server.');
            }
        } else {
            throw new \Exception("AddRecipient Error: ".$this->_getErrorFromResponse($response));
        }
    }
1172746
public void addActiveParticipant(String userId)
	{
		addActiveParticipant(
				userId, 
				null, 
				null, 
				false, 
				null, 
				null);
	}
66978
def _link_user(self, userid):
        
        # check if we have a selected user from the search-list
        if userid:
            try:
                self.context.setUser(userid)
                self.add_status_message(
                    _("User linked to this Contact"), "info")
            except ValueError, e:
                self.add_status_message(e, "error")
        else:
            self.add_status_message(
                _("Please select a User from the list"), "info")