content.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * quickly start a discussion
  4. */
  5. $widget = elgg_extract("entity", $vars);
  6. $embed = elgg_extract("embed", $vars, false);
  7. // check if logged if
  8. $user = elgg_get_logged_in_user_entity();
  9. if (!empty($user)) {
  10. $owner = $widget->getOwnerEntity();
  11. $group_membership = $user->getGroups(array("limit" => false));
  12. if (!empty($group_membership)) {
  13. $selected_group = ELGG_ENTITIES_ANY_VALUE;
  14. if (elgg_instanceof($owner, "group")) {
  15. // preselect the current group
  16. $selected_group = $owner->getGUID();
  17. }
  18. $group_selection_options = array();
  19. $group_access_options = array();
  20. if (!$selected_group) {
  21. // no group container, so add empty record, so a user is required to select a group (instead of defaulting to the first option)
  22. $group_selection_options[] = "";
  23. $group_access_options["-1"] = "";
  24. }
  25. foreach ($group_membership as $group) {
  26. $group_selection_options[$group->getGUID()] = $group->name;
  27. $group_access_options[$group->group_acl] = $group->getGUID();
  28. }
  29. // sort the groups by name
  30. natcasesort($group_selection_options);
  31. $form_vars = array(
  32. "id" => "group-tools-start-discussion-widget-form",
  33. "action" => "action/discussion/save"
  34. );
  35. $body_vars = array(
  36. "groups" => $group_selection_options,
  37. "access" => $group_access_options,
  38. "container_guid" => $selected_group
  39. );
  40. echo elgg_view_form("discussion/quick_start", $form_vars, $body_vars);
  41. } elseif (!$embed) {
  42. // you must join a group in order to use this widget
  43. $link_start = "<a href='" . elgg_get_site_url() . "/groups/all'>";
  44. $link_end = "</a>";
  45. $text = elgg_echo("group_tools:widgets:start_discussion:membership_required", array($link_start, $link_end));
  46. echo elgg_view("output/longtext", array("value" => $text));
  47. }
  48. } elseif (!$embed) {
  49. // you have to be logged in in order to use this widget
  50. echo elgg_view("output/longtext", array("value" => elgg_echo("group_tools:widgets:start_discussion:login_required")));
  51. }