SearchAdvanced.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace ColdTrick\Questions;
  3. class SearchAdvanced {
  4. /**
  5. * Change search params for combined search
  6. *
  7. * @param string $hook the name of the hook
  8. * @param string $type the type of the hook
  9. * @param mixed $return_value current return value
  10. * @param array $params supplied params
  11. *
  12. * @return void|mixed
  13. */
  14. public static function combinedParams($hook, $type, $return_value, $params) {
  15. $combined_search_type = elgg_extract('combined', $params);
  16. if (empty($combined_search_type)) {
  17. return;
  18. }
  19. switch ($combined_search_type) {
  20. case 'objects':
  21. $subtypes = elgg_extract('subtype', $return_value);
  22. if (empty($subtypes)) {
  23. return;
  24. }
  25. if (in_array(\ElggQuestion::SUBTYPE, $subtypes)) {
  26. // add answers
  27. $subtypes[] = \ElggAnswer::SUBTYPE;
  28. }
  29. $return_value['subtype'] = $subtypes;
  30. break;
  31. case 'all':
  32. $type_subtype_pairs = elgg_extract('type_subtype_pairs', $return_value);
  33. if (empty($type_subtype_pairs) || empty($type_subtype_pairs['object'])) {
  34. return;
  35. }
  36. if (in_array(\ElggQuestion::SUBTYPE, $type_subtype_pairs['object'])) {
  37. // add answers
  38. $type_subtype_pairs['object'][] = \ElggAnswer::SUBTYPE;
  39. }
  40. $return_value['type_subtype_pairs'] = $type_subtype_pairs;
  41. break;
  42. default:
  43. return;
  44. }
  45. return $return_value;
  46. }
  47. }