SLPĀ® phpDocs

MySLP_CustomerMeta_MapViews
in package

Table of Contents

Constants

INSTALLED_VERSION_OPTION  : string = 'customermeta_map_views_installed_version'
LAST_EXTRACTION_TIME_OPTION  : string = 'customermeta_map_views_last_extraction_time'
OVERAGE_BLOCK_CHARGE  : float = 5.0
OVERAGE_BLOCK_VIEWS  : int = 1000
OVERAGE_GRACE_VIEWS  : int = 100
OVERAGE_GRACE_VIEWS_LEGACY  : int = 0
TABLE_SLUG  : string = 'customermeta_map_views'

Methods

build_monthly_views_report()  : array<string, mixed>|null
Build a month-by-month report from raw rows.
calculate_overage_charge()  : float
Calculate the monthly overage charge for the number of views over the plan.
extract_legacy_data()  : void
Extract map views data from the legacy myslp_logger table.
get_latest_month_summary()  : array<string, mixed>|null
Return the latest map-view summary for a customer blog.
get_monthly_views_report()  : array<string, mixed>|null
Return a normalized month-by-month report for a customer's map views.
get_table_name()  : string
Return the multisite main-site table name.
maybe_update_schema()  : void
Create or update the table once per plugin version.
summarize_month_rows()  : array<string, mixed>|null
Build a summary array from raw month rows.
build_empty_month_summary()  : array<string, mixed>
Build an empty summary for a month without stored map-view data.
get_latest_view_limit_from_rows()  : int
Return the latest known view-limit value from a row collection.
get_limit_select_sql()  : string
Return the SQL fragment for selecting the plan-limit column.
normalize_report_range()  : array<string, DateTimeImmutable|string>|null
Normalize optional report dates into an inclusive month range.
normalize_to_month_start()  : DateTimeImmutable|null
Convert an arbitrary date string into the first moment of that month.
table_has_column()  : bool
Check whether the map views table contains a given column.

Constants

LAST_EXTRACTION_TIME_OPTION

private string LAST_EXTRACTION_TIME_OPTION = 'customermeta_map_views_last_extraction_time'

Methods

build_monthly_views_report()

Build a month-by-month report from raw rows.

public static build_monthly_views_report(array<int, array<string, int|string>> $rows[, string|null $start_date = null ][, string|null $end_date = null ]) : array<string, mixed>|null
Parameters
$rows : array<int, array<string, int|string>>

Raw table rows.

$start_date : string|null = null

Optional range start date.

$end_date : string|null = null

Optional range end date.

Return values
array<string, mixed>|null

calculate_overage_charge()

Calculate the monthly overage charge for the number of views over the plan.

public static calculate_overage_charge(int $views_over_limit) : float

The first 100 over-limit views are free. Remaining views are billed in blocks of 1000 views, rounded up to the next 1000-view block.

Parameters
$views_over_limit : int

Number of views above the plan limit.

Return values
float

extract_legacy_data()

Extract map views data from the legacy myslp_logger table.

public static extract_legacy_data() : void

Only runs for super admins. Only extracts records newer than the last extraction time.

get_latest_month_summary()

Return the latest map-view summary for a customer blog.

public static get_latest_month_summary(int $blog_id) : array<string, mixed>|null

The latest month is determined by the newest entry_date. If multiple records exist for the same year/month, the record with the highest map_views is used as the primary entry and duplicate details are included in the response.

Parameters
$blog_id : int

Customer blog ID.

Return values
array<string, mixed>|null

get_monthly_views_report()

Return a normalized month-by-month report for a customer's map views.

public static get_monthly_views_report(int $blog_id[, string|null $start_date = null ][, string|null $end_date = null ]) : array<string, mixed>|null
Parameters
$blog_id : int

Customer blog ID.

$start_date : string|null = null

Optional range start date.

$end_date : string|null = null

Optional range end date.

Return values
array<string, mixed>|null

get_table_name()

Return the multisite main-site table name.

public static get_table_name() : string
Return values
string

maybe_update_schema()

Create or update the table once per plugin version.

public static maybe_update_schema() : void

summarize_month_rows()

Build a summary array from raw month rows.

public static summarize_month_rows(array<int, array<string, int|string>> $month_rows) : array<string, mixed>|null

This helper is intentionally database-independent so it can be covered with lightweight tests.

Parameters
$month_rows : array<int, array<string, int|string>>

Ordered month rows.

Return values
array<string, mixed>|null

build_empty_month_summary()

Build an empty summary for a month without stored map-view data.

private static build_empty_month_summary(DateTimeImmutable $month_date, int $view_limit) : array<string, mixed>
Parameters
$month_date : DateTimeImmutable

Month being summarized.

$view_limit : int

View limit to display.

Return values
array<string, mixed>

get_latest_view_limit_from_rows()

Return the latest known view-limit value from a row collection.

private static get_latest_view_limit_from_rows(array<int, array<string, int|string>> $rows) : int
Parameters
$rows : array<int, array<string, int|string>>

Raw rows.

Return values
int

get_limit_select_sql()

Return the SQL fragment for selecting the plan-limit column.

private static get_limit_select_sql() : string

The schema has used both view_limit and plan_limit naming during its development, so this helper keeps reads compatible with either version.

Return values
string

normalize_report_range()

Normalize optional report dates into an inclusive month range.

private static normalize_report_range([string|null $start_date = null ][, string|null $end_date = null ]) : array<string, DateTimeImmutable|string>|null
Parameters
$start_date : string|null = null

Optional range start date.

$end_date : string|null = null

Optional range end date.

Return values
array<string, DateTimeImmutable|string>|null

normalize_to_month_start()

Convert an arbitrary date string into the first moment of that month.

private static normalize_to_month_start(string $date_string) : DateTimeImmutable|null
Parameters
$date_string : string

Date input.

Return values
DateTimeImmutable|null

table_has_column()

Check whether the map views table contains a given column.

private static table_has_column(string $column_name) : bool
Parameters
$column_name : string

Column name to inspect.

Return values
bool
On this page

Search results