Elgg  Version 4.3
ElggEntity.php
Go to the documentation of this file.
1 <?php
2 
10 
46 abstract class ElggEntity extends \ElggData implements EntityIcon {
47 
48  use Subscriptions;
49 
50  public const PRIMARY_ATTR_NAMES = [
51  'guid',
52  'type',
53  'subtype',
54  'owner_guid',
55  'container_guid',
56  'access_id',
57  'time_created',
58  'time_updated',
59  'last_action',
60  'enabled',
61  ];
62 
66  protected const INTEGER_ATTR_NAMES = [
67  'guid',
68  'owner_guid',
69  'container_guid',
70  'access_id',
71  'time_created',
72  'time_updated',
73  'last_action',
74  ];
75 
81  protected $temp_metadata = [];
82 
88  protected $temp_annotations = [];
89 
95  protected $temp_private_settings = [];
96 
102  protected $volatile = [];
103 
108  protected $orig_attributes = [];
109 
113  protected $_is_cacheable = true;
114 
125  protected $_cached_metadata;
126 
141  public function __construct(stdClass $row = null) {
142  $this->initializeAttributes();
143 
144  if ($row && !$this->load($row)) {
145  $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid;
146  throw new IOException($msg);
147  }
148  }
149 
157  protected function initializeAttributes() {
158  parent::initializeAttributes();
159 
160  $this->attributes['guid'] = null;
161  $this->attributes['type'] = $this->getType();
162  $this->attributes['subtype'] = null;
163 
164  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid();
165  $this->attributes['container_guid'] = _elgg_services()->session->getLoggedInUserGuid();
166 
167  $this->attributes['access_id'] = ACCESS_PRIVATE;
168  $this->attributes['time_updated'] = null;
169  $this->attributes['last_action'] = null;
170  $this->attributes['enabled'] = "yes";
171  }
172 
183  public function __clone() {
184  $orig_entity = get_entity($this->guid);
185  if (!$orig_entity) {
186  _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid");
187  return;
188  }
189 
190  $metadata_array = elgg_get_metadata([
191  'guid' => $this->guid,
192  'limit' => false,
193  ]);
194 
195  $this->attributes['guid'] = null;
196  $this->attributes['time_created'] = null;
197  $this->attributes['time_updated'] = null;
198  $this->attributes['last_action'] = null;
199 
200  $this->attributes['subtype'] = $orig_entity->getSubtype();
201 
202  // copy metadata over to new entity - slightly convoluted due to
203  // handling of metadata arrays
204  if (is_array($metadata_array)) {
205  // create list of metadata names
206  $metadata_names = [];
207  foreach ($metadata_array as $metadata) {
208  $metadata_names[] = $metadata->name;
209  }
210  // arrays are stored with multiple enties per name
211  $metadata_names = array_unique($metadata_names);
212 
213  // move the metadata over
214  foreach ($metadata_names as $name) {
215  $this->__set($name, $orig_entity->$name);
216  }
217  }
218  }
219 
235  public function __set($name, $value) {
236  if ($this->$name === $value) {
237  // quick return if value is not changing
238  return;
239  }
240 
241  if (array_key_exists($name, $this->attributes)) {
242  // if an attribute is 1 (integer) and it's set to "1" (string), don't consider that a change.
243  if (is_int($this->attributes[$name])
244  && is_string($value)
245  && ((string) $this->attributes[$name] === $value)) {
246  return;
247  }
248 
249  // keep original values
250  if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
251  $this->orig_attributes[$name] = $this->attributes[$name];
252  }
253 
254  // Certain properties should not be manually changed!
255  switch ($name) {
256  case 'guid':
257  case 'last_action':
258  case 'time_updated':
259  case 'type':
260  return;
261  case 'subtype':
262  throw new ElggInvalidArgumentException(elgg_echo('ElggEntity:Error:SetSubtype', ['setSubtype()']));
263  case 'enabled':
264  throw new ElggInvalidArgumentException(elgg_echo('ElggEntity:Error:SetEnabled', ['enable() / disable()']));
265  case 'access_id':
266  case 'owner_guid':
267  case 'container_guid':
268  if ($value !== null) {
269  $this->attributes[$name] = (int) $value;
270  } else {
271  $this->attributes[$name] = null;
272  }
273  break;
274  default:
275  $this->attributes[$name] = $value;
276  break;
277  }
278  return;
279  }
280 
281  $this->setMetadata($name, $value);
282  }
283 
289  public function getOriginalAttributes() {
290  return $this->orig_attributes;
291  }
292 
305  public function __get($name) {
306  if (array_key_exists($name, $this->attributes)) {
307  return $this->attributes[$name];
308  }
309 
310  return $this->getMetadata($name);
311  }
312 
318  public function getDisplayName() {
319  return (string) $this->name;
320  }
321 
328  public function setDisplayName($display_name) {
329  $this->name = $display_name;
330  }
331 
339  public function getMetadata($name) {
340  $metadata = $this->getAllMetadata();
341  return elgg_extract($name, $metadata);
342  }
343 
349  public function getAllMetadata() {
350  if (!$this->guid) {
351  return array_map(function($values) {
352  return count($values) > 1 ? $values : $values[0];
354  }
355 
356  $this->_cached_metadata = _elgg_services()->metadataCache->getAll($this->guid);
357 
359  }
360 
376  public function setMetadata($name, $value, $value_type = '', $multiple = false) {
377 
378  if ($value === null || $value === '') {
379  $result = $this->deleteMetadata($name);
380  if (is_null($result)) {
381  // null result means no metadata found to be deleted
382  return true;
383  }
384 
385  return $result;
386  }
387 
388  // normalize value to an array that we will loop over
389  // remove indexes if value already an array.
390  if (is_array($value)) {
391  $value = array_values($value);
392  } else {
393  $value = [$value];
394  }
395 
396  // strip null values from array
397  $value = array_filter($value, function($var) {
398  return !is_null($var);
399  });
400 
401  if (empty($this->guid)) {
402  // unsaved entity. store in temp array
403  return $this->setTempMetadata($name, $value, $multiple);
404  }
405 
406  // saved entity. persist md to db.
407  if (!$multiple) {
408  $current_metadata = $this->getMetadata($name);
409 
410  if ((is_array($current_metadata) || count($value) > 1 || $value === []) && isset($current_metadata)) {
411  // remove current metadata if needed
412  // need to remove access restrictions right now to delete
413  // because this is the expected behavior
414  $delete_result = elgg_call(ELGG_IGNORE_ACCESS, function() use ($name) {
415  return elgg_delete_metadata([
416  'guid' => $this->guid,
417  'metadata_name' => $name,
418  'limit' => false,
419  ]);
420  });
421 
422  if (false === $delete_result) {
423  return false;
424  }
425  }
426 
427  if (count($value) > 1) {
428  // new value is a multiple valued metadata
429  $multiple = true;
430  }
431  }
432 
433  // create new metadata
434  foreach ($value as $value_tmp) {
435  $metadata = new ElggMetadata();
436  $metadata->entity_guid = $this->guid;
437  $metadata->name = $name;
438  $metadata->value = $value_tmp;
439 
440  if (!empty($value_type)) {
441  $metadata->value_type = $value_type;
442  }
443 
444  $md_id = _elgg_services()->metadataTable->create($metadata, $multiple);
445  if ($md_id === false) {
446  return false;
447  }
448  }
449 
450  return true;
451  }
452 
463  protected function setTempMetadata($name, $value, $multiple = false) {
464  // if overwrite, delete first
465  if (!$multiple) {
466  unset($this->temp_metadata[$name]);
467  if (count($value)) {
468  // only save if value array contains data
469  $this->temp_metadata[$name] = $value;
470  }
471  return true;
472  }
473 
474  if (!isset($this->temp_metadata[$name])) {
475  $this->temp_metadata[$name] = [];
476  }
477 
478  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
479 
480  return true;
481  }
482 
483 
484 
495  public function deleteMetadata($name = null) {
496 
497  if (!$this->guid) {
498  // remove from temp_metadata
499  if ($name) {
500  if (!isset($this->temp_metadata[$name])) {
501  return null;
502  } else {
503  unset($this->temp_metadata[$name]);
504  return true;
505  }
506  } else {
507  $this->temp_metadata = [];
508  return true;
509  }
510  }
511 
512  $options = [
513  'guid' => $this->guid,
514  'limit' => false,
515  ];
516  if ($name) {
517  $options['metadata_name'] = $name;
518  }
519 
521  }
522 
530  public function getVolatileData($name) {
531  return array_key_exists($name, $this->volatile) ? $this->volatile[$name] : null;
532  }
533 
542  public function setVolatileData($name, $value) {
543  $this->volatile[$name] = $value;
544  }
545 
557  public function addRelationship($guid_two, $relationship) {
558  return _elgg_services()->relationshipsTable->add($this->guid, (string) $relationship, (int) $guid_two);
559  }
560 
572  public function hasRelationship(int $guid_two, string $relationship): bool {
573  return (bool) _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two);
574  }
575 
585  public function getRelationship(int $guid_two, string $relationship): ?\ElggRelationship {
586  return _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two) ?: null;
587  }
588 
599  public function getEntitiesFromRelationship(array $options = []) {
600  $options['relationship_guid'] = $this->guid;
601  return elgg_get_entities($options);
602  }
603 
612  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
613  return elgg_count_entities([
614  'relationship' => $relationship,
615  'relationship_guid' => $this->guid,
616  'inverse_relationship' => $inverse_relationship,
617  ]);
618  }
619 
628  public function removeRelationship($guid_two, $relationship) {
629  return _elgg_services()->relationshipsTable->remove($this->guid, (string) $relationship, (int) $guid_two);
630  }
631 
645  public function removeAllRelationships(string $relationship = null, bool $inverse_relationship = false): bool {
646  return _elgg_services()->relationshipsTable->removeAll($this->guid, $relationship, $inverse_relationship);
647  }
648 
662  public function deleteRelationships($relationship = null) {
663  elgg_deprecated_notice(__METHOD__ . ' has been deprecated. Use \ElggEntity->removeAllRelationships()', '4.3');
664 
666  return $result && $this->removeAllRelationships($relationship, true);
667  }
668 
682  public function setPrivateSetting($name, $value) {
683 
684  if ($value === null || $value === '') {
685  $this->removePrivateSetting($name);
686 
687  // do not check result of removePrivateSetting as it returns false if private setting does not exist
688  return true;
689  }
690 
691  if (is_bool($value)) {
692  $value = (int) $value;
693  }
694 
695  // checking if string value matches saved value (as get privatesettings does not know value type) and db column is a string
696  if (strval($value) === $this->getPrivateSetting($name)) {
697  // no need to update value
698  return true;
699  }
700 
701  if (!$this->guid) {
702  $this->temp_private_settings[$name] = $value;
703 
704  return true;
705  }
706 
707  return _elgg_services()->privateSettings->set($this, $name, $value);
708  }
709 
720  public function getPrivateSetting($name) {
721  if (!$this->guid) {
722  return elgg_extract($name, $this->temp_private_settings);
723  }
724 
725  return _elgg_services()->privateSettings->get($this, $name);
726  }
727 
733  public function getAllPrivateSettings() {
734  if (!$this->guid) {
736  }
737 
738  return _elgg_services()->privateSettings->getAllForEntity($this);
739  }
740 
748  public function removePrivateSetting($name) {
749  if (!$this->guid) {
750  unset($this->temp_private_settings[$name]);
751  return true;
752  }
753 
754  return _elgg_services()->privateSettings->remove($this, $name);
755  }
756 
762  public function removeAllPrivateSettings() {
763  if (!$this->guid) {
764  $this->temp_private_settings = [];
765  return true;
766  }
767 
768  return _elgg_services()->privateSettings->removeAllForEntity($this);
769  }
770 
776  public function removeAllRelatedRiverItems() {
777  elgg_delete_river(['subject_guid' => $this->guid, 'limit' => false]);
778  elgg_delete_river(['object_guid' => $this->guid, 'limit' => false]);
779  elgg_delete_river(['target_guid' => $this->guid, 'limit' => false]);
780  }
781 
792  public function deleteAnnotations($name = null) {
793  if ($this->guid) {
794  $options = [
795  'guid' => $this->guid,
796  'limit' => false,
797  ];
798  if ($name) {
799  $options['annotation_name'] = $name;
800  }
801 
803  }
804 
805  if ($name) {
806  unset($this->temp_annotations[$name]);
807  } else {
808  $this->temp_annotations = [];
809  }
810 
811  return true;
812  }
813 
822  public function deleteOwnedAnnotations($name = null) {
823  // access is turned off for this because they might
824  // no longer have access to an entity they created annotations on
825  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($name) {
826  return elgg_delete_annotations([
827  'annotation_owner_guid' => $this->guid,
828  'limit' => false,
829  'annotation_name' => $name,
830  ]);
831  });
832  }
833 
841  public function disableAnnotations($name = '') {
842  $options = [
843  'guid' => $this->guid,
844  'limit' => false,
845  ];
846  if ($name) {
847  $options['annotation_name'] = $name;
848  }
849 
851  }
852 
860  public function enableAnnotations($name = '') {
861  $options = [
862  'guid' => $this->guid,
863  'limit' => false,
864  ];
865  if ($name) {
866  $options['annotation_name'] = $name;
867  }
868 
870  }
871 
879  private function getAnnotationCalculation($name, $calculation) {
880  $options = [
881  'guid' => $this->getGUID(),
882  'distinct' => false,
883  'annotation_name' => $name,
884  'annotation_calculation' => $calculation
885  ];
886 
888  }
889 
909  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $value_type = "") {
910  if (!$this->guid) {
911  $this->temp_annotations[$name] = $value;
912  return true;
913  }
914 
915  if (!$owner_guid) {
916  $owner_guid = _elgg_services()->session->getLoggedInUserGuid();
917  }
918 
919  $annotation = new ElggAnnotation();
920  $annotation->entity_guid = $this->guid;
921  $annotation->name = $name;
922  $annotation->value = $value;
923  $annotation->owner_guid = $owner_guid;
924  $annotation->access_id = $access_id;
925 
926  if (!empty($value_type)) {
927  $annotation->value_type = $value_type;
928  }
929 
930  if ($annotation->save()) {
931  return $annotation->id;
932  }
933 
934  return false;
935  }
936 
948  public function getAnnotations(array $options = []) {
949  if ($this->guid) {
950  $options['guid'] = $this->guid;
951 
953  } else {
954  $name = elgg_extract('annotation_name', $options, '');
955 
956  if (isset($this->temp_annotations[$name])) {
957  return [$this->temp_annotations[$name]];
958  }
959  }
960 
961  return [];
962  }
963 
971  public function countAnnotations($name = "") {
972  return $this->getAnnotationCalculation($name, 'count');
973  }
974 
982  public function getAnnotationsAvg($name) {
983  return $this->getAnnotationCalculation($name, 'avg');
984  }
985 
993  public function getAnnotationsSum($name) {
994  return $this->getAnnotationCalculation($name, 'sum');
995  }
996 
1004  public function getAnnotationsMin($name) {
1005  return $this->getAnnotationCalculation($name, 'min');
1006  }
1007 
1015  public function getAnnotationsMax($name) {
1016  return $this->getAnnotationCalculation($name, 'max');
1017  }
1018 
1025  public function countComments() {
1026  if (!$this->hasCapability('commentable')) {
1027  return 0;
1028  }
1029 
1030  $params = ['entity' => $this];
1031  $num = _elgg_services()->hooks->trigger('comments:count', $this->getType(), $params);
1032 
1033  if (is_int($num)) {
1034  return $num;
1035  }
1036 
1037  return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
1038  }
1039 
1050  public function getOwnedAccessCollections($options = []) {
1051  $options['owner_guid'] = $this->guid;
1052  return _elgg_services()->accessCollections->getEntityCollections($options);
1053  }
1054 
1065  if (!is_string($subtype) || $subtype === '') {
1066  return false;
1067  }
1068 
1069  $acls = $this->getOwnedAccessCollections([
1070  'subtype' => $subtype,
1071  ]);
1072 
1073  return elgg_extract(0, $acls, false);
1074  }
1075 
1084  public function hasAccess(int $user_guid = 0): bool {
1085  return _elgg_services()->accessCollections->hasAccessToEntity($this, $user_guid);
1086  }
1087 
1088 
1089 
1099  public function canEdit($user_guid = 0) {
1100  return _elgg_services()->userCapabilities->canEdit($this, $user_guid);
1101  }
1102 
1113  public function canDelete($user_guid = 0) {
1114  return _elgg_services()->userCapabilities->canDelete($this, $user_guid);
1115  }
1116 
1127  public function canWriteToContainer($user_guid = 0, $type = '', $subtype = '') {
1128  if (empty($type) || empty($subtype)) {
1129  throw new ElggInvalidArgumentException(__METHOD__ . ' requires $type and $subtype to be set');
1130  }
1131 
1132  return _elgg_services()->userCapabilities->canWriteToContainer($this, $type, $subtype, $user_guid);
1133  }
1134 
1146  public function canComment($user_guid = 0, $default = null) {
1147  return _elgg_services()->userCapabilities->canComment($this, $user_guid, $default);
1148  }
1149 
1164  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1165  return _elgg_services()->userCapabilities->canAnnotate($this, $user_guid, $annotation_name);
1166  }
1167 
1173  public function getAccessID() {
1174  elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use the attribute "access_id" directly.', '4.1');
1175  return $this->access_id;
1176  }
1177 
1183  public function getGUID() {
1184  return $this->guid;
1185  }
1186 
1192  public function getType() {
1193  // this is just for the PHPUnit mocking framework
1194  return $this->type;
1195  }
1196 
1205  public function setSubtype(string $subtype) : void {
1206  // keep original values
1207  if ($this->guid && !array_key_exists('subtype', $this->orig_attributes)) {
1208  $this->orig_attributes['subtype'] = $this->attributes['subtype'];
1209  }
1210 
1211  $this->attributes['subtype'] = $subtype;
1212  }
1213 
1219  public function getSubtype() {
1220  return $this->attributes['subtype'];
1221  }
1222 
1228  public function getOwnerGUID() {
1229  return (int) $this->owner_guid;
1230  }
1231 
1237  public function getOwnerEntity() {
1238  return get_entity($this->owner_guid);
1239  }
1240 
1249  return $this->container_guid = (int) $container_guid;
1250  }
1251 
1257  public function getContainerGUID() {
1258  return (int) $this->container_guid;
1259  }
1260 
1267  public function getContainerEntity() {
1268  return get_entity($this->getContainerGUID());
1269  }
1270 
1276  public function getTimeUpdated() {
1277  return $this->time_updated;
1278  }
1279 
1288  public function getURL() {
1289  $url = elgg_generate_entity_url($this, 'view');
1290 
1291  $url = _elgg_services()->hooks->trigger('entity:url', $this->getType(), ['entity' => $this], $url);
1292 
1293  if (empty($url)) {
1294  return '';
1295  }
1296 
1297  return elgg_normalize_url($url);
1298  }
1299 
1308  public function saveIconFromUploadedFile($input_name, $type = 'icon', array $coords = []) {
1309  return _elgg_services()->iconService->saveIconFromUploadedFile($this, $input_name, $type, $coords);
1310  }
1311 
1320  public function saveIconFromLocalFile($filename, $type = 'icon', array $coords = []) {
1321  return _elgg_services()->iconService->saveIconFromLocalFile($this, $filename, $type, $coords);
1322  }
1323 
1332  public function saveIconFromElggFile(\ElggFile $file, $type = 'icon', array $coords = []) {
1333  return _elgg_services()->iconService->saveIconFromElggFile($this, $file, $type, $coords);
1334  }
1335 
1344  public function getIcon($size, $type = 'icon') {
1345  return _elgg_services()->iconService->getIcon($this, $size, $type);
1346  }
1347 
1354  public function deleteIcon($type = 'icon') {
1355  return _elgg_services()->iconService->deleteIcon($this, $type);
1356  }
1357 
1366  public function getIconLastChange($size, $type = 'icon') {
1367  return _elgg_services()->iconService->getIconLastChange($this, $size, $type);
1368  }
1369 
1377  public function hasIcon($size, $type = 'icon') {
1378  return _elgg_services()->iconService->hasIcon($this, $size, $type);
1379  }
1380 
1392  public function getIconURL($params = []) {
1393  return _elgg_services()->iconService->getIconURL($this, $params);
1394  }
1395 
1399  public function save() : bool {
1400  $result = false;
1401 
1402  if ($this->guid > 0) {
1403  $result = $this->update();
1404  } else {
1405  $guid = $this->create();
1406  if ($guid === false) {
1407  return false;
1408  }
1409 
1410  if (!_elgg_services()->events->trigger('create', $this->type, $this)) {
1411  // plugins that return false to event don't need to override the access system
1412  elgg_call(ELGG_IGNORE_ACCESS, function() {
1413  return $this->delete();
1414  });
1415  return false;
1416  }
1417 
1418  $result = true;
1419  }
1420 
1421  if ($result) {
1422  $this->cache();
1423  }
1424 
1425  return $result;
1426  }
1427 
1438  protected function create() {
1439 
1440  $type = $this->attributes['type'];
1441  if (!in_array($type, \Elgg\Config::ENTITY_TYPES)) {
1442  throw new InvalidParameterException('Entity type must be one of the allowed types: '
1443  . implode(', ', \Elgg\Config::ENTITY_TYPES));
1444  }
1445 
1446  $subtype = $this->attributes['subtype'];
1447  if (!$subtype) {
1448  throw new InvalidParameterException("All entities must have a subtype");
1449  }
1450 
1451  $owner_guid = (int) $this->attributes['owner_guid'];
1452  $access_id = (int) $this->attributes['access_id'];
1453  $now = $this->getCurrentTime()->getTimestamp();
1454  $time_created = isset($this->attributes['time_created']) ? (int) $this->attributes['time_created'] : $now;
1455 
1456  $container_guid = $this->attributes['container_guid'];
1457  if ($container_guid == 0) {
1459  $this->attributes['container_guid'] = $container_guid;
1460  }
1462 
1463  if ($access_id == ACCESS_DEFAULT) {
1464  throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1465  }
1466 
1467  if ($access_id == ACCESS_FRIENDS) {
1468  throw new InvalidParameterException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1469  }
1470 
1471  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1472 
1473  // If given an owner, verify it can be loaded
1474  if ($owner_guid) {
1475  $owner = $this->getOwnerEntity();
1476  if (!$owner) {
1477  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1478  . " owner $owner_guid could not be loaded.");
1479  return false;
1480  }
1481 
1482  // If different owner than logged in, verify can write to container.
1483 
1484  if ($user_guid != $owner_guid && !$owner->canEdit() && !$owner->canWriteToContainer($user_guid, $type, $subtype)) {
1485  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype) with owner"
1486  . " $owner_guid, but the user wasn't permitted to write to the owner's container.");
1487  return false;
1488  }
1489  }
1490 
1491  // If given a container, verify it can be loaded and that the current user can write to it
1492  if ($container_guid) {
1493  $container = $this->getContainerEntity();
1494  if (!$container) {
1495  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1496  . " container $container_guid could not be loaded.");
1497  return false;
1498  }
1499 
1500  if (!$container->canWriteToContainer($user_guid, $type, $subtype)) {
1501  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but was not"
1502  . " permitted to write to container $container_guid.");
1503  return false;
1504  }
1505  }
1506 
1507  // Create primary table row
1508  $guid = _elgg_services()->entityTable->insertRow((object) [
1509  'type' => $type,
1510  'subtype' => $subtype,
1511  'owner_guid' => $owner_guid,
1512  'container_guid' => $container_guid,
1513  'access_id' => $access_id,
1514  'time_created' => $time_created,
1515  'time_updated' => $now,
1516  'last_action' => $now,
1517  ], $this->attributes);
1518 
1519  if (!$guid) {
1520  throw new IOException("Unable to save new object's base entity information!");
1521  }
1522 
1523  $this->attributes['subtype'] = $subtype;
1524  $this->attributes['guid'] = (int) $guid;
1525  $this->attributes['time_created'] = (int) $time_created;
1526  $this->attributes['time_updated'] = (int) $now;
1527  $this->attributes['last_action'] = (int) $now;
1528  $this->attributes['container_guid'] = (int) $container_guid;
1529 
1530  // We are writing this new entity to cache to make sure subsequent calls
1531  // to get_entity() load the entity from cache and not from the DB. This
1532  // MUST come before the metadata and annotation writes below!
1533  $this->cache();
1534 
1535  // Save any unsaved metadata
1536  if (sizeof($this->temp_metadata) > 0) {
1537  foreach ($this->temp_metadata as $name => $value) {
1538  // temp metadata is always an array, but if there is only one value return just the value
1539  $this->setMetadata($name, $value, '', count($value) > 1);
1540  }
1541 
1542  $this->temp_metadata = [];
1543  }
1544 
1545  // Save any unsaved annotations.
1546  if (sizeof($this->temp_annotations) > 0) {
1547  foreach ($this->temp_annotations as $name => $value) {
1548  $this->annotate($name, $value);
1549  }
1550 
1551  $this->temp_annotations = [];
1552  }
1553 
1554  // Save any unsaved private settings.
1555  if (sizeof($this->temp_private_settings) > 0) {
1556  foreach ($this->temp_private_settings as $name => $value) {
1557  $this->setPrivateSetting($name, $value);
1558  }
1559 
1560  $this->temp_private_settings = [];
1561  }
1562 
1563  if (isset($container) && !$container instanceof ElggUser) {
1564  // users have their own logic for setting last action
1565  $container->updateLastAction();
1566  }
1567 
1568  return $guid;
1569  }
1570 
1578  protected function update() {
1579 
1580  if (!$this->canEdit()) {
1581  return false;
1582  }
1583 
1584  // give old update event a chance to stop the update
1585  if (!_elgg_services()->events->trigger('update', $this->type, $this)) {
1586  return false;
1587  }
1588 
1589  $this->invalidateCache();
1590 
1591  // See #6225. We copy these after the update event in case a handler changed one of them.
1592  $guid = (int) $this->guid;
1593  $owner_guid = (int) $this->owner_guid;
1594  $access_id = (int) $this->access_id;
1595  $container_guid = (int) $this->container_guid;
1596  $time_created = (int) $this->time_created;
1597  $time = $this->getCurrentTime()->getTimestamp();
1598 
1599  if ($access_id == ACCESS_DEFAULT) {
1600  throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1601  }
1602 
1603  if ($access_id == ACCESS_FRIENDS) {
1604  throw new InvalidParameterException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1605  }
1606 
1607  // Update primary table
1608  $ret = _elgg_services()->entityTable->updateRow($guid, (object) [
1609  'owner_guid' => $owner_guid,
1610  'container_guid' => $container_guid,
1611  'access_id' => $access_id,
1612  'time_created' => $time_created,
1613  'time_updated' => $time,
1614  'guid' => $guid,
1615  ]);
1616  if ($ret === false) {
1617  return false;
1618  }
1619 
1620  $this->attributes['time_updated'] = $time;
1621 
1622  _elgg_services()->events->triggerAfter('update', $this->type, $this);
1623 
1624  $this->orig_attributes = [];
1625 
1626  $this->cache();
1627 
1628  // Handle cases where there was no error BUT no rows were updated!
1629  return true;
1630  }
1631 
1639  protected function load(stdClass $row) {
1640  $attributes = array_merge($this->attributes, (array) $row);
1641 
1642  if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys($attributes)) !== []) {
1643  // Some primary attributes are missing
1644  return false;
1645  }
1646 
1647  foreach ($attributes as $name => $value) {
1648  if (!in_array($name, self::PRIMARY_ATTR_NAMES)) {
1649  $this->setVolatileData("select:$name", $value);
1650  unset($attributes[$name]);
1651  continue;
1652  }
1653 
1654  if (in_array($name, static::INTEGER_ATTR_NAMES)) {
1655  $attributes[$name] = (int) $value;
1656  }
1657  }
1658 
1659  $this->attributes = $attributes;
1660 
1661  $this->cache();
1662 
1663  return true;
1664  }
1665 
1683  public function disable($reason = "", $recursive = true) {
1684  if (!$this->guid) {
1685  return false;
1686  }
1687 
1688  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1689  return false;
1690  }
1691 
1692  if (!$this->canEdit()) {
1693  return false;
1694  }
1695 
1696  if ($this instanceof ElggUser && !$this->isBanned()) {
1697  // temporarily ban to prevent using the site during disable
1698  $this->ban();
1699  $unban_after = true;
1700  } else {
1701  $unban_after = false;
1702  }
1703 
1704  if ($reason) {
1705  $this->disable_reason = $reason;
1706  }
1707 
1708  $guid = (int) $this->guid;
1709 
1710  if ($recursive) {
1711  elgg_call(ELGG_IGNORE_ACCESS | ELGG_HIDE_DISABLED_ENTITIES, function () use ($guid, $reason) {
1712  $base_options = [
1713  'wheres' => [
1714  function(QueryBuilder $qb, $main_alias) use ($guid) {
1715  return $qb->compare("{$main_alias}.guid", '!=', $guid, ELGG_VALUE_GUID);
1716  },
1717  ],
1718  'limit' => false,
1719  'batch' => true,
1720  'batch_inc_offset' => false,
1721  ];
1722 
1723  foreach (['owner_guid', 'container_guid'] as $db_column) {
1724  $options = $base_options;
1725  $options[$db_column] = $guid;
1726 
1727  $subentities = elgg_get_entities($options);
1728 
1729  foreach ($subentities as $subentity) {
1730  /* @var $subentity \ElggEntity */
1731  if (!$subentity->isEnabled()) {
1732  continue;
1733  }
1734  $subentity->addRelationship($guid, 'disabled_with');
1735  $subentity->disable($reason, true);
1736  }
1737  }
1738  });
1739  }
1740 
1741  $this->disableAnnotations();
1742 
1743  $disabled = _elgg_services()->entityTable->disable($this);
1744 
1745  if ($unban_after) {
1746  $this->unban();
1747  }
1748 
1749  if ($disabled) {
1750  $this->invalidateCache();
1751 
1752  $this->attributes['enabled'] = 'no';
1753  _elgg_services()->events->triggerAfter('disable', $this->type, $this);
1754  }
1755 
1756  return $disabled;
1757  }
1758 
1766  public function enable($recursive = true) {
1767  if (empty($this->guid)) {
1768  return false;
1769  }
1770 
1771  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1772  return false;
1773  }
1774 
1775  if (!$this->canEdit()) {
1776  return false;
1777  }
1778 
1779  $result = elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function() use ($recursive) {
1780  $result = _elgg_services()->entityTable->enable($this);
1781 
1782  $this->deleteMetadata('disable_reason');
1783  $this->enableAnnotations();
1784 
1785  if ($recursive) {
1786  $disabled_with_it = elgg_get_entities([
1787  'relationship' => 'disabled_with',
1788  'relationship_guid' => $this->guid,
1789  'inverse_relationship' => true,
1790  'limit' => false,
1791  'batch' => true,
1792  'batch_inc_offset' => false,
1793  ]);
1794 
1795  foreach ($disabled_with_it as $e) {
1796  $e->enable($recursive);
1797  $e->removeRelationship($this->guid, 'disabled_with');
1798  }
1799  }
1800 
1801  return $result;
1802  });
1803 
1804  if ($result) {
1805  $this->attributes['enabled'] = 'yes';
1806  _elgg_services()->events->triggerAfter('enable', $this->type, $this);
1807  }
1808 
1809  return $result;
1810  }
1811 
1817  public function isEnabled() {
1818  return $this->enabled == 'yes';
1819  }
1820 
1838  public function delete($recursive = true) {
1839  // first check if we can delete this entity
1840  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1841  // which could potentially remove some content if the user didn't have access
1842  if (!$this->canDelete()) {
1843  return false;
1844  }
1845 
1846  try {
1847  return _elgg_services()->entityTable->delete($this, $recursive);
1848  } catch (DatabaseException $ex) {
1849  elgg_log($ex, 'ERROR');
1850  return false;
1851  }
1852  }
1853 
1860  public function toObject(array $params = []) {
1861  $object = $this->prepareObject(new \Elgg\Export\Entity());
1862 
1863  $params['entity'] = $this;
1864 
1865  return _elgg_services()->hooks->trigger('to:object', 'entity', $params, $object);
1866  }
1867 
1874  protected function prepareObject(\Elgg\Export\Entity $object) {
1875  $object->guid = $this->guid;
1876  $object->type = $this->getType();
1877  $object->subtype = $this->getSubtype();
1878  $object->owner_guid = $this->getOwnerGUID();
1879  $object->container_guid = $this->getContainerGUID();
1880  $object->time_created = date('c', $this->getTimeCreated());
1881  $object->time_updated = date('c', $this->getTimeUpdated());
1882  $object->url = $this->getURL();
1883  $object->read_access = (int) $this->access_id;
1884  return $object;
1885  }
1886 
1895  public function setLatLong(float $lat, float $long) {
1896  $this->{"geo:lat"} = $lat;
1897  $this->{"geo:long"} = $long;
1898  }
1899 
1905  public function getLatitude() {
1906  return (float) $this->{"geo:lat"};
1907  }
1908 
1914  public function getLongitude() {
1915  return (float) $this->{"geo:long"};
1916  }
1917 
1918  /*
1919  * SYSTEM LOG INTERFACE
1920  */
1921 
1928  public function getSystemLogID() {
1929  return $this->getGUID();
1930  }
1931 
1939  public function getObjectFromID($id) {
1940  return get_entity($id);
1941  }
1942 
1950  public function getTags($tag_names = null) {
1951  if (!isset($tag_names)) {
1952  $tag_names = ['tags'];
1953  }
1954 
1955  if ($tag_names && !is_array($tag_names)) {
1956  $tag_names = [$tag_names];
1957  }
1958 
1959  $entity_tags = [];
1960  foreach ($tag_names as $tag_name) {
1961  $tags = $this->$tag_name;
1962  if (elgg_is_empty($tags)) {
1963  continue;
1964  }
1965 
1966  // if a single tag, metadata returns a string.
1967  // if multiple tags, metadata returns an array.
1968  if (is_array($tags)) {
1969  $entity_tags = array_merge($entity_tags, $tags);
1970  } else {
1971  $entity_tags[] = $tags;
1972  }
1973  }
1974 
1975  return $entity_tags;
1976  }
1977 
1985 
1986  if (!$this->guid) {
1987  return false;
1988  }
1989 
1990  if ($this->type !== 'user') {
1991  return true;
1992  }
1993 
1994  $ac = _elgg_services()->accessCollections;
1995 
1996  $collections = $ac->getCollectionsByMember($this->guid);
1997  if (empty($collections)) {
1998  return true;
1999  }
2000 
2001  $result = true;
2002  foreach ($collections as $collection) {
2003  $result &= $ac->removeUser($this->guid, $collection->id);
2004  }
2005 
2006  return $result;
2007  }
2008 
2015  public function deleteOwnedAccessCollections() {
2016 
2017  if (!$this->guid) {
2018  return false;
2019  }
2020 
2021  $collections = $this->getOwnedAccessCollections();
2022  if (empty($collections)) {
2023  return true;
2024  }
2025 
2026  $result = true;
2027  foreach ($collections as $collection) {
2028  $result = $result & $collection->delete();
2029  }
2030 
2031  return $result;
2032  }
2033 
2044  public function updateLastAction($posted = null) {
2045  $posted = _elgg_services()->entityTable->updateLastAction($this, $posted);
2046  if ($posted) {
2047  $this->attributes['last_action'] = $posted;
2048  $this->cache();
2049  }
2050  return $posted;
2051  }
2052 
2059  public function disableCaching() {
2060  $this->_is_cacheable = false;
2061  if ($this->guid) {
2062  _elgg_services()->entityCache->delete($this->guid);
2063  }
2064  }
2065 
2072  public function enableCaching() {
2073  $this->_is_cacheable = true;
2074  }
2075 
2082  public function isCacheable() {
2083  if (!$this->guid) {
2084  return false;
2085  }
2086 
2087  if (_elgg_services()->session->getIgnoreAccess()) {
2088  return false;
2089  }
2090  return $this->_is_cacheable;
2091  }
2092 
2101  public function cache($persist = true) {
2102  if (!$this->isCacheable()) {
2103  return;
2104  }
2105 
2106  _elgg_services()->entityCache->save($this);
2107 
2108  if (!$persist) {
2109  return;
2110  }
2111 
2112  $tmp = $this->volatile;
2113 
2114  // don't store volatile data
2115  $this->volatile = [];
2116 
2117  _elgg_services()->sessionCache->entities->save($this->guid, $this);
2118 
2119  $this->volatile = $tmp;
2120  }
2121 
2128  public function invalidateCache() {
2129  if (!$this->guid) {
2130  return;
2131  }
2132 
2133  _elgg_services()->entityCache->delete($this->guid);
2134 
2135  $namespaces = [
2136  'metadata',
2137  'private_settings',
2138  ];
2139 
2140  foreach ($namespaces as $namespace) {
2141  _elgg_services()->dataCache->get($namespace)->delete($this->guid);
2142  }
2143  }
2144 
2153  public function hasCapability(string $capability): bool {
2154  return _elgg_services()->entity_capabilities->hasCapability($this->getType(), $this->getSubtype(), $capability);
2155  }
2156 }
$default
Definition: checkbox.php:31
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:592
$display_name
Definition: delete.php:19
saveIconFromUploadedFile($input_name, $type= 'icon', array $coords=[])
Saves icons using an uploaded file as the source.
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
enable($recursive=true)
Enable the entity.
removeAllPrivateSettings()
Removes all private settings.
Definition: ElggEntity.php:762
getSubtype()
Get the entity subtype.
$user_guid
Definition: login_as.php:10
getOwnerGUID()
Get the guid of the entity&#39;s owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:100
Entities that support icons should implement this interface.
Definition: EntityIcon.php:7
__clone()
Clone an entity.
Definition: ElggEntity.php:183
deleteIcon($type= 'icon')
Removes all icon files and metadata for the passed type of icon.
$input_name
Definition: crop.php:24
$params
Saves global plugin settings.
Definition: save.php:13
getAllPrivateSettings()
Returns all private settings.
Definition: ElggEntity.php:733
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:305
getOwnerEntity()
Gets the that owns this entity.
$owner
Definition: upload.php:7
const ACCESS_DEFAULT
Definition: constants.php:11
elgg_normalize_url($url)
Definition: output.php:153
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
Definition: deprecation.php:52
if($id< 1) $annotation
Definition: delete.php:11
setTempMetadata($name, $value, $multiple=false)
Set temp metadata on this entity.
Definition: ElggEntity.php:463
removePrivateSetting($name)
Removes private setting.
Definition: ElggEntity.php:748
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:841
An IO Exception, throw when an IO Exception occurs.
Definition: IOException.php:12
const PRIMARY_ATTR_NAMES
Definition: ElggEntity.php:50
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:495
$site name
Definition: settings.php:21
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
Definition: annotations.php:87
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
countAnnotations($name="")
Count annotations.
Definition: ElggEntity.php:971
const INTEGER_ATTR_NAMES
Definition: ElggEntity.php:66
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:792
invalidateCache()
Invalidate cache for entity.
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:682
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:157
const ACCESS_FRIENDS
Definition: constants.php:15
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:720
elgg_get_annotations(array $options=[])
Fetch annotations or perform a calculation on them.
Definition: annotations.php:52
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
countComments()
Count the number of comments attached to this entity.
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:133
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:822
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
$relationship
Elgg default relationship view.
Definition: default.php:10
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
const ELGG_VALUE_GUID
Definition: constants.php:128
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
Database abstraction query builder.
getGUID()
Returns the guid.
$time_updated
Definition: time.php:21
getContainerGUID()
Gets the container GUID for this entity.
$type
Definition: delete.php:21
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:860
enableCaching()
Enable runtime caching for entity.
cache($persist=true)
Cache the entity in a session and persisted caches.
canEdit($user_guid=0)
Can a user edit this entity?
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
getIcon($size, $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
Definition: ElggEntity.php:993
$options
Elgg admin footer.
Definition: footer.php:6
getEntitiesFromRelationship(array $options=[])
Gets an array of entities with a relationship to this entity.
Definition: ElggEntity.php:599
$value
Definition: generic.php:51
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:542
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:179
const ELGG_HIDE_DISABLED_ENTITIES
Definition: constants.php:149
setContainerGUID($container_guid)
Set the container for this object.
removeRelationship($guid_two, $relationship)
Remove a relationship.
Definition: ElggEntity.php:628
elgg_disable_annotations(array $options)
Disables annotations based on $options.
getCurrentTime($modifier= '')
Get the (cloned) time.
Definition: TimeUsing.php:25
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
Definition: ElggEntity.php:612
getMetadata($name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:339
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:146
$owner_guid
$namespaces
Definition: default.php:33
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
Definition: ElggEntity.php:662
saveIconFromElggFile(\ElggFile $file, $type= 'icon', array $coords=[])
Saves icons using a file located in the data store as the source.
getTags($tag_names=null)
Returns tags for this entity.
getRelationship(int $guid_two, string $relationship)
Return the relationship if this entity has a relationship with another entity.
Definition: ElggEntity.php:585
disableCaching()
Disable runtime caching for entity.
hasRelationship(int $guid_two, string $relationship)
Check if this entity has a relationship with another entity.
Definition: ElggEntity.php:572
setSubtype(string $subtype)
Set the subtype of the entity.
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:530
const ACCESS_PRIVATE
Definition: constants.php:12
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:148
removeAllRelatedRiverItems()
Removes all river items related to this entity.
Definition: ElggEntity.php:776
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
getAnnotationsAvg($name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:982
hasAccess(int $user_guid=0)
Check if the given user has access to this entity.
load(stdClass $row)
Loads attributes from the entities table into the object.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:399
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:556
A generic parent class for database exceptions.
$time_created
Definition: online.php:18
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:235
$container
Definition: delete.php:23
canAnnotate($user_guid=0, $annotation_name= '')
Can a user annotate an entity?
toObject(array $params=[])
Export an entity.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
getAnnotations(array $options=[])
Gets an array of annotations.
Definition: ElggEntity.php:948
getOwnedAccessCollections($options=[])
Returns the ACLs owned by the entity.
setLatLong(float $lat, float $long)
Set latitude and longitude metadata tags for a given entity.
hasCapability(string $capability)
Checks a specific capability is enabled for the entity type/subtype.
A generic class that contains shared code among , , and .
Definition: ElggData.php:10
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
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:547
getIconURL($params=[])
Get the URL for this entity&#39;s icon.
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:557
$size
Definition: thumb.php:23
setMetadata($name, $value, $value_type= '', $multiple=false)
Set metadata on this entity.
Definition: ElggEntity.php:376
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
elgg_get_metadata(array $options=[])
Fetch metadata or perform a calculation on them.
Definition: metadata.php:32
$posted
Definition: comment.php:86
$comment access_id
Definition: save.php:55
$temp_private_settings
Definition: ElggEntity.php:95
removeAllRelationships(string $relationship=null, bool $inverse_relationship=false)
Remove all relationships to or from this entity.
Definition: ElggEntity.php:645
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:47
canDelete($user_guid=0)
Can a user delete this entity?
setDisplayName($display_name)
Sets the title or name of this entity.
Definition: ElggEntity.php:328
hasIcon($size, $type= 'icon')
Returns if the entity has an icon of the passed type.
getOwnedAccessCollection($subtype)
Returns the first ACL owned by the entity with a given subtype.
$metadata
Output annotation metadata.
Definition: metadata.php:9
getType()
Returns the entity type.
$subtype
Definition: delete.php:22
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type="")
Adds an annotation to an entity.
Definition: ElggEntity.php:909
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
$filename
create()
Create a new entry in the entities table.
getAllMetadata()
Get all entity metadata.
Definition: ElggEntity.php:349
getIconLastChange($size, $type= 'icon')
Returns the timestamp of when the icon was changed.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
Definition: ElggEntity.php:289
updateLastAction($posted=null)
Update the last_action column in the entities table.
$access_id
Definition: access.php:11
isCacheable()
Is entity cacheable in the runtime cache.
getLatitude()
Return the entity&#39;s latitude.
__construct(stdClass $row=null)
Create a new entity.
Definition: ElggEntity.php:141
$container_guid
getContainerEntity()
Get the container entity for this object.
$tags
Output object tags.
Definition: tags.php:9
canComment($user_guid=0, $default=null)
Can a user comment on an entity?
getSystemLogID()
Return an identification for the object for storage in the system log.
$id
Generic annotation delete action.
Definition: delete.php:6
disable($reason="", $recursive=true)
Disable this entity.
$qb
Definition: queue.php:11
elgg_generate_entity_url(ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
Generate entity URL from a named route.
getURL()
Gets the URL for this entity.
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:318
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
getLongitude()
Return the entity&#39;s longitude.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69
getObjectFromID($id)
For a given ID, return the object associated with it.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=[])
Saves icons using a local file as the source.
if($entity instanceof\ElggComment) $comment container_guid
Definition: save.php:54
canWriteToContainer($user_guid=0, $type= '', $subtype= '')
Can a user add an entity to this container.