related_groups.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Action to save a new related group
  4. */
  5. $group_guid = (int) get_input("group_guid");
  6. $guid = (int) get_input("guid");
  7. if (!empty($group_guid) && !empty($guid)) {
  8. $group = get_entity($group_guid);
  9. $related = get_entity($guid);
  10. // do we have groups
  11. if (!empty($group) && elgg_instanceof($group, "group") && !empty($related) && elgg_instanceof($related, "group")) {
  12. if ($group->canEdit()) {
  13. if ($group->getGUID() != $related->getGUID()) {
  14. // not already related?
  15. if (!check_entity_relationship($group->getGUID(), "related_group", $related->getGUID())) {
  16. if (add_entity_relationship($group->getGUID(), "related_group", $related->getGUID())) {
  17. // notify the other owner about this
  18. if ($group->getOwnerGUID() != $related->getOwnerGUID()) {
  19. $subject = elgg_echo("group_tools:related_groups:notify:owner:subject");
  20. $message = elgg_echo("group_tools:related_groups:notify:owner:message", array(
  21. $related->getOwnerEntity()->name,
  22. elgg_get_logged_in_user_entity()->name,
  23. $related->name,
  24. $group->name
  25. ));
  26. notify_user($related->getOwnerGUID(), $group->getOwnerGUID(), $subject, $message);
  27. }
  28. system_message(elgg_echo("group_tools:action:related_groups:success"));
  29. } else {
  30. register_error(elgg_echo("group_tools:action:related_groups:error:add"));
  31. }
  32. } else {
  33. register_error(elgg_echo("group_tools:action:related_groups:error:already"));
  34. }
  35. } else {
  36. register_error(elgg_echo("group_tools:action:related_groups:error:same"));
  37. }
  38. } else {
  39. register_error(elgg_echo("groups:cantedit"));
  40. }
  41. } else {
  42. register_error(elgg_echo("groups:notfound:details"));
  43. }
  44. } else {
  45. register_error(elgg_echo("InvalidParameterException:MissingParameter"));
  46. }
  47. forward(REFERER);