views_plugin_query.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_query.
  5. */
  6. /**
  7. * @defgroup views_query_plugins Views query plugins
  8. * @{
  9. * A Views query plugin builds SQL to execute using the Drupal database API.
  10. *
  11. * @see hook_views_plugins()
  12. */
  13. /**
  14. * The base query class, which is the underlying layer in a View.
  15. */
  16. class views_plugin_query extends views_plugin {
  17. /**
  18. * A pager plugin that should be provided by the display.
  19. *
  20. * @var views_plugin_pager
  21. */
  22. public $pager = NULL;
  23. /**
  24. * Constructor; Create the basic query object and fill with default values.
  25. */
  26. public function init($base_table, $base_field, $options) {
  27. $this->base_table = $base_table;
  28. $this->base_field = $base_field;
  29. $this->unpack_options($this->options, $options);
  30. }
  31. /**
  32. * Generate a query and a countquery from all of the information supplied
  33. * to the object.
  34. *
  35. * @param bool $get_count
  36. * Provide a countquery if this is TRUE, otherwise provide a normal query.
  37. *
  38. * @return SelectQuery
  39. * A SelectQuery object.
  40. */
  41. public function query($get_count = FALSE) {
  42. }
  43. /**
  44. * Let modules modify the query just prior to finalizing it.
  45. *
  46. * @param view $view
  47. * The view which is executed.
  48. */
  49. public function alter(&$view) {
  50. }
  51. /**
  52. * Builds the necessary info to execute the query.
  53. *
  54. * @param view $view
  55. * The view which is executed.
  56. */
  57. public function build(&$view) {
  58. }
  59. /**
  60. * Executes the query and fills the associated view object with according
  61. * values.
  62. *
  63. * Values to set: $view->result, $view->total_rows, $view->execute_time,
  64. * $view->pager['current_page'].
  65. *
  66. * $view->result should contain an array of objects. The array must use a
  67. * numeric index starting at 0.
  68. *
  69. * @param view $view
  70. * The view which is executed.
  71. */
  72. public function execute(&$view) {
  73. }
  74. /**
  75. * Add a signature to the query, if such a thing is feasible.
  76. *
  77. * This signature is something that can be used when perusing query logs to
  78. * discern where particular queries might be coming from.
  79. *
  80. * @param view $view
  81. * The view which is executed.
  82. */
  83. public function add_signature(&$view) {
  84. }
  85. /**
  86. * Get aggregation info for group by queries.
  87. *
  88. * If NULL, aggregation is not allowed.
  89. */
  90. public function get_aggregation_info() {
  91. }
  92. /**
  93. * Add settings for the ui.
  94. */
  95. public function options_form(&$form, &$form_state) {
  96. parent::options_form($form, $form_state);
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. public function options_validate(&$form, &$form_state) {
  102. }
  103. /**
  104. * {@inheritdoc}
  105. */
  106. public function options_submit(&$form, &$form_state) {
  107. }
  108. /**
  109. * {@inheritdoc}
  110. */
  111. public function summary_title() {
  112. return t('Settings');
  113. }
  114. /**
  115. * Set a LIMIT on the query, specifying a maximum number of results.
  116. */
  117. public function set_limit($limit) {
  118. $this->limit = $limit;
  119. }
  120. /**
  121. * Set an OFFSET on the query, specifying a number of results to skip
  122. */
  123. public function set_offset($offset) {
  124. $this->offset = $offset;
  125. }
  126. /**
  127. * Render the pager, if necessary.
  128. */
  129. public function render_pager($exposed_input) {
  130. if (!empty($this->pager) && $this->pager->use_pager()) {
  131. return $this->pager->render($exposed_input);
  132. }
  133. return '';
  134. }
  135. /**
  136. * Create a new grouping for the WHERE or HAVING clause.
  137. *
  138. * @param string $type
  139. * Either 'AND' or 'OR'. All items within this group will be added
  140. * to the WHERE clause with this logical operator.
  141. * @param string $group
  142. * An ID to use for this group. If unspecified, an ID will be generated.
  143. * @param string $where
  144. * 'where' or 'having'.
  145. *
  146. * @return string
  147. * The group ID generated.
  148. */
  149. public function set_where_group($type = 'AND', $group = NULL, $where = 'where') {
  150. // Set an alias.
  151. $groups = &$this->$where;
  152. if (!isset($group)) {
  153. $group = empty($groups) ? 1 : max(array_keys($groups)) + 1;
  154. }
  155. // Create an empty group
  156. if (empty($groups[$group])) {
  157. $groups[$group] = array('conditions' => array(), 'args' => array());
  158. }
  159. $groups[$group]['type'] = strtoupper($type);
  160. return $group;
  161. }
  162. /**
  163. * Control how all WHERE and HAVING groups are put together.
  164. *
  165. * @param string $type
  166. * Either 'AND' or 'OR'.
  167. */
  168. public function set_group_operator($type = 'AND') {
  169. $this->group_operator = strtoupper($type);
  170. }
  171. /**
  172. * Returns the according entity objects for the given query results.
  173. */
  174. public function get_result_entities($results, $relationship = NULL) {
  175. return FALSE;
  176. }
  177. }
  178. /**
  179. * @}
  180. */