Elgg  Version 2.3
ElggEntity.php
Go to the documentation of this file.
1 <?php
2 
43 abstract class ElggEntity extends \ElggData implements
44  Locatable, // Geocoding interface
45  Importable, // Allow import of data (deprecated 1.9)
46  \Elgg\EntityIcon // Icon interface
47 {
48 
52  protected $url_override;
53 
58  protected $temp_metadata = array();
59 
64  protected $temp_annotations = array();
65 
70  protected $temp_private_settings = array();
71 
76  protected $volatile = array();
77 
81  protected $orig_attributes = array();
82 
90  protected function initializeAttributes() {
91  parent::initializeAttributes();
92 
93  $this->attributes['guid'] = null;
94  $this->attributes['type'] = null;
95  $this->attributes['subtype'] = null;
96 
97  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid();
98  $this->attributes['container_guid'] = _elgg_services()->session->getLoggedInUserGuid();
99 
100  $this->attributes['site_guid'] = null;
101  $this->attributes['access_id'] = ACCESS_PRIVATE;
102  $this->attributes['time_updated'] = null;
103  $this->attributes['last_action'] = null;
104  $this->attributes['enabled'] = "yes";
105  }
106 
120  public function __clone() {
121  $orig_entity = get_entity($this->guid);
122  if (!$orig_entity) {
123  _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid");
124  return;
125  }
126 
127  $metadata_array = elgg_get_metadata(array(
128  'guid' => $this->guid,
129  'limit' => 0
130  ));
131 
132  $this->attributes['guid'] = "";
133 
134  $this->attributes['subtype'] = $orig_entity->getSubtype();
135 
136  // copy metadata over to new entity - slightly convoluted due to
137  // handling of metadata arrays
138  if (is_array($metadata_array)) {
139  // create list of metadata names
140  $metadata_names = array();
141  foreach ($metadata_array as $metadata) {
142  $metadata_names[] = $metadata['name'];
143  }
144  // arrays are stored with multiple enties per name
145  $metadata_names = array_unique($metadata_names);
146 
147  // move the metadata over
148  foreach ($metadata_names as $name) {
149  $this->__set($name, $orig_entity->$name);
150  }
151  }
152  }
153 
167  public function __set($name, $value) {
168  if ($this->$name === $value) {
169  // quick return if value is not changing
170  return;
171  }
172 
173  if (array_key_exists($name, $this->attributes)) {
174  // if an attribute is 1 (integer) and it's set to "1" (string), don't consider that a change.
175  if (is_int($this->attributes[$name])
176  && is_string($value)
177  && ((string)$this->attributes[$name] === $value)) {
178  return;
179  }
180 
181  // Due to https://github.com/Elgg/Elgg/pull/5456#issuecomment-17785173, certain attributes
182  // will store empty strings as null in the DB. In the somewhat common case that we're re-setting
183  // the value to empty string, don't consider this a change.
184  if (in_array($name, ['title', 'name', 'description'])
185  && $this->attributes[$name] === null
186  && $value === "") {
187  return;
188  }
189 
190  // keep original values
191  if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
192  $this->orig_attributes[$name] = $this->attributes[$name];
193  }
194 
195  // Certain properties should not be manually changed!
196  switch ($name) {
197  case 'guid':
198  case 'time_updated':
199  case 'last_action':
200  return;
201  break;
202  case 'access_id':
203  case 'owner_guid':
204  case 'container_guid':
205  if ($value !== null) {
206  $this->attributes[$name] = (int)$value;
207  } else {
208  $this->attributes[$name] = null;
209  }
210  break;
211  default:
212  $this->attributes[$name] = $value;
213  break;
214  }
215  return;
216  }
217 
218  if ($name === 'tables_split' || $name === 'tables_loaded') {
219  elgg_deprecated_notice("Do not read/write ->tables_split or ->tables_loaded.", "2.1");
220  return;
221  }
222 
223  $this->setMetadata($name, $value);
224  }
225 
235  public function set($name, $value) {
236  elgg_deprecated_notice("Use -> instead of set()", 1.9);
237  $this->__set($name, $value);
238 
239  return true;
240  }
241 
247  public function getOriginalAttributes() {
248  return $this->orig_attributes;
249  }
250 
263  public function __get($name) {
264  if (array_key_exists($name, $this->attributes)) {
265  if ($name === 'subtype' && $this->attributes['guid']) {
266  // note: only show deprecation notice if user reads ->subtype after save/load
267  elgg_deprecated_notice("Use getSubtype()", 1.9);
268  }
269  return $this->attributes[$name];
270  }
271 
272  if ($name === 'tables_split' || $name === 'tables_loaded') {
273  elgg_deprecated_notice("Do not read/write ->tables_split or ->tables_loaded.", "2.1");
274  return 2;
275  }
276 
277  return $this->getMetadata($name);
278  }
279 
287  public function get($name) {
288  elgg_deprecated_notice("Use -> instead of get()", 1.9);
289  return $this->__get($name);
290  }
291 
297  abstract public function getDisplayName();
298 
305  abstract public function setDisplayName($displayName);
306 
314  public function getMetadata($name) {
315  $guid = $this->getGUID();
316 
317  if (!$guid) {
318  if (isset($this->temp_metadata[$name])) {
319  // md is returned as an array only if more than 1 entry
320  if (count($this->temp_metadata[$name]) == 1) {
321  return $this->temp_metadata[$name][0];
322  } else {
323  return $this->temp_metadata[$name];
324  }
325  } else {
326  return null;
327  }
328  }
329 
330  // upon first cache miss, just load/cache all the metadata and retry.
331  // if this works, the rest of this function may not be needed!
332  $cache = _elgg_services()->metadataCache;
333  if ($cache->isLoaded($guid)) {
334  return $cache->getSingle($guid, $name);
335  } else {
336  $cache->populateFromEntities(array($guid));
337  // in case ignore_access was on, we have to check again...
338  if ($cache->isLoaded($guid)) {
339  return $cache->getSingle($guid, $name);
340  }
341  }
342 
343  $md = elgg_get_metadata(array(
344  'guid' => $guid,
345  'metadata_name' => $name,
346  'limit' => 0,
347  'distinct' => false,
348  ));
349 
350  $value = null;
351 
352  if ($md && !is_array($md)) {
353  $value = $md->value;
354  } elseif (count($md) == 1) {
355  $value = $md[0]->value;
356  } else if ($md && is_array($md)) {
358  }
359 
360  return $value;
361  }
362 
373  public function __unset($name) {
374  if (array_key_exists($name, $this->attributes)) {
375  $this->attributes[$name] = "";
376  } else {
377  $this->deleteMetadata($name);
378  }
379  }
380 
402  public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) {
403 
404  // normalize value to an array that we will loop over
405  // remove indexes if value already an array.
406  if (is_array($value)) {
407  $value = array_values($value);
408  } else {
409  $value = array($value);
410  }
411 
412  // saved entity. persist md to db.
413  if ($this->guid) {
414  // if overwriting, delete first.
415  if (!$multiple) {
416  $options = array(
417  'guid' => $this->getGUID(),
418  'metadata_name' => $name,
419  'limit' => 0
420  );
421  // @todo in 1.9 make this return false if can't add metadata
422  // https://github.com/elgg/elgg/issues/4520
423  //
424  // need to remove access restrictions right now to delete
425  // because this is the expected behavior
426  $ia = elgg_set_ignore_access(true);
427  if (false === elgg_delete_metadata($options)) {
428  return false;
429  }
431  }
432 
433  $owner_guid = $owner_guid ? (int)$owner_guid : $this->owner_guid;
434 
435  if ($access_id === null) {
436  $access_id = $this->access_id;
437  } elseif ($access_id != ACCESS_PUBLIC) {
438  $access_id = (int)$access_id;
439  elgg_deprecated_notice('Setting $access_id to a value other than ACCESS_PUBLIC is deprecated. '
440  . 'All metadata will be public in 3.0.', '2.3');
441  }
442 
443  // add new md
444  $result = true;
445  foreach ($value as $value_tmp) {
446  // at this point $value is appended because it was cleared above if needed.
447  $md_id = _elgg_services()->metadataTable->create($this->guid, $name, $value_tmp, $value_type,
448  $owner_guid, $access_id, true);
449  if (!$md_id) {
450  return false;
451  }
452  }
453 
454  return $result;
455  } else {
456  // unsaved entity. store in temp array
457 
458  // returning single entries instead of an array of 1 element is decided in
459  // getMetaData(), just like pulling from the db.
460 
461  if ($owner_guid != 0 || $access_id !== null) {
462  $msg = "owner guid and access id cannot be used in \ElggEntity::setMetadata() until entity is saved.";
463  throw new \InvalidArgumentException($msg);
464  }
465 
466  // if overwrite, delete first
467  if (!$multiple || !isset($this->temp_metadata[$name])) {
468  $this->temp_metadata[$name] = array();
469  }
470 
471  // add new md
472  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
473  return true;
474  }
475  }
476 
487  public function deleteMetadata($name = null) {
488 
489  if (!$this->guid) {
490  return false;
491  }
492 
493  $options = array(
494  'guid' => $this->guid,
495  'limit' => 0
496  );
497  if ($name) {
498  $options['metadata_name'] = $name;
499  }
500 
502  }
503 
512  public function deleteOwnedMetadata($name = null) {
513  // access is turned off for this because they might
514  // no longer have access to an entity they created metadata on.
515  $ia = elgg_set_ignore_access(true);
516  $options = array(
517  'metadata_owner_guid' => $this->guid,
518  'limit' => 0
519  );
520  if ($name) {
521  $options['metadata_name'] = $name;
522  }
523 
526  return $r;
527  }
528 
536  public function disableMetadata($name = '') {
537  $options = array(
538  'guid' => $this->guid,
539  'limit' => 0
540  );
541  if ($name) {
542  $options['metadata_name'] = $name;
543  }
544 
546  }
547 
557  public function enableMetadata($name = '') {
558  $options = array(
559  'guid' => $this->guid,
560  'limit' => 0
561  );
562  if ($name) {
563  $options['metadata_name'] = $name;
564  }
565 
567  }
568 
576  public function getVolatileData($name) {
577  return array_key_exists($name, $this->volatile) ? $this->volatile[$name] : null;
578  }
579 
588  public function setVolatileData($name, $value) {
589  $this->volatile[$name] = $value;
590  }
591 
602  public function storeInPersistedCache(\ElggSharedMemoryCache $cache, $last_action = 0) {
603  $tmp = $this->volatile;
604 
605  // don't store volatile data
606  $this->volatile = [];
607  if ($last_action) {
608  $this->attributes['last_action'] = (int)$last_action;
609  }
610  $cache->save($this->guid, $this);
611 
612  $this->volatile = $tmp;
613  }
614 
628  public function deleteRelationships($relationship = null) {
629  $relationship = (string)$relationship;
630  $result = remove_entity_relationships($this->getGUID(), $relationship);
631  return $result && remove_entity_relationships($this->getGUID(), $relationship, true);
632  }
633 
646  public function addRelationship($guid_two, $relationship) {
647  return add_entity_relationship($this->getGUID(), $relationship, $guid_two);
648  }
649 
660  public function removeRelationship($guid_two, $relationship) {
661  return remove_entity_relationship($this->getGUID(), $relationship, $guid_two);
662  }
663 
675  public function setPrivateSetting($name, $value) {
676  if ((int) $this->guid > 0) {
677  return set_private_setting($this->getGUID(), $name, $value);
678  } else {
679  $this->temp_private_settings[$name] = $value;
680  return true;
681  }
682  }
683 
691  public function getPrivateSetting($name) {
692  if ((int) ($this->guid) > 0) {
693  return get_private_setting($this->getGUID(), $name);
694  } else {
695  if (isset($this->temp_private_settings[$name])) {
696  return $this->temp_private_settings[$name];
697  }
698  }
699  return null;
700  }
701 
709  public function removePrivateSetting($name) {
710  return remove_private_setting($this->getGUID(), $name);
711  }
712 
723  public function deleteAnnotations($name = null) {
724  $options = array(
725  'guid' => $this->guid,
726  'limit' => 0
727  );
728  if ($name) {
729  $options['annotation_name'] = $name;
730  }
731 
733  }
734 
743  public function deleteOwnedAnnotations($name = null) {
744  // access is turned off for this because they might
745  // no longer have access to an entity they created annotations on.
746  $ia = elgg_set_ignore_access(true);
747  $options = array(
748  'annotation_owner_guid' => $this->guid,
749  'limit' => 0
750  );
751  if ($name) {
752  $options['annotation_name'] = $name;
753  }
754 
757  return $r;
758  }
759 
767  public function disableAnnotations($name = '') {
768  $options = array(
769  'guid' => $this->guid,
770  'limit' => 0
771  );
772  if ($name) {
773  $options['annotation_name'] = $name;
774  }
775 
777  }
778 
788  public function enableAnnotations($name = '') {
789  $options = array(
790  'guid' => $this->guid,
791  'limit' => 0
792  );
793  if ($name) {
794  $options['annotation_name'] = $name;
795  }
796 
798  }
799 
807  private function getAnnotationCalculation($name, $calculation) {
808  $options = array(
809  'guid' => $this->getGUID(),
810  'distinct' => false,
811  'annotation_name' => $name,
812  'annotation_calculation' => $calculation
813  );
814 
816  }
817 
834  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $vartype = "") {
835  if ((int) $this->guid > 0) {
836  return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_guid, $access_id);
837  } else {
838  $this->temp_annotations[$name] = $value;
839  }
840  return true;
841  }
842 
858  public function getAnnotations($options = array(), $limit = 50, $offset = 0, $order = "asc") {
859  if (!is_array($options)) {
860  elgg_deprecated_notice("\ElggEntity::getAnnotations() takes an array of options.", 1.9);
861  }
862 
863  if ((int) ($this->guid) > 0) {
864  if (!is_array($options)) {
865  $options = array(
866  'guid' => $this->guid,
867  'annotation_name' => $options,
868  'limit' => $limit,
869  'offset' => $offset,
870  );
871 
872  if ($order != 'asc') {
873  $options['reverse_order_by'] = true;
874  }
875  } else {
876  $options['guid'] = $this->guid;
877  }
878 
880  } else {
881  if (!is_array($options)) {
882  $name = $options;
883  } else {
884  $name = elgg_extract('annotation_name', $options, '');
885  }
886 
887  if (isset($this->temp_annotations[$name])) {
888  return array($this->temp_annotations[$name]);
889  }
890  }
891 
892  return array();
893  }
894 
902  public function countAnnotations($name = "") {
903  return $this->getAnnotationCalculation($name, 'count');
904  }
905 
913  public function getAnnotationsAvg($name) {
914  return $this->getAnnotationCalculation($name, 'avg');
915  }
916 
924  public function getAnnotationsSum($name) {
925  return $this->getAnnotationCalculation($name, 'sum');
926  }
927 
935  public function getAnnotationsMin($name) {
936  return $this->getAnnotationCalculation($name, 'min');
937  }
938 
946  public function getAnnotationsMax($name) {
947  return $this->getAnnotationCalculation($name, 'max');
948  }
949 
956  public function countComments() {
957  $params = array('entity' => $this);
958  $num = _elgg_services()->hooks->trigger('comments:count', $this->getType(), $params);
959 
960  if (is_int($num)) {
961  return $num;
962  } else {
963  return elgg_get_entities(array(
964  'type' => 'object',
965  'subtype' => 'comment',
966  'container_guid' => $this->getGUID(),
967  'count' => true,
968  'distinct' => false,
969  ));
970  }
971  }
972 
986  public function getEntitiesFromRelationship($options = array(), $inverse = false, $limit = 50, $offset = 0) {
987  if (is_array($options)) {
988  $options['relationship_guid'] = $this->getGUID();
990  } else {
991  elgg_deprecated_notice("\ElggEntity::getEntitiesFromRelationship takes an options array", 1.9);
993  'relationship' => $options,
994  'relationship_guid' => $this->getGUID(),
995  'inverse_relationship' => $inverse,
996  'limit' => $limit,
997  'offset' => $offset
998  ));
999  }
1000  }
1001 
1010  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
1012  'relationship' => $relationship,
1013  'relationship_guid' => $this->getGUID(),
1014  'inverse_relationship' => $inverse_relationship,
1015  'count' => true
1016  ));
1017  }
1018 
1029  public function canEdit($user_guid = 0) {
1030  return _elgg_services()->userCapabilities->canEdit($this, $user_guid);
1031  }
1032 
1044  public function canDelete($user_guid = 0) {
1045  return _elgg_services()->userCapabilities->canDelete($this, $user_guid);
1046  }
1047 
1063  public function canEditMetadata($metadata = null, $user_guid = 0) {
1064  return _elgg_services()->userCapabilities->canEditMetadata($this, $user_guid, $metadata);
1065  }
1066 
1077  public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
1078  return _elgg_services()->userCapabilities->canWriteToContainer($this, $user_guid, $type, $subtype);
1079  }
1080 
1091  public function canComment($user_guid = 0, $default = null) {
1092  return _elgg_services()->userCapabilities->canComment($this, $user_guid, $default);
1093  }
1094 
1109  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1110  return _elgg_services()->userCapabilities->canAnnotate($this, $user_guid, $annotation_name);
1111  }
1112 
1118  public function getAccessID() {
1119  return $this->access_id;
1120  }
1121 
1127  public function getGUID() {
1128  return $this->guid;
1129  }
1130 
1136  public function getType() {
1137  return $this->type;
1138  }
1139 
1145  public function getSubtype() {
1146  // If this object hasn't been saved, then return the subtype string.
1147  if ($this->attributes['guid']) {
1148  return get_subtype_from_id($this->attributes['subtype']);
1149  }
1150  return $this->attributes['subtype'];
1151  }
1152 
1158  public function getOwnerGUID() {
1159  return (int)$this->owner_guid;
1160  }
1161 
1167  public function getOwnerEntity() {
1168  return get_entity($this->owner_guid);
1169  }
1170 
1179  return $this->container_guid = (int)$container_guid;
1180  }
1181 
1187  public function getContainerGUID() {
1188  return (int)$this->container_guid;
1189  }
1190 
1197  public function getContainerEntity() {
1198  return get_entity($this->getContainerGUID());
1199  }
1200 
1206  public function getTimeUpdated() {
1207  return $this->time_updated;
1208  }
1209 
1218  public function getURL() {
1219 
1220  $url = "";
1221 
1222  // @todo remove when elgg_register_entity_url_handler() has been removed
1223  if ($this->guid) {
1224  global $CONFIG;
1225  if (isset($CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1226  $function = $CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()];
1227  if (is_callable($function)) {
1228  $url = call_user_func($function, $this);
1229  }
1230  } elseif (isset($CONFIG->entity_url_handler[$this->getType()]['all'])) {
1231  $function = $CONFIG->entity_url_handler[$this->getType()]['all'];
1232  if (is_callable($function)) {
1233  $url = call_user_func($function, $this);
1234  }
1235  } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
1236  $function = $CONFIG->entity_url_handler['all']['all'];
1237  if (is_callable($function)) {
1238  $url = call_user_func($function, $this);
1239  }
1240  }
1241 
1242  if ($url) {
1244  }
1245  }
1246 
1247  $type = $this->getType();
1248  $params = array('entity' => $this);
1249  $url = _elgg_services()->hooks->trigger('entity:url', $type, $params, $url);
1250 
1251  // @todo remove when \ElggEntity::setURL() has been removed
1252  if (!empty($this->url_override)) {
1254  }
1255 
1256  return elgg_normalize_url($url);
1257  }
1258 
1269  public function setURL($url) {
1270  elgg_deprecated_notice('\ElggEntity::setURL() has been replaced by the "entity:url" plugin hook', 1.9);
1271  $this->url_override = $url;
1272  return $url;
1273  }
1274 
1283  public function saveIconFromUploadedFile($input_name, $type = 'icon', array $coords = array()) {
1284  return _elgg_services()->iconService->saveIconFromUploadedFile($this, $input_name, $type, $coords);
1285  }
1286 
1295  public function saveIconFromLocalFile($filename, $type = 'icon', array $coords = array()) {
1296  return _elgg_services()->iconService->saveIconFromLocalFile($this, $filename, $type, $coords);
1297  }
1298 
1307  public function saveIconFromElggFile(\ElggFile $file, $type = 'icon', array $coords = array()) {
1308  return _elgg_services()->iconService->saveIconFromElggFile($this, $file, $type, $coords);
1309  }
1310 
1319  public function getIcon($size, $type = 'icon') {
1320  return _elgg_services()->iconService->getIcon($this, $size, $type);
1321  }
1322 
1329  public function deleteIcon($type = 'icon') {
1330  return _elgg_services()->iconService->deleteIcon($this, $type);
1331  }
1332 
1341  public function getIconLastChange($size, $type = 'icon') {
1342  return _elgg_services()->iconService->getIconLastChange($this, $size, $type);
1343  }
1344 
1352  public function hasIcon($size, $type = 'icon') {
1353  return _elgg_services()->iconService->hasIcon($this, $size, $type);
1354  }
1355 
1367  public function getIconURL($params = array()) {
1368  return _elgg_services()->iconService->getIconURL($this, $params);
1369  }
1370 
1382  public function addToSite($site) {
1383  if (!elgg_instanceof($site, 'site')) {
1384  return false;
1385  }
1386 
1387  return $site->addEntity($this);
1388  }
1389 
1400  public function removeFromSite($site) {
1401  if (!elgg_instanceof($site, 'site')) {
1402  return false;
1403  }
1404 
1405  return $site->removeEntity($this);
1406  }
1407 
1420  public function getSites($options = array()) {
1421  $options['relationship'] = 'member_of_site';
1422  $options['relationship_guid'] = $this->guid;
1423  $options['inverse_relationship'] = false;
1424  if (!isset($options['site_guid']) || !isset($options['site_guids'])) {
1425  $options['site_guids'] = ELGG_ENTITIES_ANY_VALUE;
1426  }
1427 
1429  }
1430 
1436  public function isFullyLoaded() {
1437  return (bool)$this->guid;
1438  }
1439 
1447  public function save() {
1448  $guid = $this->guid;
1449  if ($guid > 0) {
1450  $guid = $this->update();
1451  } else {
1452  $guid = $this->create();
1453  if ($guid && !_elgg_services()->events->trigger('create', $this->type, $this)) {
1454  // plugins that return false to event don't need to override the access system
1455  $ia = elgg_set_ignore_access(true);
1456  $this->delete();
1458  return false;
1459  }
1460  }
1461 
1462  if ($guid) {
1463  _elgg_services()->entityCache->set($this);
1464  $this->storeInPersistedCache(_elgg_get_memcache('new_entity_cache'));
1465  }
1466 
1467  return $guid;
1468  }
1469 
1483  protected function create() {
1484 
1485  $allowed_types = elgg_get_config('entity_types');
1486  $type = $this->getDatabase()->sanitizeString($this->attributes['type']);
1487  if (!in_array($type, $allowed_types)) {
1488  throw new \InvalidParameterException('Entity type must be one of the allowed types: '
1489  . implode(', ', $allowed_types));
1490  }
1491 
1492  $subtype = $this->attributes['subtype'];
1493  $subtype_id = add_subtype($type, $subtype);
1494  $owner_guid = (int)$this->attributes['owner_guid'];
1495  $access_id = (int)$this->attributes['access_id'];
1496  $now = $this->getCurrentTime()->getTimestamp();
1497  $time_created = isset($this->attributes['time_created']) ? (int)$this->attributes['time_created'] : $now;
1498 
1499  $site_guid = $this->attributes['site_guid'];
1500  if ($site_guid == 0) {
1501  $site_guid = elgg_get_config('site_guid');
1502  }
1503  $site_guid = (int)$site_guid;
1504 
1505  $container_guid = $this->attributes['container_guid'];
1506  if ($container_guid == 0) {
1508  $this->attributes['container_guid'] = $container_guid;
1509  }
1511 
1512  if ($access_id == ACCESS_DEFAULT) {
1513  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1514  }
1515 
1517 
1518  // If given an owner, verify it can be loaded
1519  if ($owner_guid) {
1520  $owner = $this->getOwnerEntity();
1521  if (!$owner) {
1522  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1523  . " owner $owner_guid could not be loaded.");
1524  return false;
1525  }
1526 
1527  // If different owner than logged in, verify can write to container.
1528 
1529  if ($user_guid != $owner_guid && !$owner->canWriteToContainer(0, $type, $subtype)) {
1530  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype) with owner"
1531  . " $owner_guid, but the user wasn't permitted to write to the owner's container.");
1532  return false;
1533  }
1534  }
1535 
1536  // If given a container, verify it can be loaded and that the current user can write to it
1537  if ($container_guid) {
1538  $container = $this->getContainerEntity();
1539  if (!$container) {
1540  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1541  . " container $container_guid could not be loaded.");
1542  return false;
1543  }
1544 
1545  if (!$container->canWriteToContainer(0, $type, $subtype)) {
1546  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but was not"
1547  . " permitted to write to container $container_guid.");
1548  return false;
1549  }
1550  }
1551 
1552  $result = _elgg_services()->entityTable->insertRow((object) [
1553  'type' => $type,
1554  'subtype_id' => $subtype_id,
1555  'owner_guid' => $owner_guid,
1556  'container_guid' => $container_guid,
1557  'site_guid' => $site_guid,
1558  'access_id' => $access_id,
1559  'time_created' => $time_created,
1560  'time_updated' => $now,
1561  'last_action' => $now,
1562  ]);
1563 
1564  if (!$result) {
1565  throw new \IOException("Unable to save new object's base entity information!");
1566  }
1567 
1568  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1569  $this->attributes['subtype'] = (int)$subtype_id;
1570  $this->attributes['guid'] = (int)$result;
1571  $this->attributes['time_created'] = (int)$time_created;
1572  $this->attributes['time_updated'] = (int)$now;
1573  $this->attributes['last_action'] = (int)$now;
1574  $this->attributes['site_guid'] = (int)$site_guid;
1575  $this->attributes['container_guid'] = (int)$container_guid;
1576 
1577  // We are writing this new entity to cache to make sure subsequent calls
1578  // to get_entity() load entity from cache and not from the DB
1579  // At this point, secondary attributes have not yet been written to the DB,
1580  // but metadata and annotation event handlers may be calling get_entity()
1581  _elgg_services()->entityCache->set($this);
1582 
1583  // Save any unsaved metadata
1584  if (sizeof($this->temp_metadata) > 0) {
1585  foreach ($this->temp_metadata as $name => $value) {
1586  $this->$name = $value;
1587  }
1588 
1589  $this->temp_metadata = array();
1590  }
1591 
1592  // Save any unsaved annotations.
1593  if (sizeof($this->temp_annotations) > 0) {
1594  foreach ($this->temp_annotations as $name => $value) {
1595  $this->annotate($name, $value);
1596  }
1597 
1598  $this->temp_annotations = array();
1599  }
1600 
1601  // Save any unsaved private settings.
1602  if (sizeof($this->temp_private_settings) > 0) {
1603  foreach ($this->temp_private_settings as $name => $value) {
1604  $this->setPrivateSetting($name, $value);
1605  }
1606 
1607  $this->temp_private_settings = array();
1608  }
1609 
1610  return $result;
1611  }
1612 
1620  protected function update() {
1621 
1622  _elgg_services()->boot->invalidateCache($this->guid);
1623 
1624  if (!$this->canEdit()) {
1625  return false;
1626  }
1627 
1628  // give old update event a chance to stop the update
1629  if (!_elgg_services()->events->trigger('update', $this->type, $this)) {
1630  return false;
1631  }
1632 
1633  // See #6225. We copy these after the update event in case a handler changed one of them.
1634  $guid = (int)$this->guid;
1635  $owner_guid = (int)$this->owner_guid;
1636  $access_id = (int)$this->access_id;
1637  $container_guid = (int)$this->container_guid;
1638  $time_created = (int)$this->time_created;
1639  $time = $this->getCurrentTime()->getTimestamp();
1640 
1641  if ($access_id == ACCESS_DEFAULT) {
1642  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1643  }
1644 
1645  $ret = _elgg_services()->entityTable->updateRow($guid, (object) [
1646  'owner_guid' => $owner_guid,
1647  'container_guid' => $container_guid,
1648  'access_id' => $access_id,
1649  'time_created' => $time_created,
1650  'time_updated' => $time,
1651  'guid' => $guid,
1652  ]);
1653 
1654  elgg_trigger_after_event('update', $this->type, $this);
1655 
1656  // TODO(evan): Move this to \ElggObject?
1657  if ($this instanceof \ElggObject) {
1658  update_river_access_by_object($guid, $access_id);
1659  }
1660 
1661  if ($ret !== false) {
1662  $this->attributes['time_updated'] = $time;
1663  }
1664 
1665  $this->orig_attributes = [];
1666 
1667  // Handle cases where there was no error BUT no rows were updated!
1668  return $ret !== false;
1669  }
1670 
1678  protected function load($guid) {
1679  if ($guid instanceof \stdClass) {
1680  $row = $guid;
1681  } else {
1683  }
1684 
1685  if ($row) {
1686  // Create the array if necessary - all subclasses should test before creating
1687  if (!is_array($this->attributes)) {
1688  $this->attributes = array();
1689  }
1690 
1691  // Now put these into the attributes array as core values
1692  $objarray = (array) $row;
1693  foreach ($objarray as $key => $value) {
1694  $this->attributes[$key] = $value;
1695  }
1696 
1697  // guid needs to be an int https://github.com/elgg/elgg/issues/4111
1698  $this->attributes['guid'] = (int)$this->attributes['guid'];
1699 
1700  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1701  $this->attributes['subtype'] = (int)$this->attributes['subtype'];
1702 
1703  // Cache object handle
1704  if ($this->attributes['guid']) {
1705  _elgg_services()->entityCache->set($this);
1706  }
1707 
1708  return true;
1709  }
1710 
1711  return false;
1712  }
1713 
1720  protected function loadAdditionalSelectValues(array $data) {
1721  foreach ($data as $name => $value) {
1722  $this->setVolatileData("select:$name", $value);
1723  }
1724  }
1725 
1738  public function refresh(\stdClass $row) {
1739  if ($row instanceof \stdClass) {
1740  return $this->load($row);
1741  }
1742  return false;
1743  }
1744 
1764  public function disable($reason = "", $recursive = true) {
1765  if (!$this->guid) {
1766  return false;
1767  }
1768 
1769  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1770  return false;
1771  }
1772 
1773  if (!$this->canEdit()) {
1774  return false;
1775  }
1776 
1777  if ($this instanceof ElggUser && $this->banned === 'no') {
1778  // temporarily ban to prevent using the site during disable
1779  _elgg_services()->usersTable->markBanned($this->guid, true);
1780  $unban_after = true;
1781  } else {
1782  $unban_after = false;
1783  }
1784 
1785  if ($reason) {
1786  $this->disable_reason = $reason;
1787  }
1788 
1789  $dbprefix = elgg_get_config('dbprefix');
1790 
1791  $guid = (int) $this->guid;
1792 
1793  if ($recursive) {
1794  // Only disable enabled subentities
1797 
1798  $ia = elgg_set_ignore_access(true);
1799 
1800  $base_options = [
1801  'wheres' => [
1802  "e.guid != $guid",
1803  ],
1804  'limit' => false,
1805  ];
1806 
1807  foreach (['owner_guid', 'container_guid', 'site_guid'] as $db_column) {
1808  $options = $base_options;
1809  $options[$db_column] = $guid;
1810 
1811  $subentities = new \ElggBatch('elgg_get_entities', $options);
1812  $subentities->setIncrementOffset(false);
1813 
1814  foreach ($subentities as $subentity) {
1815  /* @var $subentity \ElggEntity */
1816  if (!$subentity->isEnabled()) {
1817  continue;
1818  }
1819  add_entity_relationship($subentity->guid, 'disabled_with', $guid);
1820  $subentity->disable($reason);
1821  }
1822  }
1823 
1826  }
1827 
1828  $this->disableMetadata();
1829  $this->disableAnnotations();
1830 
1831  _elgg_services()->entityCache->remove($guid);
1832 
1833  $sql = "
1834  UPDATE {$dbprefix}entities
1835  SET enabled = 'no'
1836  WHERE guid = :guid
1837  ";
1838  $params = [
1839  ':guid' => $guid,
1840  ];
1841  $disabled = $this->getDatabase()->updateData($sql, false, $params);
1842 
1843  if ($unban_after) {
1844  _elgg_services()->usersTable->markBanned($this->guid, false);
1845  }
1846 
1847  if ($disabled) {
1848  $this->attributes['enabled'] = 'no';
1849  _elgg_services()->events->trigger('disable:after', $this->type, $this);
1850  }
1851 
1852  return (bool) $disabled;
1853  }
1854 
1865  public function enable($recursive = true) {
1866  $guid = (int)$this->guid;
1867  if (!$guid) {
1868  return false;
1869  }
1870 
1871  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1872  return false;
1873  }
1874 
1875  if (!$this->canEdit()) {
1876  return false;
1877  }
1878 
1879  global $CONFIG;
1880 
1881  // Override access only visible entities
1882  $old_access_status = access_get_show_hidden_status();
1884 
1885  $result = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1886  SET enabled = 'yes'
1887  WHERE guid = $guid");
1888 
1889  $this->deleteMetadata('disable_reason');
1890  $this->enableMetadata();
1891  $this->enableAnnotations();
1892 
1893  if ($recursive) {
1894  $disabled_with_it = elgg_get_entities_from_relationship(array(
1895  'relationship' => 'disabled_with',
1896  'relationship_guid' => $guid,
1897  'inverse_relationship' => true,
1898  'limit' => 0,
1899  ));
1900 
1901  foreach ($disabled_with_it as $e) {
1902  $e->enable();
1903  remove_entity_relationship($e->guid, 'disabled_with', $guid);
1904  }
1905  }
1906 
1907  access_show_hidden_entities($old_access_status);
1908 
1909  if ($result) {
1910  $this->attributes['enabled'] = 'yes';
1911  _elgg_services()->events->trigger('enable:after', $this->type, $this);
1912  }
1913 
1914  return $result;
1915  }
1916 
1922  public function isEnabled() {
1923  return $this->enabled == 'yes';
1924  }
1925 
1943  public function delete($recursive = true) {
1944 
1945  $guid = $this->guid;
1946  if (!$guid) {
1947  return false;
1948  }
1949 
1950  // first check if we can delete this entity
1951  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1952  // which could potentially remove some content if the user didn't have access
1953  if (!$this->canDelete()) {
1954  return false;
1955  }
1956 
1957  // now trigger an event to let others know this entity is about to be deleted
1958  // so they can prevent it or take their own actions
1959  if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
1960  return false;
1961  }
1962 
1963  if ($this instanceof ElggUser) {
1964  // ban to prevent using the site during delete
1965  _elgg_services()->usersTable->markBanned($this->guid, true);
1966  }
1967 
1968  // Delete contained owned and otherwise releated objects (depth first)
1969  if ($recursive) {
1970  // Temporarily overriding access controls
1971  $entity_disable_override = access_get_show_hidden_status();
1973  $ia = elgg_set_ignore_access(true);
1974 
1975  // @todo there was logic in the original code that ignored
1976  // entities with owner or container guids of themselves.
1977  // this should probably be prevented in \ElggEntity instead of checked for here
1978  $base_options = [
1979  'wheres' => [
1980  "e.guid != $guid",
1981  ],
1982  'limit' => false,
1983  ];
1984 
1985  foreach (['owner_guid', 'container_guid', 'site_guid'] as $db_column) {
1986  $options = $base_options;
1987  $options[$db_column] = $guid;
1988 
1989  $batch = new \ElggBatch('elgg_get_entities', $options);
1990  $batch->setIncrementOffset(false);
1991 
1992  /* @var $e \ElggEntity */
1993  foreach ($batch as $e) {
1994  $e->delete(true);
1995  }
1996  }
1997 
1998  access_show_hidden_entities($entity_disable_override);
2000  }
2001 
2002  $entity_disable_override = access_get_show_hidden_status();
2004  $ia = elgg_set_ignore_access(true);
2005 
2006  // Now delete the entity itself
2007  $this->deleteMetadata();
2008  $this->deleteOwnedMetadata();
2009  $this->deleteAnnotations();
2010  $this->deleteOwnedAnnotations();
2011  $this->deleteRelationships();
2014 
2015  access_show_hidden_entities($entity_disable_override);
2017 
2018  _elgg_delete_river(array('subject_guid' => $guid));
2019  _elgg_delete_river(array('object_guid' => $guid));
2020  _elgg_delete_river(array('target_guid' => $guid));
2022 
2025 
2026  $dbprefix = elgg_get_config('dbprefix');
2027 
2028  $sql = "
2029  DELETE FROM {$dbprefix}entities
2030  WHERE guid = :guid
2031  ";
2032  $params = [
2033  ':guid' => $guid,
2034  ];
2035 
2036  $deleted = $this->getDatabase()->deleteData($sql, $params);
2037 
2038  if ($deleted && in_array($this->type, ['object', 'user', 'group', 'site'])) {
2039  // delete from type-specific subtable
2040  $sql = "
2041  DELETE FROM {$dbprefix}{$this->type}s_entity
2042  WHERE guid = :guid
2043  ";
2044  $this->getDatabase()->deleteData($sql, $params);
2045  }
2046 
2047  _elgg_clear_entity_files($this);
2048 
2049  return (bool)$deleted;
2050  }
2051 
2055  public function toObject() {
2056  $object = $this->prepareObject(new \stdClass());
2057  $params = array('entity' => $this);
2058  $object = _elgg_services()->hooks->trigger('to:object', 'entity', $params, $object);
2059  return $object;
2060  }
2061 
2068  protected function prepareObject($object) {
2069  $object->guid = $this->guid;
2070  $object->type = $this->getType();
2071  $object->subtype = $this->getSubtype();
2072  $object->owner_guid = $this->getOwnerGUID();
2073  $object->container_guid = $this->getContainerGUID();
2074  $object->site_guid = (int)$this->site_guid;
2075  $object->time_created = date('c', $this->getTimeCreated());
2076  $object->time_updated = date('c', $this->getTimeUpdated());
2077  $object->url = $this->getURL();
2078  $object->read_access = (int)$this->access_id;
2079  return $object;
2080  }
2081 
2082  /*
2083  * LOCATABLE INTERFACE
2084  */
2085 
2091  public function getLocation() {
2092  return $this->location;
2093  }
2094 
2102  public function setLocation($location) {
2103  $this->location = $location;
2104  }
2105 
2115  public function setLatLong($lat, $long) {
2116  $this->{"geo:lat"} = $lat;
2117  $this->{"geo:long"} = $long;
2118  }
2119 
2126  public function getLatitude() {
2127  return (float)$this->{"geo:lat"};
2128  }
2129 
2136  public function getLongitude() {
2137  return (float)$this->{"geo:long"};
2138  }
2139 
2140  /*
2141  * EXPORTABLE INTERFACE
2142  */
2143 
2150  public function getExportableValues() {
2151  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
2152  return array(
2153  'guid',
2154  'type',
2155  'subtype',
2156  'time_created',
2157  'time_updated',
2158  'container_guid',
2159  'owner_guid',
2160  'site_guid'
2161  );
2162  }
2163 
2172  public function export() {
2173  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2174  $tmp = array();
2175 
2176  // Generate uuid
2177  $uuid = guid_to_uuid($this->getGUID());
2178 
2179  // Create entity
2180  $odd = new ODDEntity(
2181  $uuid,
2182  $this->attributes['type'],
2183  get_subtype_from_id($this->attributes['subtype'])
2184  );
2185 
2186  $tmp[] = $odd;
2187 
2189 
2190  // Now add its attributes
2191  foreach ($this->attributes as $k => $v) {
2192  $meta = null;
2193 
2194  if (in_array($k, $exportable_values)) {
2195  switch ($k) {
2196  case 'guid': // Dont use guid in OpenDD
2197  case 'type': // Type and subtype already taken care of
2198  case 'subtype':
2199  break;
2200 
2201  case 'time_created': // Created = published
2202  $odd->setAttribute('published', date("r", $v));
2203  break;
2204 
2205  case 'site_guid': // Container
2206  $k = 'site_uuid';
2207  $v = guid_to_uuid($v);
2208  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2209  break;
2210 
2211  case 'container_guid': // Container
2212  $k = 'container_uuid';
2213  $v = guid_to_uuid($v);
2214  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2215  break;
2216 
2217  case 'owner_guid': // Convert owner guid to uuid, this will be stored in metadata
2218  $k = 'owner_uuid';
2219  $v = guid_to_uuid($v);
2220  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2221  break;
2222 
2223  default:
2224  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2225  }
2226 
2227  // set the time of any metadata created
2228  if ($meta) {
2229  $meta->setAttribute('published', date("r", $this->time_created));
2230  $tmp[] = $meta;
2231  }
2232  }
2233  }
2234 
2235  // Now we do something a bit special.
2236  /*
2237  * This provides a rendered view of the entity to foreign sites.
2238  */
2239 
2240  elgg_set_viewtype('default');
2241  $view = elgg_view_entity($this, array('full_view' => true));
2243 
2244  $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
2245  'renderedentity', $view, 'volatile');
2246 
2247  return $tmp;
2248  }
2249 
2250  /*
2251  * IMPORTABLE INTERFACE
2252  */
2253 
2264  public function import(ODD $data) {
2265  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2266  if (!($data instanceof ODDEntity)) {
2267  throw new \InvalidParameterException("import() passed an unexpected ODD class");
2268  }
2269 
2270  // Set type and subtype
2271  $this->attributes['type'] = $data->getAttribute('class');
2272  $this->attributes['subtype'] = $data->getAttribute('subclass');
2273 
2274  // Set owner
2275  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid(); // Import as belonging to importer.
2276 
2277  // Set time
2278  $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
2279  $this->attributes['time_updated'] = $this->getCurrentTime()->getTimestamp();
2280 
2281  return true;
2282  }
2283 
2284  /*
2285  * SYSTEM LOG INTERFACE
2286  */
2287 
2294  public function getSystemLogID() {
2295  return $this->getGUID();
2296  }
2297 
2305  public function getObjectFromID($id) {
2306  return get_entity($id);
2307  }
2308 
2318  public function getTags($tag_names = null) {
2319  if ($tag_names && !is_array($tag_names)) {
2320  $tag_names = array($tag_names);
2321  }
2322 
2324  $entity_tags = array();
2325 
2326  foreach ($valid_tags as $tag_name) {
2327  if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2328  continue;
2329  }
2330 
2331  if ($tags = $this->$tag_name) {
2332  // if a single tag, metadata returns a string.
2333  // if multiple tags, metadata returns an array.
2334  if (is_array($tags)) {
2335  $entity_tags = array_merge($entity_tags, $tags);
2336  } else {
2337  $entity_tags[] = $tags;
2338  }
2339  }
2340  }
2341 
2342  return $entity_tags;
2343  }
2344 
2352 
2353  if (!$this->guid) {
2354  return false;
2355  }
2356 
2357  if ($this->type !== 'user') {
2358  return true;
2359  }
2360 
2361  $ac = _elgg_services()->accessCollections;
2362 
2363  $collections = $ac->getCollectionsByMember($this->guid);
2364  if (empty($collections)) {
2365  return true;
2366  }
2367 
2368  $result = true;
2369  foreach ($collections as $collection) {
2370  $result = $result & $ac->removeUser($this->guid, $collection->id);
2371  }
2372 
2373  return $result;
2374  }
2375 
2382  public function deleteOwnedAccessCollections() {
2383 
2384  if (!$this->guid) {
2385  return false;
2386  }
2387 
2388  $ac = _elgg_services()->accessCollections;
2389 
2390  $collections = $ac->getEntityCollections($this->guid);
2391  if (empty($collections)) {
2392  return true;
2393  }
2394 
2395  $result = true;
2396  foreach ($collections as $collection) {
2397  $result = $result & $ac->delete($collection->id);
2398  }
2399 
2400  return $result;
2401  }
2402 
2413  public function updateLastAction($posted = null) {
2414  $posted = _elgg_services()->entityTable->updateLastAction($this, $posted);
2415  if ($posted) {
2416  $this->attributes['last_action'] = $posted;
2417  _elgg_services()->entityCache->set($this);
2418  $this->storeInPersistedCache(_elgg_get_memcache('new_entity_cache'));
2419  }
2420  return $posted;
2421  }
2422 }
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
enable($recursive=true)
Enable the entity.
$view
Definition: crop.php:34
getSubtype()
Get the entity subtype.
$r
canEditMetadata($metadata=null, $user_guid=0)
Can a user edit metadata on this entity?
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:48
elgg_get_registered_tag_metadata_names()
Returns an array of valid metadata names for tags.
Definition: tags.php:227
refresh(\stdClass $row)
Load new data from database into existing entity.
elgg_disable_metadata(array $options)
Disables metadata based on $options.
Definition: metadata.php:192
getOwnerGUID()
Get the guid of the entity&#39;s owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:112
if(!array_key_exists($filename, $text_files)) $file
_elgg_invalidate_cache_for_entity($entity_guid)
Invalidate entity cache.
Definition: cache.php:249
Entities that support icons should implement this interface.
Definition: EntityIcon.php:7
__clone()
Clone an entity.
Definition: ElggEntity.php:120
deleteIcon($type= 'icon')
Removes all icon files and metadata for the passed type of icon.
getAnnotations($options=array(), $limit=50, $offset=0, $order="asc")
Gets an array of annotations.
Definition: ElggEntity.php:858
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:263
create_annotation($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE)
Create a new annotation.
Definition: annotations.php:62
loadAdditionalSelectValues(array $data)
Stores non-attributes from the loading of the entity as volatile data.
getOwnerEntity()
Gets the that owns this entity.
remove_all_private_settings($entity_guid)
Deletes all private settings for an entity.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
elgg_normalize_url($url)
Definition: output.php:280
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
setLatLong($lat, $long)
Set latitude and longitude metadata tags for a given entity.
removePrivateSetting($name)
Removes private setting.
Definition: ElggEntity.php:709
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:767
prepareObject($object)
Prepare an object copy for toObject()
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:487
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
countAnnotations($name="")
Count annotations.
Definition: ElggEntity.php:902
$e
Definition: metadata.php:12
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:723
$CONFIG site_guid
The guid of the current site object.
Definition: config.php:65
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:675
saveIconFromUploadedFile($input_name, $type= 'icon', array $coords=array())
Saves icons using an uploaded file as the source.
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:90
canWriteToContainer($user_guid=0, $type= 'all', $subtype= 'all')
Can a user add an entity to this container.
_elgg_delete_river(array $options=[])
Alias of elgg_delete_river() that doesn&#39;t raise notices.
$exportable_values
Definition: entity.php:23
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:691
$input_name
Definition: item.php:14
deleteOwnedMetadata($name=null)
Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
Definition: ElggEntity.php:512
$metadata
Definition: entity.php:19
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
Definition: ElggEntity.php:946
countComments()
Count the number of comments attached to this entity.
Definition: ElggEntity.php:956
get_subtype_from_id($subtype_id)
Gets the denormalized string for a given subtype ID.
Definition: entities.php:39
save()
Save an entity.
setMetadata($name, $value, $value_type= '', $multiple=false, $owner_guid=0, $access_id=null)
Set metadata on this entity.
Definition: ElggEntity.php:402
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:743
$data
Definition: opendd.php:13
if($title=== ''&&$entity instanceof ElggEntity) $tags
Definition: summary.php:31
$value
Definition: longtext.php:42
$subtype
Definition: delete.php:28
isFullyLoaded()
Tests to see whether the object has been persisted.
if(!$count) $offset
Definition: pagination.php:26
getGUID()
Returns the guid.
$default
Definition: checkbox.php:34
getCurrentTime($modifier= '')
Get the (cloned) time.
Definition: TimeUsing.php:26
disableMetadata($name= '')
Disables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:536
$guid
Removes an admin notice.
getContainerGUID()
Gets the container GUID for this entity.
$collection
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=array())
Saves icons using a local file as the source.
_elgg_get_memcache($namespace= 'default')
Get a namespaced ElggMemcache object (if memcache is available) or a null cache.
Definition: memcache.php:40
storeInPersistedCache(\ElggSharedMemoryCache $cache, $last_action=0)
Cache the entity in a persisted cache.
Definition: ElggEntity.php:602
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:788
canEdit($user_guid=0)
Can a user edit this entity?
export()
Export this class into an array of ODD Elements containing all necessary fields.
$url
Definition: exceptions.php:24
getIcon($size, $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type= '')
Removes all relationships originating from a particular entity.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
Definition: ElggEntity.php:924
getSites($options=array())
Gets the sites this entity is a member of.
$options
Elgg admin footer.
Definition: footer.php:6
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:588
_elgg_invalidate_memcache_for_entity($entity_guid)
Invalidate an entity in memcache.
Definition: memcache.php:28
$params
Definition: login.php:72
list style type
Definition: admin.css.php:808
setContainerGUID($container_guid)
Set the container for this object.
removeRelationship($guid_two, $relationship)
Remove a relationship.
Definition: ElggEntity.php:660
elgg_disable_annotations(array $options)
Disables annotations based on $options.
update_river_access_by_object($object_guid, $access_id)
Sets the access ID on river items for a particular object.
Definition: river.php:652
saveIconFromElggFile(\ElggFile $file, $type= 'icon', array $coords=array())
Saves icons using a file located in the data store as the source.
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
getMetadata($name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:314
getEntitiesFromRelationship($options=array(), $inverse=false, $limit=50, $offset=0)
Gets an array of entities with a relationship to this entity.
Definition: ElggEntity.php:986
$owner_guid
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
Definition: ElggEntity.php:628
metadata_array_to_values($array)
Takes a metadata array (which has all kinds of properties) and turns it into a simple array of string...
Definition: metadata.php:332
getExportableValues()
Returns an array of fields which can be exported.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
Definition: entities.php:736
getTags($tag_names=null)
Returns tags for this entity.
$limit
Definition: userpicker.php:38
add_subtype($type, $subtype, $class="")
Register with a certain type and subtype to be loaded as a specific class.
Definition: entities.php:95
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $vartype="")
Adds an annotation to an entity.
Definition: ElggEntity.php:834
$temp_annotations
Holds annotations until entity is saved.
Definition: ElggEntity.php:64
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:576
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
elgg_enable_metadata(array $options)
Enables metadata based on $options.
Definition: metadata.php:208
$owner
Definition: crop.php:8
$key
Definition: summary.php:34
$container
Definition: delete.php:29
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
elgg_view_entity(\ElggEntity $entity, array $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:873
getAnnotationsAvg($name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:913
global $CONFIG
setLocation($location)
Sets the &#39;location&#39; metadata for the entity.
$dbprefix
Definition: index.php:13
$time_created
Definition: online.php:16
const ACCESS_PRIVATE
Definition: elgglib.php:2082
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:167
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:74
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:2095
$temp_metadata
Holds metadata until entity is saved.
Definition: ElggEntity.php:58
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:326
canAnnotate($user_guid=0, $annotation_name= '')
Can a user annotate an entity?
save($key, $data)
Save data in a cache.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
elgg global
Pointer to the global context.
Definition: elgglib.js:12
getIconURL($params=array())
Get the URL for this entity&#39;s icon.
$orig_attributes
Holds the original (persisted) attribute values that have been changed but not yet saved...
Definition: ElggEntity.php:81
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:170
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
get_entity_as_row($guid)
Returns a database row from the entities table.
Definition: entities.php:174
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1375
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:646
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
guid_to_uuid($guid)
Generate a UUID from a given GUID.
$posted
Definition: comment.php:83
$comment access_id
Definition: save.php:60
$temp_private_settings
Holds private settings until entity is saved.
Definition: ElggEntity.php:70
$size
Definition: default.php:20
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:179
const ACCESS_PUBLIC
Definition: elgglib.php:2084
canDelete($user_guid=0)
Can a user delete this entity?
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:158
$hidden
Definition: save.php:13
hasIcon($size, $type= 'icon')
Returns if the entity has an icon of the passed type.
elgg_get_metadata(array $options=array())
Returns metadata.
Definition: metadata.php:164
getType()
Returns the entity type.
elgg_get_annotations(array $options=array())
Returns annotations.
Definition: ODD.php:9
setDisplayName($displayName)
Sets the title or name of this entity.
$filename
create()
Create a new entry in the entities table.
getIconLastChange($size, $type= 'icon')
Returns the timestamp of when the icon was changed.
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
Definition: elgglib.php:654
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
Definition: ElggEntity.php:247
setURL($url)
Overrides the URL returned by getURL()
$row
set_private_setting($entity_guid, $name, $value)
Sets a private setting for an entity.
updateLastAction($posted=null)
Update the last_action column in the entities table.
getLocation()
Gets the &#39;location&#39; metadata for the entity.
getLatitude()
Return the entity&#39;s latitude.
$container_guid
getContainerEntity()
Get the container entity for this object.
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
removeFromSite($site)
Remove this entity from a site.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $coords
Definition: crop.php:15
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggEntity.php:373
$user_guid
Avatar remove action.
Definition: remove.php:6
const ACCESS_DEFAULT
Definition: elgglib.php:2081
canComment($user_guid=0, $default=null)
Can a user comment on an entity?
if(!$collection_name) $id
Definition: add.php:17
getSystemLogID()
Return an identification for the object for storage in the system log.
enableMetadata($name= '')
Enables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:557
disable($reason="", $recursive=true)
Disable this entity.
getURL()
Gets the URL for this entity.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42
load($guid)
Loads attributes from the entities table into the object.
_elgg_clear_entity_files($entity)
Removes all entity files.
Definition: filestore.php:306
getDisplayName()
Get the entity&#39;s display name.
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
Definition: ElggEntity.php:935
$comment owner_guid
Definition: save.php:58
getLongitude()
Return the entity&#39;s longitude.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204
getObjectFromID($id)
For a given ID, return the object associated with it.
if(!$display_name) $type
Definition: delete.php:27
addToSite($site)
Add this entity to a site.
$url_override
If set, overrides the value of getURL()
Definition: ElggEntity.php:52
$comment container_guid
Definition: save.php:59
$volatile
Volatile data structure for this object, allows for storage of data in-memory that isn&#39;t sync&#39;d back ...
Definition: ElggEntity.php:76