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

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 3183 to 3224

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 4th December 2024 09:05 Europe/London time based on the source file dated 27th November 2024 15:30 Europe/London time.