ContentSubscriptions.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace ColdTrick\Questions;
  3. class ContentSubscriptions {
  4. /**
  5. * Add questions to Content Subscriptions supported types
  6. *
  7. * @param string $hook the name of the hook
  8. * @param string $type the type of the hook
  9. * @param array $return_value current return value
  10. * @param array $params supplied params
  11. *
  12. * @return void|array
  13. */
  14. public static function getEntityTypes($hook, $type, $return_value, $params) {
  15. if (!is_array($return_value)) {
  16. // someone blocked all
  17. return;
  18. }
  19. $return_value['object'][] = \ElggQuestion::SUBTYPE;
  20. return $return_value;
  21. }
  22. /**
  23. * Subscribe to a question when you create an answer
  24. *
  25. * @param string $event
  26. * @param string $type
  27. * @param \ElggObject $object
  28. *
  29. * @return void
  30. */
  31. public static function createAnswer($event, $type, \ElggObject $object) {
  32. if (!elgg_is_active_plugin('content_subscriptions')) {
  33. return;
  34. }
  35. if (!($object instanceof \ElggAnswer)) {
  36. return;
  37. }
  38. $owner = $object->getOwnerEntity();
  39. $question = $object->getContainerEntity();
  40. if (!content_subscriptions_can_subscribe($question, $owner->getGUID())) {
  41. return;
  42. }
  43. // subscribe to the question
  44. content_subscriptions_autosubscribe($question->getGUID(), $owner->getGUID());
  45. }
  46. /**
  47. * Subscribe to a question when you create a comment on an answer
  48. *
  49. * @param string $event
  50. * @param string $type
  51. * @param \ElggObject $object
  52. *
  53. * @return void
  54. */
  55. public static function createCommentOnAnswer($event, $type, \ElggObject $object) {
  56. if (!elgg_is_active_plugin('content_subscriptions')) {
  57. return;
  58. }
  59. if (!($object instanceof \ElggComment)) {
  60. return;
  61. }
  62. $answer = $object->getContainerEntity();
  63. if (!($answer instanceof \ElggAnswer)) {
  64. return;
  65. }
  66. $owner = $object->getOwnerEntity();
  67. $question = $answer->getContainerEntity();
  68. if (!content_subscriptions_can_subscribe($question, $owner->getGUID())) {
  69. return;
  70. }
  71. // subscribe to the question
  72. content_subscriptions_autosubscribe($question->getGUID(), $owner->getGUID());
  73. }
  74. }