PHP code example of serj / sortable

1. Go to this page and download the library: Download serj/sortable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

serj / sortable example snippets


'components' => [
    //...
    'sortableCartoons' => [
        'class' => 'serj\sortable\Sortable',
        'targetTable' => 'cartoons',
        'srtColumn' => 'sort_inner'
    ]
]

'components' => [
    'sortInSingleCat' => [
        'class' => 'serj\sortable\Sortable',
        'targetTable' => 'cartoons',
        'grpColumn' => 'category_id',
        'pkColumn' => 'id',
        'srtColumn' => 'sort_inner',
        'skipRows' => [
            'archived' => true,
            'color' => false
        ]
    ],
    'sortThroughAllCat' => [
        'class' => 'serj\sortable\Sortable',
        'targetTable' => 'cartoons',
        'pkColumn' => 'id',
        'srtColumn' => 'sort_general',
        'skipRows' => [
            'archived' => true,
            'color' => false
        ]
    ]
]

$sortThroughAllCat = new \serj\sortable\Sortable([
    'targetTable' => 'cartoons',
    'pkColumn' => 'id',
    'srtColumn' => 'sort_general',
    'skipRows' => [
        'archived' => true,
        'color' => false
    ]
]);

$sortValLocal = \Yii::$app->sortInSingleCat->getSortVal(5, 'after', 15);
$sortValGeneral = \Yii::$app->sortThroughAllCat->getSortVal(5, 'after');

$sortValLocal = \Yii::$app->sortInSingleCat->getSortVal(5, 'before', 15);
$sortValGeneral = \Yii::$app->sortThroughAllCat->getSortVal(5, 'before');

(new Cartoon)->setAttributes([
    'title' => 'Some title',
    'category_id' => 15,
    'sort_local' => $sortValLocal,
    'sort_general' => $sortValGeneral
])->save();

// 15 is a category_id (srtColumn)
$sortValLocal = \Yii::$app->sortInSingleCat->getSortValBeforeAll(15);
$sortValGeneral = \Yii::$app->sortThroughAllCat->getSortValBeforeAll();

// 15 is a category_id (srtColumn)
$sortValLocal = \Yii::$app->sortableCartoons->getSortValAfterAll(15);
$sortValGeneral = \Yii::$app->sortThroughAllCat->getSortValAfterAll();

$sortValLocal = \Yii::$app->sortableCartoons->getIniSortVal();

//to insert to the end of the list in terms of the entire table
$sortValGeneral = \Yii::$app->sortThroughAllCat->getSortValAfterAll();

    'skipRows' => [
        'archived' => true,
        'color' => false
    ]

$connection = new \yii\db\Connection($config)
\Yii::$app->sortableCartoons->setDb($connection);

'components' => [
    'anotherDb' => [
        'class' => 'yii\db\Connection',
        ...
    ],
    ...
    'sortInSingleCat' => [
        'class' => 'serj\sortable\Sortable',
        'dbComponentId' => 'anotherDb'
        ...
    ],
    ...
]

'components' => [
    'sortInSingleCat' => [
        'class' => 'serj\sortable\Sortable',
        'databaseDriver' => serj\sortable\Sortable::DB_DRIVER_MYSQL
        ...
    ],
    ...
]