PHP Trait Lookitsatravis\Listify\Listify

http://lookitsatravis.github.io/listify Ported from https://github.com/swanandp/acts_as_list
Author: Travis Vignon ([email protected])
Show file Open project: lookitsatravis/listify

Public Methods

Method Description
addNewAt ( ) : string Returns the value of the 'add_new_at' option
bootListify ( ) : boolean Returns whether the scope has changed during the course of interaction with the model
decrementPosition ( ) : void Decrease the position of this item without adjusting the rest of the list.
defaultPosition ( ) : mixed Get the default item position
getListifyPosition ( ) : integer Returns the value of the model's current position
higherItem ( ) : mixed Return the next higher item in the list.
higherItems ( integer $limit = NULL ) : mixed Return the next n higher items in the list. Selects all higher items by default
incrementPosition ( ) : void Increase the position of this item without adjusting the rest of the list.
initListify ( array $options = [] ) : void Required to override options and kick off the Listify's automatic list management.
insertAt ( integer $position = NULL ) : void Insert the item at the given position (defaults to the top position of 1).
isDefaultPosition ( ) : boolean Returns whether the item's current position matches the default position
isFirst ( ) : boolean Returns if this object is the first in the list.
isInList ( ) : boolean Returns whether the item is in the list
isLast ( ) : boolean Returns if this object is the last in the list.
isNotInList ( ) : boolean Returns whether the item is not in the list
listifyTop ( ) : string Get the value of the "top_of_list" option
lowerItem ( ) : mixed Return the next lower item in the list.
lowerItems ( integer $limit = NULL ) : mixed Return the next n lower items in the list. Selects all lower items by default.
moveHigher ( ) : void Swap positions with the next higher item, if one exists.
moveLower ( ) : void Swap positions with the next lower item, if one exists.
moveToBottom ( ) : void Move to the bottom of the list. If the item is already in the list, the items below it have their positions adjusted accordingly.
moveToTop ( ) : void Move to the top of the list. If the item is already in the list, the items above it have their positions adjusted accordingly.
positionColumn ( ) : string Get the name of the position 'column' option
removeFromList ( ) : void Removes the item from the list.
scopeInList ( $query ) : Eloquent An Eloquent scope that returns only items currently in the list
scopeListifyScope ( $query ) : Eloquent An Eloquent scope based on the processed scope option
scopeName ( ) : mixed Get the value of the 'scope' option
setListPosition ( integer $new_position ) : void Sets the new position and saves it
setListifyConfig ( $key, $value ) : void Updates a listify config value
setListifyPosition ( integer $position ) : void Sets the value of the model's position
swapChangedAttributes ( ) : void Temporarily swap changes attributes with current attributes

Private Methods

Method Description
addToListBottom ( ) : void Adds item to the bottom of the list
addToListTop ( ) : void Adds item to the top of the list
assumeBottomPosition ( ) : void Forces item to assume the bottom position in the list.
assumeTopPosition ( ) : void Forces item to assume the top position in the list.
bottomItem ( mixed $except = NULL ) : mixed Returns the bottom item
bottomPositionInList ( mixed $except = NULL ) : integer Returns the bottom position number in the list
checkScope ( ) : void Determines whether scope has changed. If so, it will move the current item to the top/bottom of the list and update all other items
decrementPositionsOnLowerItems ( integer $position = NULL ) : void This has the effect of moving all the lower items up one.
getConditionStringFromQueryBuilder ( $query ) : string Returns a raw WHERE clause based off of a Query Builder object
hasScopeChanged ( ) : boolean Returns whether the scope has changed during the course of interaction with the model
incrementPositionsOnAllItems ( ) : void Increments position of all items in the list.
incrementPositionsOnHigherItems ( ) : void This has the effect of moving all the higher items down one.
incrementPositionsOnLowerItems ( integer $position ) : void This has the effect of moving all the lower items down one.
insertAtPosition ( integer $position ) : void Inserts the item at a particular location in the list. All items around it will be modified
listifyList ( ) : mixed Creates an instance of the current class scope as a list
primaryKey ( ) : string Returns the primary key of the current Eloquent instance
reloadPosition ( ) : void Reloads the position value of the current item. This is only called when an item is deleted and is here to prevent unsetting the position column which would prevent other items from being moved properly
scopeCondition ( ) : string Returns the raw WHERE clause to be used as the Listify scope
shufflePositionsOnIntermediateItems ( integer $old_position, integer $new_position, string $avoid_id = NULL ) : void Reorders intermediate items to support moving an item from old_position to new_position.
updatePositions ( ) : void Updates all items based on the original position of the item and the new position of the item

