Elgg  Version 4.x
ElggEntity.php
Go to the documentation of this file.
1 <?php
2 
10 
46 abstract class ElggEntity extends \ElggData implements EntityIcon {
47 
48  use Subscriptions;
49 
50  public const PRIMARY_ATTR_NAMES = [
51  'guid',
52  'type',
53  'subtype',
54  'owner_guid',
55  'container_guid',
56  'access_id',
57  'time_created',
58  'time_updated',
59  'last_action',
60  'enabled',
61  ];
62 
66  protected const INTEGER_ATTR_NAMES = [
67  'guid',
68  'owner_guid',
69  'container_guid',
70  'access_id',
71  'time_created',
72  'time_updated',
73  'last_action',
74  ];
75 
81  protected $temp_metadata = [];
82 
88  protected $temp_annotations = [];
89 
95  protected $temp_private_settings = [];
96 
102  protected $volatile = [];
103 
108  protected $orig_attributes = [];
109 
113  protected $_is_cacheable = true;
114 
125  protected $_cached_metadata;
126 
141  public function __construct(stdClass $row = null) {
142  $this->initializeAttributes();
143 
144  if ($row && !$this->load($row)) {
145  $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid;
146  throw new IOException($msg);
147  }
148  }
149 
157  protected function initializeAttributes() {
158  parent::initializeAttributes();
159 
160  $this->attributes['guid'] = null;
161  $this->attributes['type'] = $this->getType();
162  $this->attributes['subtype'] = null;
163 
164  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid();
165  $this->attributes['container_guid'] = _elgg_services()->session->getLoggedInUserGuid();
166 
167  $this->attributes['access_id'] = ACCESS_PRIVATE;
168  $this->attributes['time_updated'] = null;
169  $this->attributes['last_action'] = null;
170  $this->attributes['enabled'] = "yes";
171  }
172 
183  public function __clone() {
184  $orig_entity = get_entity($this->guid);
185  if (!$orig_entity) {
186  _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid");
187  return;
188  }
189 
190  $metadata_array = elgg_get_metadata([
191  'guid' => $this->guid,
192  'limit' => false,
193  ]);
194 
195  $this->attributes['guid'] = null;
196  $this->attributes['time_created'] = null;
197  $this->attributes['time_updated'] = null;
198  $this->attributes['last_action'] = null;
199 
200  $this->attributes['subtype'] = $orig_entity->getSubtype();
201 
202  // copy metadata over to new entity - slightly convoluted due to
203  // handling of metadata arrays
204  if (is_array($metadata_array)) {
205  // create list of metadata names
206  $metadata_names = [];
207  foreach ($metadata_array as $metadata) {
208  $metadata_names[] = $metadata->name;
209  }
210  // arrays are stored with multiple enties per name
211  $metadata_names = array_unique($metadata_names);
212 
213  // move the metadata over
214  foreach ($metadata_names as $name) {
215  $this->__set($name, $orig_entity->$name);
216  }
217  }
218  }
219 
235  public function __set($name, $value) {
236  if ($this->$name === $value) {
237  // quick return if value is not changing
238  return;
239  }
240 
241  if (array_key_exists($name, $this->attributes)) {
242  // if an attribute is 1 (integer) and it's set to "1" (string), don't consider that a change.
243  if (is_int($this->attributes[$name])
244  && is_string($value)
245  && ((string) $this->attributes[$name] === $value)) {
246  return;
247  }
248 
249  // keep original values
250  if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
251  $this->orig_attributes[$name] = $this->attributes[$name];
252  }
253 
254  // Certain properties should not be manually changed!
255  switch ($name) {
256  case 'guid':
257  case 'last_action':
258  case 'time_updated':
259  case 'type':
260  return;
261  case 'subtype':
262  throw new ElggInvalidArgumentException(elgg_echo('ElggEntity:Error:SetSubtype', ['setSubtype()']));
263  case 'enabled':
264  throw new ElggInvalidArgumentException(elgg_echo('ElggEntity:Error:SetEnabled', ['enable() / disable()']));
265  case 'access_id':
266  case 'owner_guid':
267  case 'container_guid':
268  if ($value !== null) {
269  $this->attributes[$name] = (int) $value;
270  } else {
271  $this->attributes[$name] = null;
272  }
273  break;
274  default:
275  $this->attributes[$name] = $value;
276  break;
277  }
278  return;
279  }
280 
281  $this->setMetadata($name, $value);
282  }
283 
289  public function getOriginalAttributes() {
290  return $this->orig_attributes;
291  }
292 
305  public function __get($name) {
306  if (array_key_exists($name, $this->attributes)) {
307  return $this->attributes[$name];
308  }
309 
310  return $this->getMetadata($name);
311  }
312 
318  public function getDisplayName() {
319  return (string) $this->name;
320  }
321 
328  public function setDisplayName($display_name) {
329  $this->name = $display_name;
330  }
331 
339  public function getMetadata($name) {
340  $metadata = $this->getAllMetadata();
341  return elgg_extract($name, $metadata);
342  }
343 
349  public function getAllMetadata() {
350  if (!$this->guid) {
351  return array_map(function($values) {
352  return count($values) > 1 ? $values : $values[0];
354  }
355 
356  $this->_cached_metadata = _elgg_services()->metadataCache->getAll($this->guid);
357 
359  }
360 
376  public function setMetadata($name, $value, $value_type = '', $multiple = false) {
377 
378  if ($value === null || $value === '') {
379  $result = $this->deleteMetadata($name);
380  if (is_null($result)) {
381  // null result means no metadata found to be deleted
382  return true;
383  }
384 
385  return $result;
386  }
387 
388  // normalize value to an array that we will loop over
389  // remove indexes if value already an array.
390  if (is_array($value)) {
391  $value = array_values($value);
392  } else {
393  $value = [$value];
394  }
395 
396  // strip null values from array
397  $value = array_filter($value, function($var) {
398  return !is_null($var);
399  });
400 
401  if (empty($this->guid)) {
402  // unsaved entity. store in temp array
403  return $this->setTempMetadata($name, $value, $multiple);
404  }
405 
406  // saved entity. persist md to db.
407  if (!$multiple) {
408  $current_metadata = $this->getMetadata($name);
409 
410  if ((is_array($current_metadata) || count($value) > 1 || $value === []) && isset($current_metadata)) {
411  // remove current metadata if needed
412  // need to remove access restrictions right now to delete
413  // because this is the expected behavior
414  $delete_result = elgg_call(ELGG_IGNORE_ACCESS, function() use ($name) {
415  return elgg_delete_metadata([
416  'guid' => $this->guid,
417  'metadata_name' => $name,
418  'limit' => false,
419  ]);
420  });
421 
422  if (false === $delete_result) {
423  return false;
424  }
425  }
426 
427  if (count($value) > 1) {
428  // new value is a multiple valued metadata
429  $multiple = true;
430  }
431  }
432 
433  // create new metadata
434  foreach ($value as $value_tmp) {
435  $metadata = new ElggMetadata();
436  $metadata->entity_guid = $this->guid;
437  $metadata->name = $name;
438  $metadata->value = $value_tmp;
439 
440  if (!empty($value_type)) {
441  $metadata->value_type = $value_type;
442  }
443 
444  $md_id = _elgg_services()->metadataTable->create($metadata, $multiple);
445  if ($md_id === false) {
446  return false;
447  }
448  }
449 
450  return true;
451  }
452 
463  protected function setTempMetadata($name, $value, $multiple = false) {
464  // if overwrite, delete first
465  if (!$multiple) {
466  unset($this->temp_metadata[$name]);
467  if (count($value)) {
468  // only save if value array contains data
469  $this->temp_metadata[$name] = $value;
470  }
471  return true;
472  }
473 
474  if (!isset($this->temp_metadata[$name])) {
475  $this->temp_metadata[$name] = [];
476  }
477 
478  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
479 
480  return true;
481  }
482 
483 
484 
495  public function deleteMetadata($name = null) {
496 
497  if (!$this->guid) {
498  // remove from temp_metadata
499  if ($name) {
500  if (!isset($this->temp_metadata[$name])) {
501  return null;
502  } else {
503  unset($this->temp_metadata[$name]);
504  return true;
505  }
506  } else {
507  $this->temp_metadata = [];
508  return true;
509  }
510  }
511 
512  $options = [
513  'guid' => $this->guid,
514  'limit' => false,
515  ];
516  if ($name) {
517  $options['metadata_name'] = $name;
518  }
519 
521  }
522 
530  public function getVolatileData($name) {
531  return array_key_exists($name, $this->volatile) ? $this->volatile[$name] : null;
532  }
533 
542  public function setVolatileData($name, $value) {
543  $this->volatile[$name] = $value;
544  }
545 
559  public function deleteRelationships($relationship = null) {
560  $relationship = (string) $relationship;
562  return $result && remove_entity_relationships($this->getGUID(), $relationship, true);
563  }
564 
577  public function addRelationship($guid_two, $relationship) {
578  return add_entity_relationship($this->getGUID(), $relationship, $guid_two);
579  }
580 
591  public function removeRelationship($guid_two, $relationship) {
592  return remove_entity_relationship($this->getGUID(), $relationship, $guid_two);
593  }
594 
608  public function setPrivateSetting($name, $value) {
609 
610  if ($value === null || $value === '') {
611  $this->removePrivateSetting($name);
612 
613  // do not check result of removePrivateSetting as it returns false if private setting does not exist
614  return true;
615  }
616 
617  if (is_bool($value)) {
618  $value = (int) $value;
619  }
620 
621  // checking if string value matches saved value (as get privatesettings does not know value type) and db column is a string
622  if (strval($value) === $this->getPrivateSetting($name)) {
623  // no need to update value
624  return true;
625  }
626 
627  if (!$this->guid) {
628  $this->temp_private_settings[$name] = $value;
629 
630  return true;
631  }
632 
633  return _elgg_services()->privateSettings->set($this, $name, $value);
634  }
635 
646  public function getPrivateSetting($name) {
647  if (!$this->guid) {
648  return elgg_extract($name, $this->temp_private_settings);
649  }
650 
651  return _elgg_services()->privateSettings->get($this, $name);
652  }
653 
659  public function getAllPrivateSettings() {
660  if (!$this->guid) {
662  }
663 
664  return _elgg_services()->privateSettings->getAllForEntity($this);
665  }
666 
674  public function removePrivateSetting($name) {
675  if (!$this->guid) {
676  unset($this->temp_private_settings[$name]);
677  return true;
678  }
679 
680  return _elgg_services()->privateSettings->remove($this, $name);
681  }
682 
688  public function removeAllPrivateSettings() {
689  if (!$this->guid) {
690  $this->temp_private_settings = [];
691  return true;
692  }
693 
694  return _elgg_services()->privateSettings->removeAllForEntity($this);
695  }
696 
702  public function removeAllRelatedRiverItems() {
703  elgg_delete_river(['subject_guid' => $this->guid, 'limit' => false]);
704  elgg_delete_river(['object_guid' => $this->guid, 'limit' => false]);
705  elgg_delete_river(['target_guid' => $this->guid, 'limit' => false]);
706  }
707 
718  public function deleteAnnotations($name = null) {
719  if ($this->guid) {
720  $options = [
721  'guid' => $this->guid,
722  'limit' => false,
723  ];
724  if ($name) {
725  $options['annotation_name'] = $name;
726  }
727 
729  }
730 
731  if ($name) {
732  unset($this->temp_annotations[$name]);
733  } else {
734  $this->temp_annotations = [];
735  }
736 
737  return true;
738  }
739 
748  public function deleteOwnedAnnotations($name = null) {
749  // access is turned off for this because they might
750  // no longer have access to an entity they created annotations on
751  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($name) {
752  return elgg_delete_annotations([
753  'annotation_owner_guid' => $this->guid,
754  'limit' => false,
755  'annotation_name' => $name,
756  ]);
757  });
758  }
759 
767  public function disableAnnotations($name = '') {
768  $options = [
769  'guid' => $this->guid,
770  'limit' => false,
771  ];
772  if ($name) {
773  $options['annotation_name'] = $name;
774  }
775 
777  }
778 
786  public function enableAnnotations($name = '') {
787  $options = [
788  'guid' => $this->guid,
789  'limit' => false,
790  ];
791  if ($name) {
792  $options['annotation_name'] = $name;
793  }
794 
796  }
797 
805  private function getAnnotationCalculation($name, $calculation) {
806  $options = [
807  'guid' => $this->getGUID(),
808  'distinct' => false,
809  'annotation_name' => $name,
810  'annotation_calculation' => $calculation
811  ];
812 
814  }
815 
835  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $value_type = "") {
836  if (!$this->guid) {
837  $this->temp_annotations[$name] = $value;
838  return true;
839  }
840 
841  if (!$owner_guid) {
842  $owner_guid = _elgg_services()->session->getLoggedInUserGuid();
843  }
844 
845  $annotation = new ElggAnnotation();
846  $annotation->entity_guid = $this->guid;
847  $annotation->name = $name;
848  $annotation->value = $value;
849  $annotation->owner_guid = $owner_guid;
850  $annotation->access_id = $access_id;
851 
852  if (!empty($value_type)) {
853  $annotation->value_type = $value_type;
854  }
855 
856  if ($annotation->save()) {
857  return $annotation->id;
858  }
859 
860  return false;
861  }
862 
874  public function getAnnotations(array $options = []) {
875  if ($this->guid) {
876  $options['guid'] = $this->guid;
877 
879  } else {
880  $name = elgg_extract('annotation_name', $options, '');
881 
882  if (isset($this->temp_annotations[$name])) {
883  return [$this->temp_annotations[$name]];
884  }
885  }
886 
887  return [];
888  }
889 
897  public function countAnnotations($name = "") {
898  return $this->getAnnotationCalculation($name, 'count');
899  }
900 
908  public function getAnnotationsAvg($name) {
909  return $this->getAnnotationCalculation($name, 'avg');
910  }
911 
919  public function getAnnotationsSum($name) {
920  return $this->getAnnotationCalculation($name, 'sum');
921  }
922 
930  public function getAnnotationsMin($name) {
931  return $this->getAnnotationCalculation($name, 'min');
932  }
933 
941  public function getAnnotationsMax($name) {
942  return $this->getAnnotationCalculation($name, 'max');
943  }
944 
951  public function countComments() {
952  if (!$this->hasCapability('commentable')) {
953  return 0;
954  }
955 
956  $params = ['entity' => $this];
957  $num = _elgg_services()->hooks->trigger('comments:count', $this->getType(), $params);
958 
959  if (is_int($num)) {
960  return $num;
961  }
962 
963  return \Elgg\Comments\DataService::instance()->getCommentsCount($this);
964  }
965 
976  public function getOwnedAccessCollections($options = []) {
977  $options['owner_guid'] = $this->guid;
978  return _elgg_services()->accessCollections->getEntityCollections($options);
979  }
980 
991  if (!is_string($subtype) || $subtype === '') {
992  return false;
993  }
994 
995  $acls = $this->getOwnedAccessCollections([
996  'subtype' => $subtype,
997  ]);
998 
999  return elgg_extract(0, $acls, false);
1000  }
1001 
1012  public function getEntitiesFromRelationship(array $options = []) {
1013  $options['relationship_guid'] = $this->guid;
1014  return elgg_get_entities($options);
1015  }
1016 
1025  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
1026  return elgg_count_entities([
1027  'relationship' => $relationship,
1028  'relationship_guid' => $this->getGUID(),
1029  'inverse_relationship' => $inverse_relationship,
1030  ]);
1031  }
1032 
1042  public function canEdit($user_guid = 0) {
1043  return _elgg_services()->userCapabilities->canEdit($this, $user_guid);
1044  }
1045 
1056  public function canDelete($user_guid = 0) {
1057  return _elgg_services()->userCapabilities->canDelete($this, $user_guid);
1058  }
1059 
1070  public function canWriteToContainer($user_guid = 0, $type = '', $subtype = '') {
1071  if (empty($type) || empty($subtype)) {
1072  throw new ElggInvalidArgumentException(__METHOD__ . ' requires $type and $subtype to be set');
1073  }
1074 
1075  return _elgg_services()->userCapabilities->canWriteToContainer($this, $type, $subtype, $user_guid);
1076  }
1077 
1089  public function canComment($user_guid = 0, $default = null) {
1090  return _elgg_services()->userCapabilities->canComment($this, $user_guid, $default);
1091  }
1092 
1107  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1108  return _elgg_services()->userCapabilities->canAnnotate($this, $user_guid, $annotation_name);
1109  }
1110 
1116  public function getAccessID() {
1117  elgg_deprecated_notice(__METHOD__ . ' is deprecated. Use the attribute "access_id" directly.', '4.1');
1118  return $this->access_id;
1119  }
1120 
1126  public function getGUID() {
1127  return $this->guid;
1128  }
1129 
1135  public function getType() {
1136  // this is just for the PHPUnit mocking framework
1137  return $this->type;
1138  }
1139 
1148  public function setSubtype(string $subtype) : void {
1149  // keep original values
1150  if ($this->guid && !array_key_exists('subtype', $this->orig_attributes)) {
1151  $this->orig_attributes['subtype'] = $this->attributes['subtype'];
1152  }
1153 
1154  $this->attributes['subtype'] = $subtype;
1155  }
1156 
1162  public function getSubtype() {
1163  return $this->attributes['subtype'];
1164  }
1165 
1171  public function getOwnerGUID() {
1172  return (int) $this->owner_guid;
1173  }
1174 
1180  public function getOwnerEntity() {
1181  return get_entity($this->owner_guid);
1182  }
1183 
1192  return $this->container_guid = (int) $container_guid;
1193  }
1194 
1200  public function getContainerGUID() {
1201  return (int) $this->container_guid;
1202  }
1203 
1210  public function getContainerEntity() {
1211  return get_entity($this->getContainerGUID());
1212  }
1213 
1219  public function getTimeUpdated() {
1220  return $this->time_updated;
1221  }
1222 
1231  public function getURL() {
1232  $url = elgg_generate_entity_url($this, 'view');
1233 
1234  $url = _elgg_services()->hooks->trigger('entity:url', $this->getType(), ['entity' => $this], $url);
1235 
1236  if (empty($url)) {
1237  return '';
1238  }
1239 
1240  return elgg_normalize_url($url);
1241  }
1242 
1251  public function saveIconFromUploadedFile($input_name, $type = 'icon', array $coords = []) {
1252  return _elgg_services()->iconService->saveIconFromUploadedFile($this, $input_name, $type, $coords);
1253  }
1254 
1263  public function saveIconFromLocalFile($filename, $type = 'icon', array $coords = []) {
1264  return _elgg_services()->iconService->saveIconFromLocalFile($this, $filename, $type, $coords);
1265  }
1266 
1275  public function saveIconFromElggFile(\ElggFile $file, $type = 'icon', array $coords = []) {
1276  return _elgg_services()->iconService->saveIconFromElggFile($this, $file, $type, $coords);
1277  }
1278 
1287  public function getIcon($size, $type = 'icon') {
1288  return _elgg_services()->iconService->getIcon($this, $size, $type);
1289  }
1290 
1297  public function deleteIcon($type = 'icon') {
1298  return _elgg_services()->iconService->deleteIcon($this, $type);
1299  }
1300 
1309  public function getIconLastChange($size, $type = 'icon') {
1310  return _elgg_services()->iconService->getIconLastChange($this, $size, $type);
1311  }
1312 
1320  public function hasIcon($size, $type = 'icon') {
1321  return _elgg_services()->iconService->hasIcon($this, $size, $type);
1322  }
1323 
1335  public function getIconURL($params = []) {
1336  return _elgg_services()->iconService->getIconURL($this, $params);
1337  }
1338 
1342  public function save() : bool {
1343  $result = false;
1344 
1345  if ($this->guid > 0) {
1346  $result = $this->update();
1347  } else {
1348  $guid = $this->create();
1349  if ($guid === false) {
1350  return false;
1351  }
1352 
1353  if (!_elgg_services()->events->trigger('create', $this->type, $this)) {
1354  // plugins that return false to event don't need to override the access system
1355  elgg_call(ELGG_IGNORE_ACCESS, function() {
1356  return $this->delete();
1357  });
1358  return false;
1359  }
1360 
1361  $result = true;
1362  }
1363 
1364  if ($result) {
1365  $this->cache();
1366  }
1367 
1368  return $result;
1369  }
1370 
1381  protected function create() {
1382 
1383  $type = $this->attributes['type'];
1384  if (!in_array($type, \Elgg\Config::ENTITY_TYPES)) {
1385  throw new InvalidParameterException('Entity type must be one of the allowed types: '
1386  . implode(', ', \Elgg\Config::ENTITY_TYPES));
1387  }
1388 
1389  $subtype = $this->attributes['subtype'];
1390  if (!$subtype) {
1391  throw new InvalidParameterException("All entities must have a subtype");
1392  }
1393 
1394  $owner_guid = (int) $this->attributes['owner_guid'];
1395  $access_id = (int) $this->attributes['access_id'];
1396  $now = $this->getCurrentTime()->getTimestamp();
1397  $time_created = isset($this->attributes['time_created']) ? (int) $this->attributes['time_created'] : $now;
1398 
1399  $container_guid = $this->attributes['container_guid'];
1400  if ($container_guid == 0) {
1402  $this->attributes['container_guid'] = $container_guid;
1403  }
1405 
1406  if ($access_id == ACCESS_DEFAULT) {
1407  throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1408  }
1409 
1410  if ($access_id == ACCESS_FRIENDS) {
1411  throw new InvalidParameterException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1412  }
1413 
1414  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1415 
1416  // If given an owner, verify it can be loaded
1417  if ($owner_guid) {
1418  $owner = $this->getOwnerEntity();
1419  if (!$owner) {
1420  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1421  . " owner $owner_guid could not be loaded.");
1422  return false;
1423  }
1424 
1425  // If different owner than logged in, verify can write to container.
1426 
1427  if ($user_guid != $owner_guid && !$owner->canEdit() && !$owner->canWriteToContainer($user_guid, $type, $subtype)) {
1428  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype) with owner"
1429  . " $owner_guid, but the user wasn't permitted to write to the owner's container.");
1430  return false;
1431  }
1432  }
1433 
1434  // If given a container, verify it can be loaded and that the current user can write to it
1435  if ($container_guid) {
1436  $container = $this->getContainerEntity();
1437  if (!$container) {
1438  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1439  . " container $container_guid could not be loaded.");
1440  return false;
1441  }
1442 
1443  if (!$container->canWriteToContainer($user_guid, $type, $subtype)) {
1444  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but was not"
1445  . " permitted to write to container $container_guid.");
1446  return false;
1447  }
1448  }
1449 
1450  // Create primary table row
1451  $guid = _elgg_services()->entityTable->insertRow((object) [
1452  'type' => $type,
1453  'subtype' => $subtype,
1454  'owner_guid' => $owner_guid,
1455  'container_guid' => $container_guid,
1456  'access_id' => $access_id,
1457  'time_created' => $time_created,
1458  'time_updated' => $now,
1459  'last_action' => $now,
1460  ], $this->attributes);
1461 
1462  if (!$guid) {
1463  throw new IOException("Unable to save new object's base entity information!");
1464  }
1465 
1466  $this->attributes['subtype'] = $subtype;
1467  $this->attributes['guid'] = (int) $guid;
1468  $this->attributes['time_created'] = (int) $time_created;
1469  $this->attributes['time_updated'] = (int) $now;
1470  $this->attributes['last_action'] = (int) $now;
1471  $this->attributes['container_guid'] = (int) $container_guid;
1472 
1473  // We are writing this new entity to cache to make sure subsequent calls
1474  // to get_entity() load the entity from cache and not from the DB. This
1475  // MUST come before the metadata and annotation writes below!
1476  $this->cache();
1477 
1478  // Save any unsaved metadata
1479  if (sizeof($this->temp_metadata) > 0) {
1480  foreach ($this->temp_metadata as $name => $value) {
1481  // temp metadata is always an array, but if there is only one value return just the value
1482  $this->setMetadata($name, $value, '', count($value) > 1);
1483  }
1484 
1485  $this->temp_metadata = [];
1486  }
1487 
1488  // Save any unsaved annotations.
1489  if (sizeof($this->temp_annotations) > 0) {
1490  foreach ($this->temp_annotations as $name => $value) {
1491  $this->annotate($name, $value);
1492  }
1493 
1494  $this->temp_annotations = [];
1495  }
1496 
1497  // Save any unsaved private settings.
1498  if (sizeof($this->temp_private_settings) > 0) {
1499  foreach ($this->temp_private_settings as $name => $value) {
1500  $this->setPrivateSetting($name, $value);
1501  }
1502 
1503  $this->temp_private_settings = [];
1504  }
1505 
1506  if (isset($container) && !$container instanceof ElggUser) {
1507  // users have their own logic for setting last action
1508  $container->updateLastAction();
1509  }
1510 
1511  return $guid;
1512  }
1513 
1521  protected function update() {
1522 
1523  if (!$this->canEdit()) {
1524  return false;
1525  }
1526 
1527  // give old update event a chance to stop the update
1528  if (!_elgg_services()->events->trigger('update', $this->type, $this)) {
1529  return false;
1530  }
1531 
1532  $this->invalidateCache();
1533 
1534  // See #6225. We copy these after the update event in case a handler changed one of them.
1535  $guid = (int) $this->guid;
1536  $owner_guid = (int) $this->owner_guid;
1537  $access_id = (int) $this->access_id;
1538  $container_guid = (int) $this->container_guid;
1539  $time_created = (int) $this->time_created;
1540  $time = $this->getCurrentTime()->getTimestamp();
1541 
1542  if ($access_id == ACCESS_DEFAULT) {
1543  throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in constants.php');
1544  }
1545 
1546  if ($access_id == ACCESS_FRIENDS) {
1547  throw new InvalidParameterException('ACCESS_FRIENDS is not a valid access level. See its documentation in constants.php');
1548  }
1549 
1550  // Update primary table
1551  $ret = _elgg_services()->entityTable->updateRow($guid, (object) [
1552  'owner_guid' => $owner_guid,
1553  'container_guid' => $container_guid,
1554  'access_id' => $access_id,
1555  'time_created' => $time_created,
1556  'time_updated' => $time,
1557  'guid' => $guid,
1558  ]);
1559  if ($ret === false) {
1560  return false;
1561  }
1562 
1563  $this->attributes['time_updated'] = $time;
1564 
1565  _elgg_services()->events->triggerAfter('update', $this->type, $this);
1566 
1567  $this->orig_attributes = [];
1568 
1569  $this->cache();
1570 
1571  // Handle cases where there was no error BUT no rows were updated!
1572  return true;
1573  }
1574 
1582  protected function load(stdClass $row) {
1583  $attributes = array_merge($this->attributes, (array) $row);
1584 
1585  if (array_diff(self::PRIMARY_ATTR_NAMES, array_keys($attributes)) !== []) {
1586  // Some primary attributes are missing
1587  return false;
1588  }
1589 
1590  foreach ($attributes as $name => $value) {
1591  if (!in_array($name, self::PRIMARY_ATTR_NAMES)) {
1592  $this->setVolatileData("select:$name", $value);
1593  unset($attributes[$name]);
1594  continue;
1595  }
1596 
1597  if (in_array($name, static::INTEGER_ATTR_NAMES)) {
1598  $attributes[$name] = (int) $value;
1599  }
1600  }
1601 
1602  $this->attributes = $attributes;
1603 
1604  $this->cache();
1605 
1606  return true;
1607  }
1608 
1626  public function disable($reason = "", $recursive = true) {
1627  if (!$this->guid) {
1628  return false;
1629  }
1630 
1631  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1632  return false;
1633  }
1634 
1635  if (!$this->canEdit()) {
1636  return false;
1637  }
1638 
1639  if ($this instanceof ElggUser && !$this->isBanned()) {
1640  // temporarily ban to prevent using the site during disable
1641  $this->ban();
1642  $unban_after = true;
1643  } else {
1644  $unban_after = false;
1645  }
1646 
1647  if ($reason) {
1648  $this->disable_reason = $reason;
1649  }
1650 
1651  $guid = (int) $this->guid;
1652 
1653  if ($recursive) {
1654  elgg_call(ELGG_IGNORE_ACCESS | ELGG_HIDE_DISABLED_ENTITIES, function () use ($guid, $reason) {
1655  $base_options = [
1656  'wheres' => [
1657  function(QueryBuilder $qb, $main_alias) use ($guid) {
1658  return $qb->compare("{$main_alias}.guid", '!=', $guid, ELGG_VALUE_GUID);
1659  },
1660  ],
1661  'limit' => false,
1662  'batch' => true,
1663  'batch_inc_offset' => false,
1664  ];
1665 
1666  foreach (['owner_guid', 'container_guid'] as $db_column) {
1667  $options = $base_options;
1668  $options[$db_column] = $guid;
1669 
1670  $subentities = elgg_get_entities($options);
1671 
1672  foreach ($subentities as $subentity) {
1673  /* @var $subentity \ElggEntity */
1674  if (!$subentity->isEnabled()) {
1675  continue;
1676  }
1677  add_entity_relationship($subentity->guid, 'disabled_with', $guid);
1678  $subentity->disable($reason, true);
1679  }
1680  }
1681  });
1682  }
1683 
1684  $this->disableAnnotations();
1685 
1686  $disabled = _elgg_services()->entityTable->disable($this);
1687 
1688  if ($unban_after) {
1689  $this->unban();
1690  }
1691 
1692  if ($disabled) {
1693  $this->invalidateCache();
1694 
1695  $this->attributes['enabled'] = 'no';
1696  _elgg_services()->events->triggerAfter('disable', $this->type, $this);
1697  }
1698 
1699  return $disabled;
1700  }
1701 
1709  public function enable($recursive = true) {
1710  if (empty($this->guid)) {
1711  return false;
1712  }
1713 
1714  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1715  return false;
1716  }
1717 
1718  if (!$this->canEdit()) {
1719  return false;
1720  }
1721 
1722  $result = elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function() use ($recursive) {
1723  $result = _elgg_services()->entityTable->enable($this);
1724 
1725  $this->deleteMetadata('disable_reason');
1726  $this->enableAnnotations();
1727 
1728  if ($recursive) {
1729  $disabled_with_it = elgg_get_entities([
1730  'relationship' => 'disabled_with',
1731  'relationship_guid' => $this->guid,
1732  'inverse_relationship' => true,
1733  'limit' => false,
1734  'batch' => true,
1735  'batch_inc_offset' => false,
1736  ]);
1737 
1738  foreach ($disabled_with_it as $e) {
1739  $e->enable($recursive);
1740  remove_entity_relationship($e->guid, 'disabled_with', $this->guid);
1741  }
1742  }
1743 
1744  return $result;
1745  });
1746 
1747  if ($result) {
1748  $this->attributes['enabled'] = 'yes';
1749  _elgg_services()->events->triggerAfter('enable', $this->type, $this);
1750  }
1751 
1752  return $result;
1753  }
1754 
1760  public function isEnabled() {
1761  return $this->enabled == 'yes';
1762  }
1763 
1781  public function delete($recursive = true) {
1782  // first check if we can delete this entity
1783  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1784  // which could potentially remove some content if the user didn't have access
1785  if (!$this->canDelete()) {
1786  return false;
1787  }
1788 
1789  try {
1790  return _elgg_services()->entityTable->delete($this, $recursive);
1791  } catch (DatabaseException $ex) {
1792  elgg_log($ex, 'ERROR');
1793  return false;
1794  }
1795  }
1796 
1803  public function toObject(array $params = []) {
1804  $object = $this->prepareObject(new \Elgg\Export\Entity());
1805 
1806  $params['entity'] = $this;
1807 
1808  return _elgg_services()->hooks->trigger('to:object', 'entity', $params, $object);
1809  }
1810 
1817  protected function prepareObject(\Elgg\Export\Entity $object) {
1818  $object->guid = $this->guid;
1819  $object->type = $this->getType();
1820  $object->subtype = $this->getSubtype();
1821  $object->owner_guid = $this->getOwnerGUID();
1822  $object->container_guid = $this->getContainerGUID();
1823  $object->time_created = date('c', $this->getTimeCreated());
1824  $object->time_updated = date('c', $this->getTimeUpdated());
1825  $object->url = $this->getURL();
1826  $object->read_access = (int) $this->access_id;
1827  return $object;
1828  }
1829 
1838  public function setLatLong(float $lat, float $long) {
1839  $this->{"geo:lat"} = $lat;
1840  $this->{"geo:long"} = $long;
1841  }
1842 
1848  public function getLatitude() {
1849  return (float) $this->{"geo:lat"};
1850  }
1851 
1857  public function getLongitude() {
1858  return (float) $this->{"geo:long"};
1859  }
1860 
1861  /*
1862  * SYSTEM LOG INTERFACE
1863  */
1864 
1871  public function getSystemLogID() {
1872  return $this->getGUID();
1873  }
1874 
1882  public function getObjectFromID($id) {
1883  return get_entity($id);
1884  }
1885 
1893  public function getTags($tag_names = null) {
1894  if (!isset($tag_names)) {
1895  $tag_names = ['tags'];
1896  }
1897 
1898  if ($tag_names && !is_array($tag_names)) {
1899  $tag_names = [$tag_names];
1900  }
1901 
1902  $entity_tags = [];
1903  foreach ($tag_names as $tag_name) {
1904  $tags = $this->$tag_name;
1905  if (elgg_is_empty($tags)) {
1906  continue;
1907  }
1908 
1909  // if a single tag, metadata returns a string.
1910  // if multiple tags, metadata returns an array.
1911  if (is_array($tags)) {
1912  $entity_tags = array_merge($entity_tags, $tags);
1913  } else {
1914  $entity_tags[] = $tags;
1915  }
1916  }
1917 
1918  return $entity_tags;
1919  }
1920 
1928 
1929  if (!$this->guid) {
1930  return false;
1931  }
1932 
1933  if ($this->type !== 'user') {
1934  return true;
1935  }
1936 
1937  $ac = _elgg_services()->accessCollections;
1938 
1939  $collections = $ac->getCollectionsByMember($this->guid);
1940  if (empty($collections)) {
1941  return true;
1942  }
1943 
1944  $result = true;
1945  foreach ($collections as $collection) {
1946  $result &= $ac->removeUser($this->guid, $collection->id);
1947  }
1948 
1949  return $result;
1950  }
1951 
1958  public function deleteOwnedAccessCollections() {
1959 
1960  if (!$this->guid) {
1961  return false;
1962  }
1963 
1964  $collections = $this->getOwnedAccessCollections();
1965  if (empty($collections)) {
1966  return true;
1967  }
1968 
1969  $result = true;
1970  foreach ($collections as $collection) {
1971  $result = $result & $collection->delete();
1972  }
1973 
1974  return $result;
1975  }
1976 
1987  public function updateLastAction($posted = null) {
1988  $posted = _elgg_services()->entityTable->updateLastAction($this, $posted);
1989  if ($posted) {
1990  $this->attributes['last_action'] = $posted;
1991  $this->cache();
1992  }
1993  return $posted;
1994  }
1995 
2002  public function disableCaching() {
2003  $this->_is_cacheable = false;
2004  if ($this->guid) {
2005  _elgg_services()->entityCache->delete($this->guid);
2006  }
2007  }
2008 
2015  public function enableCaching() {
2016  $this->_is_cacheable = true;
2017  }
2018 
2025  public function isCacheable() {
2026  if (!$this->guid) {
2027  return false;
2028  }
2029 
2030  if (_elgg_services()->session->getIgnoreAccess()) {
2031  return false;
2032  }
2033  return $this->_is_cacheable;
2034  }
2035 
2044  public function cache($persist = true) {
2045  if (!$this->isCacheable()) {
2046  return;
2047  }
2048 
2049  _elgg_services()->entityCache->save($this);
2050 
2051  if (!$persist) {
2052  return;
2053  }
2054 
2055  $tmp = $this->volatile;
2056 
2057  // don't store volatile data
2058  $this->volatile = [];
2059 
2060  _elgg_services()->sessionCache->entities->save($this->guid, $this);
2061 
2062  $this->volatile = $tmp;
2063  }
2064 
2071  public function invalidateCache() {
2072  if (!$this->guid) {
2073  return;
2074  }
2075 
2076  _elgg_services()->entityCache->delete($this->guid);
2077 
2078  $namespaces = [
2079  'metadata',
2080  'private_settings',
2081  ];
2082 
2083  foreach ($namespaces as $namespace) {
2084  _elgg_services()->dataCache->get($namespace)->delete($this->guid);
2085  }
2086  }
2087 
2096  public function hasCapability(string $capability): bool {
2097  return _elgg_services()->entity_capabilities->hasCapability($this->getType(), $this->getSubtype(), $capability);
2098  }
2099 }
$default
Definition: checkbox.php:31
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:731
saveIconFromUploadedFile($input_name, $type= 'icon', array $coords=[])
Saves icons using an uploaded file as the source.
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
enable($recursive=true)
Enable the entity.
removeAllPrivateSettings()
Removes all private settings.
Definition: ElggEntity.php:688
getSubtype()
Get the entity subtype.
$display_name
Definition: delete.php:19
$user_guid
Definition: login_as.php:10
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getOwnerGUID()
Get the guid of the entity&#39;s owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:100
Entities that support icons should implement this interface.
Definition: EntityIcon.php:7
__clone()
Clone an entity.
Definition: ElggEntity.php:183
deleteIcon($type= 'icon')
Removes all icon files and metadata for the passed type of icon.
$input_name
Definition: crop.php:24
$params
Saves global plugin settings.
Definition: save.php:13
getAllPrivateSettings()
Returns all private settings.
Definition: ElggEntity.php:659
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:305
getOwnerEntity()
Gets the that owns this entity.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
$owner
Definition: upload.php:7
const ACCESS_DEFAULT
Definition: constants.php:11
elgg_normalize_url($url)
Definition: output.php:152
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
Definition: deprecation.php:52
setTempMetadata($name, $value, $multiple=false)
Set temp metadata on this entity.
Definition: ElggEntity.php:463
removePrivateSetting($name)
Removes private setting.
Definition: ElggEntity.php:674
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:767
An IO Exception, throw when an IO Exception occurs.
Definition: IOException.php:12
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
const PRIMARY_ATTR_NAMES
Definition: ElggEntity.php:50
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:495
$site name
Definition: settings.php:21
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
Definition: annotations.php:87
countAnnotations($name="")
Count annotations.
Definition: ElggEntity.php:897
const INTEGER_ATTR_NAMES
Definition: ElggEntity.php:66
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:718
invalidateCache()
Invalidate cache for entity.
$access_id
Definition: access.php:11
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:608
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:157
const ACCESS_FRIENDS
Definition: constants.php:15
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:646
elgg_get_annotations(array $options=[])
Fetch annotations or perform a calculation on them.
Definition: annotations.php:52
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
Definition: ElggEntity.php:941
countComments()
Count the number of comments attached to this entity.
Definition: ElggEntity.php:951
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:133
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:748
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
$relationship
Elgg default relationship view.
Definition: default.php:10
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
const ELGG_VALUE_GUID
Definition: constants.php:128
$subtype
Definition: delete.php:22
prepareObject(\Elgg\Export\Entity $object)
Prepare an object copy for toObject()
Database abstraction query builder.
getGUID()
Returns the guid.
$time_updated
Definition: time.php:21
getContainerGUID()
Gets the container GUID for this entity.
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
$type
Definition: delete.php:21
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:786
enableCaching()
Enable runtime caching for entity.
cache($persist=true)
Cache the entity in a session and persisted caches.
canEdit($user_guid=0)
Can a user edit this entity?
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
getIcon($size, $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type= '')
Removes all relationships originating from a particular entity.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
Definition: ElggEntity.php:919
$options
Elgg admin footer.
Definition: footer.php:6
getEntitiesFromRelationship(array $options=[])
Gets an array of entities with a relationship to this entity.
$value
Definition: generic.php:51
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:542
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:201
const ELGG_HIDE_DISABLED_ENTITIES
Definition: constants.php:149
setContainerGUID($container_guid)
Set the container for this object.
removeRelationship($guid_two, $relationship)
Remove a relationship.
Definition: ElggEntity.php:591
elgg_disable_annotations(array $options)
Disables annotations based on $options.
getCurrentTime($modifier= '')
Get the (cloned) time.
Definition: TimeUsing.php:25
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
getMetadata($name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:339
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:146
$owner_guid
$namespaces
Definition: default.php:34
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
Definition: ElggEntity.php:559
saveIconFromElggFile(\ElggFile $file, $type= 'icon', array $coords=[])
Saves icons using a file located in the data store as the source.
getTags($tag_names=null)
Returns tags for this entity.
disableCaching()
Disable runtime caching for entity.
setSubtype(string $subtype)
Set the subtype of the entity.
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:530
const ACCESS_PRIVATE
Definition: constants.php:12
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:148
removeAllRelatedRiverItems()
Removes all river items related to this entity.
Definition: ElggEntity.php:702
$container
Definition: delete.php:23
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
getAnnotationsAvg($name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:908
load(stdClass $row)
Loads attributes from the entities table into the object.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:399
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:556
A generic parent class for database exceptions.
if($id< 1) $annotation
Definition: delete.php:11
$time_created
Definition: online.php:18
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:235
canAnnotate($user_guid=0, $annotation_name= '')
Can a user annotate an entity?
toObject(array $params=[])
Export an entity.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
getAnnotations(array $options=[])
Gets an array of annotations.
Definition: ElggEntity.php:874
getOwnedAccessCollections($options=[])
Returns the ACLs owned by the entity.
Definition: ElggEntity.php:976
setLatLong(float $lat, float $long)
Set latitude and longitude metadata tags for a given entity.
hasCapability(string $capability)
Checks a specific capability is enabled for the entity type/subtype.
A generic class that contains shared code among , , and .
Definition: ElggData.php:10
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:686
getIconURL($params=[])
Get the URL for this entity&#39;s icon.
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:577
$size
Definition: thumb.php:23
setMetadata($name, $value, $value_type= '', $multiple=false)
Set metadata on this entity.
Definition: ElggEntity.php:376
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
elgg_get_metadata(array $options=[])
Fetch metadata or perform a calculation on them.
Definition: metadata.php:46
$posted
Definition: comment.php:86
$comment access_id
Definition: save.php:55
$temp_private_settings
Definition: ElggEntity.php:95
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:61
canDelete($user_guid=0)
Can a user delete this entity?
setDisplayName($display_name)
Sets the title or name of this entity.
Definition: ElggEntity.php:328
hasIcon($size, $type= 'icon')
Returns if the entity has an icon of the passed type.
getOwnedAccessCollection($subtype)
Returns the first ACL owned by the entity with a given subtype.
Definition: ElggEntity.php:990
$metadata
Output annotation metadata.
Definition: metadata.php:9
getType()
Returns the entity type.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type="")
Adds an annotation to an entity.
Definition: ElggEntity.php:835
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
Definition: deactivate.php:39
$filename
create()
Create a new entry in the entities table.
getAllMetadata()
Get all entity metadata.
Definition: ElggEntity.php:349
getIconLastChange($size, $type= 'icon')
Returns the timestamp of when the icon was changed.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:777
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
Definition: ElggEntity.php:289
updateLastAction($posted=null)
Update the last_action column in the entities table.
isCacheable()
Is entity cacheable in the runtime cache.
getLatitude()
Return the entity&#39;s latitude.
__construct(stdClass $row=null)
Create a new entity.
Definition: ElggEntity.php:141
$container_guid
getContainerEntity()
Get the container entity for this object.
$tags
Output object tags.
Definition: tags.php:9
canComment($user_guid=0, $default=null)
Can a user comment on an entity?
$id
Generic annotation delete action.
Definition: delete.php:6
getSystemLogID()
Return an identification for the object for storage in the system log.
disable($reason="", $recursive=true)
Disable this entity.
$qb
Definition: queue.php:11
elgg_generate_entity_url(ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
Generate entity URL from a named route.
getURL()
Gets the URL for this entity.
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:318
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
Definition: ElggEntity.php:930
getLongitude()
Return the entity&#39;s longitude.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69
getObjectFromID($id)
For a given ID, return the object associated with it.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=[])
Saves icons using a local file as the source.
if($entity instanceof\ElggComment) $comment container_guid
Definition: save.php:54
canWriteToContainer($user_guid=0, $type= '', $subtype= '')
Can a user add an entity to this container.