Collections functions
General functions
Render functions
Theme permission functions
Resource functions

swap_collection_order()

Description

Inserts $resource1 into the position currently occupied by $resource2

Parameters

ColumnTypeDefaultDescription
$resource1 integer
$resource2 integer
$collection integer

Return

void

Location

include/collections_functions.php lines 3035 to 3077

Definition

 
function swap_collection_order($resource1,$resource2,$collection)
    {

    
// sanity check -- we should only be getting IDs here
    
if (!is_numeric($resource1) || !is_numeric($resource2) || !is_numeric($collection)){
        exit (
"Error: invalid input to swap collection function.");
    }
    
//exit ("Swapping " . $resource1 . " for " . $resource2);
    
    
$query "select resource,date_added,sortorder  from collection_resource where collection=? and resource in (?,?)  order by sortorder asc, date_added desc";
    
$existingorder ps_query($query,array("i",$collection,"i",$resource1,"i",$resource2));

    
$counter 1;
    foreach (
$existingorder as $record){
        
$rec[$counter]['resource']= $record['resource'];        
        
$rec[$counter]['date_added']= $record['date_added'];
        if (
strlen($record['sortorder']) == 0){
            
$rec[$counter]['sortorder'] = "NULL";
        } else {        
            
$rec[$counter]['sortorder']= "'" $record['sortorder'] . "'";
        }
            
        
$counter++;    
    }

    
ps_query("update collection_resource set date_added = ?, sortorder = ? where collection = ? and resource = ?"
        [
        
's'$rec[1]['date_added'],
        
'i'$rec[1]['sortorder'], 
        
'i'$collection
        
'i'$rec[2]['resource']
        ]
    );
    
ps_query("update collection_resource set date_added = ?, sortorder = ? where collection = ? and resource = ?",
        [
        
's'$rec[2]['date_added'],
        
'i'$rec[2]['sortorder'], 
        
'i'$collection
        
'i'$rec[1]['resource']
        ]
    );

    }

This article was last updated 3rd October 2022 12:35 Europe/London time based on the source file dated 22nd September 2022 11:00 Europe/London time.