Method Details

addNewAt() public method

Returns the value of the 'add_new_at' option
public addNewAt ( ) : string
return string

bootListify() public static method

Returns whether the scope has changed during the course of interaction with the model
public static bootListify ( ) : boolean
return boolean

decrementPosition() public method

Decrease the position of this item without adjusting the rest of the list.
public decrementPosition ( ) : void
return void

defaultPosition() public method

Get the default item position
public defaultPosition ( ) : mixed
return mixed

getListifyPosition() public method

Returns the value of the model's current position
public getListifyPosition ( ) : integer
return integer

higherItem() public method

Return the next higher item in the list.
public higherItem ( ) : mixed
return mixed Returned item will be of the same type as the current class instance

higherItems() public method

Return the next n higher items in the list. Selects all higher items by default
public higherItems ( integer $limit = NULL ) : mixed
$limit integer The number of items to return
return mixed Returned items will be of the same type as the current class instance

incrementPosition() public method

Increase the position of this item without adjusting the rest of the list.
public incrementPosition ( ) : void
return void

initListify() public method

Required to override options and kick off the Listify's automatic list management.
public initListify ( array $options = [] ) : void
$options array [column=>string, scope=>string|BelongsTo|Builder, top_of_list=>int, add_new_at=>string]
return void

insertAt() public method

Insert the item at the given position (defaults to the top position of 1).
public insertAt ( integer $position = NULL ) : void
$position integer
return void

isDefaultPosition() public method

Returns whether the item's current position matches the default position
public isDefaultPosition ( ) : boolean
return boolean

isFirst() public method

Returns if this object is the first in the list.
public isFirst ( ) : boolean
return boolean

isInList() public method

Returns whether the item is in the list
public isInList ( ) : boolean
return boolean

isLast() public method

Returns if this object is the last in the list.
public isLast ( ) : boolean
return boolean

isNotInList() public method

Returns whether the item is not in the list
public isNotInList ( ) : boolean
return boolean

listifyTop() public method

Get the value of the "top_of_list" option
public listifyTop ( ) : string
return string

lowerItem() public method

Return the next lower item in the list.
public lowerItem ( ) : mixed
return mixed Returned item will be of the same type as the current class instance

lowerItems() public method

Return the next n lower items in the list. Selects all lower items by default.
public lowerItems ( integer $limit = NULL ) : mixed
$limit integer The number of items to return
return mixed Returned items will be of the same type as the current class instance

moveHigher() public method

Swap positions with the next higher item, if one exists.
public moveHigher ( ) : void
return void

moveLower() public method

Swap positions with the next lower item, if one exists.
public moveLower ( ) : void
return void

moveToBottom() public method

Move to the bottom of the list. If the item is already in the list, the items below it have their positions adjusted accordingly.
public moveToBottom ( ) : void
return void

moveToTop() public method

Move to the top of the list. If the item is already in the list, the items above it have their positions adjusted accordingly.
public moveToTop ( ) : void
return void

positionColumn() public method

Get the name of the position 'column' option
public positionColumn ( ) : string
return string

removeFromList() public method

Removes the item from the list.
public removeFromList ( ) : void
return void

scopeInList() public method

An Eloquent scope that returns only items currently in the list
public scopeInList ( $query ) : Eloquent
$query
return Eloquent Query Builder instance

scopeListifyScope() public method

An Eloquent scope based on the processed scope option
public scopeListifyScope ( $query ) : Eloquent
$query An Eloquent Query Builder instance
return Eloquent Query Builder instance

scopeName() public method

Get the value of the 'scope' option
public scopeName ( ) : mixed
return mixed Can be a string, an Eloquent BelongsTo, or an Eloquent Builder

setListPosition() public method

Sets the new position and saves it
public setListPosition ( integer $new_position ) : void
$new_position integer
return void

setListifyConfig() public method

Updates a listify config value
public setListifyConfig ( $key, $value ) : void
return void

setListifyPosition() public method

Sets the value of the model's position
public setListifyPosition ( integer $position ) : void
$position integer
return void

swapChangedAttributes() public method

Temporarily swap changes attributes with current attributes
public swapChangedAttributes ( ) : void
return void