PHP Class Tools\Model\Table\Table

Inheritance: extends Shim\Model\Table\Table
Show file Open project: dereuromark/cakephp-tools Class Usage Examples

Public Methods

Method Description
getFieldInUse ( string $groupField, string $type = 'all', array $options = [] ) : Query Get all fields that have been used so far
getNextAutoIncrement ( ) : integer | boolean Return the next auto increment id from the current table UUIDs will return false
getRelatedInUse ( string $tableName, string | null $groupField = null, string $type = 'all', array $options = [] ) : Query Get all related entries that have been used so far
truncate ( ) : void truncate()
validateAll ( array $entities ) : boolean
validateDate ( mixed $value, array $options = [], array $context = [] ) : boolean Validation of Date fields (as the core one is buggy!!!)
validateDateRange ( mixed $value, array $options = [], array $context = [] ) : boolean Validation of Date Fields (>= minDate && <= maxDate)
validateDateTime ( mixed $value, array $options = [], array $context = [] ) : boolean Validation of DateTime Fields (both Date and Time together)
validateIdentical ( mixed $value, array | string $options = [], array $context = [] ) : boolean Checks if the content of 2 fields are equal Does not check on empty fields! Return TRUE even if both are empty (secure against empty in another rule)!
validateTime ( mixed $value, array $options = [], array $context = [] ) : boolean Validation of Time fields
validateTimeRange ( mixed $value, array $options = [], array $context = [] ) : boolean Validation of Time Fields (>= minTime && <= maxTime)
validateUniqueExt ( mixed $value, array $options, array $context = [] ) : boolean Validator method used to check the uniqueness of a value for a column.
validateUrl ( array | string $url, array $options = [], array $context = [] ) : boolean Checks if a URL is valid AND accessible (returns false otherwise)

Protected Methods

Method Description
_autoCompleteUrl ( string $url ) : string Prepend protocol if missing
_validUrl ( string $url ) : boolean Checks if a url is valid

Method Details

_autoCompleteUrl() protected method

Prepend protocol if missing
protected _autoCompleteUrl ( string $url ) : string
$url string
return string URL

_validUrl() protected method

Checks if a url is valid
protected _validUrl ( string $url ) : boolean
$url string
return boolean Success

getFieldInUse() public method

Get all fields that have been used so far
public getFieldInUse ( string $groupField, string $type = 'all', array $options = [] ) : Query
$groupField string Field to group by
$type string Find type
$options array
return Cake\ORM\Query

getNextAutoIncrement() public method

Return the next auto increment id from the current table UUIDs will return false
public getNextAutoIncrement ( ) : integer | boolean
return integer | boolean next auto increment value or False on failure

getRelatedInUse() public method

Get all related entries that have been used so far
public getRelatedInUse ( string $tableName, string | null $groupField = null, string $type = 'all', array $options = [] ) : Query
$tableName string The related model
$groupField string | null Field to group by
$type string Find type
$options array
return Cake\ORM\Query

truncate() public method

truncate()
public truncate ( ) : void
return void

validateAll() public method

public validateAll ( array $entities ) : boolean
$entities array
return boolean

validateDate() public method

Validation of Date fields (as the core one is buggy!!!)
public validateDate ( mixed $value, array $options = [], array $context = [] ) : boolean
$value mixed
$options array - dateFormat (defaults to 'ymd') - allowEmpty - after/before (fieldName to validate against) - min (defaults to 0 - equal is OK too)
$context array
return boolean Success

validateDateRange() public method

Validation of Date Fields (>= minDate && <= maxDate)
public validateDateRange ( mixed $value, array $options = [], array $context = [] ) : boolean
$value mixed
$options array - min/max (TODO!!)
$context array
return boolean

validateDateTime() public method

Validation of DateTime Fields (both Date and Time together)
public validateDateTime ( mixed $value, array $options = [], array $context = [] ) : boolean
$value mixed
$options array - dateFormat (defaults to 'ymd') - allowEmpty - after/before (fieldName to validate against) - min/max (defaults to >= 1 - at least 1 minute apart)
$context array
return boolean Success

validateIdentical() public method

Options: - compare: field to compare to - cast: if casting should be applied to both values
public validateIdentical ( mixed $value, array | string $options = [], array $context = [] ) : boolean
$value mixed
$options array | string
$context array
return boolean Success

validateTime() public method

Validation of Time fields
public validateTime ( mixed $value, array $options = [], array $context = [] ) : boolean
$value mixed
$options array - timeFormat (defaults to 'hms') - allowEmpty - after/before (fieldName to validate against) - min/max (defaults to >= 1 - at least 1 minute apart)
$context array
return boolean Success

validateTimeRange() public method

Validation of Time Fields (>= minTime && <= maxTime)
public validateTimeRange ( mixed $value, array $options = [], array $context = [] ) : boolean
$value mixed
$options array - min/max (TODO!!)
$context array
return boolean

validateUniqueExt() public method

This is meant to be used with the validation API and not to be called directly. ### Example: {{{ $validator->add('email', [ 'unique' => ['rule' => 'validateUnique', 'provider' => 'table'] ]) }}} Unique validation can be scoped to the value of another column: {{{ $validator->add('email', [ 'unique' => [ 'rule' => ['validateUnique', ['scope' => 'site_id']], 'provider' => 'table' ] ]); }}} In the above example, the email uniqueness will be scoped to only rows having the same site_id. Scoping will only be used if the scoping field is present in the data to be validated.
public validateUniqueExt ( mixed $value, array $options, array $context = [] ) : boolean
$value mixed The value of column to be checked for uniqueness
$options array The options array, optionally containing the 'scope' key
$context array The validation context as provided by the validation routine
return boolean true if the value is unique

validateUrl() public method

Options: - allowEmpty TRUE/FALSE (TRUE: if empty => return TRUE) - required TRUE/FALSE (TRUE: overrides allowEmpty) - autoComplete (default: TRUE) - deep (default: TRUE)
public validateUrl ( array | string $url, array $options = [], array $context = [] ) : boolean
$url array | string Full URL starting with http://...
$options array
$context array
return boolean Success