tp TouchPointWP Report - TenthPres/TouchPoint-WP GitHub Wiki

tp\TouchPointWP\Report

The Report class gets and processes a SQL or Python report from TouchPoint and presents it in the UX.


Constants

Constant Visibility Type Value
SHORTCODE_REPORT public \tp\TouchPointWP\TouchPointWP::SHORTCODE_PREFIX . "Report"
POST_TYPE public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "report"
META_PREFIX public \tp\TouchPointWP\TouchPointWP::SETTINGS_PREFIX . "rpt_"
CRON_HOOK public \tp\TouchPointWP\TouchPointWP::HOOK_PREFIX . "report_cron_hook"
TYPE_META_KEY public self::META_PREFIX . "type"
NAME_META_KEY public self::META_PREFIX . "name"
P1_META_KEY public self::META_PREFIX . "p1"
DEFAULT_CONTENT public ''

Properties

classDefault

public static string $classDefault
  • This property is static.

_isLoaded

public static bool $_isLoaded
  • This property is static.

Methods

fromParams

Get a Report object, based on standard parameters (generally, the parameters used for the shortcode)

public static fromParams(mixed $params): self
  • This method is static. Parameters:
Parameter Type Description
$params mixed

Throws:


load

Loads the module and initializes the other actions.

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

init

Register stuff

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

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.


reportShortcode

Handle the report shortcode.

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

getPost

Get the WP_Post object corresponding to the Report.

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.

content

Get the report content. If no content is available, return the provided default content instead.

public content(string $contentIfError = \self::DEFAULT_CONTENT): string

Parameters:

Parameter Type Description
$contentIfError string

updateFromTouchPoint

Update all reports from TouchPoint that are due for an update.

public static updateFromTouchPoint(bool $forceEvenIfNotDue = false): int
  • This method is static. Parameters:
Parameter Type Description
$forceEvenIfNotDue bool

Throws:


needsUpdate

Determines if THIS report is due for an update. Does NOT process the update itself.

public needsUpdate(): bool

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.

jsonSerialize

Handle which data should be converted to JSON. Used for posting to the API.

public jsonSerialize(): array

Return Value:

data which can be serialized by json_encode


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.