tp TouchPointWP Person - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\Person

The Person class connects a WordPress User with a TouchPoint Person.


Constants

Constant Visibility Type Value
SHORTCODE_PEOPLE_LIST public \tp\TouchPointWP\TouchPointWP::SHORTCODE_PREFIX . "People"
CRON_HOOK public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "person_cron_hook"
BACKUP_USER_PREFIX public "touchpoint-"
META_PEOPLEID public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . 'peopleId'
META_FAMILYID public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . 'familyId'
META_GENDERID public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . 'genderId'
META_CUSTOM_PREFIX public 'c_'
META_INV_MEMBER_PREFIX public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "inv_mem_"
META_INV_ATTEND_PREFIX public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "inv_att_"
META_INV_DESC_PREFIX public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "inv_desc_"
META_PEOPLE_EV_PREFIX public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "pev_"

Properties

peopleId

public int $peopleId

familyId

public int $familyId

Methods

fromQueryResult

public static fromQueryResult(mixed $queryResult): \tp\TouchPointWP\Person|\tp\TouchPointWP\TouchPointWP_Exception
  • This method is static. Parameters:
Parameter Type Description
$queryResult mixed

Return Value:

If a WP User ID is not provided, this exception is returned.


fromId

Get a person from a WordPress User ID

public static fromId(mixed $id): \tp\TouchPointWP\Person|null
  • This method is static. Parameters:
Parameter Type Description
$id mixed int|array|object The WordPress user ID, or an object/array with an ID property representing that ID.

fromPeopleId

Get a person from a TouchPoint PeopleID

public static fromPeopleId(int $pid): \tp\TouchPointWP\Person|null
  • This method is static. Parameters:
Parameter Type Description
$pid int

from

public static from(mixed $field, mixed $value): \tp\TouchPointWP\Person|null
  • This method is static. Parameters:
Parameter Type Description
$field mixed
$value mixed

__get

Generic getter for fields and meta attributes.

public __get(string $key): int|mixed

Parameters:

Parameter Type Description
$key string

__set

Generic setter. Does not get submitted to the database until

public __set(string $key, mixed $value): mixed

Parameters:

Parameter Type Description
$key string
$value mixed

peopleListShortcode

Display a collection of People, such as a list of leaders

public static peopleListShortcode(array|string $params = [], string $content = ""): string
  • This method is static. Parameters:
Parameter Type Description
$params array|string
$content string

getInvolvementMemberships

Gets Involvement Memberships. If an involvement ID is provided, the matching membership is provided or null if no membership exists.

public getInvolvementMemberships(?int $iid = null): \tp\TouchPointWP\InvolvementMembership[]|\tp\TouchPointWP\InvolvementMembership

Parameters:

Parameter Type Description
$iid ?int

getPictureUrl

public getPictureUrl(array $args = []): string|null

Parameters:

Parameter Type Description
$args array

getPictureForPerson

public static getPictureForPerson(mixed $idEmailUserOrPerson, ?array $args = []): string|null
  • This method is static. Parameters:
Parameter Type Description
$idEmailUserOrPerson mixed
$args ?array

pictureFilter

public static pictureFilter(string|mixed $url, mixed $idEmailOrObject, array|mixed $args = []): ?string
  • This method is static. Parameters:
Parameter Type Description
$url string|mixed The URL of the avatar. Type is not guaranteed.
$idEmailOrObject mixed The person for whom to retrieve. Accepts a user_id, gravatar md5 hash, user
email, WP_User object, WP_Post object, or WP_Comment object.
$args array|mixed Arguments passed to get_avatar_data(…), after processing. Type is not guaranteed.

userContactMethods

Controls the list of Contact Methods visible on the wp-admin/user-edit view. Allows admins to add/edit TouchPoint People IDs. Array is keyed on the Meta name.

public static userContactMethods(mixed $methods): string[]
  • This method is static. Parameters:
Parameter Type Description
$methods mixed string[] Methods available before this filter.

Return Value:

Methods available after this filter.


updateCron

Run the updating cron task. Fail quietly to not disturb the visitor experience if using WP default cron handling.

public static updateCron(): void
  • This method is static.

updatePersonFromApiData

Update a single person's information on WordPress, and WP User ID TouchPoint.

public static updatePersonFromApiData(mixed $pData, bool $allowCreation, bool $verbose = false, bool $deferTPUpdate = false): ?\tp\TouchPointWP\Person
  • This method is static. Parameters:
Parameter Type Description
$pData mixed
$allowCreation bool
$verbose bool
$deferTPUpdate bool

Return Value:

The updated person, or null if no user was found/updated.


getActionButtons

Returns the html with buttons for actions the user can perform. This must be called within an element with the data-tp-person attribute with the peopleId as the value.

