Documentation

CodeRangeGenerator
in package

CodeRangeGenerator

Given a table "type" (e.g. 'kpi'), this class:

  1. Looks up the row in table code_range where code_range_table_name = :type
  2. Ensures code_range_type contains 'MPA_PREFIX'
  3. Reads code_range_prefix (e.g. 'CMP-') to know the code prefix
  4. Scans the target data table (e.g. kpi) for the highest numeric suffix after the prefix on the column <type>_code (e.g. kpi_code) where the format is EXACTLY "PREFIX-######"
  5. Returns the next code, zero-padded to PAD (default 6)

Table of Contents

Constants

PAD  = 6

Properties

$db  : MySql

Methods

__construct()  : mixed
nextCode()  : string
Returns the next available code for the given table type.
escapeForMysqlRegex()  : string
Escape characters in a literal to be safely used inside a MySQL REGEXP (which uses a PCRE-like engine).
loadCodeRangeRow()  : array<string|int, mixed>|null
Load the code_range row for the given table (type).
normalizePrefix()  : string
Ensure prefix ends with exactly one '-' and no trailing spaces.

Constants

Properties

Methods

nextCode()

Returns the next available code for the given table type.

public nextCode(string $type) : string

Example: nextCode('kpi') => 'CMP-000082'

Parameters
$type : string

Table name / type (e.g. 'kpi', 'unit', etc.)

Return values
string

Next code

escapeForMysqlRegex()

Escape characters in a literal to be safely used inside a MySQL REGEXP (which uses a PCRE-like engine).

private escapeForMysqlRegex(string $literal) : string
Parameters
$literal : string
Return values
string

loadCodeRangeRow()

Load the code_range row for the given table (type).

private loadCodeRangeRow(string $type) : array<string|int, mixed>|null

Expects columns:

  • code_range_table_name
  • code_range_type (should contain 'MPA_PREFIX')
  • code_range_prefix (e.g., 'CMP-' or 'CMP')
Parameters
$type : string
Return values
array<string|int, mixed>|null

normalizePrefix()

Ensure prefix ends with exactly one '-' and no trailing spaces.

private normalizePrefix(string $prefix) : string

Examples: 'CMP' -> 'CMP-' 'CMP-' -> 'CMP-' 'CMP--' -> 'CMP-'

Parameters
$prefix : string
Return values
string

        
On this page

Search results