diff --git a/includes/content_model.autocomplete.inc b/includes/content_model.autocomplete.inc new file mode 100644 index 00000000..2392ab2e --- /dev/null +++ b/includes/content_model.autocomplete.inc @@ -0,0 +1,73 @@ + $label) { + if (preg_match("/{$string}/i", $label) !== 0) { + $output[$model] = $label; + } + } + return drupal_json_output($output); +} + +/** + * Gets a map of form names suitable for use as select #options. + */ +function islandora_get_content_model_names() { + $results = islandora_query_content_models(); + $ret = array(); + foreach ($results as $result) { + $ret[$result['model']['value']] = "{$result['label']['value']} ({$result['model']['value']})"; + } + return $ret; +} + +/** + * Perform a resource index query to determine get a list of content models. + * + * Only returns content models with at least one subscribing object. + * + * @return array + * An array of RI results, as given by the Tuque RI query interface. + */ +function islandora_query_content_models() { + $connection = islandora_get_tuque_connection(); + if ($connection) { + $query = 'select $model $label from <#ri> where + $model and $model $label + minus $model + minus $model + minus $model + minus $model '; + $results = $connection->repository->ri->itqlQuery($query); + return $results; + } + return array(); +} + +/** + * Minor array transformation. + * + * @param array $content + * The array of results as returned from Tuque's RI query interface. + * @return array + * An array of results in a more usable format. + */ +function islandora_parse_query($content) { + $content_models = array(); + foreach ($content as $model) { + $content_models[] = $model['object']['value']; + } + $content_models = array_unique($content_models); + $content_models = array_values($content_models); + return $content_models; +} diff --git a/islandora.module b/islandora.module index 79672625..974d526e 100644 --- a/islandora.module +++ b/islandora.module @@ -52,6 +52,9 @@ define('ISLANDORA_DATASTREAM_MODIFIED_HOOK', 'islandora_datastream_modified'); define('ISLANDORA_DATASTREAM_PURGED_HOOK', 'islandora_datastream_purged'); define('ISLANDORA_INGEST_STEP_HOOK', 'islandora_ingest_steps'); +// Autocomplete paths. +define('ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE', 'islandora/autocomplete/content-models'); + /** * Implements hook_menu(). * @@ -246,6 +249,15 @@ function islandora_menu() { 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), 'load arguments' => array(2), ); + $items[ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE] = array( + 'title' => 'Autocomplete callback', + 'description' => 'Autocomplete a Fedora content model PID.', + 'file' => 'includes/content_model.autocomplete.inc', + 'page callback' => 'islandora_content_model_autocomplete', + 'page arguments' => array(3), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, + ); return $items; }