Elgg  Version 4.3
ElggRiverItem.php
Go to the documentation of this file.
1 <?php
2 
17 
21  protected const INTEGER_ATTR_NAMES = [
22  'id',
23  'subject_guid',
24  'object_guid',
25  'target_guid',
26  'annotation_id',
27  'access_id',
28  'posted',
29  ];
30 
36  public function __construct(\stdClass $row = null) {
37  if (!empty($row)) {
38  // build from database
39  foreach ($row as $key => $value) {
40  if (in_array($key, static::INTEGER_ATTR_NAMES)) {
41  $this->$key = (int) $value;
42  } else {
43  $this->$key = $value;
44  }
45  }
46  }
47  }
48 
52  public function __set(string $name, $value) {
53  $this->$name = $value;
54  }
55 
59  public function __get($name) {
60  switch ($name) {
61  case 'type' :
62  case 'subtype' :
63  $object = get_entity($this->object_guid);
64  if ($object) {
65  return $object->$name;
66  }
67  break;
68  }
69  }
70 
76  public function getSubjectEntity() {
77  return get_entity($this->subject_guid);
78  }
79 
85  public function getObjectEntity() {
86  return get_entity($this->object_guid);
87  }
88 
94  public function getTargetEntity() {
95  return get_entity($this->target_guid);
96  }
97 
103  public function getAnnotation() {
104  return elgg_get_annotation_from_id($this->annotation_id);
105  }
106 
112  public function getView() {
113  return $this->view;
114  }
115 
121  public function getTimePosted() {
122  return (int) $this->posted;
123  }
124 
133  public function getType() {
134  return 'river';
135  }
136 
144  public function getSubtype() {
145  return 'item';
146  }
147 
158  public function canDelete($user_guid = 0) {
159  return _elgg_services()->userCapabilities->canDeleteRiverItem($this, $user_guid);
160  }
161 
168  public function delete() {
169  if (!$this->canDelete()) {
170  return false;
171  }
172 
173  return _elgg_services()->riverTable->delete($this);
174  }
175 
181  public function toObject() {
182  $object = new \stdClass();
183  $object->id = $this->id;
184  $object->subject_guid = $this->subject_guid;
185  $object->target_guid = $this->target_guid;
186  $object->object_guid = $this->object_guid;
187  $object->annotation_id = $this->annotation_id;
188  $object->read_access = $this->access_id;
189  $object->action = $this->action_type;
190  $object->view = $this->view;
191  $object->time_posted = date('c', $this->getTimePosted());
192 
193  $params = ['item' => $this];
194  return _elgg_services()->hooks->trigger('to:object', 'river_item', $params, $object);
195  }
196 
202  public function save(): bool {
203  if ($this->id) {
204  // update (not supported)
205  return true;
206  }
207 
208  return (bool) _elgg_services()->riverTable->create($this);
209  }
210 }
getType()
Get the type of the object.
$user_guid
Definition: login_as.php:10
$params
Saves global plugin settings.
Definition: save.php:13
toObject()
Get a plain old object copy for public consumption.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getSubjectEntity()
Get the subject of this river item.
const INTEGER_ATTR_NAMES
$target_guid
Definition: groups.php:25
getTimePosted()
Get the time this activity was posted.
__get($name)
{}
$value
Definition: generic.php:51
getSubtype()
Get the subtype of the object.
save()
Save the river item to the database.
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
getAnnotation()
Get the Annotation for this river item.
__construct(\stdClass $row=null)
Construct a river item object.
canDelete($user_guid=0)
Can a user delete this river item?
__set(string $name, $value)
{}
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
$posted
Definition: comment.php:86
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
elgg_get_annotation_from_id(int $id)
Elgg annotations Functions to manage object annotations.
Definition: annotations.php:16
getView()
Get the view used to display this river item.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
$access_id
Definition: access.php:11
$id
Generic annotation delete action.
Definition: delete.php:6
getTargetEntity()
Get the target of this river item.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69
getObjectEntity()
Get the object of this river item.