BBoss_Global_Search_AWPCP

BuddyPress Global Search - search AWPCP listings **************************************.

Defined (1)

The class is defined in the following location(s).

/includes/plugins/awpcp/class.BBoss_Global_Search_AWPCP.php  
  1. class BBoss_Global_Search_AWPCP extends BBoss_Global_Search_Type { 
  2. private $type = 'awpcp_ad_listing'; 
  3.  
  4. /** 
  5. * Insures that only one instance of Class exists in memory at any 
  6. * one time. Also prevents needing to define globals all over the place. 
  7. * @since 1.0.9 
  8. * @return object BBoss_Global_Search_AWPCP 
  9. */ 
  10. public static function instance() { 
  11. // Store the instance locally to avoid private static replication 
  12. static $instance = null; 
  13.  
  14. // Only run these methods if they haven't been run previously 
  15. if (null === $instance) { 
  16. $instance = new BBoss_Global_Search_AWPCP(); 
  17.  
  18. // Always return the instance 
  19. return $instance; 
  20.  
  21. /** 
  22. * A dummy constructor to prevent this class from being loaded more than once. 
  23. * @since 1.0.9 
  24. */ 
  25. private function __construct() { /** Do nothing here */ 
  26.  
  27. public function sql( $search_term, $only_totalrow_count=false ) { 
  28. global $wpdb, $bp; 
  29. $query_placeholder = array();  
  30.  
  31. $sql = " SELECT "; 
  32.  
  33. if( $only_totalrow_count ) { 
  34. $sql .= " COUNT( DISTINCT awpcp_table_ads.ad_id ) "; 
  35. } else { 
  36. $sql .= " DISTINCT awpcp_table_ads.ad_id as id, 'awpcp_ad_listing' as type, awpcp_table_ads.ad_title LIKE '%%%s%%' AS relevance, awpcp_table_ads.ad_postdate as entry_date "; 
  37. $query_placeholder[] = $search_term; 
  38.  
  39. $sql .= " FROM " . AWPCP_TABLE_ADS . " awpcp_table_ads  
  40.  
  41. WHERE  
  42. 1=1  
  43. AND ( 
  44. (awpcp_table_ads.ad_title LIKE '%%%s%%')  
  45. OR (awpcp_table_ads.ad_details LIKE '%%%s%%') 
  46. AND awpcp_table_ads.disabled=0  
  47. "; 
  48.  
  49. $query_placeholder[] = $search_term; 
  50. $query_placeholder[] = $search_term; 
  51. $sql = $wpdb->prepare( $sql, $query_placeholder ); 
  52.  
  53. return apply_filters(  
  54. 'BBoss_Global_Search_AWPCP_sql',  
  55. $sql,  
  56. array(  
  57. 'search_term' => $search_term,  
  58. 'only_totalrow_count' => $only_totalrow_count,  
  59. )  
  60. ); 
  61.  
  62. protected function generate_html( $template_type='' ) { 
  63. $post_ids = array(); 
  64. foreach( $this->search_results['items'] as $item_id=>$item_html ) { 
  65. $post_ids[] = $item_id; 
  66.  
  67. $conditions = array(); 
  68. $conditions[] = "ad_id IN ( " . implode( ', ', $post_ids ) . " ) "; 
  69.  
  70. $args = array(); 
  71. $ads = AWPCP_Ad::get_enabled_ads( $args, $conditions ); 
  72.  
  73. $parity = array( 'displayaditemseven', 'displayaditemsodd' ); 
  74.  
  75. if( 'ajax'== $template_type ) { 
  76. $layout = buddyboss_global_search_buffer_template_part( 'loop/' . $this->type, $template_type, false ); 
  77. } else { 
  78. $layout = get_awpcp_option('displayadlayoutcode'); 
  79.  
  80. if ( empty( $layout) ) { 
  81. $layout = awpcp()->settings->get_option_default_value( 'displayadlayoutcode' ); 
  82.  
  83. if( !empty( $ads ) ) { 
  84. foreach( $ads as $i => $listing ) { 
  85. $rendered_listing = awpcp_do_placeholders( $listing, $layout, $context ); 
  86. $rendered_listing = str_replace( "\$awpcpdisplayaditems", $parity[$i % 2], $rendered_listing ); 
  87.  
  88. if ( function_exists( 'awpcp_featured_ads' ) ) { 
  89. $rendered_listing = awpcp_featured_ad_class( $listing->ad_id, $rendered_listing ); 
  90.  
  91. $rendered_listing = apply_filters( 'awpcp-render-listing-item', $rendered_listing, $i + 1, $template_type ); 
  92.  
  93. $result = array( 
  94. 'id' => $listing->ad_id,  
  95. 'type' => $this->type,  
  96. 'title' => $listing->ad_title,  
  97. 'html' => $rendered_listing,  
  98. ); 
  99.  
  100. $this->search_results['items'][$listing->ad_id] = $result;