heartbeatstream.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * @file
  4. * HeartbeatStream object takes configuration parameters to create a stream of activity objects.
  5. * pre-query, query and post-query phases of the stream can be specified and manipulated here
  6. */
  7. /**
  8. * Abstract Class HeartbeatStream
  9. * Base class with template methods. HeartbeatStream is a state object given to the HeartbeatStreamBuilder
  10. * to set access on current request
  11. */
  12. abstract class HeartbeatStream
  13. {
  14. // Query object for this stream.
  15. protected $query = NULL;
  16. // Configuration object for this stream.
  17. public $config = NULL;
  18. // Well-formed activity messages.
  19. public $messages = array();
  20. // String prefix on top of the stream.
  21. public $prefix = '';
  22. // String suffix under a stream.
  23. public $suffix = '';
  24. // Templates available to show.
  25. public $templates = array();
  26. // Contextual arguments.
  27. public $contextual_arguments = array();
  28. // Denied templates.
  29. protected $templates_denied = array();
  30. // Language at display time.
  31. protected $language = LANGUAGE_NONE;
  32. // exclude Og.
  33. protected $exclude_og = FALSE;
  34. // The stream owner or activity watcher.
  35. protected $_uid = 0;
  36. // Array of runtime notices, warnings and errors.
  37. protected $_errors = array();
  38. // Indicates if there are runtime errors.
  39. protected $_has_errors = FALSE;
  40. // Indicates whether the page has modal requirement.
  41. protected $needsModal = TRUE;
  42. // Time where activity starts.
  43. protected $_offset_time = 0;
  44. // Maximum time where activity must end.
  45. protected $oldest_date = 604800;
  46. // Maximum number of activity messages to show.
  47. protected $messages_max = 0;
  48. // Latest user activity id fetched.
  49. protected $latest_activity_id = 0;
  50. // Indicates if the stream is displayed on a page or not.
  51. protected $_page = FALSE;
  52. // Indicates if this is an ajax request.
  53. protected $ajax = 0;
  54. // Can page means if we can show more messages
  55. protected $canPage = FALSE;
  56. // User view type of the stream instance.
  57. protected $_whoisuser_type = self::VIEWER;
  58. // The user who is viewing the activity stream.
  59. protected $viewer = null;
  60. // The user who's activity stream is viewed.
  61. protected $viewed = null;
  62. // View mode to display message.
  63. protected $view_mode = 'default';
  64. protected $_whoisuser_types = array(
  65. self::VIEWER => 'Viewing user',
  66. self::VIEWED => 'Viewed user'
  67. );
  68. // User viewer types.
  69. const VIEWER = 0;
  70. const VIEWED = 1;
  71. final public function __construct(HeartbeatStreamConfig $streamConfig, $page = FALSE, $account = NULL) {
  72. $this->_page = $page;
  73. $this->setConfig($streamConfig);
  74. $this->setAjax();
  75. if (empty($this->_offset_time)) {
  76. $this->setOffsetTime();
  77. }
  78. $this->setViewer(\Drupal::currentUser());
  79. $this->setViewed($account);
  80. $this->setAvailableTemplates();
  81. $this->construct();
  82. $this->setContextualArguments();
  83. }
  84. /**
  85. * Fake Constructor Method
  86. */
  87. public function construct() {
  88. }
  89. /**
  90. *
  91. */
  92. protected function setContextualArguments() {
  93. $contextualArguments = \Drupal::request()->query->get('contextualArguments');
  94. if (!empty($contextualArguments) && isset($contextualArguments['uid_target'])) {
  95. $this->contextual_arguments = $contextualArguments['uid_target'];
  96. } elseif ($this->viewed->uid != $this->viewer->uid) {
  97. $this->contextual_arguments['uid_target'] = $this->viewed->uid;
  98. }
  99. //TODO Figure out a way to attach $this->contextual_arguments to the drupalSettings object with an id of "heartbeatContextualArguments"
  100. //see below for implementation in a page callback or form alter
  101. // $variables['#attached']['drupalSettings']['heartbeatContextualArguments'] = $this->contextual_arguments;
  102. }
  103. }