Collections functions
General functions
Render functions
Theme permission functions
Resource functions

reorder_collections()

Description

Re-order collections

Parameters

ColumnTypeDefaultDescription
$refs array List of collection IDs in the new order

Return

void

Location

include/collections_functions.php lines 6777 to 6804

Definition

 
function reorder_collections(array $refs)
    {
    
$refs array_values(array_filter($refs'is_int_loose'));
    
$order_by 0;

    
// Chunking the list of collection IDs in batches of 500 should be within the default max_allowed_packet size (with highest ID length)
    
$refs_chunked array_filter(count($refs) <= 500 ? [$refs] : array_chunk($refs500));
    foreach(
$refs_chunked as $refs)
        {
        
$cases_params = [];
        
$cases '';

        foreach(
$refs as $ref)
            {
            
$order_by += 10;
            
$cases .= ' WHEN ? THEN ?';
            
$cases_params array_merge($cases_params, ['i'$ref'i'$order_by]);
            }

        
$sql sprintf('UPDATE collection SET order_by = (CASE ref %s END) WHERE ref IN (%s)',
             
$cases,
             
ps_param_insert(count($refs))
         );
        
ps_query($sqlarray_merge($cases_paramsps_param_fill($refs'i')));
        }

    return;
    }

This article was last updated 30th June 2022 11:05 Europe/London time based on the source file dated 29th June 2022 17:05 Europe/London time.