/** * Removes a contact from the system. * @param {array} $_REQUEST * @param {string} $_REQUEST.label The label of the contact * @param {string} $_REQUEST.contactUserId The contactUserId of the contact * @param {string} [$_REQUEST.userId=Users::loggedInUser(true)->id] You can override the user id, if another plugin adds a hook that allows you to do this */ function Users_contact_delete($params = array()) { $req = array_merge($_REQUEST, $params); Q_Request::requireFields(array('label', 'contactUserId'), $req, true); $loggedInUserId = Users::loggedInUser(true)->id; $userId = Q::ifset($req, 'userId', $loggedInUserId); $label = $req['label']; $contactUserId = $req['contactUserId']; Users::canManageContacts($loggedInUserId, $userId, $label, true); $contact = new Users_Contact(); $contact->userId = $userId; $contact->label = $label; $contact->contactUserId = $contactUserId; return $contact->remove(); }
/** * Remove contact from label * @method removeContact * @static * @param {string} $userId * @param {string} $label * @param {string} $contactId * @return {boolean} */ static function removeContact($userId, $label, $contactId) { foreach (array('userId', 'label', 'contactUserId') as $field) { if (empty(${$field})) { throw new Q_Exception_RequiredField(compact('field')); } } $contact = new Users_Contact(); $contact->userId = $userId; $contact->label = $label; $contact->contactUserId = $contactId; return !!$contact->remove(); }
/** * Remove contact from label * @method removeContact * @static * @param {string} $userId * @param {string} $label * @param {string} $contactId * @param {string} [$asUserId=null] The user to do this operation as. * Defaults to the logged-in user. Pass false to skip access checks. * @throws {Users_Exception_NotAuthorized} * @return {Db_Query_Mysql} */ static function removeContact($userId, $label, $contactId, $asUserId = null) { foreach (array('userId', 'label', 'contactUserId') as $field) { if (empty(${$field})) { throw new Q_Exception_RequiredField(compact($field)); } } Users::canManageContacts($asUserId, $userId, $label, $contactId, true); $contact = new Users_Contact(); $contact->userId = $userId; $contact->label = $label; $contact->contactUserId = $contactId; return $contact->remove(); }