content.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * content of the index groups widget
  4. */
  5. $widget = $vars["entity"];
  6. // get widget settings
  7. $count = sanitise_int($widget->group_count, false);
  8. if (empty($count)) {
  9. $count = 8;
  10. }
  11. $options = array(
  12. "type" => "group",
  13. "limit" => $count,
  14. "full_view" => false,
  15. "pagination" => false,
  16. "metadata_name_value_pairs" => array(),
  17. "metadata_case_sensitive" => false
  18. );
  19. // limit to featured groups?
  20. if ($widget->featured == "yes") {
  21. $options["metadata_name_value_pairs"][] = array(
  22. "name" => "featured_group",
  23. "value" => "yes"
  24. );
  25. }
  26. // enable advanced filter
  27. $filter_name = $widget->filter_name;
  28. $filter_value = $widget->filter_value;
  29. if (!empty($filter_name) && !empty($filter_value)) {
  30. $profile_fields = elgg_get_config("group");
  31. if (!empty($profile_fields)) {
  32. $found = false;
  33. foreach ($profile_fields as $name => $type) {
  34. if (($name == $filter_name) && ($type == "tags")) {
  35. $found = true;
  36. break;
  37. }
  38. }
  39. if ($found) {
  40. $filter_value = string_to_tag_array($filter_value);
  41. $options["metadata_name_value_pairs"][] = array(
  42. "name" => $filter_name,
  43. "value" => $filter_value
  44. );
  45. }
  46. }
  47. }
  48. $sorting_value = $widget->sorting;
  49. if (empty($sorting_value) && ($widget->apply_sorting == "yes")) {
  50. $sorting_value = "ordered";
  51. }
  52. $getter = "elgg_get_entities_from_metadata";
  53. // check if groups should respect a specific order
  54. switch ($sorting_value) {
  55. case "ordered":
  56. $dbprefix = elgg_get_config("dbprefix");
  57. $order_id = elgg_get_metastring_id("order");
  58. $options["selects"] = array(
  59. "IFNULL((
  60. SELECT order_ms.string as order_val
  61. FROM " . $dbprefix . "metadata mo
  62. JOIN " . $dbprefix . "metastrings order_ms ON mo.value_id = order_ms.id
  63. WHERE e.guid = mo.entity_guid
  64. AND mo.name_id = " . $order_id . "
  65. ), 99999) AS order_val"
  66. );
  67. $options["order_by"] = "CAST(order_val AS SIGNED) ASC, e.time_created DESC";
  68. break;
  69. case "popular":
  70. $getter = "elgg_get_entities_from_relationship_count";
  71. $options["relationship"] = "member";
  72. $options["inverse_relationship"] = false;
  73. break;
  74. default:
  75. // just use default time created sorting
  76. break;
  77. }
  78. // show group member count
  79. if ($widget->show_members == "yes") {
  80. $show_members = true;
  81. elgg_push_context("widgets_groups_show_members");
  82. } else {
  83. $show_members = false;
  84. }
  85. // list groups
  86. $groups = elgg_list_entities($options, $getter);
  87. if (!empty($groups)) {
  88. echo $groups;
  89. } else {
  90. echo elgg_echo("groups:none");
  91. }
  92. if ($show_members) {
  93. elgg_pop_context();
  94. }