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.";
1301  _elgg_services()->logger->error($error);
1302  return false;
1303  }
1304 
1305  // If different owner than logged in, verify can write to container.
1306  if ($user_guid !== $owner_guid && !$owner->canEdit() && !$owner->canWriteToContainer($user_guid, $type, $subtype)) {
1307  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}) with owner {$owner_guid},";
1308  $error .= " but the user wasn't permitted to write to the owner's container.";
1309  _elgg_services()->logger->error($error);
1310  return false;
1311  }
1312  }
1313 
1314  // If given a container, verify it can be loaded and that the current user can write to it
1315  if (!empty($container_guid)) {
1316  $container = $this->getContainerEntity();
1317  if (!$container instanceof \ElggEntity) {
1318  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}),";
1319  $error .= " but the given container {$container_guid} could not be loaded.";
1320  _elgg_services()->logger->error($error);
1321  return false;
1322  }
1323 
1324  if (!$container->canWriteToContainer($user_guid, $type, $subtype)) {
1325  $error = "User {$user_guid} tried to create a ({$type}, {$subtype}),";
1326  $error .= " but was not permitted to write to container {$container_guid}.";
1327  _elgg_services()->logger->error($error);
1328  return false;
1329  }
1330  }
1331 
1332  if (!_elgg_services()->events->triggerBefore('create', $this->type, $this)) {
1333  return false;
1334  }
1335 
1336  // Create primary table row
1337  $guid = _elgg_services()->entityTable->insertRow((object) [
1338  'type' => $type,
1339  'subtype' => $subtype,
1340  'owner_guid' => $owner_guid,
1341  'container_guid' => $container_guid,
1342  'access_id' => $access_id,
1343  'time_created' => $time_created,
1344  'time_updated' => $now,
1345  'last_action' => $now,
1346  ], $this->attributes);
1347 
1348  if (!$guid) {
1349  throw new IOException("Unable to save new object's base entity information!");
1350  }
1351 
1352  $this->attributes['subtype'] = $subtype;
1353  $this->attributes['guid'] = (int) $guid;
1354  $this->attributes['time_created'] = (int) $time_created;
1355  $this->attributes['time_updated'] = (int) $now;
1356  $this->attributes['last_action'] = (int) $now;
1357  $this->attributes['container_guid'] = (int) $container_guid;
1358 
1359  // We are writing this new entity to cache to make sure subsequent calls
1360  // to get_entity() load the entity from cache and not from the DB. This
1361  // MUST come before the metadata and annotation writes below!
1362  $this->cache();
1363 
1364  // Save any unsaved metadata
1365  if (count($this->temp_metadata) > 0) {
1366  foreach ($this->temp_metadata as $name => $value) {
1367  // temp metadata is always an array, but if there is only one value return just the value
1368  $this->setMetadata($name, $value, '', count($value) > 1);
1369  }
1370 
1371  $this->temp_metadata = [];
1372  }
1373 
1374  // Save any unsaved annotations.
1375  if (count($this->temp_annotations) > 0) {
1376  foreach ($this->temp_annotations as $name => $value) {
1377  $this->annotate($name, $value);
1378  }
1379 
1380  $this->temp_annotations = [];
1381  }
1382 
1383  if (isset($container) && !$container instanceof \ElggUser) {
1384  // users have their own logic for setting last action
1385  $container->updateLastAction();
1386  }
1387 
1388  // for BC reasons this event is still needed (for example for notifications)
1389  _elgg_services()->events->trigger('create', $this->type, $this);
1390 
1391  _elgg_services()->events->triggerAfter('create', $this->type, $this);
1392 
1393  return $guid;
1394  }
1395 
1403  protected function update(): bool {
1404 
1405  if (!$this->canEdit()) {
1406  return false;
1407  }
1408 
1409  // give old update event a chance to stop the update
1410  if (!_elgg_services()->events->trigger('update', $this->type, $this)) {
1411  return false;
1412  }
1413 
1414  $this->invalidateCache();
1415 
1416  // See #6225. We copy these after the update event in case a handler changed one of them.
1417  $guid = (int) $this->guid;
1418  $owner_guid = (int) $this->owner_guid;
1419  $access_id = (int) $this->access_id;
1420  $container_guid = (int) $this->container_guid;
1421  $time_created = (int) $this->time_created;
1422  $time = $this->getCurrentTime()->getTimestamp();
1423 
1424  if ($access_id == ACCESS_DEFAULT) {
1425  throw new ElggInvalidArgumentException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1426  }
1427 
1428  if ($access_id == ACCESS_FRIENDS) {
1429  throw new ElggInvalidArgumentException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1430  }
1431 
1432  // Update primary table
1433  $ret = _elgg_services()->entityTable->updateRow($guid, (object) [
1434  'owner_guid' => $owner_guid,
1435  'container_guid' => $container_guid,
1436  'access_id' => $access_id,
1437  'time_created' => $time_created,
1438  'time_updated' => $time,
1439  'guid' => $guid,
1440  ]);
1441  if ($ret === false) {
1442  return false;
1443  }
1444 
1445  $this->attributes['time_updated'] = $time;
1446 
1447  _elgg_services()->events->triggerAfter('update', $this->type, $this);
1448 
1449  $this->orig_attributes = [];
1450 
1451  $this->cache();
1452 
1453  // Handle cases where there was no error BUT no rows were updated!
1454  return true;
1455  }
1456 
1464  protected function load(stdClass $row): bool {
1465  $attributes = array_merge($this->attributes, (array) $row);
1466 
1467  if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys($attributes)) !== []) {
1468  // Some primary attributes are missing
1469  return false;
1470  }
1471 
1472  foreach ($attributes as $name => $value) {
1473  if (!in_array($name, self::PRIMARY_ATTR_NAMES)) {
1474  $this->setVolatileData("select:{$name}", $value);
1475  unset($attributes[$name]);
1476  continue;
1477  }
1478 
1479  if (in_array($name, static::INTEGER_ATTR_NAMES)) {
1480  $attributes[$name] = (int) $value;
1481  }
1482  }
1483 
1484  $this->attributes = $attributes;
1485 
1486  $this->cache();
1487 
1488  return true;
1489  }
1490 
1508  public function disable(string $reason = '', bool $recursive = true): bool {
1509  if (!$this->guid) {
1510  return false;
1511  }
1512 
1513  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1514  return false;
1515  }
1516 
1517  if (!$this->canEdit()) {
1518  return false;
1519  }
1520 
1521  if ($this instanceof ElggUser && !$this->isBanned()) {
1522  // temporarily ban to prevent using the site during disable
1523  $this->ban();
1524  $unban_after = true;
1525  } else {
1526  $unban_after = false;
1527  }
1528 
1529  if (!empty($reason)) {
1530  $this->disable_reason = $reason;
1531  }
1532 
1533  $guid = (int) $this->guid;
1534 
1535  if ($recursive) {
1536  elgg_call(ELGG_IGNORE_ACCESS | ELGG_HIDE_DISABLED_ENTITIES, function () use ($guid, $reason) {
1537  $base_options = [
1538  'wheres' => [
1539  function(QueryBuilder $qb, $main_alias) use ($guid) {
1540  return $qb->compare("{$main_alias}.guid", '!=', $guid, ELGG_VALUE_GUID);
1541  },
1542  ],
1543  'limit' => false,
1544  'batch' => true,
1545  'batch_inc_offset' => false,
1546  ];
1547 
1548  foreach (['owner_guid', 'container_guid'] as $db_column) {
1549  $options = $base_options;
1550  $options[$db_column] = $guid;
1551 
1552  $subentities = elgg_get_entities($options);
1553  /* @var $subentity \ElggEntity */
1554  foreach ($subentities as $subentity) {
1555  if (!$subentity->isEnabled()) {
1556  continue;
1557  }
1558 
1559  $subentity->addRelationship($guid, 'disabled_with');
1560  $subentity->disable($reason, true);
1561  }
1562  }
1563  });
1564  }
1565 
1566  $this->disableAnnotations();
1567 
1568  $disabled = _elgg_services()->entityTable->disable($this);
1569 
1570  if ($unban_after) {
1571  $this->unban();
1572  }
1573 
1574  if ($disabled) {
1575  $this->invalidateCache();
1576 
1577  $this->attributes['enabled'] = 'no';
1578  _elgg_services()->events->triggerAfter('disable', $this->type, $this);
1579  }
1580 
1581  return $disabled;
1582  }
1583 
1591  public function enable(bool $recursive = true): bool {
1592  if (empty($this->guid)) {
1593  return false;
1594  }
1595 
1596  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1597  return false;
1598  }
1599 
1600  if (!$this->canEdit()) {
1601  return false;
1602  }
1603 
1604  $result = elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function() use ($recursive) {
1605  $result = _elgg_services()->entityTable->enable($this);
1606 
1607  $this->deleteMetadata('disable_reason');
1608  $this->enableAnnotations();
1609 
1610  if ($recursive) {
1611  $disabled_with_it = elgg_get_entities([
1612  'relationship' => 'disabled_with',
1613  'relationship_guid' => $this->guid,
1614  'inverse_relationship' => true,
1615  'limit' => false,
1616  'batch' => true,
1617  'batch_inc_offset' => false,
1618  ]);
1619 
1620  foreach ($disabled_with_it as $e) {
1621  $e->enable($recursive);
1622  $e->removeRelationship($this->guid, 'disabled_with');
1623  }
1624  }
1625 
1626  return $result;
1627  });
1628 
1629  if ($result) {
1630  $this->attributes['enabled'] = 'yes';
1631  _elgg_services()->events->triggerAfter('enable', $this->type, $this);
1632  }
1633 
1634  return $result;
1635  }
1636 
1642  public function isEnabled(): bool {
1643  return $this->enabled == 'yes';
1644  }
1645 
1663  public function delete(bool $recursive = true): bool {
1664  // first check if we can delete this entity
1665  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1666  // which could potentially remove some content if the user didn't have access
1667  if (!$this->canDelete()) {
1668  return false;
1669  }
1670 
1671  try {
1672  return _elgg_services()->entityTable->delete($this, $recursive);
1673  } catch (DatabaseException $ex) {
1674  elgg_log($ex, 'ERROR');
1675  return false;
1676  }
1677  }
1678 
1685  public function toObject(array $params = []) {
1686  $object = $this->prepareObject(new \Elgg\Export\Entity());
1687 
1688  $params['entity'] = $this;
1689 
1690  return _elgg_services()->events->triggerResults('to:object', 'entity', $params, $object);
1691  }
1692 
1699  protected function prepareObject(\Elgg\Export\Entity $object) {
1700  $object->guid = $this->guid;
1701  $object->type = $this->getType();
1702  $object->subtype = $this->getSubtype();
1703  $object->owner_guid = $this->getOwnerGUID();
1704  $object->container_guid = $this->getContainerGUID();
1705  $object->time_created = date('c', $this->getTimeCreated());
1706  $object->time_updated = date('c', $this->getTimeUpdated());
1707  $object->url = $this->getURL();
1708  $object->read_access = (int) $this->access_id;
1709  return $object;
1710  }
1711 
1720  public function setLatLong(float $lat, float $long): void {
1721  $this->{'geo:lat'} = $lat;
1722  $this->{'geo:long'} = $long;
1723  }
1724 
1730  public function getLatitude(): float {
1731  return (float) $this->{'geo:lat'};
1732  }
1733 
1739  public function getLongitude(): float {
1740  return (float) $this->{'geo:long'};
1741  }
1742 
1743  /*
1744  * SYSTEM LOG INTERFACE
1745  */
1746 
1750  public function getSystemLogID(): int {
1751  return (int) $this->getGUID();
1752  }
1753 
1762  public function getObjectFromID(int $id): ?\ElggEntity {
1763  return get_entity($id);
1764  }
1765 
1773  public function getTags($tag_names = null) {
1774  if (!isset($tag_names)) {
1775  $tag_names = ['tags'];
1776  }
1777 
1778  if ($tag_names && !is_array($tag_names)) {
1779  $tag_names = [$tag_names];
1780  }
1781 
1782  $entity_tags = [];
1783  foreach ($tag_names as $tag_name) {
1784  $tags = $this->$tag_name;
1785  if (elgg_is_empty($tags)) {
1786  continue;
1787  }
1788 
1789  // if a single tag, metadata returns a string.
1790  // if multiple tags, metadata returns an array.
1791  if (is_array($tags)) {
1792  $entity_tags = array_merge($entity_tags, $tags);
1793  } else {
1794  $entity_tags[] = $tags;
1795  }
1796  }
1797 
1798  return $entity_tags;
1799  }
1800 
1808 
1809  if (!$this->guid) {
1810  return false;
1811  }
1812 
1813  if ($this->type !== 'user') {
1814  return true;
1815  }
1816 
1817  $ac = _elgg_services()->accessCollections;
1818 
1819  $collections = $ac->getCollectionsByMember($this->guid);
1820  if (empty($collections)) {
1821  return true;
1822  }
1823 
1824  $result = true;
1825  foreach ($collections as $collection) {
1826  $result &= $ac->removeUser($this->guid, $collection->id);
1827  }
1828 
1829  return $result;
1830  }
1831 
1838  public function deleteOwnedAccessCollections() {
1839 
1840  if (!$this->guid) {
1841  return false;
1842  }
1843 
1844  $collections = $this->getOwnedAccessCollections();
1845  if (empty($collections)) {
1846  return true;
1847  }
1848 
1849  $result = true;
1850  foreach ($collections as $collection) {
1851  $result = $result & $collection->delete();
1852  }
1853 
1854  return $result;
1855  }
1856 
1867  public function updateLastAction(int $posted = null): int {
1868  $posted = _elgg_services()->entityTable->updateLastAction($this, $posted);
1869 
1870  $this->attributes['last_action'] = $posted;
1871  $this->cache();
1872 
1873  return $posted;
1874  }
1875 
1882  public function disableCaching(): void {
1883  $this->_is_cacheable = false;
1884  if ($this->guid) {
1885  _elgg_services()->entityCache->delete($this->guid);
1886  }
1887  }
1888 
1895  public function enableCaching(): void {
1896  $this->_is_cacheable = true;
1897  }
1898 
1905  public function isCacheable(): bool {
1906  if (!$this->guid) {
1907  return false;
1908  }
1909 
1910  if (_elgg_services()->session_manager->getIgnoreAccess()) {
1911  return false;
1912  }
1913 
1914  return $this->_is_cacheable;
1915  }
1916 
1925  public function cache(bool $persist = true): void {
1926  if (!$this->isCacheable()) {
1927  return;
1928  }
1929 
1930  _elgg_services()->entityCache->save($this);
1931 
1932  if (!$persist) {
1933  return;
1934  }
1935 
1936  $tmp = $this->volatile;
1937 
1938  // don't store volatile data
1939  $this->volatile = [];
1940 
1941  _elgg_services()->sessionCache->entities->save($this->guid, $this);
1942 
1943  $this->volatile = $tmp;
1944  }
1945 
1952  public function invalidateCache(): void {
1953  if (!$this->guid) {
1954  return;
1955  }
1956 
1957  _elgg_services()->entityCache->delete($this->guid);
1958  _elgg_services()->dataCache->get('metadata')->delete($this->guid);
1959  }
1960 
1969  public function hasCapability(string $capability): bool {
1970  return _elgg_services()->entity_capabilities->hasCapability($this->getType(), $this->getSubtype(), $capability);
1971  }
1972 }
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.