Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

create_collection()

Description

Creates a new collection for user $userid called $name

Parameters

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

Return

integer

Location

include/collections_functions.php lines 596 to 661

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] = escape_check($extraparams[$coloption]);
            }
        }

    
$setcolumns["name"]             = escape_check(mb_strcut($name0100));
    
$setcolumns["user"]             = is_numeric($userid) ? $userid 0;
    
$setcolumns["allow_changes"]    = escape_check($allowchanges);
    
$setcolumns["cant_delete"]      = escape_check($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"]   = escape_check($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
            ('" 
implode("','",$insert_values). "',NOW())";
    
    
sql_query($sql);

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

    return 
$ref;
    }

This article was last updated 11th May 2021 12:05 Europe/London time based on the source file dated 10th May 2021 09:15 Europe/London time.