tp TouchPointWP Partner - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\Partner

An Outreach partner, corresponding to a family in TouchPoint.


Constants

Constant Visibility Type Value
SHORTCODE_MAP public \tp\TouchPointWP\TouchPointWP::SHORTCODE_PREFIX . "Partner-Map"
SHORTCODE_FILTER public \tp\TouchPointWP\TouchPointWP::SHORTCODE_PREFIX . "Partner-Filters"
SHORTCODE_ACTIONS public \tp\TouchPointWP\TouchPointWP::SHORTCODE_PREFIX . "Partner-Actions"
SHORTCODE_LIST public \tp\TouchPointWP\TouchPointWP::SHORTCODE_PREFIX . "Partner-List"
CRON_HOOK public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "global_cron_hook"
FAMILY_META_KEY public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "famId"
POST_TYPE public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "partner"
META_FEV_PREFIX public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "fev_"

Properties

containerClass

public static string $containerClass
  • This property is static.

itemClass

public static string $itemClass
  • This property is static.

geo

public ?object $geo

decoupleLocation

public bool $decoupleLocation

color

public ?string $color

name

public string $name

attributes

public object $attributes

Methods

init

Register stuff

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

checkUpdates

Check to see if a cron run is needed, and run it if so. Connected to an init function.

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

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.

updateFromTouchPoint

Query TouchPoint and update Partners in WordPress

public static updateFromTouchPoint(bool $verbose = false): false|int
  • This method is static. Parameters:
Parameter Type Description
$verbose bool Whether to print debugging info.

Return Value:

False on failure, or the number of partner posts that were updated or deleted.

Throws:


templateFilter

public static templateFilter(string $template): string
  • This method is static. Parameters:
Parameter Type Description
$template string

actionsShortcode

Display action buttons for a partner. Takes an id parameter for the family ID. If not provided, the current post will be used.

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

listShortcode

Display a list of the partners, as used in the templates.

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

filterShortcode

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

fromPost

Create a Partner object from an object from a WP_Post object.

public static fromPost(\WP_Post $post): \tp\TouchPointWP\Partner
  • This method is static. Parameters:
Parameter Type Description
$post \WP_Post

Throws:

If the partner can't be created from the post, an exception is thrown.


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.

sort

Put Partner objects in order.

public static sort(\tp\TouchPointWP\Partner $a, \tp\TouchPointWP\Partner $b): int
  • This method is static. Parameters:
Parameter Type Description
$a \tp\TouchPointWP\Partner
$b \tp\TouchPointWP\Partner

sortPosts

Put Post objects that represent Partners in order of increasing distance.

public static sortPosts(\WP_Post $a, \WP_Post $b): int
  • This method is static. Parameters:
Parameter Type Description
$a \WP_Post
$b \WP_Post

registerScriptsAndStyles

Register scripts and styles to be used on display pages.

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

mapShortcode

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

filterPublishDate

Replace the date with information that's relevant

public static filterPublishDate(mixed $theDate, mixed $format, mixed $post = null): string
  • This method is static. Parameters:
Parameter Type Description
$theDate mixed
$format mixed
$post mixed

filterAuthor

Prevents the author from being shown

public static filterAuthor(mixed $author): string
  • This method is static. Parameters:
Parameter Type Description
$author mixed

getFamEvAsContent

Format an EV value for use as content.

public static getFamEvAsContent(string $ev, object $famObj, ?string $default): ?string
  • This method is static. Parameters:
Parameter Type Description
$ev string The name of the extra value
$famObj object The family object from the API call
$default ?string Value to use if no content is provided in the EV.

notableAttributes

Get notable attributes as strings.

public notableAttributes(array|\tp\TouchPointWP\Utilities\StringableArray $exclude = []): \tp\TouchPointWP\Utilities\NotableAttributes

Parameters:

Parameter Type Description
$exclude array|\tp\TouchPointWP\Utilities\StringableArray Attributes listed here will be excluded. (e.g. if shown for a parent, not needed here.)

