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

add_saved_search_items()

Description

Adds all the resources in the provided search to $collection

Parameters

ColumnTypeDefaultDescription
$collection integer
$search string ""
$restypes string ""
$archivesearch string ""
$order_by string "relevance"
$sort string "desc"
$daylimit string ""
$starsearch string ""
$res_access int "" The ID of the resource access level

Return

boolean

Location

include/collections_functions.php lines 1847 to 1956

Definition

 
function add_saved_search_items($collection$search ""$restypes ""$archivesearch ""$order_by "relevance"$sort "desc"$daylimit ""$starsearch "",$res_access "")
    {
    if((string)(int)
$collection != $collection)
        {
        
// Not an integer
        
return false;
        }
    
    global 
$collection_share_warning$collection_allow_not_approved_share$userref$collection_block_restypes$search_all_workflow_states;
    
    
# Adds resources from a search to the collection.
    
if($search_all_workflow_states && != $archivesearch)
        {
        
$search_all_workflow_states false;
        }
   
    
$results=do_search($search$restypes$order_by$archivesearch,-1,$sort,false,$starsearch,false,false,$daylimit,false,true,false,false,false,$res_access);

    if(!
is_array($results) || count($results) == 0)
        {
        return 
false;
        }
        
    
# Check if this collection has already been shared externally. If it has, we must add a further entry
    # for this specific resource, and warn the user that this has happened.
    
$keys get_collection_external_access($collection);
    
$resourcesnotadded = array(); # record the resources that are not added so we can display to the user
    
$blockedtypes = array();# Record the resource types that are not added 
    
    // To maintain current collection order but add the search items in the correct order we must first ove the existing collection resoruces out the way
    
$searchcount count($results);
    if(
$searchcount 0)
        {
        
sql_query("UPDATE collection_resource SET sortorder = if(isnull(sortorder),'" $searchcount "',sortorder + '" $searchcount "') WHERE collection='" $collection "'");
        }

    for (
$r=0;$r<$searchcount;$r++)
        {
        
$resource=$results[$r]["ref"];
        
$archivestatus=$results[$r]["archive"];
        
        if(
in_array($results[$r]["resource_type"],$collection_block_restypes))
            {
            
$blockedtypes[] = $results[$r]["resource_type"];
            continue;
            }

        if (
count($keys)>0)
            {            
            if (
$archivestatus<&& !$collection_allow_not_approved_share)
                {
                
$resourcesnotadded[$resource] = $results[$r];
                continue;
                }
            for (
$n=0;$n<count($keys);$n++)
                {
                
# Insert a new access key entry for this resource/collection.
                
sql_query("insert into external_access_keys(resource,access_key,user,collection,date,expires,access,usergroup,password_hash) values ('" escape_check($resource) . "','" escape_check($keys[$n]["access_key"]) . "','$userref','" escape_check($collection) . "',now()," . ($keys[$n]["expires"]==''?'null':"'" escape_check($keys[$n]["expires"]) . "'") . ",'" escape_check($keys[$n]["access"]) . "'," . (($keys[$n]["usergroup"]!="")?"'" escape_check($keys[$n]["usergroup"]) ."'":"NULL") . ",'" $keys[$n]["password_hash"] . "')");
                
#log this
                
collection_log($collection,"s",$resource$keys[$n]["access_key"]);    
                
                
# Set the flag so a warning appears.
                
$collection_share_warning=true;    
                }
            }
        }    
        
        
    if (
is_array($results))
        {        
        
$modifyNotAdded hook('modifynotaddedsearchitems''', array($results$resourcesnotadded));
        if (
is_array($modifyNotAdded))
            
$resourcesnotadded $modifyNotAdded;

        for (
$n=0;$n<$searchcount;$n++)
            {
            
$resource=$results[$n]["ref"];
            if (!isset(
$resourcesnotadded[$resource]) && !in_array($results[$n]["resource_type"],$collection_block_restypes))
                {
                
sql_query("delete from collection_resource where resource='$resource' and collection='$collection'");
                
sql_query("insert into collection_resource(resource,collection,sortorder) values ('$resource','$collection','$n')");
                
                
#log this
                
collection_log($collection,"a",$resource);
                }
            }
        }

    if (!empty(
$resourcesnotadded) || count($blockedtypes)>0)
        {
        
# Translate to titles only for displaying them to the user
        
global $view_title_field;
        
$titles = array();
        foreach (
$resourcesnotadded as $resource)
            {
            
$titles[] = i18n_get_translated($resource['field' $view_title_field]);
            }
        if(
count($blockedtypes)>0)
            {
            
$blocked_restypes=array_unique($blockedtypes);
            
// Return a list of blocked resouce types
            
$titles["blockedtypes"]=$blocked_restypes;
            }
        return 
$titles;
        }
    if(
count($blockedtypes)>0)
        {
        }
    return array();
    }

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