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_resource_type_field()

Description

Create a new resource type field with the specified name of the required type

Parameters

ColumnTypeDefaultDescription
$name string - name of new field
$restype integer|array 0 - resource type - resource type(s) that field applies to (0 = global, single value = one type, array = multiple types)
$type integer FIELD_TYPE_TEXT_BOX_SINGLE_LINE - field type - refer to include/definitions.php
$shortname string "" - shortname of new field
$index boolean false - should new field be indexed?

Return

boolean|integer - ref of new field, false if unsuccessful

Location

include/resource_functions.php lines 8731 to 8779

Definition

 
function create_resource_type_field($name$restype 0$type FIELD_TYPE_TEXT_BOX_SINGLE_LINE$shortname ""$index=false)
    {
    if((
trim($name)=="") || !is_numeric($type) || !(is_numeric($restype) || is_array($restype)))
        {
        return 
false;
        }

    if(
trim($shortname) == "")
        {
        
$shortname mb_substr(mb_strtolower(str_replace(array("_""-"), ""safe_file_name($name))), 020);
        }

    
$duplicate = (boolean) ps_value("SELECT count(ref) AS `value` FROM resource_type_field WHERE `name` = ?", array("s",$shortname), 0"schema");
    
$order_by_current ps_value("SELECT MAX(order_by) AS `value` FROM resource_type_field",[],0,"schema");
    
$default_tab ps_value("SELECT MIN(ref) value FROM tab",[],0,"schema");

    
// Global type?
    
if ($restype==0)
        {
        
$global 1;
        
$restypes = [];
        }
    else
        {
        
$global 0;
        
$restypes is_array($restype) ? $restype : [$restype];
        }

    
ps_query("INSERT INTO resource_type_field (title, global, type, `name`, keywords_index, order_by, tab) VALUES (?, ?, ?, ?, ?, ?, ?)",
    array(
"s",$name,"i",$global,"i",$type,"s",$shortname,"i",($index "1" "0"),"i",$order_by_current+10,"i",$default_tab));
    
$new sql_insert_id();

    
// Add joins
    
foreach ($restypes as $resinsert)
        {
        
ps_query("INSERT INTO resource_type_field_resource_type (resource_type_field,resource_type) VALUES (?, ?)", array("i",$new,"i",$resinsert));
        }

    if(
$duplicate)
        {
        
ps_query("UPDATE resource_type_field SET `name` = ? WHERE ref = ?", array("s",$shortname $new,"i",$new));
        }

    
log_activity(nullLOG_CODE_CREATED$name'resource_type_field''title'$newnull'');

    
clear_query_cache("schema");

    return 
$new;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.