Elgg  Version 2.3
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 $type;
29  public $subtype;
30  public $action_type;
31  public $access_id;
32  public $view;
33  public $posted;
34  public $enabled;
35 
41  public function __construct($object) {
42  if (!($object instanceof \stdClass)) {
43  throw new \InvalidParameterException("Invalid input to \ElggRiverItem constructor");
44  }
45 
46  // the casting is to support typed serialization like json
47  $int_types = array('id', 'subject_guid', 'object_guid', 'target_guid', 'annotation_id', 'access_id', 'posted');
48  foreach ($object as $key => $value) {
49  if (in_array($key, $int_types)) {
50  $this->$key = (int)$value;
51  } else {
52  $this->$key = $value;
53  }
54  }
55  }
56 
62  public function getSubjectEntity() {
63  return get_entity($this->subject_guid);
64  }
65 
71  public function getObjectEntity() {
72  return get_entity($this->object_guid);
73  }
74 
80  public function getTargetEntity() {
81  return get_entity($this->target_guid);
82  }
83 
89  public function getAnnotation() {
90  return elgg_get_annotation_from_id($this->annotation_id);
91  }
92 
98  public function getView() {
99  return $this->view;
100  }
101 
108  public function getPostedTime() {
109  elgg_deprecated_notice("\ElggRiverItem::getPostedTime() deprecated in favor of getTimePosted()", 1.9);
110  return (int)$this->posted;
111  }
112 
118  public function getTimePosted() {
119  return (int)$this->posted;
120  }
121 
130  public function getType() {
131  return 'river';
132  }
133 
141  public function getSubtype() {
142  return 'item';
143  }
144 
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 = array('item' => $this);
202  return _elgg_services()->hooks->trigger('to:object', 'river_item', $params, $object);
203  }
204 
205 }
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
getType()
Get the type of the object.
__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.
$value
Definition: longtext.php:42
getTimePosted()
Get the time this activity was posted.
getSubtype()
Get the subtype of the object.
$params
Definition: login.php:72
elgg_get_annotation_from_id($id)
Get a specific annotation by its id.
Definition: annotations.php:36
$key
Definition: summary.php:34
getAnnotation()
Get the Annotation for this river item.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
canDelete($user_guid=0)
Can a user delete this river item?
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
getView()
Get the view used to display this river item.
$user_guid
Avatar remove action.
Definition: remove.php:6
getTargetEntity()
Get the target of this river item.
getPostedTime()
Get the time this activity was posted.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204
getObjectEntity()
Get the object of this river item.