search.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Overrule to group search page
  4. */
  5. elgg_push_breadcrumb(elgg_echo("groups"), "groups/all");
  6. elgg_push_breadcrumb(elgg_echo("search"));
  7. $db_prefix = elgg_get_config("dbprefix");
  8. $query = sanitise_string(get_input("tag"));
  9. $title = elgg_echo("groups:search:title", array($query));
  10. $content = false;
  11. if (!empty($query)) {
  12. $params = array(
  13. "type" => "group",
  14. "full_view" => FALSE,
  15. );
  16. // search all profile fields
  17. $profile_fields = array_keys(elgg_get_config("group"));
  18. if (!empty($profile_fields)) {
  19. $params["joins"] = array(
  20. "JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid",
  21. "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid",
  22. "JOIN {$db_prefix}metastrings msv ON md.value_id = msv.id"
  23. );
  24. } else {
  25. $params["joins"] = array("JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid");
  26. }
  27. $where = "ge.name LIKE '%$query%' OR ge.description LIKE '%$query%'";
  28. if (!empty($profile_fields)) {
  29. // get the where clauses for the md names
  30. // can't use egef_metadata() because the n_table join comes too late.
  31. // $clauses = elgg_entities_get_metastrings_options("metadata", array(
  32. // "metadata_names" => $profile_fields,
  33. // ));
  34. // $params["joins"] = array_merge($clauses["joins"], $params["joins"]);
  35. $tag_name_ids = array();
  36. foreach ($profile_fields as $field) {
  37. $tag_name_ids[] = elgg_get_metastring_id($field);
  38. }
  39. $md_where = "((md.name_id IN (" . implode(",", $tag_name_ids) . ")) AND (msv.string LIKE '%$query%'))";
  40. $params["wheres"] = array("(($where) OR ($md_where))");
  41. } else {
  42. $params["wheres"] = array($where);
  43. }
  44. $content = elgg_list_entities($params);
  45. }
  46. if (empty($content)) {
  47. $content = elgg_echo("groups:search:none");
  48. }
  49. $sidebar = elgg_view("groups/sidebar/find");
  50. //$sidebar .= elgg_view("groups/sidebar/featured");
  51. $params = array(
  52. "content" => $content,
  53. "sidebar" => $sidebar,
  54. "filter" => false,
  55. "title" => $title,
  56. );
  57. $body = elgg_view_layout("content", $params);
  58. echo elgg_view_page($title, $body);