Collections functions
General functions
Node functions
Render functions
Theme permission functions
User 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 3152 to 3193

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.");
    }
    
    
$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 19th March 2024 04:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.