You are here

function cmis_path_autocomplete in CMIS API 6

Utitily function for supporting CMIS repository path auto-complete.

1 string reference to 'cmis_path_autocomplete'
cmis_menu in ./cmis.module
Implementation of hook_menu() for CMIS module.

File

./cmis.module, line 126

Code

function cmis_path_autocomplete() {
  module_load_include('api.inc', 'cmis');
  $args = func_get_args();
  $path = '/' . implode('/', array_slice($args, 0, sizeof($args) - 1));
  $key = end($args);
  $matches = array();
  $repository = cmisapi_getRepositoryInfo();
  if ($path == '/') {
    $folderId_parts = explode('/', $repository->rootFolderId);
    $path = '/' . end($folderId_parts);
    $matches[$path] = $path;
    print drupal_to_js($matches);
    return;
  }
  $folderObject = cmisapi_getProperties($repository->repositoryId, drupal_urlencode($path));
  foreach (array(
    'folder',
    'document',
  ) as $cmis_base_type) {
    $cmis_objects = cmisapi_query($repository->repositoryId, "SELECT * FROM {$cmis_base_type} WHERE " . ($key != '*' ? "Name like '%{$key}%' AND" : "") . " IN_FOLDER('{$folderObject->id}')");
    foreach ($cmis_objects as $cmis_object) {
      $matches[$path . '/' . $cmis_object->title . ($cmis_base_type == 'folder' ? '/' : '')] = $cmis_object->title;
    }
  }
  print drupal_to_js($matches);
}