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

update_collection_order()

Description

Reorder the items in a collection using $neworder as the order by metric

Parameters

ColumnTypeDefaultDescription
$neworder array Array of columns to order by
$collection integer
$offset integer 0

Return

void

Location

include/collections_functions.php lines 3032 to 3071

Definition

 
function update_collection_order($neworder$collection$offset 0)
{
    global 
$pagename$username;

    if (!
is_array($neworder)) {
        exit(
"Error: invalid input to update collection function.");
    }

    
$neworder array_filter($neworder'is_numeric');
    if (
count($neworder) > 0) {
        
$updatesql "update collection_resource set sortorder=(case resource ";
        
$counter $offset;
        
$params = [];
        foreach (
$neworder as $colresource) {
            
$updatesql .= "when ? then ? ";
            
$params array_merge($params, ['i'$colresource'i'$counter]);
            
$counter++;
        }
        
$updatesql .= "else sortorder END) WHERE collection= ?";
        
ps_query($updatesqlarray_merge($params, ['i'$collection]));
    }
    
$updatesql "update collection_resource set sortorder=99999 WHERE collection= ? and sortorder is NULL";
    
ps_query($updatesql, ['i'$collection]);
    
// Only log reordering if there is something new to log, i.e. different user, ordered from a different page
    
$last_log get_collection_log($collection1);
    if (
        (
            
count($last_log['data']) > 0
            
&& (
                
$last_log['data'][0]['type'] !== LOG_CODE_COLLECTION_REORDER 
                
|| date('Y-m-d'strtotime($last_log['data'][0]['date'])) !== date('Y-m-d')
                || 
strpos($last_log['data'][0]['notes'], $pagename) == 0
                
|| $last_log['data'][0]['username'] !== $username
            
)
        )
        || 
count($last_log['data']) == 0
    
) {
        
collection_log($collectionLOG_CODE_COLLECTION_REORDERnull"Collection reordered via " $pagename);
    }
}

This article was last updated 19th March 2026 12:35 Europe/London time based on the source file dated 17th March 2026 15:20 Europe/London time.