You are here

function bynder_generate_results in Bynder 7

Organize results from search engine to visualize them.

1 call to bynder_generate_results()
bynder_generate_search in includes/bynder.browser.inc
Generate search page.

File

includes/bynder.browser.inc, line 719
Manages the Bynder media browser functionality

Code

function bynder_generate_results($results) {
  if (isset($results['totalNrOfResults'])) {
    unset($results['totalNrOfResults']);
  }
  if (isset($results['startIndex'])) {
    unset($results['startIndex']);
  }
  $results = $results['media'];
  $output = false;
  if (!empty($results)) {
    foreach ($results as $key => $media_item) {
      if (isset($media_item['thumbnails']['thul'])) {
        if (!isset($media_item['idHash'])) {
          return "image has no idHash";
        }
        $output['thumbnail-' . $media_item['id']] = array(
          '#type' => 'container',
          '#attributes' => array(
            'id' => $media_item['id'],
            'class' => array(
              'grid-item',
            ),
          ),
        );
        $output['thumbnail-' . $media_item['id']]['check_' . $media_item['id']] = array(
          '#type' => 'checkbox',
          '#parents' => array(
            'selected_assets',
            $media_item['id'],
          ),
          '#attributes' => array(
            'class' => [
              'item-selector',
            ],
          ),
        );
        $output['thumbnail-' . $media_item['id']]['image'] = array(
          '#name' => $media_item['name'],
          '#type' => 'markup',
          '#markup' => '<img src="' . $media_item['thumbnails']['thul'] . '" alt="' . $media_item['name'] . '"/>
                                    <div class="more-info">
                                      <h4 class="name">' . $media_item['name'] . '</h4>
                                    </div>',
        );
      }
    }
  }
  else {
    return false;
  }
  return $output;
}