Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 2280 to 2317

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='$collection' and resource in ('$resource1','$resource2')  order by sortorder asc, date_added desc";
    
$existingorder sql_query($query);

    
$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++;    
    }

    
    
$sql1 "update collection_resource set date_added = '" $rec[1]['date_added'] . "', 
        sortorder = " 
$rec[1]['sortorder'] . " where collection = '$collection
        and resource = '" 
$rec[2]['resource'] . "'";

    
$sql2 "update collection_resource set date_added = '" $rec[2]['date_added'] . "', 
        sortorder = " 
$rec[2]['sortorder'] . " where collection = '$collection
        and resource = '" 
$rec[1]['resource'] . "'";

    
sql_query($sql1);
    
sql_query($sql2);

    }

This article was last updated 30th November 2020 20:05 Europe/London time based on the source file dated 30th November 2020 16:50 Europe/London time.