content.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * content of the featured groups widget
  4. */
  5. $widget = elgg_extract("entity", $vars);
  6. $num_display = (int) $widget->num_display;
  7. if ($num_display < 1) {
  8. $num_display = 5;
  9. }
  10. $show_random = $widget->show_random;
  11. $featured_options = array(
  12. "type" => "group",
  13. "limit" => $num_display,
  14. "full_view" => false,
  15. "pagination" => false,
  16. "metadata_name_value_pairs" => array("featured_group" => "yes"),
  17. "order_by" => "RAND()"
  18. );
  19. if ($widget->show_members == "yes") {
  20. $show_members = true;
  21. } else {
  22. $show_members = false;
  23. }
  24. if ($show_members) {
  25. elgg_push_context("widgets_groups_show_members");
  26. }
  27. $featured = elgg_list_entities_from_metadata($featured_options);
  28. if ($show_members) {
  29. elgg_pop_context();
  30. }
  31. $random = "";
  32. if ($show_random == "yes") {
  33. $dbprefix = elgg_get_config("dbprefix");
  34. $featured_id = elgg_get_metastring_id("featured_group");
  35. $yes_id = elgg_get_metastring_id("yes");
  36. $random_options = array(
  37. "type" => "group",
  38. "limit" => 1,
  39. "order_by" => "RAND()",
  40. "wheres" => array("NOT EXISTS (
  41. SELECT 1 FROM {$dbprefix}metadata md
  42. WHERE md.entity_guid = e.guid
  43. AND md.name_id = $featured_id
  44. AND md.value_id = $yes_id)")
  45. );
  46. if ($random_groups = elgg_get_entities($random_options)) {
  47. $group = $random_groups[0];
  48. $title = elgg_view("output/url", array("text" => $group->name, "href" => $group->getURL()));
  49. $icon = elgg_view_entity_icon($group, "large");
  50. $random = elgg_view_module("main", $title, $icon, array("class" => "center"));
  51. }
  52. }
  53. $list = $featured . $random;
  54. if (empty($list)) {
  55. $list = elgg_echo("notfound");
  56. }
  57. echo $list;