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

create_collection()

Parameters

ColumnTypeDefaultDescription
$userid
$name
$allowchanges 0
$cant_delete 0
$ref 0
$public false
$extraparams array

Location

include/collections_functions.php lines 815 to 882

Definition

 
function create_collection($userid,$name,$allowchanges=0,$cant_delete=0,$ref=0,$public=false$extraparams=array())
    {
    
debug_function_call("create_collection"func_get_args());

    global 
$username,$anonymous_login,$rs_session$anonymous_user_session_collection;
    if((
$username==$anonymous_login && $anonymous_user_session_collection) || upload_share_active())
        {       
        
// We need to set a collection session_id for the anonymous user. Get session ID to create collection with this set
        
$rs_session=get_rs_session_id(true);
        }
    else
        {   
        
$rs_session="";
        }
        
    
$setcolumns = array();
    
$extracolopts = array("type",
                        
"keywords",
                        
"saved_search",
                        
"session_id",
                        
"description",
                        
"savedsearch",
                        
"parent",
                        
"thumbnail_selection_method",
                    );
    foreach(
$extracolopts as $coloption)
        {
        if(isset(
$extraparams[$coloption]))
            {
            
$setcolumns[$coloption] = $extraparams[$coloption];
            }
        }

    
$setcolumns["name"]             = mb_strcut($name0100);
    
$setcolumns["user"]             = is_numeric($userid) ? $userid 0;
    
$setcolumns["allow_changes"]    = $allowchanges;
    
$setcolumns["cant_delete"]      = $cant_delete;
    
$setcolumns["public"]           = $public COLLECTION_TYPE_PUBLIC COLLECTION_TYPE_STANDARD;
    if(
$ref != 0)
        {
        
$setcolumns["ref"] = (int)$ref;
        }
    if(
is_int_loose(trim($rs_session)))
        {
        
$setcolumns["session_id"]   = $rs_session;
        }
    if(
$public)
        {
        
$setcolumns["type"]         = COLLECTION_TYPE_PUBLIC;
        }

    
$insert_columns array_keys($setcolumns);
    
$insert_values  array_values($setcolumns);
    
    
$sql "INSERT INTO collection
            (" 
implode(",",$insert_columns) . ", created)
            VALUES
            ("
ps_param_insert(count($insert_values)) .",NOW())";
    
    
ps_query($sqlps_param_fill($insert_values's'));

    
$ref sql_insert_id();
    
index_collection($ref);

    
clear_query_cache('collection_access' $userid);

    return 
$ref;
    }

This article was last updated 8th December 2024 10:05 Europe/London time based on the source file dated 4th December 2024 16:35 Europe/London time.