Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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.