You are here

function cmis_query_cmis_query in CMIS API 6

Executes CMIS search and process search return. $query CMIS SQL query.

1 call to cmis_query_cmis_query()
cmis_query_form_submit in cmis_query/cmis_query.module
Form submit for cmis_query_form

File

cmis_query/cmis_query.module, line 68
Search functions

Code

function cmis_query_cmis_query($query, $p = 1) {
  module_load_include('api.inc', 'cmis');

  // Set default page size
  $default_page_size = 10;
  $skip_count = ($p - 1) * $default_page_size;
  $repository = cmisapi_getRepositoryInfo();
  $query_result = cmisapi_query($repository->repositoryId, $query);
  if (false !== $query_result) {

    // Process the returned XML
    $contents = "<br/><b>Query results</b><br/>";
    $header = array(
      t('name'),
      t('type'),
      t('size'),
      t('author'),
      t('last modified'),
    );
    $folder_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/space.gif');
    $file_img = theme('image', drupal_get_path('module', 'cmis_browser') . '/images/file.png');
    for ($i = $skip_count; $i < sizeof($query_result); $i++) {
      $entry = $query_result[$i];
      if (empty($entry->title)) {
        continue;
      }
      $summary = $entry->summary;
      $type = $entry->type;
      $updated = $entry->updated;
      if ($updated) {
        $updatedStr = date_format($updated, 'n/j/Y g:i A');
      }
      if ($type == 'folder') {
        $folderlink = l($entry->title, 'cmis/browser' . $path . '/' . $entry->title);
        $rows[] = array(
          $folder_img . ' ' . $folderlink,
          'Space',
          '',
          $entry->author,
          $updatedStr,
        );
      }
      else {
        $size = $entry->size;
        $docType = $entry->contentMimeType;
        $icon = $entry->icon;
        $documentLink = l($entry->title, 'cmis/get', array(
          'query' => array(
            'id' => $entry->id,
          ),
        ));
        $rows[] = array(
          $file_img . $documentLink,
          $docType,
          number_format($size / 1000, 2, '.', ',') . ' K',
          $entry->author,
          $updatedStr,
        );
      }
    }
    $contents .= theme('table', $header, $rows);

    // Add pagination bar

    /* pagination disabled temp
       $base_search_url = 'cmis/query/?query='.$query.'&p=';
       $next_p = $p+1;
       $prev_p = $p-1;

       $contents .= '<div class="pagination">';
       if($p!=1)
             $contents .= l(t('Prev'), $base_search_url.$prev_p);

       // Check to see if it has next
       $contents .= l(t('Next'), $base_search_url.$next_p);*/
  }
  else {
    $contents = 'Error';
  }
  return $contents;
}