getActionButtons

Returns the html with buttons for actions the user can perform. This must be called within an element with the data-tp-partner attribute with the post_id as the value or 0 for secure partners.

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

Parameters:

Parameter Type Description
$context string|null A string that gives filters some context for where the request is coming from
$btnClass string HTML class names to put into the buttons/links
$withTouchPointLink bool Whether to include a link to the item within TouchPoint. (not used)
$absoluteLinks bool Set true to make the links absolute, so they work from apps or emails.

getJsInstantiationString

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

getTouchPointId

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

public getTouchPointId(): int

jsId

Return the Post ID as needed by the JS classes. Typically, this will be the post_id, but this can be overridden.

public jsId(): int

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.


postIsType

Indicates if the given post can be instantiated as a Partner.

public static postIsType(\WP_Post $post): bool
  • This method is static. Parameters:
Parameter Type Description
$post \WP_Post

postTypeMatches

Indicates if the given post type name is the post type for this class.

public static postTypeMatches(string $postType): bool
  • This method is static. Parameters:
Parameter Type Description
$postType string

jsonSerialize

Serialize. Mostly, manage the security requirements.

public jsonSerialize(): object

hasGeo

Indicates whether a map of a single Partner can be displayed.

public hasGeo(): bool

asGeoIFace

Returns a standardized stdObject, or null if not viable.

public asGeoIFace(string $type = "unknown"): object|null

Return object properties are lat, lng, human, and type.

Parameters:

Parameter Type Description
$type string 'loc' for navigator location, or 'ip' for ip address location

locationName

Get the name of the location.

public locationName(): ?string

Inherited methods

post_id

Get the Post_id.

public post_id(): int

getPost

Get the WP_Post object corresponding to the object.

public getPost(bool $create = false): \WP_Post|null

Parameters:

Parameter Type Description
$create bool Set true if the post should be created if it doesn't exist. This would need to be
implemented in each module, and is not implemented in most.

fromPost

Create relevant objects from a given post

public static fromPost(\WP_Post $post): ?\tp\TouchPointWP\PostTypeCapable
  • This method is static. Parameters:
Parameter Type Description
$post \WP_Post

Throws:


permalink

Get the link for the post.

public permalink(): string

titleWithinParent

Get the title for display within its parent, such as in the parent's list of its parts. If the title starts with the parent's title and a separator, the parent's title is left out, since the parent's title is already visible: "Global Outreach Conference: Q&A Luncheon" is displayed as "Q&A Luncheon" within "Global Outreach Conference". The stored title isn't changed.

public titleWithinParent(?\WP_Post $parent = null): string

The result is filtered like any other title, so it can be printed in place of the_title().

Parameters:

Parameter Type Description
$parent ?\WP_Post The parent to display this within. Default is its own parent.

titleInList

Get the title for display in a list. If the list is on the page of this one's parent, this is the title within its parent (see titleWithinParent()). Otherwise, such as in an archive or a list on some other page, this is displayed on its own, and its full title is needed.

public titleInList(): string

notableAttributes

Get notable attributes.

public notableAttributes(array|\tp\TouchPointWP\Utilities\StringableArray $exclude = []): \tp\TouchPointWP\Utilities\NotableAttributes
  • This method is abstract. Parameters:
Parameter Type Description
$exclude array|\tp\TouchPointWP\Utilities\StringableArray Attributes listed here will be excluded. (e.g. if shown for a parent, not needed here.)

postIsType

Indicates if the given post can be instantiated as the given post type.

public static postIsType(\WP_Post $post): bool
  • This method is static.* This method is abstract. Parameters:
Parameter Type Description
$post \WP_Post

postTypeMatches

Indicates if the given post type name is the post type for this class.

public static postTypeMatches(string $postType): bool
  • This method is static.* This method is abstract. Parameters:
Parameter Type Description
$postType string

getTouchPointId

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

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

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

getJsInstantiationString

Get the JS for instantiation.

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