| 1 |
<?php |
| 2 |
/** |
| 3 |
* Provider identification helpers. |
| 4 |
* |
| 5 |
* MLS providers are allocated by numeric mls_id range. These are pure functions |
| 6 |
* (no WordPress dependency) so they can be unit tested in isolation. |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Whether an mls_id belongs to a PropTx / AMPRE RESO Web API board (e.g. TRREB). |
| 15 |
* |
| 16 |
* PropTx boards are allocated the 9000-9999 id block, consistent with the |
| 17 |
* exclusive-upper 1000-wide blocks used by the other providers. |
| 18 |
* |
| 19 |
* @param int|string $mls_id |
| 20 |
* @return bool |
| 21 |
*/ |
| 22 |
function mlsimport_is_proptx_provider( $mls_id ) { |
| 23 |
$mls_id_int = (int) $mls_id; |
| 24 |
return $mls_id_int >= 9000 && $mls_id_int < 10000; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Normalise a stored last-import date into a full OData DateTimeOffset literal. |
| 29 |
* |
| 30 |
* The plugin stores the last-import marker as 'Y-m-d\TH:i' (e.g. 2026-07-01T00:00), |
| 31 |
* which RESO Web API providers such as AMPRE reject in a |
| 32 |
* $filter=ModificationTimestamp comparison. This produces a UTC literal with a Z |
| 33 |
* offset (e.g. 2026-07-01T00:00:00.000Z). An empty input is returned unchanged so |
| 34 |
* callers can keep treating '' as "no incremental marker". |
| 35 |
* |
| 36 |
* @param string $last_date |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
function mlsimport_format_odata_modification_time( $last_date ) { |
| 40 |
if ( '' === $last_date ) { |
| 41 |
return ''; |
| 42 |
} |
| 43 |
|
| 44 |
$date_time = new DateTime( $last_date, new DateTimeZone( 'UTC' ) ); |
| 45 |
return $date_time->format( 'Y-m-d\TH:i:s.000\Z' ); |
| 46 |
} |
| 47 |
|