Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -425,6 +425,42 @@ |
426 | 426 | return $pages; |
427 | 427 | } |
428 | 428 | |
| 429 | + /** |
| 430 | + * Creates an array of values that match the specified source name and type, |
| 431 | + * for use by both Javascript autocompletion and comboboxes. |
| 432 | + */ |
| 433 | + static function getAutocompleteValues( $source_name, $source_type ) { |
| 434 | + $names_array = array(); |
| 435 | + // the query depends on whether this is a property, category, concept |
| 436 | + // or namespace |
| 437 | + if ( $source_type == 'property' || $source_type == 'attribute' || $source_type == 'relation' ) { |
| 438 | + $names_array = self::getAllValuesForProperty( $source_name ); |
| 439 | + } elseif ( $source_type == 'category' ) { |
| 440 | + $names_array = self::getAllPagesForCategory( $source_name, 10 ); |
| 441 | + } elseif ( $source_type == 'concept' ) { |
| 442 | + $names_array = self::getAllPagesForConcept( $source_name ); |
| 443 | + } else { // i.e., $source_type == 'namespace' |
| 444 | + // switch back to blank for main namespace |
| 445 | + if ( $source_name == "Main" ) |
| 446 | + $source_name = ""; |
| 447 | + $names_array = self::getAllPagesForNamespace( $source_name ); |
| 448 | + } |
| 449 | + return $names_array; |
| 450 | + } |
| 451 | + |
| 452 | + /** |
| 453 | + * Helper function to get an array of values out of what may be either |
| 454 | + * an array or a delimited string |
| 455 | + */ |
| 456 | + static function getValuesArray( $value, $delimiter ) { |
| 457 | + if ( is_array( $value ) ) { |
| 458 | + return $value; |
| 459 | + } else { |
| 460 | + // remove extra spaces |
| 461 | + return array_map( 'trim', explode( $delimiter, $value ) ); |
| 462 | + } |
| 463 | + } |
| 464 | + |
429 | 465 | static function getValuesFromExternalURL( $external_url_alias, $substring ) { |
430 | 466 | global $sfgAutocompletionURLs; |
431 | 467 | if ( empty( $sfgAutocompletionURLs ) ) return array(); |