Collections functions
General functions
Render functions
Theme permission functions
Resource 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 0 - resource type - resource type that field applies to (0 = global)
$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 8222 to 8250

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))
        {
        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");

    
ps_query("INSERT INTO resource_type_field (title, resource_type, type, `name`, keywords_index) VALUES (?, ?, ?, ?, ?)",
    array(
"s",$name,"i",$restype,"i",$type,"s",$shortname,"i",($index "1" "0")));
    
$new sql_insert_id();

    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 4th October 2022 11:05 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.