Source for file dbsearch-defs.php

Documentation is available at dbsearch-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: dbsearch-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for interfacing to the database to perform */
  24. /* a search. This module sits on the same level as the */
  25. /* swish-defs.php module, and like that module extends */
  26. /* the functionality in search-defs.php. */
  27. /* */
  28. /* ******************************************************************** */
  29. /** @package search */
  30. include_once("search-defs.php");
  31.  
  32. // ----------------------------------------------------------------------
  33. /**
  34. * DB Search class
  35. * This class inherits the functionality of the generic 'search'
  36. * class. It extends it to implement a database search.
  37. * @package search
  38. */
  39. class db_search extends search {
  40. /** The query which runs the search */
  41.  
  42. var $searchquery = false;
  43. // ....................................................................
  44. /**
  45. * Constructor
  46. *
  47. * The constructor. Usually the query will be built separately and added
  48. * via set_searchquery(), but we also allow a ready-made query object to
  49. * be passed in here. This object should be a valid dbquery() object as
  50. * returned by the likes of dbselect() (see query-defs.php).
  51. *
  52. * @param string $title Title describing this search
  53. * @param mixed $searchquery Either a dbselect() object, or false
  54. */
  55. function db_search($title="Search Results", $searchquery=false) {
  56. $this->search($title);
  57. $this->max_results = 25;
  58. $this->skip_results = 0;
  59. if (!$searchquery) {
  60. $this->searchquery = new dbselect();
  61. }
  62. $this->initialise();
  63. }
  64. // ....................................................................
  65. /**
  66. * Define the search query object
  67. *
  68. * The query object will usually be an executed dbselect() object
  69. * @see dbselect
  70. * @param mixed $query The dbselect() object to use for searching
  71. */
  72. function set_searchquery($query=false) {
  73. if ($query) {
  74. $this->searchquery = $query;
  75. }
  76. }
  77. // ....................................................................
  78. /**
  79. * Define search table FROM list
  80. * @see sqlquery::from()
  81. * @see sqlquery::tables()
  82. * @param string $table_spec The table list to add to the query
  83. */
  84. function from($table_spec) {
  85. $this->searchquery->from($table_spec);
  86. }
  87. // ....................................................................
  88. /**
  89. * Define search WHERE clause
  90. * @see sqlquery::where()
  91. * @param string $where_clause The WHERE clause, without the word "WHERE".
  92. */
  93. function where($where_clause) {
  94. $this->searchquery->where($where_clause);
  95. }
  96. // ....................................................................
  97. /**
  98. * Define search ORDER BY clause
  99. * @see sqlquery::orderby()
  100. * @param string $field_spec The ORDER BY field list, without the words "ORDER BY".
  101. */
  102. function orderby($field_spec="") {
  103. $this->searchquery->orderby($field_spec);
  104. }
  105. // ....................................................................
  106. /**
  107. * Define search LIMIT clause
  108. * @see sqlquery::limit()
  109. * @param string $limit A numeric value. Do not include the word "LIMIT".
  110. */
  111. function limit($limit) {
  112. $this->searchquery->limit($limit);
  113. }
  114. // ....................................................................
  115. /**
  116. * Define search fields list
  117. * @see sqlquery::fieldlist()
  118. * @param string $field_spec A list of fields separated by commas.
  119. */
  120. function fieldlist($field_spec="*") {
  121. $this->searchquery->fieldlist($field_spec);
  122. }
  123. // ....................................................................
  124. /**
  125. * Execute the search
  126. * Execute the database query search and store any hits.
  127. */
  128. function execute() {
  129. debug_trace($this);
  130. $this->hit = array();
  131. if (isset($this->searchquery)) {
  132. $this->searchquery->execute();
  133. if ($this->searchquery->hasdata) {
  134. $this->searchquery->get_first();
  135. do {
  136. // The db search query returns an associative array which
  137. // is a row. We store this as our hit information..
  138. $hitfields = $this->searchquery->current_row;
  139. $this->hit[] = $hitfields;
  140. } while ($this->searchquery->get_next());
  141. }
  142. }
  143. debug_trace();
  144. } // execute
  145.  
  146.  
  147.  
  148. } // db_search class
  149. // ----------------------------------------------------------------------
  150.  
  151. ?>

Documentation generated by phpDocumentor 1.3.0RC3