PHP Class OrderedBehavior

Author: Alexander Morland aka alkemann
Inheritance: extends ModelBehavior
Datei anzeigen Open project: croogo/croogo

Public Properties

Property Type Description
$name

Protected Properties

Property Type Description
$_defaults foreign_key : (string) The field to identify one SET by. Each set has their own order (ie they start at 1). Set to FALSE to not use this feature (and use only 1 set)

Public Methods

Method Description
afterDelete ( Model $Model )
beforeDelete ( Model $Model, $cascade = true )
beforeSave ( Model $Model, $options = [] ) Sets the weight for new items so they end up at end
isFirst ( Model $Model, Int $id = null ) : Boolean, Returns true if the specified item is the first item
isLast ( Model $Model, Int $id = null ) : Boolean, Returns true if the specified item is the last item
moveDown ( Model $Model, mixed $id = null, mixed $number = 1 ) : boolean Reorder the node, by moving it $number spaces down. Defaults to 1
moveTo ( Model $Model, integer $id = null, integer $newWeight = null ) : boolean Moving a node to specific weight, it will shift the rest of the table to make room.
moveUp ( Model $Model, mixed $id = null, mixed $number = 1 ) : boolean Reorder the node, by moving it $number spaces up. Defaults to 1
removefromlist ( Model $Model, integer $id ) : boolean Removing an item from the list means to set its field to 0 and updating the other items to be "complete"
resetWeights ( Model $Model ) : boolean This will create weights based on display field. The purpose of the method is to create weights for tables that existed before this behavior was added.
setup ( Model $Model, $config = [] )
sortBy ( Model $Model, array $order, mixed $foreignKey = null ) Take in an order array and sorts the list based on that order specification and creates new weights for it. If no foreign key is supplied, all lists will be sorted.

Protected Methods

Method Description
_all ( Model $Model )
_findbyweight ( Model $Model, $weight )
_highest ( Model $Model )
_next ( Model $Model )
_previous ( Model $Model )
_read ( Model $Model, $id )

Method Details

_all() protected method

protected _all ( Model $Model )
$Model Model

_findbyweight() protected method

protected _findbyweight ( Model $Model, $weight )
$Model Model

_highest() protected method

protected _highest ( Model $Model )
$Model Model

_next() protected method

protected _next ( Model $Model )
$Model Model

_previous() protected method

protected _previous ( Model $Model )
$Model Model

_read() protected method

protected _read ( Model $Model, $id )
$Model Model

afterDelete() public method

public afterDelete ( Model $Model )
$Model Model

beforeDelete() public method

public beforeDelete ( Model $Model, $cascade = true )
$Model Model

beforeSave() public method

Sets the weight for new items so they end up at end
public beforeSave ( Model $Model, $options = [] )
$Model Model

isFirst() public method

Returns true if the specified item is the first item
public isFirst ( Model $Model, Int $id = null ) : Boolean,
$Model Model
$id Int
return Boolean,

isLast() public method

Returns true if the specified item is the last item
public isLast ( Model $Model, Int $id = null ) : Boolean,
$Model Model
$id Int
return Boolean,

moveDown() public method

If the node is the last node (or less then $number spaces from last) this method will return false.
public moveDown ( Model $Model, mixed $id = null, mixed $number = 1 ) : boolean
$Model Model
$id mixed The ID of the record to move
$number mixed how many places to move the node or true to move to last position
return boolean true on success, false on failure

moveTo() public method

Moving a node to specific weight, it will shift the rest of the table to make room.
public moveTo ( Model $Model, integer $id = null, integer $newWeight = null ) : boolean
$Model Model
$id integer The id of the node to move
$newWeight integer the new weight of the node
return boolean True of move successful

moveUp() public method

If the node is the first node (or less then $number spaces from first) this method will return false.
public moveUp ( Model $Model, mixed $id = null, mixed $number = 1 ) : boolean
$Model Model
$id mixed The ID of the record to move
$number mixed how many places to move the node or true to move to last position
return boolean true on success, false on failure

removefromlist() public method

Removing an item from the list means to set its field to 0 and updating the other items to be "complete"
public removefromlist ( Model $Model, integer $id ) : boolean
$Model Model
$id integer
return boolean

resetWeights() public method

This will create weights based on display field. The purpose of the method is to create weights for tables that existed before this behavior was added.
public resetWeights ( Model $Model ) : boolean
$Model Model
return boolean success

setup() public method

public setup ( Model $Model, $config = [] )
$Model Model

sortBy() public method

Take in an order array and sorts the list based on that order specification and creates new weights for it. If no foreign key is supplied, all lists will be sorted.
public sortBy ( Model $Model, array $order, mixed $foreignKey = null )
$Model Model
$order array
$foreignKey mixed $returns boolean true if successfull

Property Details

$_defaults protected_oe property

foreign_key : (string) The field to identify one SET by. Each set has their own order (ie they start at 1). Set to FALSE to not use this feature (and use only 1 set)
protected $_defaults

$name public_oe property

public $name