ElggRiverItem.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * River item class.
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Core
  7. *
  8. * @property-read int $id The unique identifier (read-only)
  9. * @property-read int $subject_guid The GUID of the actor
  10. * @property-read int $object_guid The GUID of the object
  11. * @property-read int $target_guid The GUID of the object's container
  12. * @property-read int $annotation_id The ID of the annotation involved in the action
  13. * @property-read string $type The type of one of the entities involved in the action
  14. * @property-read string $subtype The subtype of one of the entities involved in the action
  15. * @property-read string $action_type The name of the action
  16. * @property-read string $view The view for displaying this river item
  17. * @property-read int $access_id The visibility of the river item
  18. * @property-read int $posted UNIX timestamp when the action occurred
  19. * @property-read string $enabled Is the river item enabled yes|no
  20. */
  21. class ElggRiverItem {
  22. public $id;
  23. public $subject_guid;
  24. public $object_guid;
  25. public $target_guid;
  26. public $annotation_id;
  27. public $type;
  28. public $subtype;
  29. public $action_type;
  30. public $access_id;
  31. public $view;
  32. public $posted;
  33. public $enabled;
  34. /**
  35. * Construct a river item object given a database row.
  36. *
  37. * @param \stdClass $object Object obtained from database
  38. */
  39. public function __construct($object) {
  40. if (!($object instanceof \stdClass)) {
  41. throw new \InvalidParameterException("Invalid input to \ElggRiverItem constructor");
  42. }
  43. // the casting is to support typed serialization like json
  44. $int_types = array('id', 'subject_guid', 'object_guid', 'target_guid', 'annotation_id', 'access_id', 'posted');
  45. foreach ($object as $key => $value) {
  46. if (in_array($key, $int_types)) {
  47. $this->$key = (int)$value;
  48. } else {
  49. $this->$key = $value;
  50. }
  51. }
  52. }
  53. /**
  54. * Get the subject of this river item
  55. *
  56. * @return \ElggEntity
  57. */
  58. public function getSubjectEntity() {
  59. return get_entity($this->subject_guid);
  60. }
  61. /**
  62. * Get the object of this river item
  63. *
  64. * @return \ElggEntity
  65. */
  66. public function getObjectEntity() {
  67. return get_entity($this->object_guid);
  68. }
  69. /**
  70. * Get the target of this river item
  71. *
  72. * @return \ElggEntity
  73. */
  74. public function getTargetEntity() {
  75. return get_entity($this->target_guid);
  76. }
  77. /**
  78. * Get the Annotation for this river item
  79. *
  80. * @return \ElggAnnotation
  81. */
  82. public function getAnnotation() {
  83. return elgg_get_annotation_from_id($this->annotation_id);
  84. }
  85. /**
  86. * Get the view used to display this river item
  87. *
  88. * @return string
  89. */
  90. public function getView() {
  91. return $this->view;
  92. }
  93. /**
  94. * Get the time this activity was posted
  95. *
  96. * @return int
  97. * @deprecated 1.9 Use getTimePosted()
  98. */
  99. public function getPostedTime() {
  100. elgg_deprecated_notice("\ElggRiverItem::getPostedTime() deprecated in favor of getTimePosted()", 1.9);
  101. return (int)$this->posted;
  102. }
  103. /**
  104. * Get the time this activity was posted
  105. *
  106. * @return int
  107. */
  108. public function getTimePosted() {
  109. return (int)$this->posted;
  110. }
  111. /**
  112. * Get the type of the object
  113. *
  114. * This is required for elgg_view_list_item(). All the other data types
  115. * (entities, extenders, relationships) have a type/subtype.
  116. *
  117. * @return string 'river'
  118. */
  119. public function getType() {
  120. return 'river';
  121. }
  122. /**
  123. * Get the subtype of the object
  124. *
  125. * This is required for elgg_view_list_item().
  126. *
  127. * @return string 'item'
  128. */
  129. public function getSubtype() {
  130. return 'item';
  131. }
  132. /**
  133. * Get a plain old object copy for public consumption
  134. *
  135. * @return \stdClass
  136. */
  137. public function toObject() {
  138. $object = new \stdClass();
  139. $object->id = $this->id;
  140. $object->subject_guid = $this->subject_guid;
  141. $object->object_guid = $this->object_guid;
  142. $object->annotation_id = $this->annotation_id;
  143. $object->read_access = $this->access_id;
  144. $object->action = $this->action_type;
  145. $object->time_posted = date('c', $this->getTimePosted());
  146. $object->enabled = $this->enabled;
  147. $params = array('item' => $this);
  148. return _elgg_services()->hooks->trigger('to:object', 'river_item', $params, $object);
  149. }
  150. }