You are here

function _imagepicker_search_opts in Image Picker 7

Same name and namespace in other branches
  1. 6.2 imagepicker.functions.inc \_imagepicker_search_opts()
3 calls to _imagepicker_search_opts()
imagepicker_browse_admin_form in ./imagepicker.functions.inc
_imagepicker_browse in ./imagepicker.functions.inc
_imagepicker_browse_public in ./imagepicker.functions.inc

File

./imagepicker.functions.inc, line 2472
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function _imagepicker_search_opts($searchs, $account) {
  if ($account) {
    $search_opts = imagepicker_variable_get('imagepicker_browser_search_opts', array());
  }
  else {
    global $user;
    $search_opts = imagepicker_variable_get('imagepicker_browser_search_opts', imagepicker_variable_get('imagepicker_browser_search_opts', array()), $user->uid);
  }
  if (!isset($search_opts['name'])) {
    $search_opts['name'] = FALSE;
  }
  if (!isset($search_opts['desc'])) {
    $search_opts['desc'] = FALSE;
  }
  if (!isset($search_opts['title'])) {
    $search_opts['title'] = FALSE;
  }
  $os = $searchs;
  $searchs = '%' . db_like($searchs) . '%';
  if ($search_opts['name'] && !$search_opts['desc'] && !$search_opts['title']) {
    $conditions = array(
      'img_name',
      $searchs,
      'LIKE',
    );
  }
  elseif ($search_opts['name'] && $search_opts['desc'] && !$search_opts['title']) {
    $conditions = db_or()
      ->condition('img_name', $searchs, 'LIKE')
      ->condition('img_description', $searchs, 'LIKE');
  }
  elseif ($search_opts['name'] && !$search_opts['desc'] && $search_opts['title']) {
    $conditions = db_or()
      ->condition('img_name', $searchs, 'LIKE')
      ->condition('img_title', $searchs, 'LIKE');
  }
  elseif (!$search_opts['name'] && $search_opts['desc'] && $search_opts['title']) {
    $conditions = db_or()
      ->condition('img_description', $searchs, 'LIKE')
      ->condition('img_title', $searchs, 'LIKE');
  }
  elseif (!$search_opts['name'] && !$search_opts['desc'] && $search_opts['title']) {
    $conditions = array(
      'img_title',
      $searchs,
      'LIKE',
    );
  }
  elseif (!$search_opts['name'] && $search_opts['desc'] && !$search_opts['title']) {
    $conditions = array(
      'img_description',
      $searchs,
      'LIKE',
    );
  }
  else {
    $conditions = db_or()
      ->condition('img_name', $searchs, 'LIKE')
      ->condition('img_description', $searchs, 'LIKE')
      ->condition('img_title', $searchs, 'LIKE');
  }
  return $conditions;
}