BBoss_Global_Search_Type

BuddyPress Global Search Type - Parent class **************************************.

Defined (1)

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

/includes/search-types/class.BBoss_Global_Search_Type.php  
  1. abstract class BBoss_Global_Search_Type { 
  2.  
  3. /** 
  4. * search term. might be used later for caching purposes 
  5. * @var string 
  6. */ 
  7. protected $search_term = ''; 
  8.  
  9. /** 
  10. * The variable to hold search results. 
  11. *  
  12. * @var array 
  13. */ 
  14. protected $search_results = array( 'total_match_count'=>false, 'items'=> array(), 'items_title'=> array(), 'html_generated' => false ); 
  15.  
  16. /** Magic Methods 
  17. * =================================================================== 
  18. */ 
  19.  
  20. /** 
  21. * A dummy magic method to prevent this class from being cloned. 
  22. * @since 1.0.0 
  23. */ 
  24. public function __clone() { 
  25. _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'buddypress-global-search'), '1.7'); 
  26.  
  27. /** 
  28. * A dummy magic method to prevent this class being unserialized. 
  29. * @since 1.0.0 
  30. */ 
  31. public function __wakeup() { 
  32. _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'buddypress-global-search'), '1.7'); 
  33.  
  34. /** 
  35. * Returns the sql query to be used in performing an 'all' items search. 
  36. *  
  37. * @param string $search_term 
  38. * @return string sql query 
  39. * @since 1.0.0 
  40. */ 
  41. public function union_sql( $search_term ) { 
  42. $this->search_term = $search_term;//save it for future reference may be. 
  43.  
  44. return $this->sql($search_term); 
  45.  
  46. public function add_search_item( $item_id ) { 
  47. if( !in_array( $item_id, $this->search_results['items'] ) ) 
  48. $this->search_results['items'][$item_id] = ''; 
  49.  
  50. public function get_title( $item_id ) { 
  51. if( !$this->search_results['html_generated'] ) { 
  52. $this->generate_html(); 
  53. $this->search_results['html_generated'] = true;//do once only 
  54.  
  55. return isset( $this->search_results['items'][$item_id]['title'] ) ? $this->search_results['items'][$item_id]['title'] : $this->search_term; 
  56.  
  57. public function get_total_match_count( $search_term ) { 
  58. $this->search_term = $search_term;//save it for future reference may be. 
  59.  
  60. global $wpdb; 
  61. $sql = $this->sql( $search_term, true ); 
  62. return $wpdb->get_var( $sql ); 
  63.  
  64. /** 
  65. * This function must be overriden by inheritingn classes 
  66. * @param string $search_term 
  67. * @param boolean $only_totalrow_count 
  68. */ 
  69. abstract function sql( $search_term, $only_totalrow_count=false ); 
  70.  
  71. /** 
  72. * Get the html for given search result. 
  73. * @param int $itemid 
  74. * @param string $template_type Optional 
  75. * @return string 
  76. */ 
  77. public function get_html( $itemid, $template_type='' ) { 
  78. if( !$this->search_results['html_generated'] ) { 
  79. $this->generate_html( $template_type ); 
  80. $this->search_results['html_generated'] = true;//do once only 
  81.  
  82. return isset( $this->search_results['items'][$itemid] ) ? @$this->search_results['items'][$itemid]['html'] : '';