1: <?php
2: /**
3: * River item class.
4: *
5: * @package Elgg.Core
6: * @subpackage Core
7: *
8: * @property int $id The unique identifier (read-only)
9: * @property int $subject_guid The GUID of the actor
10: * @property int $object_guid The GUID of the object
11: * @property int $annotation_id The ID of the annotation involved in the action
12: * @property string $type The type of one of the entities involved in the action
13: * @property string $subtype The subtype of one of the entities involved in the action
14: * @property string $action_type The name of the action
15: * @property string $view The view for displaying this river item
16: * @property int $access_id The visibility of the river item
17: * @property int $posted UNIX timestamp when the action occurred
18: */
19: class ElggRiverItem {
20: public $id;
21: public $subject_guid;
22: public $object_guid;
23: public $annotation_id;
24: public $type;
25: public $subtype;
26: public $action_type;
27: public $access_id;
28: public $view;
29: public $posted;
30:
31: /**
32: * Construct a river item object given a database row.
33: *
34: * @param stdClass $object Object obtained from database
35: */
36: function __construct($object) {
37: if (!($object instanceof stdClass)) {
38: // throw exception
39: }
40:
41: // the casting is to support typed serialization like json
42: $int_types = array('id', 'subject_guid', 'object_guid', 'annotation_id', 'access_id', 'posted');
43: foreach ($object as $key => $value) {
44: if (in_array($key, $int_types)) {
45: $this->$key = (int)$value;
46: } else {
47: $this->$key = $value;
48: }
49: }
50: }
51:
52: /**
53: * Get the subject of this river item
54: *
55: * @return ElggEntity
56: */
57: public function getSubjectEntity() {
58: return get_entity($this->subject_guid);
59: }
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: /**
71: * Get the Annotation for this river item
72: *
73: * @return ElggAnnotation
74: */
75: public function getAnnotation() {
76: return elgg_get_annotation_from_id($this->annotation_id);
77: }
78:
79: /**
80: * Get the view used to display this river item
81: *
82: * @return string
83: */
84: public function getView() {
85: return $this->view;
86: }
87:
88: /**
89: * Get the time this activity was posted
90: *
91: * @return int
92: */
93: public function getPostedTime() {
94: return (int)$this->posted;
95: }
96:
97: /**
98: * Get the type of the object
99: *
100: * @return string 'river'
101: */
102: public function getType() {
103: return 'river';
104: }
105:
106: /**
107: * Get the subtype of the object
108: *
109: * @return string 'item'
110: */
111: public function getSubtype() {
112: return 'item';
113: }
114:
115: }
116: