Esempio n. 1
0
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));
	
	# For the given field, fetch a stats count for each keyword.
	$usage=sql_query("select rk.resource_type_field,k.keyword,count(*) c from resource_keyword rk join keyword k on rk.keyword=k.ref where resource_type_field='$field' group by k.keyword");
	
	$return=array();
	for ($n=0;$n<count($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;
	}
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));
    # For the given field, fetch a stats count for each keyword.
    $usage = sql_query("\n\t\t  SELECT rk.resource_type_field,\n\t\t         k.keyword,\n\t\t         count(DISTINCT rk.resource) c\n\t\t    FROM resource_keyword rk\n\t\t    JOIN keyword k ON rk.keyword = k.ref\n\t\t   WHERE rk.resource > 0\n\t\t     AND resource_type_field = '{$field}'\n\t\tGROUP BY k.keyword;\n\t");
    $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;
}