\Charcoal\Source\DatabaseDatabaseOrder

The DatabaseOrder makes a Order SQL-aware.

Available modes:

  • asc to order in ascending (A-Z / 0-9) order.
  • desc to order in descending (Z-A / 9-0) order.
  • rand to order in a random fashion.
  • values to order by a defined array of properties.
  • custom to order by a custom SQL string.

Summary

Methods
Properties
Constants
setData()
setProperty()
property()
setMode()
mode()
setValues()
values()
setString()
string()
setActive()
active()
sql()
No public properties found
MODE_ASC
MODE_DESC
MODE_RANDOM
MODE_VALUES
MODE_CUSTOM
validModes()
$property
$mode
$values
$string
$active
N/A
byRandom()
byCustom()
byValues()
No private properties found
N/A

Constants

MODE_ASC

MODE_ASC

MODE_DESC

MODE_DESC

MODE_RANDOM

MODE_RANDOM

MODE_VALUES

MODE_VALUES

MODE_CUSTOM

MODE_CUSTOM

Properties

$property

$property : string

The model property (SQL column).

Type

string

$mode

$mode : string

The sort mode.

Type

string

$values

$values : array

The values when {@see self::$mode} is {@see self::MODE_VALUES}.

Type

array

$string

$string : string

Raw SQL clause when {@see self::$mode} is {@see self::MODE_CUSTOM}.

Type

string

$active

$active : boolean

Whether the order is active.

Type

boolean

Methods

setData()

setData(array  $data) : \Charcoal\Source\Order

Parameters

array $data

The order data.

Returns

\Charcoal\Source\Order

Chainable

setProperty()

setProperty(string  $property) : \Charcoal\Source\Order

Parameters

string $property

The order property.

Throws

\InvalidArgumentException

If the property argument is not a string.

Returns

\Charcoal\Source\Order

(Chainable)

property()

property() : string

Returns

string

setMode()

setMode(string  $mode) : \Charcoal\Source\Order

Parameters

string $mode

The order mode.

Throws

\InvalidArgumentException

If the mode is not a string or invalid.

Returns

\Charcoal\Source\Order

Chainable

mode()

mode() : string

Returns

string

setValues()

setValues(string|array  $values) : \Charcoal\Source\Order

Set the values.

Values are ignored if the mode is not "values"

If the $values argument is a string, it will be split by ",". If it is an array, the values will be used as is. Otherwise, the function will throw an error

Parameters

string|array $values

The order values.

Throws

\InvalidArgumentException

If the parameter is not an array or a string.

Returns

\Charcoal\Source\Order

(Chainable)

values()

values() : array

Returns

array

setString()

setString(string  $sql) : \Charcoal\Source\Order

Parameters

string $sql

The custom order SQL string.

Throws

\InvalidArgumentException

If the parameter is not a valid operand.

Returns

\Charcoal\Source\Order

(Chainable)

string()

string() : string

Returns

string

setActive()

setActive(boolean  $active) : \Charcoal\Source\Order

Parameters

boolean $active

The active flag.

Returns

\Charcoal\Source\Order

(Chainable)

active()

active() : boolean

Returns

boolean

sql()

sql() : string

Retrieve the Order's SQL string to append to an ORDER BY clause.

Throws

\DomainException

If any required property is empty.

Returns

string

validModes()

validModes() : array

Supported modes

Returns

array

byRandom()

byRandom() : string

Retrieve the ORDER BY clause for the {@see self::MODE_RANDOM} mode.

Returns

string

byCustom()

byCustom() : string

Retrieve the ORDER BY clause for the {@see self::MODE_CUSTOM} mode.

Returns

string

byValues()

byValues() : string

Retrieve the ORDER BY clause for the {@see self::MODE_VALUES} mode.

Throws

\DomainException

If any required property or values is empty.

Returns

string