Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The behavior adds the following methods to the extended model classes:

getPosition(): Gets the position of a sortable object

setPosition($position): Sets the position of a sortable object. Beware that there is no check made on the value passed. If the position already exists, or if it is superior to the highest position + 1, the method does not throw any exception

getNext(): Returns the next item in the list, i.e. the one for which position is immediately higher

getPrevious(): Returns the previous item in the list, i.e. the one for which position is immediately lower

isFirst(): Checks if the object is first in the list, i.e. if it has 1 for position

isLast(): Checks if the object is last in the list, i.e. if its position is the highest position

moveUp(): Moves the object higher in the list, i.e. exchanges its position with the one of the previous object

moveDown(): Moves the object lower in the list, i.e. exchanges its position with the one of the next object

swapWith($object): Exchanges the position of the object with the one passed as argument

moveToPosition($object, $newPosition, $con = null): Moves the object to a new position, and shifts the position of the objects inbetween the old and new position accordingly

moveToTop($object, $con = null): Moves the object to the top of the list (i.e. gives it position 1), and shifts the position of the objects lower in the list accordingly

moveToBottom($object, $con = null): Moves the object to the top of the list (i.e. gives it position maxPosition), and shifts the position of the objects higher in the list accordingly

insertAtPosition($object, $position, $con = null): Inserts the object in the list at a given position, and shifts the position of the objects lower in the list accordingly

Behaviors cannot automatically extend the Peer classes (due to limitations of PHP). However, if you followed the optional installation instruction, the Peer class of a sortable model can also have new static methods:

retrieveByPosition($position, $con = null): Returns an item from the list based on its position

getMaxPosition($con = null): Returns the highest position of a class of sortable objects

doSort($order, $con = null): Reorders a set of sortable objects based on a list of id/position. Beware that there is no check made on the positions passed, so incoherent positions will result in an incoherent list.

If you don't want to copy the code, you can still use the static methods of the sfPropelActAsSortableBehavior class, with an additional parameter at the beginning being the Peer class name.

Todo

add more documentation and usage examples

add removeFromList() method to remove an element from the list without deleting it