public getActionButtons(?string $context = null, string $btnClass = "", bool $withTouchPointLink = true, bool $absoluteLinks = false): \tp\TouchPointWP\Utilities\StringableArray

Parameters:

Parameter Type Description
$context ?string A reference to where the action buttons are meant to be used.
$btnClass string A string for classes to add to the buttons. Note that buttons can be a or button
elements.
$withTouchPointLink bool
$absoluteLinks bool

enqueueForJS_byPeopleId

Ensure a person with a given PeopleId will be available in JS.

public static enqueueForJS_byPeopleId(int $pid): ?bool
  • This method is static. Parameters:
Parameter Type Description
$pid int TouchPoint People ID

Return Value:

null if person is not found. True if newly enqueued, false if it was already enqueued.


enqueueUsersForJsInstantiation

Call this function if user (and immediate family members, probably) should be automatically instantiated in JS on page load. (e.g. if the page contains an RSVP button)

public static enqueueUsersForJsInstantiation(): void
  • This method is static.

jsonSerialize

Controls the information that's actually serialized for jsInstantiation

public jsonSerialize(): array

getJsInstantiationString

Returns the raw JS that creates the Person objects

public static getJsInstantiationString(): string
  • This method is static.

getTouchPointId

Gets the PeopleId number. Required by jsInstantiation trait.

public getTouchPointId(): int

hasUserPage

Returns true if the person has posts and therefore has a user page.

public hasUserPage(): bool

getUserUrl

Get the link to the person's author post page.

public getUserUrl(): ?string

getProfileUrl

Returns the person's TouchPoint profile URL.

public getProfileUrl(): ?string

arrangeNamesForPeople

Take an array of Person-ish objects and return a nicely human-readable list of names.

public static arrangeNamesForPeople(\tp\TouchPointWP\Person[]|\tp\TouchPointWP\Utilities\PersonArray $people, bool $asLink = false, int $familyLimit = 3): ?string
  • This method is static. Parameters:
Parameter Type Description
$people \tp\TouchPointWP\Person[]|\tp\TouchPointWP\Utilities\PersonArray TODO make api compliant with Person object--remove coalesces. (#120)

TODO merge with Utilities::stringArrayToListString() | | $asLink | bool | | | $familyLimit | int | |

Return Value:

Returns a human-readable list of names, nicely formatted with commas and such.


toNewWpUser

Functionally convert this Person object to a WP_User object for working with the WP API.

public toNewWpUser(): \WP_User

groupByFamily

Take an array of Person-like objects and group them by family id.

public static groupByFamily(\tp\TouchPointWP\Person[]|object[]|\tp\TouchPointWP\Utilities\PersonArray $people): \tp\TouchPointWP\Person[][]|object[][]

Objects must have a FamilyId or familyId field. TODO standardize... (#120)

  • This method is static. Parameters:
Parameter Type Description
$people \tp\TouchPointWP\Person[]|object[]|\tp\TouchPointWP\Utilities\PersonArray

ident

Make the API call to get family members and return them.

public static ident(mixed $inputData): array

This is used for both formal and informal auth. Email addresses should be checked for spam likelihood before this point.

  • This method is static. Parameters:
Parameter Type Description
$inputData mixed

api

Handle API requests

public static api(array $uri): bool
  • This method is static. Parameters:
Parameter Type Description
$uri array The request URI already parsed by parse_url()

Return Value:

False if endpoint is not found. Should print the result.


load

Loads the module and initializes the other actions.

public static load(): bool
  • This method is static.

checkUpdates

Run cron if it hasn't been run before or is overdue.

public static checkUpdates(): void
  • This method is static.

getExtraValue

Get an Extra Value.

public getExtraValue(string $name): mixed

Parameters:

Parameter Type Description
$name string The name of the extra value to get.

Return Value:

The value of the extra value. Returns null if it doesn't exist.


Inherited methods

ExtraValues

public ExtraValues(): ?\tp\TouchPointWP\ExtraValueHandler

getExtraValue

Get an Extra Value.

public getExtraValue(string $name): mixed
  • This method is abstract. Parameters:
Parameter Type Description
$name string The name of the extra value to get.

Return Value:

The value of the extra value. Returns null if it doesn't exist.


requireAllObjectsInJs

If all objects need to be included in the JS,

public static requireAllObjectsInJs(bool $require = true): void
  • This method is static. Parameters:
Parameter Type Description
$require bool Whether all objects should be required. Almost always should be left with the default.

jsonSerialize

Get the JS for instantiation.

public jsonSerialize(): object

getTouchPointId

Gets a TouchPoint item ID number, regardless of what type of object this is.

public getTouchPointId(): int
  • This method is abstract.

getJsInstantiationString

Get the JS for instantiation.

public static getJsInstantiationString(): string
  • This method is static.* This method is abstract.