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

get_field_options_with_stats()

Parameters

ColumnTypeDefaultDescription
$field

Location

include/resource_functions.php lines 4295 to 4335

Definition

 
function get_field_options_with_stats($field)
    {
    
# For a given field, list all options with usage stats.
    # This is for the 'manage field options' page.

    //$rawoptions=sql_value("select options value from resource_type_field where ref='$field'","");
    //$options=trim_array(explode(",",i18n_get_translated($rawoptions)));
    //$rawoptions=trim_array(explode(",",$rawoptions));

    
$rawoptions=array();
    
node_field_options_override($rawoptions,$field);

    
# For the given field, fetch a stats count for each keyword.
    
$usage=sql_query("
          SELECT rk.resource_type_field,
                 k.keyword,
                 count(DISTINCT rk.resource) c
            FROM resource_keyword rk
            JOIN keyword k ON rk.keyword = k.ref
           WHERE rk.resource > 0
             AND resource_type_field = '
$field'
        GROUP BY k.keyword;
    "
);
    
    
$return=array();
    for (
$n=0;$n<count($options);$n++)
        {
        if(
$options[$n]!=''){
            
# Find the option in the usage array and extract the count
            
$count=0;
            for (
$m=0;$m<count($usage);$m++)
                {
                
$keyword=get_keyword_from_option($options[$n]);
                if (
$keyword==$usage[$m]["keyword"]) {$count=$usage[$m]["c"];}
                }
                
            
$return[]=array("option"=>$options[$n],"rawoption"=>$rawoptions[$n],"count"=>$count);
            }
        }
    return 
$return;
    }

This article was last updated 8th July 2020 11:35 Europe/London time based on the source file dated 7th July 2020 16:18 Europe/London time.