Elgg  Version master
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 $volatile = [];
96 
101  protected $orig_attributes = [];
102 
106  protected $_is_cacheable = true;
107 
118  protected $_cached_metadata;
119 
134  public function __construct(stdClass $row = null) {
135  $this->initializeAttributes();
136 
137  if (!empty($row) && !$this->load($row)) {
138  throw new IOException('Failed to load new ' . get_class() . " for GUID: {$row->guid}");
139  }
140  }
141 
149  protected function initializeAttributes() {
150  parent::initializeAttributes();
151 
152  $this->attributes['guid'] = null;
153  $this->attributes['type'] = $this->getType();
154  $this->attributes['subtype'] = null;
155 
156  $this->attributes['owner_guid'] = _elgg_services()->session_manager->getLoggedInUserGuid();
157  $this->attributes['container_guid'] = _elgg_services()->session_manager->getLoggedInUserGuid();
158 
159  $this->attributes['access_id'] = ACCESS_PRIVATE;
160  $this->attributes['time_updated'] = null;
161  $this->attributes['last_action'] = null;
162  $this->attributes['enabled'] = 'yes';
163  }
164 
175  public function __clone() {
176  $orig_entity = get_entity($this->guid);
177  if (!$orig_entity) {
178  _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid");
179  return;
180  }
181 
182  $metadata_array = elgg_get_metadata([
183  'guid' => $this->guid,
184  'limit' => false,
185  ]);
186 
187  $this->attributes['guid'] = null;
188  $this->attributes['time_created'] = null;
189  $this->attributes['time_updated'] = null;
190  $this->attributes['last_action'] = null;
191 
192  $this->attributes['subtype'] = $orig_entity->getSubtype();
193 
194  // copy metadata over to new entity - slightly convoluted due to
195  // handling of metadata arrays
196  if (is_array($metadata_array)) {
197  // create list of metadata names
198  $metadata_names = [];
199  foreach ($metadata_array as $metadata) {
200  $metadata_names[] = $metadata->name;
201  }
202 
203  // arrays are stored with multiple enties per name
204  $metadata_names = array_unique($metadata_names);
205 
206  // move the metadata over
207  foreach ($metadata_names as $name) {
208  $this->__set($name, $orig_entity->$name);
209  }
210  }
211  }
212 
228  public function __set($name, $value) {
229  if ($this->$name === $value) {
230  // quick return if value is not changing
231  return;
232  }
233 
234  if (array_key_exists($name, $this->attributes)) {
235  // if an attribute is 1 (integer) and it's set to "1" (string), don't consider that a change.
236  if (is_int($this->attributes[$name])
237  && is_string($value)
238  && ((string) $this->attributes[$name] === $value)) {
239  return;
240  }
241 
242  // keep original values
243  if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
244  $this->orig_attributes[$name] = $this->attributes[$name];
245  }
246 
247  // Certain properties should not be manually changed!
248  switch ($name) {
249  case 'guid':
250  case 'last_action':
251  case 'time_updated':
252  case 'type':
253  return;
254  case 'subtype':
255  throw new ElggInvalidArgumentException(elgg_echo('ElggEntity:Error:SetSubtype', ['setSubtype()']));
256  case 'enabled':
257  throw new ElggInvalidArgumentException(elgg_echo('ElggEntity:Error:SetEnabled', ['enable() / disable()']));
258  case 'access_id':
259  case 'owner_guid':
260  case 'container_guid':
261  if ($value !== null) {
262  $this->attributes[$name] = (int) $value;
263  } else {
264  $this->attributes[$name] = null;
265  }
266  break;
267  default:
268  $this->attributes[$name] = $value;
269  break;
270  }
271 
272  return;
273  }
274 
275  $this->setMetadata($name, $value);
276  }
277 
283  public function getOriginalAttributes(): array {
284  return $this->orig_attributes;
285  }
286 
299  public function __get($name) {
300  if (array_key_exists($name, $this->attributes)) {
301  return $this->attributes[$name];
302  }
303 
304  return $this->getMetadata($name);
305  }
306 
312  public function getDisplayName(): string {
313  return (string) $this->name;
314  }
315 
322  public function setDisplayName(string $display_name): void {
323  $this->name = $display_name;
324  }
325 
333  public function getMetadata(string $name) {
334  $metadata = $this->getAllMetadata();
335  return elgg_extract($name, $metadata);
336  }
337 
343  public function getAllMetadata(): array {
344  if (!$this->guid) {
345  return array_map(function($values) {
346  return count($values) > 1 ? $values : $values[0];
348  }
349 
350  $this->_cached_metadata = _elgg_services()->metadataCache->getAll($this->guid);
351 
353  }
354 
370  public function setMetadata(string $name, $value, string $value_type = '', bool $multiple = false): bool {
371 
372  if ($value === null || $value === '') {
373  return $this->deleteMetadata($name);
374  }
375 
376  // normalize value to an array that we will loop over
377  // remove indexes if value already an array.
378  if (is_array($value)) {
379  $value = array_values($value);
380  } else {
381  $value = [$value];
382  }
383 
384  // strip null values from array
385  $value = array_filter($value, function($var) {
386  return !is_null($var);
387  });
388 
389  if (empty($this->guid)) {
390  // unsaved entity. store in temp array
391  return $this->setTempMetadata($name, $value, $multiple);
392  }
393 
394  // saved entity. persist md to db.
395  if (!$multiple) {
396  $current_metadata = $this->getMetadata($name);
397 
398  if ((is_array($current_metadata) || count($value) > 1 || $value === []) && isset($current_metadata)) {
399  // remove current metadata if needed
400  // need to remove access restrictions right now to delete
401  // because this is the expected behavior
402  $delete_result = elgg_call(ELGG_IGNORE_ACCESS, function() use ($name) {
403  return elgg_delete_metadata([
404  'guid' => $this->guid,
405  'metadata_name' => $name,
406  'limit' => false,
407  ]);
408  });
409 
410  if ($delete_result === false) {
411  return false;
412  }
413  }
414 
415  if (count($value) > 1) {
416  // new value is a multiple valued metadata
417  $multiple = true;
418  }
419  }
420 
421  // create new metadata
422  foreach ($value as $value_tmp) {
423  $metadata = new ElggMetadata();
424  $metadata->entity_guid = $this->guid;
425  $metadata->name = $name;
426  $metadata->value = $value_tmp;
427 
428  if (!empty($value_type)) {
429  $metadata->value_type = $value_type;
430  }
431 
432  $md_id = _elgg_services()->metadataTable->create($metadata, $multiple);
433  if ($md_id === false) {
434  return false;
435  }
436  }
437 
438  return true;
439  }
440 
451  protected function setTempMetadata(string $name, $value, bool $multiple = false): bool {
452  // if overwrite, delete first
453  if (!$multiple) {
454  unset($this->temp_metadata[$name]);
455  if (count($value)) {
456  // only save if value array contains data
457  $this->temp_metadata[$name] = $value;
458  }
459 
460  return true;
461  }
462 
463  if (!isset($this->temp_metadata[$name])) {
464  $this->temp_metadata[$name] = [];
465  }
466 
467  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
468 
469  return true;
470  }
471 
483  public function deleteMetadata(string $name = null): bool {
484 
485  if (!$this->guid) {
486  // remove from temp_metadata
487  if (isset($name)) {
488  if (isset($this->temp_metadata[$name])) {
489  unset($this->temp_metadata[$name]);
490  }
491  } else {
492  $this->temp_metadata = [];
493  }
494 
495  return true;
496  }
497 
498  return elgg_delete_metadata([
499  'guid' => $this->guid,
500  'limit' => false,
501  'metadata_name' => $name,
502  ]);
503  }
504 
512  public function getVolatileData(string $name) {
513  return array_key_exists($name, $this->volatile) ? $this->volatile[$name] : null;
514  }
515 
524  public function setVolatileData(string $name, $value): void {
525  $this->volatile[$name] = $value;
526  }
527 
539  public function addRelationship(int $guid_two, string $relationship): bool {
540  return _elgg_services()->relationshipsTable->add($this->guid, (string) $relationship, (int) $guid_two);
541  }
542 
554  public function hasRelationship(int $guid_two, string $relationship): bool {
555  return (bool) _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two);
556  }
557 
567  public function getRelationship(int $guid_two, string $relationship): ?\ElggRelationship {
568  return _elgg_services()->relationshipsTable->check($this->guid, $relationship, $guid_two) ?: null;
569  }
570 
581  public function getEntitiesFromRelationship(array $options = []) {
582  $options['relationship_guid'] = $this->guid;
583  return elgg_get_entities($options);
584  }
585 
594  public function countEntitiesFromRelationship(string $relationship, bool $inverse_relationship = false): int {
595  return elgg_count_entities([
596  'relationship' => $relationship,
597  'relationship_guid' => $this->guid,
598  'inverse_relationship' => $inverse_relationship,
599  ]);
600  }
601 
610  public function removeRelationship(int $guid_two, string $relationship): bool {
611  return _elgg_services()->relationshipsTable->remove($this->guid, (string) $relationship, (int) $guid_two);
612  }
613 
627  public function removeAllRelationships(string $relationship = '', bool $inverse_relationship = false): bool {
628  return _elgg_services()->relationshipsTable->removeAll($this->guid, $relationship, $inverse_relationship);
629  }
630 
636  public function removeAllRelatedRiverItems(): void {
637  elgg_delete_river(['subject_guid' => $this->guid, 'limit' => false]);
638  elgg_delete_river(['object_guid' => $this->guid, 'limit' => false]);
639  elgg_delete_river(['target_guid' => $this->guid, 'limit' => false]);
640  }
641 
652  public function deleteAnnotations(string $name = null): bool {
653  if ($this->guid) {
654  return elgg_delete_annotations([
655  'guid' => $this->guid,
656  'limit' => false,
657  'annotation_name' => $name,
658  ]);
659  }
660 
661  if ($name) {
662  unset($this->temp_annotations[$name]);
663  } else {
664  $this->temp_annotations = [];
665  }
666 
667  return true;
668  }
669 
678  public function deleteOwnedAnnotations(string $name = null): bool {
679  // access is turned off for this because they might
680  // no longer have access to an entity they created annotations on
681  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($name) {
682  return elgg_delete_annotations([
683  'annotation_owner_guid' => $this->guid,
684  'limit' => false,
685  'annotation_name' => $name,
686  ]);
687  });
688  }
689 
697  public function disableAnnotations(string $name = null): bool {
698  return elgg_disable_annotations([
699  'guid' => $this->guid,
700  'limit' => false,
701  'annotation_name' => $name,
702  ]);
703  }
704 
712  public function enableAnnotations(string $name = null) {
713  return elgg_enable_annotations([
714  'guid' => $this->guid,
715  'limit' => false,
716  'annotation_name' => $name,
717  ]);
718  }
719 
727  private function getAnnotationCalculation($name, $calculation) {
728  $options = [
729  'guid' => $this->getGUID(),
730  'distinct' => false,
731  'annotation_name' => $name,
732  'annotation_calculation' => $calculation
733  ];
734 
736  }
737 
757  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $value_type = '') {
758  if (!$this->guid) {
759  $this->temp_annotations[$name] = $value;
760  return true;
761  }
762 
763  if (!$owner_guid) {
764  $owner_guid = _elgg_services()->session_manager->getLoggedInUserGuid();
765  }
766 
767  $annotation = new ElggAnnotation();
768  $annotation->entity_guid = $this->guid;
769  $annotation->name = $name;
770  $annotation->value = $value;
771  $annotation->owner_guid = $owner_guid;
772  $annotation->access_id = $access_id;
773 
774  if (!empty($value_type)) {
775  $annotation->value_type = $value_type;
776  }
777 
778  if ($annotation->save()) {
779  return $annotation->id;
780  }
781 
782  return false;
783  }
784 
796  public function getAnnotations(array $options = []) {
797  if ($this->guid) {
798  $options['guid'] = $this->guid;
799 
801  } else {
802  $name = elgg_extract('annotation_name', $options, '');
803 
804  if (isset($this->temp_annotations[$name])) {
805  return [$this->temp_annotations[$name]];
806  }
807  }
808 
809  return [];
810  }
811 
819  public function countAnnotations(string $name = ''): int {
820  return $this->getAnnotationCalculation($name, 'count');
821  }
822 
830  public function getAnnotationsAvg(string $name) {
831  return $this->getAnnotationCalculation($name, 'avg');
832  }
833 
841  public function getAnnotationsSum(string $name) {
842  return $this->getAnnotationCalculation($name, 'sum');
843  }
844 
852  public function getAnnotationsMin(string $name) {
853  return $this->getAnnotationCalculation($name, 'min');
854  }
855 
863  public function getAnnotationsMax(string $name) {
864  return $this->getAnnotationCalculation($name, 'max');
865  }
866 
873  public function countComments(): int {
874  if (!$this->hasCapability('commentable')) {
875  return 0;
876  }
877 
878  $params = ['entity' => $this];
879  $num = _elgg_services()->events->triggerResults('comments:count', $this->getType(), $params);
880 
881  if (is_int($num)) {
882  return $num;
883  }
884 
885  return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
886  }
887 
898  public function getOwnedAccessCollections(array $options = []): array {
899  $options['owner_guid'] = $this->guid;
900  return _elgg_services()->accessCollections->getEntityCollections($options);
901  }
902 
914  if ($subtype === '') {
915  throw new ElggInvalidArgumentException(__METHOD__ . ' requires $subtype to be non empty');
916  }
917 
918  $acls = $this->getOwnedAccessCollections([
919  'subtype' => $subtype,
920  ]);
921 
922  return elgg_extract(0, $acls);
923  }
924 
933  public function hasAccess(int $user_guid = 0): bool {
934  return _elgg_services()->accessCollections->hasAccessToEntity($this, $user_guid);
935  }
936 
946  public function canEdit(int $user_guid = 0): bool {
947  return _elgg_services()->userCapabilities->canEdit($this, $user_guid);
948  }
949 
960  public function canDelete(int $user_guid = 0): bool {
961  return _elgg_services()->userCapabilities->canDelete($this, $user_guid);
962  }
963 
974  public function canWriteToContainer(int $user_guid = 0, string $type = '', string $subtype = ''): bool {
975  if (empty($type) || empty($subtype)) {
976  throw new ElggInvalidArgumentException(__METHOD__ . ' requires $type and $subtype to be set');
977  }
978 
979  return _elgg_services()->userCapabilities->canWriteToContainer($this, $type, $subtype, $user_guid);
980  }
981 
991  public function canComment(int $user_guid = 0): bool {
992  return _elgg_services()->userCapabilities->canComment($this, $user_guid);
993  }
994 
1009  public function canAnnotate(int $user_guid = 0, string $annotation_name = ''): bool {
1010  return _elgg_services()->userCapabilities->canAnnotate($this, $user_guid, $annotation_name);
1011  }
1012 
1018  public function getGUID(): ?int {
1019  return $this->guid;
1020  }
1021 
1027  public function getType(): string {
1028  // this is just for the PHPUnit mocking framework
1029  return (string) $this->type;
1030  }
1031 
1040  public function setSubtype(string $subtype): void {
1041  // keep original values
1042  if ($this->guid && !array_key_exists('subtype', $this->orig_attributes)) {
1043  $this->orig_attributes['subtype'] = $this->attributes['subtype'];
1044  }
1045 
1046  $this->attributes['subtype'] = $subtype;
1047  }
1048 
1054  public function getSubtype(): string {
1055  return (string) $this->attributes['subtype'];
1056  }
1057 
1063  public function getOwnerGUID(): int {
1064  return (int) $this->owner_guid;
1065  }
1066 
1072  public function getOwnerEntity(): ?\ElggEntity {
1073  return $this->owner_guid ? get_entity($this->owner_guid) : null;
1074  }
1075 
1083  public function setContainerGUID(int $container_guid): void {
1085  }
1086 
1092  public function getContainerGUID(): int {
1093  return (int) $this->container_guid;
1094  }
1095 
1102  public function getContainerEntity(): ?\ElggEntity {
1103  return $this->container_guid ? get_entity($this->getContainerGUID()) : null;
1104  }
1105 
1111  public function getTimeUpdated(): int {
1112  return (int) $this->time_updated;
1113  }
1114 
1123  public function getURL(): string {
1124  $url = elgg_generate_entity_url($this, 'view');
1125 
1126  $url = _elgg_services()->events->triggerResults('entity:url', $this->getType(), ['entity' => $this], $url);
1127 
1128  if (empty($url)) {
1129  return '';
1130  }
1131 
1132  return elgg_normalize_url($url);
1133  }
1134 
1143  public function saveIconFromUploadedFile(string $input_name, string $type = 'icon', array $coords = []): bool {
1144  return _elgg_services()->iconService->saveIconFromUploadedFile($this, $input_name, $type, $coords);
1145  }
1146 
1155  public function saveIconFromLocalFile(string $filename, string $type = 'icon', array $coords = []): bool {
1156  return _elgg_services()->iconService->saveIconFromLocalFile($this, $filename, $type, $coords);
1157  }
1158 
1167  public function saveIconFromElggFile(\ElggFile $file, string $type = 'icon', array $coords = []): bool {
1168  return _elgg_services()->iconService->saveIconFromElggFile($this, $file, $type, $coords);
1169  }
1170 
1179  public function getIcon(string $size, string $type = 'icon'): \ElggIcon {
1180  return _elgg_services()->iconService->getIcon($this, $size, $type);
1181  }
1182 
1189  public function deleteIcon(string $type = 'icon'): bool {
1190  return _elgg_services()->iconService->deleteIcon($this, $type);
1191  }
1192 
1201  public function getIconLastChange(string $size, string $type = 'icon'): ?int {
1202  return _elgg_services()->iconService->getIconLastChange($this, $size, $type);
1203  }
1204 
1212  public function hasIcon(string $size, string $type = 'icon'): bool {
1213  return _elgg_services()->iconService->hasIcon($this, $size, $type);
1214  }
1215 
1227  public function getIconURL(string|array $params = []): string {
1228  return _elgg_services()->iconService->getIconURL($this, $params);
1229  }
1230 
1234  public function save(): bool {
1235  if ($this->guid > 0) {
1236  $result = $this->update();
1237  } else {
1238  $result = $this->create() !== false;
1239  }
1240 
1241  if ($result) {
1242  $this->cache();
1243  }
1244 
1245  return $result;
1246  }
1247 
1260  protected function create() {
1261 
1262  $type = $this->attributes['type'];
1263  if (!in_array($type, \Elgg\Config::ENTITY_TYPES)) {
1264  throw new ElggDomainException('Entity type must be one of the allowed types: ' . implode(', ', \Elgg\Config::ENTITY_TYPES));
1265  }
1266 
1267  $subtype = $this->attributes['subtype'];
1268  if (!$subtype) {
1269  throw new ElggInvalidArgumentException('All entities must have a subtype');
1270  }
1271 
1272  $owner_guid = (int) $this->attributes['owner_guid'];
1273  $access_id = (int) $this->attributes['access_id'];
1274  $now = $this->getCurrentTime()->getTimestamp();
1275  $time_created = isset($this->attributes['time_created']) ? (int) $this->attributes['time_created'] : $now;
1276 
1277  $container_guid = $this->attributes['container_guid'];
1278  if ($container_guid == 0) {
1280  $this->attributes['container_guid'] = $container_guid;
1281  }
1282 
1284 
1285  if ($access_id === ACCESS_DEFAULT) {
1286  throw new ElggInvalidArgumentException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1287  }
1288 
1289  if ($access_id === ACCESS_FRIENDS) {
1290  throw new ElggInvalidArgumentException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1291  }
1292 
1293  $user_guid = _elgg_services()->session_manager->getLoggedInUserGuid();
1294 
1295  // If given an owner, verify it can be loaded
1296  if (!empty($owner_guid)) {
1297  $owner = $this->getOwnerEntity();
1298  if (!$owner instanceof \ElggEntity) {
1299  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}),";
1300  $error .= " but the given owner {$owner_guid} could not be loaded.";
1302  }
1303 
1304  // If different owner than logged in, verify can write to container.
1305  if ($user_guid !== $owner_guid && !$owner->canEdit() && !$owner->canWriteToContainer($user_guid, $type, $subtype)) {
1306  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}) with owner {$owner_guid},";
1307  $error .= " but the user wasn't permitted to write to the owner's container.";
1309  }
1310  }
1311 
1312  // If given a container, verify it can be loaded and that the current user can write to it
1313  if (!empty($container_guid)) {
1314  $container = $this->getContainerEntity();
1315  if (!$container instanceof \ElggEntity) {
1316  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}),";
1317  $error .= " but the given container {$container_guid} could not be loaded.";
1319  }
1320 
1321  if (!$container->canWriteToContainer($user_guid, $type, $subtype)) {
1322  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}),";
1323  $error .= " but was not permitted to write to container {$container_guid}.";
1325  }
1326  }
1327 
1328  if (!_elgg_services()->events->triggerBefore('create', $this->type, $this)) {
1329  return false;
1330  }
1331 
1332  // Create primary table row
1333  $guid = _elgg_services()->entityTable->insertRow((object) [
1334  'type' => $type,
1335  'subtype' => $subtype,
1336  'owner_guid' => $owner_guid,
1337  'container_guid' => $container_guid,
1338  'access_id' => $access_id,
1339  'time_created' => $time_created,
1340  'time_updated' => $now,
1341  'last_action' => $now,
1342  ], $this->attributes);
1343 
1344  if (!$guid) {
1345  throw new IOException("Unable to save new object's base entity information!");
1346  }
1347 
1348  $this->attributes['subtype'] = $subtype;
1349  $this->attributes['guid'] = (int) $guid;
1350  $this->attributes['time_created'] = (int) $time_created;
1351  $this->attributes['time_updated'] = (int) $now;
1352  $this->attributes['last_action'] = (int) $now;
1353  $this->attributes['container_guid'] = (int) $container_guid;
1354 
1355  // We are writing this new entity to cache to make sure subsequent calls
1356  // to get_entity() load the entity from cache and not from the DB. This
1357  // MUST come before the metadata and annotation writes below!
1358  $this->cache();
1359 
1360  // Save any unsaved metadata
1361  if (count($this->temp_metadata) > 0) {
1362  foreach ($this->temp_metadata as $name => $value) {
1363  // temp metadata is always an array, but if there is only one value return just the value
1364  $this->setMetadata($name, $value, '', count($value) > 1);
1365  }
1366 
1367  $this->temp_metadata = [];
1368  }
1369 
1370  // Save any unsaved annotations.
1371  if (count($this->temp_annotations) > 0) {
1372  foreach ($this->temp_annotations as $name => $value) {
1373  $this->annotate($name, $value);
1374  }
1375 
1376  $this->temp_annotations = [];
1377  }
1378 
1379  if (isset($container) && !$container instanceof \ElggUser) {
1380  // users have their own logic for setting last action
1381  $container->updateLastAction();
1382  }
1383 
1384  // for BC reasons this event is still needed (for example for notifications)
1385  _elgg_services()->events->trigger('create', $this->type, $this);
1386 
1387  _elgg_services()->events->triggerAfter('create', $this->type, $this);
1388 
1389  return $guid;
1390  }
1391 
1399  protected function update(): bool {
1400 
1401  if (!$this->canEdit()) {
1402  return false;
1403  }
1404 
1405  // give old update event a chance to stop the update
1406  if (!_elgg_services()->events->trigger('update', $this->type, $this)) {
1407  return false;
1408  }
1409 
1410  $this->invalidateCache();
1411 
1412  // See #6225. We copy these after the update event in case a handler changed one of them.
1413  $guid = (int) $this->guid;
1414  $owner_guid = (int) $this->owner_guid;
1415  $access_id = (int) $this->access_id;
1416  $container_guid = (int) $this->container_guid;
1417  $time_created = (int) $this->time_created;
1418  $time = $this->getCurrentTime()->getTimestamp();
1419 
1420  if ($access_id == ACCESS_DEFAULT) {
1421  throw new ElggInvalidArgumentException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1422  }
1423 
1424  if ($access_id == ACCESS_FRIENDS) {
1425  throw new ElggInvalidArgumentException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1426  }
1427 
1428  // Update primary table
1429  $ret = _elgg_services()->entityTable->updateRow($guid, (object) [
1430  'owner_guid' => $owner_guid,
1431  'container_guid' => $container_guid,
1432  'access_id' => $access_id,
1433  'time_created' => $time_created,
1434  'time_updated' => $time,
1435  'guid' => $guid,
1436  ]);
1437  if ($ret === false) {
1438  return false;
1439  }
1440 
1441  $this->attributes['time_updated'] = $time;
1442 
1443  _elgg_services()->events->triggerAfter('update', $this->type, $this);
1444 
1445  $this->orig_attributes = [];
1446 
1447  $this->cache();
1448 
1449  // Handle cases where there was no error BUT no rows were updated!
1450  return true;
1451  }
1452 
1460  protected function load(stdClass $row): bool {
1461  $attributes = array_merge($this->attributes, (array) $row);
1462 
1463  if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys($attributes)) !== []) {
1464  // Some primary attributes are missing
1465  return false;
1466  }
1467 
1468  foreach ($attributes as $name => $value) {
1469  if (!in_array($name, self::PRIMARY_ATTR_NAMES)) {
1470  $this->setVolatileData("select:{$name}", $value);
1471  unset($attributes[$name]);
1472  continue;
1473  }
1474 
1475  if (in_array($name, static::INTEGER_ATTR_NAMES)) {
1476  $attributes[$name] = (int) $value;
1477  }
1478  }
1479 
1480  $this->attributes = $attributes;
1481 
1482  $this->cache();
1483 
1484  return true;
1485  }
1486 
1504  public function disable(string $reason = '', bool $recursive = true): bool {
1505  if (!$this->guid) {
1506  return false;
1507  }
1508 
1509  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1510  return false;
1511  }
1512 
1513  if (!$this->canEdit()) {
1514  return false;
1515  }
1516 
1517  if ($this instanceof ElggUser && !$this->isBanned()) {
1518  // temporarily ban to prevent using the site during disable
1519  $this->ban();
1520  $unban_after = true;
1521  } else {
1522  $unban_after = false;
1523  }
1524 
1525  if (!empty($reason)) {
1526  $this->disable_reason = $reason;
1527  }
1528 
1529  $guid = (int) $this->guid;
1530 
1531  if ($recursive) {
1532  elgg_call(ELGG_IGNORE_ACCESS | ELGG_HIDE_DISABLED_ENTITIES, function () use ($guid, $reason) {
1533  $base_options = [
1534  'wheres' => [
1535  function(QueryBuilder $qb, $main_alias) use ($guid) {
1536  return $qb->compare("{$main_alias}.guid", '!=', $guid, ELGG_VALUE_GUID);
1537  },
1538  ],
1539  'limit' => false,
1540  'batch' => true,
1541  'batch_inc_offset' => false,
1542  ];
1543 
1544  foreach (['owner_guid', 'container_guid'] as $db_column) {
1545  $options = $base_options;
1546  $options[$db_column] = $guid;
1547 
1548  $subentities = elgg_get_entities($options);
1549  /* @var $subentity \ElggEntity */
1550  foreach ($subentities as $subentity) {
1551  if (!$subentity->isEnabled()) {
1552  continue;
1553  }
1554 
1555  $subentity->addRelationship($guid, 'disabled_with');
1556  $subentity->disable($reason, true);
1557  }
1558  }
1559  });
1560  }
1561 
1562  $this->disableAnnotations();
1563 
1564  $disabled = _elgg_services()->entityTable->disable($this);
1565 
1566  if ($unban_after) {
1567  $this->unban();
1568  }
1569 
1570  if ($disabled) {
1571  $this->invalidateCache();
1572 
1573  $this->attributes['enabled'] = 'no';
1574  _elgg_services()->events->triggerAfter('disable', $this->type, $this);
1575  }
1576 
1577  return $disabled;
1578  }
1579 
1587  public function enable(bool $recursive = true): bool {
1588  if (empty($this->guid)) {
1589  return false;
1590  }
1591 
1592  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1593  return false;
1594  }
1595 
1596  if (!$this->canEdit()) {
1597  return false;
1598  }
1599 
1600  $result = elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function() use ($recursive) {
1601  $result = _elgg_services()->entityTable->enable($this);
1602 
1603  $this->deleteMetadata('disable_reason');
1604  $this->enableAnnotations();
1605 
1606  if ($recursive) {
1607  $disabled_with_it = elgg_get_entities([
1608  'relationship' => 'disabled_with',
1609  'relationship_guid' => $this->guid,
1610  'inverse_relationship' => true,
1611  'limit' => false,
1612  'batch' => true,
1613  'batch_inc_offset' => false,
1614  ]);
1615 
1616  foreach ($disabled_with_it as $e) {
1617  $e->enable($recursive);
1618  $e->removeRelationship($this->guid, 'disabled_with');
1619  }
1620  }
1621 
1622  return $result;
1623  });
1624 
1625  if ($result) {
1626  $this->attributes['enabled'] = 'yes';
1627  _elgg_services()->events->triggerAfter('enable', $this->type, $this);
1628  }
1629 
1630  return $result;
1631  }
1632 
1638  public function isEnabled(): bool {
1639  return $this->enabled == 'yes';
1640  }
1641 
1659  public function delete(bool $recursive = true): bool {
1660  // first check if we can delete this entity
1661  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1662  // which could potentially remove some content if the user didn't have access
1663  if (!$this->canDelete()) {
1664  return false;
1665  }
1666 
1667  try {
1668  return _elgg_services()->entityTable->delete($this, $recursive);
1669  } catch (DatabaseException $ex) {
1670  elgg_log($ex, 'ERROR');
1671  return false;
1672  }
1673  }
1674 
1681  public function toObject(array $params = []) {
1682  $object = $this->prepareObject(new \Elgg\Export\Entity());
1683 
1684  $params['entity'] = $this;
1685 
1686  return _elgg_services()->events->triggerResults('to:object', 'entity', $params, $object);
1687  }
1688 
1695  protected function prepareObject(\Elgg\Export\Entity $object) {
1696  $object->guid = $this->guid;
1697  $object->type = $this->getType();
1698  $object->subtype = $this->getSubtype();
1699  $object->owner_guid = $this->getOwnerGUID();
1700  $object->container_guid = $this->getContainerGUID();
1701  $object->time_created = date('c', $this->getTimeCreated());
1702  $object->time_updated = date('c', $this->getTimeUpdated());
1703  $object->url = $this->getURL();
1704  $object->read_access = (int) $this->access_id;
1705  return $object;
1706  }
1707 
1716  public function setLatLong(float $lat, float $long): void {
1717  $this->{'geo:lat'} = $lat;
1718  $this->{'geo:long'} = $long;
1719  }
1720 
1726  public function getLatitude(): float {
1727  return (float) $this->{'geo:lat'};
1728  }
1729 
1735  public function getLongitude(): float {
1736  return (float) $this->{'geo:long'};
1737  }
1738 
1739  /*
1740  * SYSTEM LOG INTERFACE
1741  */
1742 
1746  public function getSystemLogID(): int {
1747  return (int) $this->getGUID();
1748  }
1749 
1758  public function getObjectFromID(int $id): ?\ElggEntity {
1759  return get_entity($id);
1760  }
1761 
1769  public function getTags($tag_names = null) {
1770  if (!isset($tag_names)) {
1771  $tag_names = ['tags'];
1772  }
1773 
1774  if ($tag_names && !is_array($tag_names)) {
1775  $tag_names = [$tag_names];
1776  }
1777 
1778  $entity_tags = [];
1779  foreach ($tag_names as $tag_name) {
1780  $tags = $this->$tag_name;
1781  if (elgg_is_empty($tags)) {
1782  continue;
1783  }
1784 
1785  // if a single tag, metadata returns a string.
1786  // if multiple tags, metadata returns an array.
1787  if (is_array($tags)) {
1788  $entity_tags = array_merge($entity_tags, $tags);
1789  } else {
1790  $entity_tags[] = $tags;
1791  }
1792  }
1793 
1794  return $entity_tags;
1795  }
1796 
1804 
1805  if (!$this->guid) {
1806  return false;
1807  }
1808 
1809  if ($this->type !== 'user') {
1810  return true;
1811  }
1812 
1813  $ac = _elgg_services()->accessCollections;
1814 
1815  $collections = $ac->getCollectionsByMember($this->guid);
1816  if (empty($collections)) {
1817  return true;
1818  }
1819 
1820  $result = true;
1821  foreach ($collections as $collection) {
1822  $result &= $ac->removeUser($this->guid, $collection->id);
1823  }
1824 
1825  return $result;
1826  }
1827 
1834  public function deleteOwnedAccessCollections() {
1835 
1836  if (!$this->guid) {
1837  return false;
1838  }
1839 
1840  $collections = $this->getOwnedAccessCollections();
1841  if (empty($collections)) {
1842  return true;
1843  }
1844 
1845  $result = true;
1846  foreach ($collections as $collection) {
1847  $result = $result & $collection->delete();
1848  }
1849 
1850  return $result;
1851  }
1852 
1863  public function updateLastAction(int $posted = null): int {
1864  $posted = _elgg_services()->entityTable->updateLastAction($this, $posted);
1865 
1866  $this->attributes['last_action'] = $posted;
1867  $this->cache();
1868 
1869  return $posted;
1870  }
1871 
1878  public function disableCaching(): void {
1879  $this->_is_cacheable = false;
1880  if ($this->guid) {
1881  _elgg_services()->entityCache->delete($this->guid);
1882  }
1883  }
1884 
1891  public function enableCaching(): void {
1892  $this->_is_cacheable = true;
1893  }
1894 
1901  public function isCacheable(): bool {
1902  if (!$this->guid) {
1903  return false;
1904  }
1905 
1906  if (_elgg_services()->session_manager->getIgnoreAccess()) {
1907  return false;
1908  }
1909 
1910  return $this->_is_cacheable;
1911  }
1912 
1921  public function cache(bool $persist = true): void {
1922  if (!$this->isCacheable()) {
1923  return;
1924  }
1925 
1926  _elgg_services()->entityCache->save($this);
1927 
1928  if (!$persist) {
1929  return;
1930  }
1931 
1932  $tmp = $this->volatile;
1933 
1934  // don't store volatile data
1935  $this->volatile = [];
1936 
1937  _elgg_services()->sessionCache->entities->save($this->guid, $this);
1938 
1939  $this->volatile = $tmp;
1940  }
1941 
1948  public function invalidateCache(): void {
1949  if (!$this->guid) {
1950  return;
1951  }
1952 
1953  _elgg_services()->entityCache->delete($this->guid);
1954  _elgg_services()->dataCache->get('metadata')->delete($this->guid);
1955  }
1956 
1965  public function hasCapability(string $capability): bool {
1966  return _elgg_services()->entity_capabilities->hasCapability($this->getType(), $this->getSubtype(), $capability);
1967  }
1968 }
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:299
$display_name
Definition: delete.php:20
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
getSubtype()
Get the entity subtype.
setMetadata(string $name, $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
Definition: ElggEntity.php:370
$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:99
Entities that support icons should implement this interface.
Definition: EntityIcon.php:7
enableAnnotations(string $name=null)
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:712
__clone()
Clone an entity.
Definition: ElggEntity.php:175
$input_name
Definition: crop.php:24
$params
Saves global plugin settings.
Definition: save.php:13
saveIconFromLocalFile(string $filename, string $type= 'icon', array $coords=[])
Saves icons using a local file as the source.
setVolatileData(string $name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:524
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:299
getOwnerEntity()
Gets the that owns this entity.
$owner
Definition: upload.php:7
const ACCESS_DEFAULT
Controls access levels on entities, metadata, and annotations.
Definition: constants.php:9
getIconLastChange(string $size, string $type= 'icon')
Returns the timestamp of when the icon was changed.
if($id< 1) $annotation
Definition: delete.php:11
An IO Exception, throw when an IO Exception occurs.
Definition: IOException.php:12
canWriteToContainer(int $user_guid=0, string $type= '', string $subtype= '')
Can a user add an entity to this container.
Definition: ElggEntity.php:974
const PRIMARY_ATTR_NAMES
Definition: ElggEntity.php:50
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
Definition: annotations.php:87
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
canDelete(int $user_guid=0)
Can a user delete this entity?
Definition: ElggEntity.php:960
const INTEGER_ATTR_NAMES
Definition: ElggEntity.php:66
invalidateCache()
Invalidate cache for entity.
canComment(int $user_guid=0)
Can a user comment on an entity?
Definition: ElggEntity.php:991
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:149
const ACCESS_FRIENDS
Definition: constants.php:13
if(!$user instanceof\ElggUser) $time_created
Definition: online.php:13
saveIconFromElggFile(\ElggFile $file, string $type= 'icon', array $coords=[])
Saves icons using a file located in the data store as the source.
deleteOwnedAnnotations(string $name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:678
elgg_get_annotations(array $options=[])
Fetch annotations or perform a calculation on them.
Definition: annotations.php:52
countComments()
Count the number of comments attached to this entity.
Definition: ElggEntity.php:873
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:135
getVolatileData(string $name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:512
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
countEntitiesFromRelationship(string $relationship, bool $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
Definition: ElggEntity.php:594
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
enable(bool $recursive=true)
Enable the entity.
$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:113
cache(bool $persist=true)
Cache the entity in a session and persisted caches.
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
Database abstraction query builder.
getGUID()
Returns the guid.
getIconURL(string|array $params=[])
Get the URL for this entity&#39;s icon.
$time_updated
Definition: time.php:21
getContainerGUID()
Gets the container GUID for this entity.
$type
Definition: delete.php:22
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
enableCaching()
Enable runtime caching for entity.
deleteAnnotations(string $name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:652
addRelationship(int $guid_two, string $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:539
canAnnotate(int $user_guid=0, string $annotation_name= '')
Can a user annotate an entity?
disableAnnotations(string $name=null)
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:697
$options
Elgg admin footer.
Definition: footer.php:6
canEdit(int $user_guid=0)
Can a user edit this entity?
Definition: ElggEntity.php:946
getEntitiesFromRelationship(array $options=[])
Gets an array of entities with a relationship to this entity.
Definition: ElggEntity.php:581
setTempMetadata(string $name, $value, bool $multiple=false)
Set temp metadata on this entity.
Definition: ElggEntity.php:451
$value
Definition: generic.php:51
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
const ELGG_HIDE_DISABLED_ENTITIES
Definition: constants.php:133
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
getAnnotationsSum(string $name)
Get the sum of integer type annotations of a given name.
Definition: ElggEntity.php:841
elgg_disable_annotations(array $options)
Disables annotations based on $options.
getObjectFromID(int $id)
For a given ID, return the object associated with it.
countAnnotations(string $name= '')
Count annotations.
Definition: ElggEntity.php:819
getCurrentTime($modifier= '')
Get the (cloned) time.
Definition: TimeUsing.php:25
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:130
$owner_guid
$error
Bad request error.
Definition: 400.php:6
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:567
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:554
setSubtype(string $subtype)
Set the subtype of the entity.
getAnnotationsMin(string $name)
Get the minimum of integer type annotations of given name.
Definition: ElggEntity.php:852
const ACCESS_PRIVATE
Definition: constants.php:10
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:132
removeAllRelatedRiverItems()
Removes all river items related to this entity.
Definition: ElggEntity.php:636
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:67
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:504
getAnnotationsAvg(string $name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:830
hasAccess(int $user_guid=0)
Check if the given user has access to this entity.
Definition: ElggEntity.php:933
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:86
elgg_generate_entity_url(ElggEntity $entity, string $resource= 'view', string $subresource=null, array $parameters=[])
Generate entity URL from a named route.
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:515
A generic parent class for database exceptions.
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:228
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:483
$container
Definition: delete.php:24
saveIconFromUploadedFile(string $input_name, string $type= 'icon', array $coords=[])
Saves icons using an uploaded file as the source.
getIcon(string $size, string $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
toObject(array $params=[])
Export an entity.
ElggMetadata.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
getAnnotations(array $options=[])
Gets an array of annotations.
Definition: ElggEntity.php:796
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?
$size
Definition: thumb.php:23
update()
Update the entity in the database.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type= '')
Adds an annotation to an entity.
Definition: ElggEntity.php:757
elgg_get_metadata(array $options=[])
Fetch metadata or perform a calculation on them.
Definition: metadata.php:32
if($entity instanceof\ElggComment) $comment container_guid
Definition: save.php:54
$posted
Definition: comment.php:86
$comment access_id
Definition: save.php:55
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:49
$metadata
Output annotation metadata.
Definition: metadata.php:9
removeAllRelationships(string $relationship= '', bool $inverse_relationship=false)
Remove all relationships to or from this entity.
Definition: ElggEntity.php:627
getType()
Returns the entity type.
$subtype
Definition: delete.php:23
getOwnedAccessCollection(string $subtype)
Returns the first ACL owned by the entity with a given subtype.
Definition: ElggEntity.php:913
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
removeRelationship(int $guid_two, string $relationship)
Remove a relationship.
Definition: ElggEntity.php:610
$access_id
Definition: access.php:10
create()
Create a new entry in the entities table.
setContainerGUID(int $container_guid)
Set the container for this object.
getAllMetadata()
Get all entity metadata.
Definition: ElggEntity.php:343
Entity icon class.
Definition: ElggIcon.php:8
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
Definition: ElggEntity.php:283
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:134
$container_guid
getContainerEntity()
Get the container entity for this object.
elgg_normalize_url(string $url)
Definition: output.php:163
$tags
Output object tags.
Definition: tags.php:9
disable(string $reason= '', bool $recursive=true)
Disable this entity.
$site name
Definition: settings.php:15
updateLastAction(int $posted=null)
Update the last_action column in the entities table.
getSystemLogID()
{}
$id
Generic annotation delete action.
Definition: delete.php:6
$qb
Definition: queue.php:11
getAnnotationsMax(string $name)
Get the maximum of integer type annotations of a given name.
Definition: ElggEntity.php:863
getOwnedAccessCollections(array $options=[])
Returns the ACLs owned by the entity.
Definition: ElggEntity.php:898
getURL()
Gets the URL for this entity.
setDisplayName(string $display_name)
Sets the title or name of this entity.
Definition: ElggEntity.php:322
getMetadata(string $name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:333
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:312
deleteIcon(string $type= 'icon')
Removes all icon files and metadata for the passed type of icon.
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
getLongitude()
Return the entity&#39;s longitude.
hasIcon(string $size, string $type= 'icon')
Returns if the entity has an icon of the passed type.