All Projects → ADmad → cakephp-sequence

ADmad / cakephp-sequence

Licence: MIT license
CakePHP plugin for maintaining a contiguous sequence of records

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to cakephp-sequence

cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (+17.07%)
Mutual labels:  cakephp, cakephp-plugin
Orderly
Default ordering for your CakePHP tables
Stars: ✭ 21 (-48.78%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-feed
CakePHP Plugin with RssView to create RSS feeds.
Stars: ✭ 13 (-68.29%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Jwt Auth
A CakePHP plugin for authenticating using JSON Web Tokens
Stars: ✭ 153 (+273.17%)
Mutual labels:  cakephp, cakephp-plugin
elastic-search
Elastic search datasource for CakePHP
Stars: ✭ 85 (+107.32%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Csvview
CakePHP: A view class for generating CSV
Stars: ✭ 174 (+324.39%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-i18n
A CakePHP plugin with I18n related tools.
Stars: ✭ 40 (-2.44%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Proffer
An upload plugin for CakePHP 3
Stars: ✭ 121 (+195.12%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-glide
CakePHP plugin for using Glide image manipulation library
Stars: ✭ 34 (-17.07%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-shim
CakePHP plugin to "shim" functionality up and down for major versions of the framework.
Stars: ✭ 37 (-9.76%)
Mutual labels:  cakephp, cakephp-plugin
Search
CakePHP: Easy model searching
Stars: ✭ 153 (+273.17%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-translate
A CakePHP plugin to manage translations of your static content the easy way via web backend.
Stars: ✭ 18 (-56.1%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Imagine Plugin
CakePHP wrapper for the powerful Imagine image processing library. Makes images manipulation easy and powerful.
Stars: ✭ 140 (+241.46%)
Mutual labels:  cakephp, cakephp-plugin
auth
Auth objects for CakePHP
Stars: ✭ 28 (-31.71%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Ide Helper
IDE Helper plugin for CakePHP
Stars: ✭ 138 (+236.59%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-error-email
ErrorEmail Plugin for CakePHP3.x
Stars: ✭ 16 (-60.98%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Tinyauth
CakePHP TinyAuth plugin for an easy and fast user authentication and authorization. Single or multi role. DB or config file based.
Stars: ✭ 114 (+178.05%)
Mutual labels:  cakephp, cakephp-plugin
Migrations
CakePHP database migrations plugin
Stars: ✭ 114 (+178.05%)
Mutual labels:  cakephp, cakephp-plugin
plum search
Plum Search plugin for CakePHP
Stars: ✭ 20 (-51.22%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-ajax
AJAX for CakePHP: A plugin to ease handling AJAX requests.
Stars: ✭ 55 (+34.15%)
Mutual labels:  cakephp, cakephp-plugin

Sequence plugin to maintain ordered list of records

Build Status Coverage Total Downloads License

Installation

Install this plugin into your CakePHP application using composer:

composer require admad/cakephp-sequence

Then load the plugin by running CLI command:

./bin/cake plugin load ADmad/Sequence

How it works

SequenceBehavior provided by this plugin maintains a contiguous sequence of integers in a selected column, for records in a table records (optionally with grouping) when adding, editing (including moving groups) or deleting records.

Usage

Add the SequenceBehavior for your table and viola:

$this->addBehavior('ADmad/Sequence.Sequence');

You can customize various options as shown:

$this->addBehavior('ADmad/Sequence.Sequence', [
    'sequenceField' => 'position', // Field to use to store integer sequence. Default "position".
    'scope' => ['group_id'], // Array of field names to use for grouping records. Default [].
    'startAt' => 1, // Initial value for sequence. Default 1.
]);

Now whenever to add a new record its position field will be automatically set to current largest value in sequence plus one.

When editing records you can set the position to a new value and the position of other records in the list will be automatically updated to maintain proper sequence.

When doing a find on the table an order clause is automatically added to the query to order by the position field if a order clause has not already been set.

Methods

moveUp(\Cake\Datasource\EntityInterface $entity)

Move up record by one position:

$modelObject->moveUp($entity);

moveDown(\Cake\Datasource\EntityInterface $entity)

Move down record by one position:

$modelObject->moveDown($entity);

setOrder(array $record)

Set order for list of records provided. Records can be provided as array of entities or array of associative arrays like [['id' => 1], ['id' => 2]] or array of primary key values like [1, 2].

Acknowledgement

Shout out to @neilcrookes for his wonderful Sequence Behavior for CakePHP 1.3 which was the inspiration for this plugin.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].