Ignore:
Timestamp:
Feb 19, 2007, 5:25:47 PM (17 years ago)
Author:
rvelices
Message:

web service: added method to query search elements
picture: small correction on my last commit
monthly calendar nice view: always use getimagesize instead of guessing the size
query search: improved results (filename is searched separately) and sometimes less sql queries than before

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r1820 r1837  
    604604}
    605605
     606/**
     607 * returns a list of elements corresponding to a query search
     608 */
     609function ws_images_search($params, &$service)
     610{
     611  global $page;
     612  $images = array();
     613  include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
     614  include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     615
     616  $where_clauses = ws_std_image_sql_filter( $params );
     617  $order_by = ws_std_image_sql_order($params);
     618
     619  if ( !empty($where_clauses) and !empty($order_by) )
     620  {
     621    $page['super_order_by']=1; // quick_search_result might be faster
     622  }
     623  $search_result = get_quick_search_results($params['query']);
     624
     625  global $image_ids; //needed for sorting by rank (usort)
     626  if ( ( !isset($search_result['as_is'])
     627      or !empty($where_clauses)
     628      or !empty($order_by) )
     629      and !empty($search_result['items']) )
     630  {
     631    $where_clauses[] = 'id IN ('
     632        .wordwrap(implode(', ', $search_result['items']), 80, "\n")
     633        .')';
     634    $where_clauses[] = get_sql_condition_FandF(
     635        array
     636          (
     637            'forbidden_categories' => 'category_id',
     638            'visible_categories' => 'category_id',
     639            'visible_images' => 'id'
     640          ),
     641        '', true
     642      );
     643    $query = '
     644SELECT DISTINCT id FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     645  WHERE '.implode('
     646    AND ', $where_clauses);
     647    if (!empty($order_by))
     648    {
     649      $query .= '
     650  ORDER BY '.$order_by;
     651    }
     652    $image_ids = array_from_query($query, 'id');
     653    global $ranks;
     654    $ranks = array_flip( $search_result['items'] );
     655    usort(
     656      $image_ids,
     657      create_function('$i1,$i2', 'global $ranks; return $ranks[$i1]-$ranks[$i2];')
     658    );
     659    unset ($ranks);
     660  }
     661  else
     662  {
     663    $image_ids = $search_result['items'];
     664  }
     665 
     666  $image_ids = array_slice($image_ids,
     667    $params['page']*$params['per_page'],
     668    $params['per_page'] );
     669
     670  if ( count($image_ids) )
     671  {
     672    $query = '
     673SELECT * FROM '.IMAGES_TABLE.'
     674  WHERE id IN ('
     675        .wordwrap(implode(', ', $image_ids), 80, "\n")
     676        .')';
     677
     678    $result = pwg_query($query);
     679    while ($row = mysql_fetch_assoc($result))
     680    {
     681      $image = array();
     682      foreach ( array('id', 'width', 'height', 'hit') as $k )
     683      {
     684        if (isset($row[$k]))
     685        {
     686          $image[$k] = (int)$row[$k];
     687        }
     688      }
     689      foreach ( array('name', 'file') as $k )
     690      {
     691        $image[$k] = $row[$k];
     692      }
     693      $image = array_merge( $image, ws_std_get_urls($row) );
     694      array_push($images, $image);
     695    }
     696
     697    $image_ids = array_flip($image_ids);
     698    usort(
     699        $images,
     700        create_function('$i1,$i2', 'global $image_ids; return $image_ids[$i1["id"]]-$image_ids[$i2["id"]];')
     701      );
     702  }
     703
     704
     705  return array( 'images' =>
     706    array (
     707      WS_XML_ATTRIBUTES =>
     708        array(
     709            'page' => $params['page'],
     710            'per_page' => $params['per_page'],
     711            'count' => count($images)
     712          ),
     713       WS_XML_CONTENT => new PwgNamedArray($images, 'image',
     714          array('id', 'tn_url', 'element_url', 'file','width','height','hit') )
     715      )
     716    );
     717}
    606718
    607719/**
Note: See TracChangeset for help on using the changeset viewer.