Download the PHP package nickbeen/sequential-rank without Composer

On this page you can find all versions of the php package nickbeen/sequential-rank. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sequential-rank

Sequential Rank

Latest version Build status Total downloads PHP Version License

Simple ranking system for ordering results by sequence. Usually you'll need to sort your results alphabetically or chronologically (or even manually), but what if you need to order specific fields based on their exact order. Doable when working with justs integers or a handful of possible sequences, but can get quite complicated with dozens of possible sequences. Be sure to check the example if the concept sounds too vague.

Sequential Ranking is a simple ranking system that relies on ordering instructions provided by you. While number based ranking systems require updating many -if not all- models, ranking systems such as Sequential Rank only need to update the re-ordered model.

Requirements

Installation

Install the library into your project with Composer.

Usage

The library requires the data to be injected into the constructor as an array. You can provide instructions for ordening with either an array or an enum. While get() returns the sequential ranks, you can also just call orderBy() to get your original array in the correct order.

Order by array

The most common way to provide instructions for ordering is to use an associative array. When working with databases, constructing an array is the most straight-forward choice.

Order by enum

Another way to provide instructions for ordering is to use an enumeration. Enums allows you to bundle both the values and the provided order into one file. Useful when you want your application instead of your database to keep tabs of the desired order.

Your enum must provide an order() method containing the order you want. This implementation ensures your data and order stay decoupled to remove any friction when adding or updating the model.

Order without provided order

If no order is provided, the results will be ordered by natural sort. In short this means strings will be ordered in alphabetical order while multi-digit numbers are treated atomically. This is only useful when your values and display order are identical.

Example

We need to document a list of attacks of a video game. Each attack has its own input consisting of a sequence of buttons. To keep things readable, we need to display the list of attacks in a specific order. First, we need to document which buttons could exist in the list of attacks, and while we're at it, decide on a display order for these buttons.

Notice how we increased the order by 10 for each button. This allows us to add new buttons in the future without needing to reorganise and re-order the whole list of attacks. If you expect to frequently add new fields, you should use bigger gaps. Since the whole ranking system is driven by natural sorting, you can also use more complicated values to e.g. categorize values like a-10 or d1-a4.

Anyway, now let's think of a list of attacks containing any of these 8 buttons.

Let's start using Sequential Rank to reorder the list of attacks to be more readable.

We're calling get() to get the actual Sequential Ranks returned to us.

When working with a database, you can save the Sequential Rank with the attack data and instruct your database to order by Sequential Rank to get what we want.

id buttons sequential_rank
5 forward, forward, b 10-10-80
2 forward, down, y 10-20-60
7 forward, back, x 10-30-50
1 down, forward, y 20-10-60
8 back, x, down, y ,a 30-50-20-60-70
6 back, a, y 30-70-60
3 up, x 40-50
4 x, y, a 50-60-70

FAQ

What are the pitfalls of Sequential Rank?

A poorly constructed order (e.g. 1,2,3,4) can force you to reorganize your order and recalculate the Sequential Ranks of all your models. One could debate if a string-based field is less performant than an integer based id, but putting an index on the Sequential Rank in your database will definitely help. Lastly, Sequential Rank is not battle-tested.

If you need something more robust, find a package that incorporates Lexorank, the ranking system that drives the drag 'n drop ordering in JIRA. Lexorank offers better tools for easy reordering, but however require you to calculate the exact positions due to its agnostic state.

How should I store Sequential Ranks in my database?

I recommend using a VARCHAR(255) column unless you're absolutely positively able to predict the future changes to the order and structure of your data.

License

This library is licensed under the MIT License (MIT). See the LICENSE for more details.


All versions of sequential-rank with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nickbeen/sequential-rank contains the following files

Loading the files please wait ....