PHP Class Helper

Author: Clemens John ([email protected])
显示文件 Open project: openeyes/openeyes Class Usage Examples

Public Methods

Method Description
convertDate2HTML ( $value, $empty_string = '-' )
convertDate2NHS ( string $value, string $empty_string = '-' ) : string Convert date(time) value to NHS format.
convertMySQL2HTML ( $value, $empty_string = '-' )
convertMySQL2NHS ( string $value, string $empty_string = '-' ) : string Convert MySQL date(time) value to NHS format.
convertNHS2MySQL ( string | array $data, array $fields = null ) : string | array Convert NHS dates to MySQL format.
convertToBytes ( $val ) : mixed convert string of format n[units] to bytes units can be one of B, KB, MB, GB, TB, PB, EB, ZB or YB (case-insensitive).
elementFinder ( $needle, array $haystack, string $delimiter = '.' ) : null Find an element in a nested hasharray $haystack with a string $needle separated by $delimiter
extractValues ( array $objects, $attribute, mixed $default = null ) : array Extract values from a list of objects or arrays using {@link CHtml value}.
formatFuzzyDate ( string $value ) : string generate string representation of a fuzzy date (fuzzy dates are strings of the format yyyy-mm-dd, where mm and dd can be 00 to indicate not being set).
formatList ( array $items ) : string Format a list of strings with comma separators and a final 'and'.
generateUuid ( ) : string Generate a version 4 UUID.
getAge ( string $dob, string $date_of_death = null, string $check_date = null ) : string Calculate age from dob.
getDateForAge ( $dob, $age, null $date_of_death = null ) : null | string Given a dob and an age (in years) returns the date at which the person would reach the given age.
getMonthText ( $month, $long = false )
getNSShortname ( $instance )
getWeekdayText ( $weekday )
lineLimit ( $string, integer $line_count, integer $protect, string $delimiter = " ", string $joiner = ', ' ) : string
md5Verified ( $data ) : null | string Extracts what should be the md5 from the end of a string to verify against the remainder Returns the verified data if the md5 is correct, null otherwise.
mysqlDate2JsTimestamp ( string $value ) : float Convert mysql format datetime to JS timestamp (milliseconds since unix epoch).
padFuzzyDate ( $day, $month, $year )
timestampToDB ( integer $timestamp ) : string generate string representation of timestamp for the database.

Method Details

convertDate2HTML() public static method

public static convertDate2HTML ( $value, $empty_string = '-' )

convertDate2NHS() public static method

Strings that do not return a valid date return $empty_string.
public static convertDate2NHS ( string $value, string $empty_string = '-' ) : string
$value string
$empty_string string
return string

convertMySQL2HTML() public static method

public static convertMySQL2HTML ( $value, $empty_string = '-' )

convertMySQL2NHS() public static method

Strings that do not match MySQL date(time) format return $empty_string.
public static convertMySQL2NHS ( string $value, string $empty_string = '-' ) : string
$value string
$empty_string string
return string

convertNHS2MySQL() public static method

Strings that do not match the NHS format are returned unchanged or are not valid dates.
public static convertNHS2MySQL ( string | array $data, array $fields = null ) : string | array
$data string | array Data containing one or more NHS dates
$fields array Fields (keys) to convert (optional, if empty then all fields are checked for dates)
return string | array

convertToBytes() public static method

convert string of format n[units] to bytes units can be one of B, KB, MB, GB, TB, PB, EB, ZB or YB (case-insensitive).
public static convertToBytes ( $val ) : mixed
$val
return mixed

elementFinder() public static method

Find an element in a nested hasharray $haystack with a string $needle separated by $delimiter
public static elementFinder ( $needle, array $haystack, string $delimiter = '.' ) : null
$needle
$haystack array
$delimiter string
return null

extractValues() public static method

Extract values from a list of objects or arrays using {@link CHtml value}.
public static extractValues ( array $objects, $attribute, mixed $default = null ) : array
$objects array
$default mixed
return array

formatFuzzyDate() public static method

generate string representation of a fuzzy date (fuzzy dates are strings of the format yyyy-mm-dd, where mm and dd can be 00 to indicate not being set).
public static formatFuzzyDate ( string $value ) : string
$value string
return string

formatList() public static method

Format a list of strings with comma separators and a final 'and'.
public static formatList ( array $items ) : string
$items array
return string

generateUuid() public static method

Generate a version 4 UUID.
public static generateUuid ( ) : string
return string

getAge() public static method

If date of death provided, then returns age at point of death
public static getAge ( string $dob, string $date_of_death = null, string $check_date = null ) : string
$dob string
$date_of_death string
$check_date string Optional date to check age at (default is today)
return string $age

getDateForAge() public static method

If given a date of death, and they will never reach the age, returns null.
public static getDateForAge ( $dob, $age, null $date_of_death = null ) : null | string
$dob
$age
$date_of_death null
return null | string

getMonthText() public static method

public static getMonthText ( $month, $long = false )

getNSShortname() public static method

public static getNSShortname ( $instance )

getWeekdayText() public static method

public static getWeekdayText ( $weekday )

lineLimit() public static method

public static lineLimit ( $string, integer $line_count, integer $protect, string $delimiter = " ", string $joiner = ', ' ) : string
$string
$line_count integer
$protect integer
$delimiter string
$joiner string
return string $result

md5Verified() public static method

Extracts what should be the md5 from the end of a string to verify against the remainder Returns the verified data if the md5 is correct, null otherwise.
public static md5Verified ( $data ) : null | string
$data
return null | string

mysqlDate2JsTimestamp() public static method

Convert mysql format datetime to JS timestamp (milliseconds since unix epoch).
public static mysqlDate2JsTimestamp ( string $value ) : float
$value string
return float

padFuzzyDate() public static method

public static padFuzzyDate ( $day, $month, $year )

timestampToDB() public static method

generate string representation of timestamp for the database.
public static timestampToDB ( integer $timestamp ) : string
$timestamp integer
return string