You are here

private function CmisQueryForm::prepareResult in CMIS API 8.2

Same name and namespace in other branches
  1. 8 src/Form/CmisQueryForm.php \Drupal\cmis\Form\CmisQueryForm::prepareResult()
  2. 3.0.x src/Form/CmisQueryForm.php \Drupal\cmis\Form\CmisQueryForm::prepareResult()

Prepare results to rendered table.

Parameters

array $results: Get result.

string $query: CMIS query.

Return value

string Return content.

1 call to CmisQueryForm::prepareResult()
CmisQueryForm::queryExec in src/Form/CmisQueryForm.php
Execute query string.

File

src/Form/CmisQueryForm.php, line 161

Class

CmisQueryForm
Provides a form with a documents list.

Namespace

Drupal\cmis\Form

Code

private function prepareResult(array $results, $query) {
  $content = '';
  $rows = [];
  $table_header = [
    $this
      ->t('Name'),
    $this
      ->t('Details'),
    $this
      ->t('Author'),
    $this
      ->t('Created'),
    $this
      ->t('Description'),
    $this
      ->t('Operation'),
  ];
  $root = $this->connection
    ->getRootFolder();
  $element = new CmisElement($this->config, FALSE, NULL, $query, $root
    ->getId());
  if ($session = $this->connection
    ->getSession()) {
    foreach ($results as $result) {
      $id = $result
        ->getPropertyValueById('cmis:objectId');
      $cid = $session
        ->createObjectId($id);
      if ($object = $session
        ->getObject($cid)) {
        $element
          ->setElement('query', $object);
        $rows[] = $element
          ->getData();
      }
    }
    if (!empty($rows)) {
      $table = [
        '#theme' => 'cmis_browser',
        '#header' => $table_header,
        '#elements' => $rows,
      ];
      $content = render($table);
    }
  }
  return $content;
}