Elgg  Version 3.0
ElggRiverItem.php
Go to the documentation of this file.
1 <?php
2 
23  public $id;
24  public $subject_guid;
25  public $object_guid;
26  public $target_guid;
28  public $action_type;
29  public $access_id;
30  public $view;
31  public $posted;
32  public $enabled;
33 
39  public function __construct($object) {
40  if (!($object instanceof \stdClass)) {
41  throw new \InvalidParameterException("Invalid input to \ElggRiverItem constructor");
42  }
43 
44  // the casting is to support typed serialization like json
45  $int_types = ['id', 'subject_guid', 'object_guid', 'target_guid', 'annotation_id', 'access_id', 'posted'];
46  foreach ($object as $key => $value) {
47  if (in_array($key, $int_types)) {
48  $this->$key = (int) $value;
49  } else {
50  $this->$key = $value;
51  }
52  }
53  }
54 
58  public function __get($name) {
59  switch ($name) {
60  case 'type' :
61  case 'subtype' :
62  $object = get_entity($this->object_guid);
63  if ($object) {
64  return $object->$name;
65  }
66  break;
67  }
68  }
69 
75  public function getSubjectEntity() {
76  return get_entity($this->subject_guid);
77  }
78 
84  public function getObjectEntity() {
85  return get_entity($this->object_guid);
86  }
87 
93  public function getTargetEntity() {
94  return get_entity($this->target_guid);
95  }
96 
102  public function getAnnotation() {
103  return elgg_get_annotation_from_id($this->annotation_id);
104  }
105 
111  public function getView() {
112  return $this->view;
113  }
114 
120  public function getTimePosted() {
121  return (int) $this->posted;
122  }
123 
132  public function getType() {
133  return 'river';
134  }
135 
143  public function getSubtype() {
144  return 'item';
145  }
146 
157  public function canDelete($user_guid = 0) {
158  return _elgg_services()->userCapabilities->canDeleteRiverItem($this, $user_guid);
159  }
160 
167  public function delete() {
168  if (!$this->canDelete()) {
169  return false;
170  }
171 
172  $events = _elgg_services()->events;
173  if (!$events->triggerBefore('delete', 'river', $this)) {
174  return false;
175  }
176 
177  $db = _elgg_services()->db;
178  $prefix = $db->prefix;
179  _elgg_services()->db->deleteData("DELETE FROM {$prefix}river WHERE id = ?", [$this->id]);
180 
181  $events->triggerAfter('delete', 'river', $this);
182 
183  return true;
184  }
185 
191  public function toObject() {
192  $object = new \stdClass();
193  $object->id = $this->id;
194  $object->subject_guid = $this->subject_guid;
195  $object->object_guid = $this->object_guid;
196  $object->annotation_id = $this->annotation_id;
197  $object->read_access = $this->access_id;
198  $object->action = $this->action_type;
199  $object->time_posted = date('c', $this->getTimePosted());
200  $object->enabled = $this->enabled;
201  $params = ['item' => $this];
202  return _elgg_services()->hooks->trigger('to:object', 'river_item', $params, $object);
203  }
204 
205 }
getType()
Get the type of the object.
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$params
Saves global plugin settings.
Definition: save.php:13
__construct($object)
Construct a river item object given a database row.
toObject()
Get a plain old object copy for public consumption.
getSubjectEntity()
Get the subject of this river item.
getTimePosted()
Get the time this activity was posted.
__get($name)
{}
getSubtype()
Get the subtype of the object.
$user_guid
Validate a user.
Definition: validate.php:6
elgg_get_annotation_from_id($id)
Elgg annotations Functions to manage object annotations.
Definition: annotations.php:16
getAnnotation()
Get the Annotation for this river item.
canDelete($user_guid=0)
Can a user delete this river item?
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$value
Definition: debugging.php:7
getView()
Get the view used to display this river item.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
getTargetEntity()
Get the target of this river item.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87
getObjectEntity()
Get the object of this river item.