You are here

function bynder_search_facets in Bynder 7

Search with selected facets and a search term.

File

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

Code

function bynder_search_facets($selected_facets, $search_term) {
  $query = array();
  foreach ($selected_facets as $selected_facet_group_name => $selected_facet_group) {
    $query[$selected_facet_group_name] = implode(",", $selected_facet_group);
  }
  if (isset($search) && strlen($search) > 0) {
    $query['keyword'] = urlencode($search_term);
  }
  $query['count'] = 1;

  // Hardcoding this now cause we only support images at the moment.
  $query['type'] = 'image';
  $bynderApi = bynder_init_api();
  $assetBank = $bynderApi
    ->getAssetBankManager();
  $assets = $assetBank
    ->getMediaList($query)
    ->wait();
  $arr_facets_json = $assets['count'];
  if ($arr_facets_json) {
    return $arr_facets_json;
  }
  else {
    drupal_set_message("Error fetching media", 'error');
    return false;
  }
}