Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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.