asset_list_filter_form

Versions
mediamosa-174
asset_list_filter_form()

The asset filter form.

Code

vpx_beheer_mm/asset/asset.module, line 380

<?php
function asset_list_filter_form() {

  global $user;

  asset_js_progress();

  $cql_collapsed = (isset($_SESSION['asset_filter_form']['cql_filter'])) ? FALSE : TRUE;

  $form = array();
  $form['filter'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filter'),
    '#collapsed' => !$cql_collapsed,
    '#collapsible' => TRUE,
    '#prefix' => '<div id="search-terms">',
    '#suffix' => '</div>',
  );

  // global search operator
  $form['filter']['operator'] = array(
    '#type' => 'select',
    '#title' => t('Filter operator'),
    '#description' => t('Filter on all search criteria (\'AND\') or a least one criterium (\'OR\').'),
    '#options' => array('and' => t('And'), 'or' => t('Or')),
    '#submit' => array('asset_list_filter_form_submit'),
  );
  if (isset($_SESSION['asset_filter_form']['operator'])) {
    $form['filter']['operator']['#default_value'] = $_SESSION['asset_filter_form']['operator'];
  }

  // get all available collections
  $item_limit = variable_get('vpx_connector_item_limit', 200);
  $url = sprintf('/collection?limit=%d&order_by=title', $item_limit);
  $vpx = new vpx_connector();
  $result = $vpx->request('GET', $url);
  $item_count = (int)$result->header->item_count_total;

  $collections = array('' => '');
  for ($i = 0; $i < ceil($item_count / $item_limit); $i++) {
    if (!isset($result)) {
      $result = $vpx->request('GET', $url . sprintf('&offset=%d', $i * $item_limit));
      $vpx->check_result($result);
    }
    foreach ($result->items->item as $item) {
      $collections[(string)$item->coll_id] = pa_trim_string((string)$item->title, 60, FALSE);
    }
    unset($result);
  }

  $form['filter']['coll_id'] = array(
    '#type' => 'select',
    '#title' => t('Collection'),
    '#description' => t('Select collection to be searched. Leave empty for all collections.'),
    '#options' => $collections,
    '#submit' => array('asset_list_filter_form_submit'),
  );
  if (isset($_SESSION['asset_filter_form']['coll_id'])) {
    $form['filter']['coll_id']['#default_value'] = $_SESSION['asset_filter_form']['coll_id'];
  }

  // Add the current filters to the form.
  $search_fields = 1;
  if (isset($_SESSION['asset_filter_form']['filters'])) {
    $search_fields = count($_SESSION['asset_filter_form']['filters']);
  }
  for ($delta = 0; $delta < $search_fields; $delta++) {
    $values = $_SESSION['asset_filter_form']['filters'][$delta];
    $form['filter']['fields']['field_'. $delta] = _asset_list_filter_form($delta, $values);
  }

  $form['filter']['progressbar'] = array(
    '#type' => 'item',
    '#prefix' => '<span>Processing: </span><br><span class="progressbar" id="processprogressbar">0%</span>'
  );

  $form['filter']['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Apply filter',
    '#submit' => array('asset_list_filter_form_submit'),
  );
  $form['filter']['clear'] = array(
    '#type' => 'submit',
    '#value' => 'Clear',
    '#submit' => array('asset_list_filter_form_clear_submit'),
  );
  $form['filter']['form_more'] = array(
    '#type' => 'submit',
    '#value' => t('Add search field'),
    '#submit' => array('asset_list_filter_form_add_search_submit'),
    '#ahah' => array(
      'path' => variable_get('vpx_connector_menu_prefix', '') .'asset/add_search_field',
      'wrapper' => 'search-terms',
      'method' => 'replace',
    ),
  );

  $form['#attributes'] = array('onSubmit' => 'monitorProgress();');


  if (variable_get('pa_batch_processing_enabled', TRUE)) {
    $form['filter']['batch'] = array(
      '#type' => 'submit',
      '#value' => t('Use these assets for batch processing'),
      '#submit' => array('asset_step_1_submit'),
      '#disabled' => !user_access('edit assets'),
    );
  }
  return $form;
}
?>