facetapi.facetapi.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * @file
  4. * Facet API hook implementations.
  5. */
  6. /**
  7. * Implements hook_facetapi_realm_info().
  8. */
  9. function facetapi_facetapi_realm_info() {
  10. $realms = array();
  11. $realms['block'] = array(
  12. 'label' => t('Blocks'),
  13. 'weight' => -10,
  14. 'sortable' => FALSE,
  15. 'default widget' => 'facetapi_links',
  16. 'element type' => 'links',
  17. 'description' => t(
  18. 'The <em>Blocks</em> realm displays each facet in a separate <a href="@block-page">block</a>. Users are able to refine their searches in a drill-down fashion.',
  19. array('@block-page' => url('admin/structure/block', array('query' => array('destination' => current_path()))))
  20. ),
  21. );
  22. return $realms;
  23. }
  24. /**
  25. * Implements hook_facetapi_facet_info().
  26. */
  27. function facetapi_facetapi_facet_info($searcher_info) {
  28. $facets = array();
  29. if (isset($searcher_info['types']['node']) && $searcher_info['include default facets']) {
  30. $facets['bundle'] = array(
  31. 'label' => t('Content type'),
  32. 'description' => t('Filter by content type.'),
  33. 'field api bundles' => array('node'),
  34. 'map callback' => 'facetapi_map_bundle',
  35. 'values callback' => 'facetapi_callback_type_values',
  36. 'facet mincount allowed' => TRUE,
  37. 'dependency plugins' => array('role'),
  38. );
  39. $facets['author'] = array(
  40. 'label' => t('Author'),
  41. 'description' => t('Filter by author.'),
  42. 'field' => 'uid',
  43. 'map callback' => 'facetapi_map_author',
  44. 'values callback' => 'facetapi_callback_user_values',
  45. 'facet mincount allowed' => TRUE,
  46. 'dependency plugins' => array('bundle', 'role'),
  47. );
  48. $facets['language'] = array(
  49. 'label' => t('Language'),
  50. 'description' => t('Filter by language.'),
  51. 'field' => 'language',
  52. 'map callback' => 'facetapi_map_language',
  53. 'values callback' => 'facetapi_callback_language_values',
  54. 'facet mincount allowed' => TRUE,
  55. 'dependency plugins' => array('bundle', 'role'),
  56. );
  57. $facets['created'] = array(
  58. 'label' => t('Post date'),
  59. 'description' => t('Filter by the date the node was posted.'),
  60. 'query types' => array('date'),
  61. 'allowed operators' => array(FACETAPI_OPERATOR_AND => TRUE),
  62. 'map callback' => 'facetapi_map_date',
  63. 'min callback' => 'facetapi_get_min_date',
  64. 'max callback' => 'facetapi_get_max_date',
  65. 'dependency plugins' => array('bundle', 'role'),
  66. 'default sorts' => array(
  67. array('active', SORT_DESC),
  68. array('indexed', SORT_ASC),
  69. ),
  70. );
  71. $facets['changed'] = array(
  72. 'label' => t('Updated date'),
  73. 'description' => t('Filter by the date the node was last modified.'),
  74. 'query types' => array('date'),
  75. 'allowed operators' => array(FACETAPI_OPERATOR_AND => TRUE),
  76. 'map callback' => 'facetapi_map_date',
  77. 'min callback' => 'facetapi_get_min_date',
  78. 'max callback' => 'facetapi_get_max_date',
  79. 'dependency plugins' => array('bundle', 'role'),
  80. 'default sorts' => array(
  81. array('active', SORT_DESC),
  82. array('indexed', SORT_ASC),
  83. ),
  84. );
  85. }
  86. return $facets;
  87. }
  88. /**
  89. * Implements hook_facetapi_sort_info().
  90. */
  91. function facetapi_facetapi_sort_info() {
  92. $sorts = array();
  93. $sorts['active'] = array(
  94. 'label' => t('Facet active'),
  95. 'callback' => 'facetapi_sort_active',
  96. 'description' => t('Sort by whether the facet is active or not.'),
  97. 'weight' => -50,
  98. );
  99. $sorts['count'] = array(
  100. 'label' => t('Count'),
  101. 'callback' => 'facetapi_sort_count',
  102. 'description' => t('Sort by the facet count.'),
  103. 'weight' => -49,
  104. );
  105. $sorts['display'] = array(
  106. 'label' => t('Display value'),
  107. 'callback' => 'facetapi_sort_display',
  108. 'description' => t('Sort by the value displayed to the user.'),
  109. 'weight' => -48,
  110. );
  111. $sorts['indexed'] = array(
  112. 'label' => t('Indexed value'),
  113. 'callback' => 'facetapi_sort_indexed',
  114. 'description' => t('Sort by the raw value stored in the index.'),
  115. 'weight' => -47,
  116. );
  117. return $sorts;
  118. }
  119. /**
  120. * Implements hook_facetapi_widgets().
  121. */
  122. function facetapi_facetapi_widgets() {
  123. return array(
  124. 'facetapi_links' => array(
  125. 'handler' => array(
  126. 'label' => t('Links'),
  127. 'class' => 'FacetapiWidgetLinks',
  128. 'query types' => array('term', 'date'),
  129. ),
  130. ),
  131. 'facetapi_checkbox_links' => array(
  132. 'handler' => array(
  133. 'label' => t('Links with checkboxes'),
  134. 'class' => 'FacetapiWidgetCheckboxLinks',
  135. 'query types' => array('term', 'date'),
  136. ),
  137. ),
  138. );
  139. }
  140. /**
  141. * Implements hook_facetapi_filters().
  142. */
  143. function facetapi_facetapi_filters() {
  144. return array(
  145. 'active_items' => array(
  146. 'handler' => array(
  147. 'label' => t('Do not display active items'),
  148. 'class' => 'FacetapiFilterActiveItems',
  149. ),
  150. ),
  151. 'current_depth' => array(
  152. 'handler' => array(
  153. 'label' => t('Only show items in the current level of the hierarchy'),
  154. 'class' => 'FacetapiFilterCurrentDepth',
  155. 'requirements' => array('facetapi_requirement_facet_hierarchical' => TRUE),
  156. ),
  157. ),
  158. );
  159. }
  160. /**
  161. * Implements hook_facetapi_dependencies().
  162. */
  163. function facetapi_facetapi_dependencies() {
  164. return array(
  165. 'bundle' => array(
  166. 'handler' => array(
  167. 'label' => t('Bundles'),
  168. 'class' => 'FacetapiDependencyBundle',
  169. ),
  170. ),
  171. 'role' => array(
  172. 'handler' => array(
  173. 'label' => t('Roles'),
  174. 'class' => 'FacetapiDependencyRole',
  175. ),
  176. ),
  177. );
  178. }
  179. /**
  180. * Implements hook_facetapi_empty_behaviors().
  181. */
  182. function facetapi_facetapi_empty_behaviors() {
  183. return array(
  184. 'none' => array(
  185. 'handler' => array(
  186. 'label' => t('Do not display facet'),
  187. 'class' => 'FacetapiEmptyBehaviorNone',
  188. ),
  189. ),
  190. 'text' => array(
  191. 'handler' => array(
  192. 'label' => t('Display text'),
  193. 'class' => 'FacetapiEmptyBehaviorText',
  194. ),
  195. ),
  196. );
  197. }
  198. /**
  199. * Implements hook_facetapi_url_processors().
  200. */
  201. function facetapi_facetapi_url_processors() {
  202. return array(
  203. 'standard' => array(
  204. 'handler' => array(
  205. 'label' => t('Standard URL processors'),
  206. 'class' => 'FacetapiUrlProcessorStandard',
  207. ),
  208. ),
  209. );
  210. }