Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 3203 to 3225

Definition

 
function update_collection_order($neworder,$collection,$offset=0)
    {   
    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]);
    }

This article was last updated 19th March 2024 06:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.