Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
ElggEntity.php
Go to the documentation of this file.
1 <?php
2 
42 abstract class ElggEntity extends \ElggData implements
43  Locatable, // Geocoding interface
44  Importable, // Allow import of data (deprecated 1.9)
45  \Elgg\EntityIcon // Icon interface
46 {
47 
51  protected $url_override;
52 
57  protected $temp_metadata = array();
58 
63  protected $temp_annotations = array();
64 
69  protected $temp_private_settings = array();
70 
75  protected $volatile = array();
76 
80  protected $orig_attributes = array();
81 
89  protected function initializeAttributes() {
90  parent::initializeAttributes();
91 
92  $this->attributes['guid'] = null;
93  $this->attributes['type'] = null;
94  $this->attributes['subtype'] = null;
95 
96  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid();
97  $this->attributes['container_guid'] = _elgg_services()->session->getLoggedInUserGuid();
98 
99  $this->attributes['site_guid'] = null;
100  $this->attributes['access_id'] = ACCESS_PRIVATE;
101  $this->attributes['time_updated'] = null;
102  $this->attributes['last_action'] = null;
103  $this->attributes['enabled'] = "yes";
104  }
105 
119  public function __clone() {
120  $orig_entity = get_entity($this->guid);
121  if (!$orig_entity) {
122  _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid");
123  return;
124  }
125 
126  $metadata_array = elgg_get_metadata(array(
127  'guid' => $this->guid,
128  'limit' => 0
129  ));
130 
131  $this->attributes['guid'] = "";
132 
133  $this->attributes['subtype'] = $orig_entity->getSubtype();
134 
135  // copy metadata over to new entity - slightly convoluted due to
136  // handling of metadata arrays
137  if (is_array($metadata_array)) {
138  // create list of metadata names
139  $metadata_names = array();
140  foreach ($metadata_array as $metadata) {
141  $metadata_names[] = $metadata['name'];
142  }
143  // arrays are stored with multiple enties per name
144  $metadata_names = array_unique($metadata_names);
145 
146  // move the metadata over
147  foreach ($metadata_names as $name) {
148  $this->__set($name, $orig_entity->$name);
149  }
150  }
151  }
152 
166  public function __set($name, $value) {
167  if ($this->$name === $value) {
168  // quick return if value is not changing
169  return;
170  }
171 
172  if (array_key_exists($name, $this->attributes)) {
173  // if an attribute is 1 (integer) and it's set to "1" (string), don't consider that a change.
174  if (is_int($this->attributes[$name])
175  && is_string($value)
176  && ((string)$this->attributes[$name] === $value)) {
177  return;
178  }
179 
180  // Due to https://github.com/Elgg/Elgg/pull/5456#issuecomment-17785173, certain attributes
181  // will store empty strings as null in the DB. In the somewhat common case that we're re-setting
182  // the value to empty string, don't consider this a change.
183  if (in_array($name, ['title', 'name', 'description'])
184  && $this->attributes[$name] === null
185  && $value === "") {
186  return;
187  }
188 
189  // keep original values
190  if ($this->guid && !array_key_exists($name, $this->orig_attributes)) {
191  $this->orig_attributes[$name] = $this->attributes[$name];
192  }
193 
194  // Certain properties should not be manually changed!
195  switch ($name) {
196  case 'guid':
197  case 'time_updated':
198  case 'last_action':
199  return;
200  break;
201  case 'access_id':
202  case 'owner_guid':
203  case 'container_guid':
204  if ($value !== null) {
205  $this->attributes[$name] = (int)$value;
206  } else {
207  $this->attributes[$name] = null;
208  }
209  break;
210  default:
211  $this->attributes[$name] = $value;
212  break;
213  }
214  return;
215  }
216 
217  if ($name === 'tables_split' || $name === 'tables_loaded') {
218  elgg_deprecated_notice("Do not read/write ->tables_split or ->tables_loaded.", "2.1");
219  return;
220  }
221 
222  $this->setMetadata($name, $value);
223  }
224 
234  public function set($name, $value) {
235  elgg_deprecated_notice("Use -> instead of set()", 1.9);
236  $this->__set($name, $value);
237 
238  return true;
239  }
240 
246  public function getOriginalAttributes() {
247  return $this->orig_attributes;
248  }
249 
262  public function __get($name) {
263  if (array_key_exists($name, $this->attributes)) {
264  if ($name === 'subtype' && $this->attributes['guid']) {
265  // note: only show deprecation notice if user reads ->subtype after save/load
266  elgg_deprecated_notice("Use getSubtype()", 1.9);
267  }
268  return $this->attributes[$name];
269  }
270 
271  if ($name === 'tables_split' || $name === 'tables_loaded') {
272  elgg_deprecated_notice("Do not read/write ->tables_split or ->tables_loaded.", "2.1");
273  return 2;
274  }
275 
276  return $this->getMetadata($name);
277  }
278 
286  public function get($name) {
287  elgg_deprecated_notice("Use -> instead of get()", 1.9);
288  return $this->__get($name);
289  }
290 
296  abstract public function getDisplayName();
297 
304  abstract public function setDisplayName($displayName);
305 
313  public function getMetadata($name) {
314  $guid = $this->getGUID();
315 
316  if (!$guid) {
317  if (isset($this->temp_metadata[$name])) {
318  // md is returned as an array only if more than 1 entry
319  if (count($this->temp_metadata[$name]) == 1) {
320  return $this->temp_metadata[$name][0];
321  } else {
322  return $this->temp_metadata[$name];
323  }
324  } else {
325  return null;
326  }
327  }
328 
329  // upon first cache miss, just load/cache all the metadata and retry.
330  // if this works, the rest of this function may not be needed!
331  $cache = _elgg_services()->metadataCache;
332  if ($cache->isLoaded($guid)) {
333  return $cache->getSingle($guid, $name);
334  } else {
335  $cache->populateFromEntities(array($guid));
336  // in case ignore_access was on, we have to check again...
337  if ($cache->isLoaded($guid)) {
338  return $cache->getSingle($guid, $name);
339  }
340  }
341 
342  $md = elgg_get_metadata(array(
343  'guid' => $guid,
344  'metadata_name' => $name,
345  'limit' => 0,
346  'distinct' => false,
347  ));
348 
349  $value = null;
350 
351  if ($md && !is_array($md)) {
352  $value = $md->value;
353  } elseif (count($md) == 1) {
354  $value = $md[0]->value;
355  } else if ($md && is_array($md)) {
357  }
358 
359  return $value;
360  }
361 
372  public function __unset($name) {
373  if (array_key_exists($name, $this->attributes)) {
374  $this->attributes[$name] = "";
375  } else {
376  $this->deleteMetadata($name);
377  }
378  }
379 
400  public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) {
401 
402  // normalize value to an array that we will loop over
403  // remove indexes if value already an array.
404  if (is_array($value)) {
405  $value = array_values($value);
406  } else {
407  $value = array($value);
408  }
409 
410  // saved entity. persist md to db.
411  if ($this->guid) {
412  // if overwriting, delete first.
413  if (!$multiple) {
414  $options = array(
415  'guid' => $this->getGUID(),
416  'metadata_name' => $name,
417  'limit' => 0
418  );
419  // @todo in 1.9 make this return false if can't add metadata
420  // https://github.com/elgg/elgg/issues/4520
421  //
422  // need to remove access restrictions right now to delete
423  // because this is the expected behavior
424  $ia = elgg_set_ignore_access(true);
425  if (false === elgg_delete_metadata($options)) {
426  return false;
427  }
429  }
430 
431  $owner_guid = (int)$owner_guid;
432  $access_id = ($access_id === null) ? $this->getAccessId() : (int)$access_id;
434 
435  // add new md
436  $result = true;
437  foreach ($value as $value_tmp) {
438  // at this point $value is appended because it was cleared above if needed.
439  $md_id = create_metadata($this->getGUID(), $name, $value_tmp, $value_type,
440  $owner_guid, $access_id, true);
441  if (!$md_id) {
442  return false;
443  }
444  }
445 
446  return $result;
447  } else {
448  // unsaved entity. store in temp array
449 
450  // returning single entries instead of an array of 1 element is decided in
451  // getMetaData(), just like pulling from the db.
452 
453  if ($owner_guid != 0 || $access_id !== null) {
454  $msg = "owner guid and access id cannot be used in \ElggEntity::setMetadata() until entity is saved.";
455  throw new \InvalidArgumentException($msg);
456  }
457 
458  // if overwrite, delete first
459  if (!$multiple || !isset($this->temp_metadata[$name])) {
460  $this->temp_metadata[$name] = array();
461  }
462 
463  // add new md
464  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
465  return true;
466  }
467  }
468 
479  public function deleteMetadata($name = null) {
480 
481  if (!$this->guid) {
482  return false;
483  }
484 
485  $options = array(
486  'guid' => $this->guid,
487  'limit' => 0
488  );
489  if ($name) {
490  $options['metadata_name'] = $name;
491  }
492 
494  }
495 
504  public function deleteOwnedMetadata($name = null) {
505  // access is turned off for this because they might
506  // no longer have access to an entity they created metadata on.
507  $ia = elgg_set_ignore_access(true);
508  $options = array(
509  'metadata_owner_guid' => $this->guid,
510  'limit' => 0
511  );
512  if ($name) {
513  $options['metadata_name'] = $name;
514  }
515 
518  return $r;
519  }
520 
528  public function disableMetadata($name = '') {
529  $options = array(
530  'guid' => $this->guid,
531  'limit' => 0
532  );
533  if ($name) {
534  $options['metadata_name'] = $name;
535  }
536 
538  }
539 
549  public function enableMetadata($name = '') {
550  $options = array(
551  'guid' => $this->guid,
552  'limit' => 0
553  );
554  if ($name) {
555  $options['metadata_name'] = $name;
556  }
557 
559  }
560 
568  public function getVolatileData($name) {
569  if (!is_array($this->volatile)) {
570  $this->volatile = array();
571  }
572 
573  if (array_key_exists($name, $this->volatile)) {
574  return $this->volatile[$name];
575  } else {
576  return null;
577  }
578  }
579 
588  public function setVolatileData($name, $value) {
589  if (!is_array($this->volatile)) {
590  $this->volatile = array();
591  }
592 
593  $this->volatile[$name] = $value;
594  }
595 
609  public function deleteRelationships($relationship = null) {
610  $relationship = (string)$relationship;
611  $result = remove_entity_relationships($this->getGUID(), $relationship);
612  return $result && remove_entity_relationships($this->getGUID(), $relationship, true);
613  }
614 
627  public function addRelationship($guid_two, $relationship) {
628  return add_entity_relationship($this->getGUID(), $relationship, $guid_two);
629  }
630 
641  public function removeRelationship($guid_two, $relationship) {
642  return remove_entity_relationship($this->getGUID(), $relationship, $guid_two);
643  }
644 
656  public function setPrivateSetting($name, $value) {
657  if ((int) $this->guid > 0) {
658  return set_private_setting($this->getGUID(), $name, $value);
659  } else {
660  $this->temp_private_settings[$name] = $value;
661  return true;
662  }
663  }
664 
672  public function getPrivateSetting($name) {
673  if ((int) ($this->guid) > 0) {
674  return get_private_setting($this->getGUID(), $name);
675  } else {
676  if (isset($this->temp_private_settings[$name])) {
677  return $this->temp_private_settings[$name];
678  }
679  }
680  return null;
681  }
682 
690  public function removePrivateSetting($name) {
691  return remove_private_setting($this->getGUID(), $name);
692  }
693 
704  public function deleteAnnotations($name = null) {
705  $options = array(
706  'guid' => $this->guid,
707  'limit' => 0
708  );
709  if ($name) {
710  $options['annotation_name'] = $name;
711  }
712 
714  }
715 
724  public function deleteOwnedAnnotations($name = null) {
725  // access is turned off for this because they might
726  // no longer have access to an entity they created annotations on.
727  $ia = elgg_set_ignore_access(true);
728  $options = array(
729  'annotation_owner_guid' => $this->guid,
730  'limit' => 0
731  );
732  if ($name) {
733  $options['annotation_name'] = $name;
734  }
735 
738  return $r;
739  }
740 
748  public function disableAnnotations($name = '') {
749  $options = array(
750  'guid' => $this->guid,
751  'limit' => 0
752  );
753  if ($name) {
754  $options['annotation_name'] = $name;
755  }
756 
758  }
759 
769  public function enableAnnotations($name = '') {
770  $options = array(
771  'guid' => $this->guid,
772  'limit' => 0
773  );
774  if ($name) {
775  $options['annotation_name'] = $name;
776  }
777 
779  }
780 
788  private function getAnnotationCalculation($name, $calculation) {
789  $options = array(
790  'guid' => $this->getGUID(),
791  'distinct' => false,
792  'annotation_name' => $name,
793  'annotation_calculation' => $calculation
794  );
795 
797  }
798 
815  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $vartype = "") {
816  if ((int) $this->guid > 0) {
817  return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_guid, $access_id);
818  } else {
819  $this->temp_annotations[$name] = $value;
820  }
821  return true;
822  }
823 
839  public function getAnnotations($options = array(), $limit = 50, $offset = 0, $order = "asc") {
840  if (!is_array($options)) {
841  elgg_deprecated_notice("\ElggEntity::getAnnotations() takes an array of options.", 1.9);
842  }
843 
844  if ((int) ($this->guid) > 0) {
845  if (!is_array($options)) {
846  $options = array(
847  'guid' => $this->guid,
848  'annotation_name' => $options,
849  'limit' => $limit,
850  'offset' => $offset,
851  );
852 
853  if ($order != 'asc') {
854  $options['reverse_order_by'] = true;
855  }
856  } else {
857  $options['guid'] = $this->guid;
858  }
859 
861  } else {
862  if (!is_array($options)) {
863  $name = $options;
864  } else {
865  $name = elgg_extract('annotation_name', $options, '');
866  }
867 
868  if (isset($this->temp_annotations[$name])) {
869  return array($this->temp_annotations[$name]);
870  }
871  }
872 
873  return array();
874  }
875 
883  public function countAnnotations($name = "") {
884  return $this->getAnnotationCalculation($name, 'count');
885  }
886 
894  public function getAnnotationsAvg($name) {
895  return $this->getAnnotationCalculation($name, 'avg');
896  }
897 
905  public function getAnnotationsSum($name) {
906  return $this->getAnnotationCalculation($name, 'sum');
907  }
908 
916  public function getAnnotationsMin($name) {
917  return $this->getAnnotationCalculation($name, 'min');
918  }
919 
927  public function getAnnotationsMax($name) {
928  return $this->getAnnotationCalculation($name, 'max');
929  }
930 
937  public function countComments() {
938  $params = array('entity' => $this);
939  $num = _elgg_services()->hooks->trigger('comments:count', $this->getType(), $params);
940 
941  if (is_int($num)) {
942  return $num;
943  } else {
944  return elgg_get_entities(array(
945  'type' => 'object',
946  'subtype' => 'comment',
947  'container_guid' => $this->getGUID(),
948  'count' => true,
949  'distinct' => false,
950  ));
951  }
952  }
953 
967  public function getEntitiesFromRelationship($options = array(), $inverse = false, $limit = 50, $offset = 0) {
968  if (is_array($options)) {
969  $options['relationship_guid'] = $this->getGUID();
971  } else {
972  elgg_deprecated_notice("\ElggEntity::getEntitiesFromRelationship takes an options array", 1.9);
974  'relationship' => $options,
975  'relationship_guid' => $this->getGUID(),
976  'inverse_relationship' => $inverse,
977  'limit' => $limit,
978  'offset' => $offset
979  ));
980  }
981  }
982 
991  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
993  'relationship' => $relationship,
994  'relationship_guid' => $this->getGUID(),
995  'inverse_relationship' => $inverse_relationship,
996  'count' => true
997  ));
998  }
999 
1010  public function canEdit($user_guid = 0) {
1011  return _elgg_services()->userCapabilities->canEdit($this, $user_guid);
1012  }
1013 
1025  public function canDelete($user_guid = 0) {
1026  return _elgg_services()->userCapabilities->canDelete($this, $user_guid);
1027  }
1028 
1044  public function canEditMetadata($metadata = null, $user_guid = 0) {
1045  return _elgg_services()->userCapabilities->canEditMetadata($this, $user_guid, $metadata);
1046  }
1047 
1058  public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
1059  return _elgg_services()->userCapabilities->canWriteToContainer($this, $user_guid, $type, $subtype);
1060  }
1061 
1072  public function canComment($user_guid = 0) {
1073  return _elgg_services()->userCapabilities->canComment($this, $user_guid);
1074  }
1075 
1090  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1091  return _elgg_services()->userCapabilities->canAnnotate($this, $user_guid, $annotation_name);
1092  }
1093 
1099  public function getAccessID() {
1100  return $this->access_id;
1101  }
1102 
1108  public function getGUID() {
1109  return $this->guid;
1110  }
1111 
1117  public function getType() {
1118  return $this->type;
1119  }
1120 
1126  public function getSubtype() {
1127  // If this object hasn't been saved, then return the subtype string.
1128  if ($this->attributes['guid']) {
1129  return get_subtype_from_id($this->attributes['subtype']);
1130  }
1131  return $this->attributes['subtype'];
1132  }
1133 
1139  public function getOwnerGUID() {
1140  return (int)$this->owner_guid;
1141  }
1142 
1148  public function getOwnerEntity() {
1149  return get_entity($this->owner_guid);
1150  }
1151 
1160  return $this->container_guid = (int)$container_guid;
1161  }
1162 
1168  public function getContainerGUID() {
1169  return (int)$this->container_guid;
1170  }
1171 
1178  public function getContainerEntity() {
1179  return get_entity($this->getContainerGUID());
1180  }
1181 
1187  public function getTimeUpdated() {
1188  return $this->time_updated;
1189  }
1190 
1199  public function getURL() {
1200 
1201  $url = "";
1202 
1203  // @todo remove when elgg_register_entity_url_handler() has been removed
1204  if ($this->guid) {
1205  global $CONFIG;
1206  if (isset($CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1207  $function = $CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()];
1208  if (is_callable($function)) {
1209  $url = call_user_func($function, $this);
1210  }
1211  } elseif (isset($CONFIG->entity_url_handler[$this->getType()]['all'])) {
1212  $function = $CONFIG->entity_url_handler[$this->getType()]['all'];
1213  if (is_callable($function)) {
1214  $url = call_user_func($function, $this);
1215  }
1216  } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
1217  $function = $CONFIG->entity_url_handler['all']['all'];
1218  if (is_callable($function)) {
1219  $url = call_user_func($function, $this);
1220  }
1221  }
1222 
1223  if ($url) {
1225  }
1226  }
1227 
1228  $type = $this->getType();
1229  $params = array('entity' => $this);
1230  $url = _elgg_services()->hooks->trigger('entity:url', $type, $params, $url);
1231 
1232  // @todo remove when \ElggEntity::setURL() has been removed
1233  if (!empty($this->url_override)) {
1235  }
1236 
1237  return elgg_normalize_url($url);
1238  }
1239 
1250  public function setURL($url) {
1251  elgg_deprecated_notice('\ElggEntity::setURL() has been replaced by the "entity:url" plugin hook', 1.9);
1252  $this->url_override = $url;
1253  return $url;
1254  }
1255 
1264  public function saveIconFromUploadedFile($input_name, $type = 'icon', array $coords = array()) {
1265  return _elgg_services()->iconService->saveIconFromUploadedFile($this, $input_name, $type, $coords);
1266  }
1267 
1276  public function saveIconFromLocalFile($filename, $type = 'icon', array $coords = array()) {
1277  return _elgg_services()->iconService->saveIconFromLocalFile($this, $filename, $type, $coords);
1278  }
1279 
1288  public function saveIconFromElggFile(\ElggFile $file, $type = 'icon', array $coords = array()) {
1289  return _elgg_services()->iconService->saveIconFromElggFile($this, $file, $type, $coords);
1290  }
1291 
1300  public function getIcon($size, $type = 'icon') {
1301  return _elgg_services()->iconService->getIcon($this, $size, $type);
1302  }
1303 
1310  public function deleteIcon($type = 'icon') {
1311  return _elgg_services()->iconService->deleteIcon($this, $type);
1312  }
1313 
1322  public function getIconLastChange($size, $type = 'icon') {
1323  return _elgg_services()->iconService->getIconLastChange($this, $size, $type);
1324  }
1325 
1333  public function hasIcon($size, $type = 'icon') {
1334  return _elgg_services()->iconService->hasIcon($this, $size, $type);
1335  }
1336 
1348  public function getIconURL($params = array()) {
1349  return _elgg_services()->iconService->getIconURL($this, $params);
1350  }
1351 
1363  public function addToSite($site) {
1364  if (!elgg_instanceof($site, 'site')) {
1365  return false;
1366  }
1367 
1368  return $site->addEntity($this);
1369  }
1370 
1381  public function removeFromSite($site) {
1382  if (!elgg_instanceof($site, 'site')) {
1383  return false;
1384  }
1385 
1386  return $site->removeEntity($this);
1387  }
1388 
1401  public function getSites($options = array()) {
1402  $options['relationship'] = 'member_of_site';
1403  $options['relationship_guid'] = $this->guid;
1404  $options['inverse_relationship'] = false;
1405  if (!isset($options['site_guid']) || !isset($options['site_guids'])) {
1406  $options['site_guids'] = ELGG_ENTITIES_ANY_VALUE;
1407  }
1408 
1410  }
1411 
1417  public function isFullyLoaded() {
1418  return (bool)$this->guid;
1419  }
1420 
1428  public function save() {
1429  $guid = $this->getGUID();
1430  if ($guid > 0) {
1431  return $this->update();
1432  } else {
1433  $guid = $this->create();
1434  if ($guid) {
1435  if (_elgg_services()->events->trigger('create', $this->type, $this)) {
1436  return $guid;
1437  } else {
1438  // plugins that return false to event don't need to override the access system
1439  $ia = elgg_set_ignore_access(true);
1440  $this->delete();
1442  }
1443  }
1444  }
1445 
1446  return false;
1447  }
1448 
1462  protected function create() {
1463  global $CONFIG;
1464 
1465  // Using attribute array directly; get function does something special!
1466  $type = $this->getDatabase()->sanitizeString($this->attributes['type']);
1467  if ($type == "") {
1468  throw new \InvalidParameterException("Entity type must be set.");
1469  }
1470 
1471  $subtype = $this->attributes['subtype'];
1472  $subtype_id = add_subtype($type, $subtype);
1473  $owner_guid = (int)$this->attributes['owner_guid'];
1474  $access_id = (int)$this->attributes['access_id'];
1475  $now = (string)time();
1476  $time_created = isset($this->attributes['time_created']) ? (int)$this->attributes['time_created'] : $now;
1477 
1478  $site_guid = $this->attributes['site_guid'];
1479  if ($site_guid == 0) {
1480  $site_guid = $CONFIG->site_guid;
1481  }
1482  $site_guid = (int)$site_guid;
1483 
1484  $container_guid = $this->attributes['container_guid'];
1485  if ($container_guid == 0) {
1487  $this->attributes['container_guid'] = $container_guid;
1488  }
1490 
1491  if ($access_id == ACCESS_DEFAULT) {
1492  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1493  }
1494 
1496 
1497  // If given an owner, verify it can be loaded
1498  if ($owner_guid) {
1499  $owner = $this->getOwnerEntity();
1500  if (!$owner) {
1501  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1502  . " owner $owner_guid could not be loaded.");
1503  return false;
1504  }
1505 
1506  // If different owner than logged in, verify can write to container.
1507 
1508  if ($user_guid != $owner_guid && !$owner->canWriteToContainer(0, $type, $subtype)) {
1509  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype) with owner"
1510  . " $owner_guid, but the user wasn't permitted to write to the owner's container.");
1511  return false;
1512  }
1513  }
1514 
1515  // If given a container, verify it can be loaded and that the current user can write to it
1516  if ($container_guid) {
1517  $container = $this->getContainerEntity();
1518  if (!$container) {
1519  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but the given"
1520  . " container $container_guid could not be loaded.");
1521  return false;
1522  }
1523 
1524  if (!$container->canWriteToContainer(0, $type, $subtype)) {
1525  _elgg_services()->logger->error("User $user_guid tried to create a ($type, $subtype), but was not"
1526  . " permitted to write to container $container_guid.");
1527  return false;
1528  }
1529  }
1530 
1531  $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities
1532  (type, subtype, owner_guid, site_guid, container_guid,
1533  access_id, time_created, time_updated, last_action)
1534  values
1535  ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1536  $access_id, $time_created, $now, $now)");
1537 
1538  if (!$result) {
1539  throw new \IOException("Unable to save new object's base entity information!");
1540  }
1541 
1542  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1543  $this->attributes['subtype'] = (int)$subtype_id;
1544  $this->attributes['guid'] = (int)$result;
1545  $this->attributes['time_created'] = (int)$time_created;
1546  $this->attributes['time_updated'] = (int)$now;
1547  $this->attributes['last_action'] = (int)$now;
1548  $this->attributes['site_guid'] = (int)$site_guid;
1549  $this->attributes['container_guid'] = (int)$container_guid;
1550 
1551  // Save any unsaved metadata
1552  if (sizeof($this->temp_metadata) > 0) {
1553  foreach ($this->temp_metadata as $name => $value) {
1554  $this->$name = $value;
1555  }
1556 
1557  $this->temp_metadata = array();
1558  }
1559 
1560  // Save any unsaved annotations.
1561  if (sizeof($this->temp_annotations) > 0) {
1562  foreach ($this->temp_annotations as $name => $value) {
1563  $this->annotate($name, $value);
1564  }
1565 
1566  $this->temp_annotations = array();
1567  }
1568 
1569  // Save any unsaved private settings.
1570  if (sizeof($this->temp_private_settings) > 0) {
1571  foreach ($this->temp_private_settings as $name => $value) {
1572  $this->setPrivateSetting($name, $value);
1573  }
1574 
1575  $this->temp_private_settings = array();
1576  }
1577 
1578  _elgg_services()->entityCache->set($this);
1579 
1580  return $result;
1581  }
1582 
1590  protected function update() {
1591  global $CONFIG;
1592 
1593  _elgg_services()->boot->invalidateCache($this->guid);
1594 
1595  if (!$this->canEdit()) {
1596  return false;
1597  }
1598 
1599  // give old update event a chance to stop the update
1600  if (!_elgg_services()->events->trigger('update', $this->type, $this)) {
1601  return false;
1602  }
1603 
1604  // See #6225. We copy these after the update event in case a handler changed one of them.
1605  $guid = (int)$this->guid;
1606  $owner_guid = (int)$this->owner_guid;
1607  $access_id = (int)$this->access_id;
1608  $container_guid = (int)$this->container_guid;
1609  $time_created = (int)$this->time_created;
1610  $time = time();
1611 
1612  if ($access_id == ACCESS_DEFAULT) {
1613  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1614  }
1615 
1616  $query = "
1617  UPDATE {$CONFIG->dbprefix}entities
1618  SET owner_guid = '$owner_guid',
1619  access_id = '$access_id',
1620  container_guid = '$container_guid',
1621  time_created = '$time_created',
1622  time_updated = '$time'
1623  WHERE guid = $guid
1624  ";
1625  $ret = $this->getDatabase()->updateData($query);
1626 
1627  elgg_trigger_after_event('update', $this->type, $this);
1628 
1629  // TODO(evan): Move this to \ElggObject?
1630  if ($this instanceof \ElggObject) {
1631  update_river_access_by_object($guid, $access_id);
1632  }
1633 
1634  // If memcache is available then delete this entry from the cache
1635  static $newentity_cache;
1636  if ((!$newentity_cache) && (is_memcache_available())) {
1637  $newentity_cache = new \ElggMemcache('new_entity_cache');
1638  }
1639  if ($newentity_cache) {
1640  $newentity_cache->delete($guid);
1641  }
1642 
1643  if ($ret !== false) {
1644  $this->attributes['time_updated'] = $time;
1645  }
1646 
1647  _elgg_services()->entityCache->set($this);
1648 
1649  $this->orig_attributes = [];
1650 
1651  // Handle cases where there was no error BUT no rows were updated!
1652  return $ret !== false;
1653  }
1654 
1662  protected function load($guid) {
1663  if ($guid instanceof \stdClass) {
1664  $row = $guid;
1665  } else {
1667  }
1668 
1669  if ($row) {
1670  // Create the array if necessary - all subclasses should test before creating
1671  if (!is_array($this->attributes)) {
1672  $this->attributes = array();
1673  }
1674 
1675  // Now put these into the attributes array as core values
1676  $objarray = (array) $row;
1677  foreach ($objarray as $key => $value) {
1678  $this->attributes[$key] = $value;
1679  }
1680 
1681  // guid needs to be an int https://github.com/elgg/elgg/issues/4111
1682  $this->attributes['guid'] = (int)$this->attributes['guid'];
1683 
1684  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1685  $this->attributes['subtype'] = (int)$this->attributes['subtype'];
1686 
1687  // Cache object handle
1688  if ($this->attributes['guid']) {
1689  _elgg_services()->entityCache->set($this);
1690  }
1691 
1692  return true;
1693  }
1694 
1695  return false;
1696  }
1697 
1704  protected function loadAdditionalSelectValues(array $data) {
1705  foreach ($data as $name => $value) {
1706  $this->setVolatileData("select:$name", $value);
1707  }
1708  }
1709 
1722  public function refresh(\stdClass $row) {
1723  if ($row instanceof \stdClass) {
1724  return $this->load($row);
1725  }
1726  return false;
1727  }
1728 
1748  public function disable($reason = "", $recursive = true) {
1749  if (!$this->guid) {
1750  return false;
1751  }
1752 
1753  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1754  return false;
1755  }
1756 
1757  if (!$this->canEdit()) {
1758  return false;
1759  }
1760 
1761  if ($this instanceof ElggUser && $this->banned === 'no') {
1762  // temporarily ban to prevent using the site during disable
1763  _elgg_services()->usersTable->markBanned($this->guid, true);
1764  $unban_after = true;
1765  } else {
1766  $unban_after = false;
1767  }
1768 
1769  _elgg_services()->entityCache->remove($this->guid);
1770 
1771  if ($reason) {
1772  $this->disable_reason = $reason;
1773  }
1774 
1775  global $CONFIG;
1776  $guid = (int)$this->guid;
1777 
1778  if ($recursive) {
1781  $ia = elgg_set_ignore_access(true);
1782 
1783  $query = "
1784  SELECT *
1785  FROM {$CONFIG->dbprefix}entities
1786  WHERE (
1787  container_guid = $guid
1788  OR owner_guid = $guid
1789  OR site_guid = $guid
1790  )
1791  AND enabled = 'yes'
1792  ";
1793  $sub_entities = $this->getDatabase()->getData($query, 'entity_row_to_elggstar');
1794 
1795  if ($sub_entities) {
1796  /* @var ElggEntity[] $sub_entities */
1797  foreach ($sub_entities as $e) {
1798  add_entity_relationship($e->guid, 'disabled_with', $this->guid);
1799  $e->disable($reason);
1800  }
1801  }
1802 
1805  }
1806 
1807  $this->disableMetadata();
1808  $this->disableAnnotations();
1809 
1810  $res = $this->getDatabase()->updateData("
1811  UPDATE {$CONFIG->dbprefix}entities
1812  SET enabled = 'no'
1813  WHERE guid = $guid
1814  ");
1815 
1816  if ($unban_after) {
1817  _elgg_services()->usersTable->markBanned($this->guid, false);
1818  }
1819 
1820  if ($res) {
1821  $this->attributes['enabled'] = 'no';
1822  _elgg_services()->events->trigger('disable:after', $this->type, $this);
1823  }
1824 
1825  return $res;
1826  }
1827 
1838  public function enable($recursive = true) {
1839  $guid = (int)$this->guid;
1840  if (!$guid) {
1841  return false;
1842  }
1843 
1844  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1845  return false;
1846  }
1847 
1848  if (!$this->canEdit()) {
1849  return false;
1850  }
1851 
1852  global $CONFIG;
1853 
1854  // Override access only visible entities
1855  $old_access_status = access_get_show_hidden_status();
1857 
1858  $result = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1859  SET enabled = 'yes'
1860  WHERE guid = $guid");
1861 
1862  $this->deleteMetadata('disable_reason');
1863  $this->enableMetadata();
1864  $this->enableAnnotations();
1865 
1866  if ($recursive) {
1867  $disabled_with_it = elgg_get_entities_from_relationship(array(
1868  'relationship' => 'disabled_with',
1869  'relationship_guid' => $guid,
1870  'inverse_relationship' => true,
1871  'limit' => 0,
1872  ));
1873 
1874  foreach ($disabled_with_it as $e) {
1875  $e->enable();
1876  remove_entity_relationship($e->guid, 'disabled_with', $guid);
1877  }
1878  }
1879 
1880  access_show_hidden_entities($old_access_status);
1881 
1882  if ($result) {
1883  $this->attributes['enabled'] = 'yes';
1884  _elgg_services()->events->trigger('enable:after', $this->type, $this);
1885  }
1886 
1887  return $result;
1888  }
1889 
1895  public function isEnabled() {
1896  return $this->enabled == 'yes';
1897  }
1898 
1916  public function delete($recursive = true) {
1917  global $CONFIG;
1918 
1919  $guid = $this->guid;
1920  if (!$guid) {
1921  return false;
1922  }
1923 
1924  // first check if we can delete this entity
1925  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1926  // which could potentially remove some content if the user didn't have access
1927  if (!$this->canDelete()) {
1928  return false;
1929  }
1930 
1931  // now trigger an event to let others know this entity is about to be deleted
1932  // so they can prevent it or take their own actions
1933  if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
1934  return false;
1935  }
1936 
1937  if ($this instanceof ElggUser) {
1938  // ban to prevent using the site during delete
1939  _elgg_services()->usersTable->markBanned($this->guid, true);
1940  }
1941 
1942  _elgg_services()->entityCache->remove($guid);
1943 
1944  // If memcache is available then delete this entry from the cache
1945  static $newentity_cache;
1946  if ((!$newentity_cache) && (is_memcache_available())) {
1947  $newentity_cache = new \ElggMemcache('new_entity_cache');
1948  }
1949  if ($newentity_cache) {
1950  $newentity_cache->delete($guid);
1951  }
1952 
1953  // Delete contained owned and otherwise releated objects (depth first)
1954  if ($recursive) {
1955  // Temporarily overriding access controls
1956  $entity_disable_override = access_get_show_hidden_status();
1958  $ia = elgg_set_ignore_access(true);
1959 
1960  // @todo there was logic in the original code that ignored
1961  // entities with owner or container guids of themselves.
1962  // this should probably be prevented in \ElggEntity instead of checked for here
1963  $options = array(
1964  'wheres' => array(
1965  "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
1966  . " AND guid != $guid)"
1967  ),
1968  'limit' => 0
1969  );
1970 
1971  $batch = new \ElggBatch('elgg_get_entities', $options);
1972  $batch->setIncrementOffset(false);
1973 
1974  foreach ($batch as $e) {
1975  $e->delete(true);
1976  }
1977 
1978  access_show_hidden_entities($entity_disable_override);
1980  }
1981 
1982  $entity_disable_override = access_get_show_hidden_status();
1984  $ia = elgg_set_ignore_access(true);
1985 
1986  // Now delete the entity itself
1987  $this->deleteMetadata();
1988  $this->deleteOwnedMetadata();
1989  $this->deleteAnnotations();
1990  $this->deleteOwnedAnnotations();
1991  $this->deleteRelationships();
1994 
1995  access_show_hidden_entities($entity_disable_override);
1997 
1998  elgg_delete_river(array('subject_guid' => $guid));
1999  elgg_delete_river(array('object_guid' => $guid));
2000  elgg_delete_river(array('target_guid' => $guid));
2002 
2003  $res = $this->getDatabase()->deleteData("
2004  DELETE FROM {$CONFIG->dbprefix}entities
2005  WHERE guid = $guid
2006  ");
2007 
2008  if ($res && in_array($this->type, ['object', 'user', 'group', 'site'])) {
2009  // delete from secondary table
2010  $sub_table = "{$CONFIG->dbprefix}{$this->type}s_entity";
2011 
2012  $this->getDatabase()->deleteData("
2013  DELETE FROM $sub_table
2014  WHERE guid = $guid
2015  ");
2016  }
2017 
2018  _elgg_clear_entity_files($this);
2019 
2020  return (bool)$res;
2021  }
2022 
2026  public function toObject() {
2027  $object = $this->prepareObject(new \stdClass());
2028  $params = array('entity' => $this);
2029  $object = _elgg_services()->hooks->trigger('to:object', 'entity', $params, $object);
2030  return $object;
2031  }
2032 
2039  protected function prepareObject($object) {
2040  $object->guid = $this->guid;
2041  $object->type = $this->getType();
2042  $object->subtype = $this->getSubtype();
2043  $object->owner_guid = $this->getOwnerGUID();
2044  $object->container_guid = $this->getContainerGUID();
2045  $object->site_guid = (int)$this->site_guid;
2046  $object->time_created = date('c', $this->getTimeCreated());
2047  $object->time_updated = date('c', $this->getTimeUpdated());
2048  $object->url = $this->getURL();
2049  $object->read_access = (int)$this->access_id;
2050  return $object;
2051  }
2052 
2053  /*
2054  * LOCATABLE INTERFACE
2055  */
2056 
2062  public function getLocation() {
2063  return $this->location;
2064  }
2065 
2073  public function setLocation($location) {
2074  $this->location = $location;
2075  }
2076 
2086  public function setLatLong($lat, $long) {
2087  $this->{"geo:lat"} = $lat;
2088  $this->{"geo:long"} = $long;
2089  }
2090 
2097  public function getLatitude() {
2098  return (float)$this->{"geo:lat"};
2099  }
2100 
2107  public function getLongitude() {
2108  return (float)$this->{"geo:long"};
2109  }
2110 
2111  /*
2112  * EXPORTABLE INTERFACE
2113  */
2114 
2121  public function getExportableValues() {
2122  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
2123  return array(
2124  'guid',
2125  'type',
2126  'subtype',
2127  'time_created',
2128  'time_updated',
2129  'container_guid',
2130  'owner_guid',
2131  'site_guid'
2132  );
2133  }
2134 
2143  public function export() {
2144  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2145  $tmp = array();
2146 
2147  // Generate uuid
2148  $uuid = guid_to_uuid($this->getGUID());
2149 
2150  // Create entity
2151  $odd = new ODDEntity(
2152  $uuid,
2153  $this->attributes['type'],
2154  get_subtype_from_id($this->attributes['subtype'])
2155  );
2156 
2157  $tmp[] = $odd;
2158 
2160 
2161  // Now add its attributes
2162  foreach ($this->attributes as $k => $v) {
2163  $meta = null;
2164 
2165  if (in_array($k, $exportable_values)) {
2166  switch ($k) {
2167  case 'guid': // Dont use guid in OpenDD
2168  case 'type': // Type and subtype already taken care of
2169  case 'subtype':
2170  break;
2171 
2172  case 'time_created': // Created = published
2173  $odd->setAttribute('published', date("r", $v));
2174  break;
2175 
2176  case 'site_guid': // Container
2177  $k = 'site_uuid';
2178  $v = guid_to_uuid($v);
2179  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2180  break;
2181 
2182  case 'container_guid': // Container
2183  $k = 'container_uuid';
2184  $v = guid_to_uuid($v);
2185  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2186  break;
2187 
2188  case 'owner_guid': // Convert owner guid to uuid, this will be stored in metadata
2189  $k = 'owner_uuid';
2190  $v = guid_to_uuid($v);
2191  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2192  break;
2193 
2194  default:
2195  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2196  }
2197 
2198  // set the time of any metadata created
2199  if ($meta) {
2200  $meta->setAttribute('published', date("r", $this->time_created));
2201  $tmp[] = $meta;
2202  }
2203  }
2204  }
2205 
2206  // Now we do something a bit special.
2207  /*
2208  * This provides a rendered view of the entity to foreign sites.
2209  */
2210 
2211  elgg_set_viewtype('default');
2212  $view = elgg_view_entity($this, array('full_view' => true));
2214 
2215  $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
2216  'renderedentity', $view, 'volatile');
2217 
2218  return $tmp;
2219  }
2220 
2221  /*
2222  * IMPORTABLE INTERFACE
2223  */
2224 
2235  public function import(ODD $data) {
2236  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2237  if (!($data instanceof ODDEntity)) {
2238  throw new \InvalidParameterException("import() passed an unexpected ODD class");
2239  }
2240 
2241  // Set type and subtype
2242  $this->attributes['type'] = $data->getAttribute('class');
2243  $this->attributes['subtype'] = $data->getAttribute('subclass');
2244 
2245  // Set owner
2246  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid(); // Import as belonging to importer.
2247 
2248  // Set time
2249  $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
2250  $this->attributes['time_updated'] = time();
2251 
2252  return true;
2253  }
2254 
2255  /*
2256  * SYSTEM LOG INTERFACE
2257  */
2258 
2265  public function getSystemLogID() {
2266  return $this->getGUID();
2267  }
2268 
2276  public function getObjectFromID($id) {
2277  return get_entity($id);
2278  }
2279 
2289  public function getTags($tag_names = null) {
2290  if ($tag_names && !is_array($tag_names)) {
2291  $tag_names = array($tag_names);
2292  }
2293 
2295  $entity_tags = array();
2296 
2297  foreach ($valid_tags as $tag_name) {
2298  if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2299  continue;
2300  }
2301 
2302  if ($tags = $this->$tag_name) {
2303  // if a single tag, metadata returns a string.
2304  // if multiple tags, metadata returns an array.
2305  if (is_array($tags)) {
2306  $entity_tags = array_merge($entity_tags, $tags);
2307  } else {
2308  $entity_tags[] = $tags;
2309  }
2310  }
2311  }
2312 
2313  return $entity_tags;
2314  }
2315 
2323 
2324  if (!$this->guid) {
2325  return false;
2326  }
2327 
2328  if ($this->type !== 'user') {
2329  return true;
2330  }
2331 
2332  $ac = _elgg_services()->accessCollections;
2333 
2334  $collections = $ac->getCollectionsByMember($this->guid);
2335  if (empty($collections)) {
2336  return true;
2337  }
2338 
2339  $result = true;
2340  foreach ($collections as $collection) {
2341  $result = $result & $ac->removeUser($this->guid, $collection->id);
2342  }
2343 
2344  return $result;
2345  }
2346 
2353  public function deleteOwnedAccessCollections() {
2354 
2355  if (!$this->guid) {
2356  return false;
2357  }
2358 
2359  $ac = _elgg_services()->accessCollections;
2360 
2361  $collections = $ac->getEntityCollections($this->guid);
2362  if (empty($collections)) {
2363  return true;
2364  }
2365 
2366  $result = true;
2367  foreach ($collections as $collection) {
2368  $result = $result & $ac->delete($collection->id);
2369  }
2370 
2371  return $result;
2372  }
2373 }
$tags
Definition: summary.php:41
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
enable($recursive=true)
Enable the entity.
$view
Definition: crop.php:34
canComment($user_guid=0)
Can a user comment on an entity?
getSubtype()
Get the entity subtype.
$r
canEditMetadata($metadata=null, $user_guid=0)
Can a user edit metadata on this entity?
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:46
elgg_get_registered_tag_metadata_names()
Returns an array of valid metadata names for tags.
Definition: tags.php:227
refresh(\stdClass $row)
Load new data from database into existing entity.
elgg_disable_metadata(array $options)
Disables metadata based on $options.
Definition: metadata.php:171
getOwnerGUID()
Get the guid of the entity's owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:110
if(!array_key_exists($filename, $text_files)) $file
Entities that support icons should implement this interface.
Definition: EntityIcon.php:7
__clone()
Clone an entity.
Definition: ElggEntity.php:119
deleteIcon($type= 'icon')
Removes all icon files and metadata for the passed type of icon.
getAnnotations($options=array(), $limit=50, $offset=0, $order="asc")
Gets an array of annotations.
Definition: ElggEntity.php:839
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:262
create_annotation($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE)
Create a new annotation.
Definition: annotations.php:62
loadAdditionalSelectValues(array $data)
Stores non-attributes from the loading of the entity as volatile data.
getOwnerEntity()
Gets the that owns this entity.
remove_all_private_settings($entity_guid)
Deletes all private settings for an entity.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
elgg_normalize_url($url)
Definition: output.php:290
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
setLatLong($lat, $long)
Set latitude and longitude metadata tags for a given entity.
removePrivateSetting($name)
Removes private setting.
Definition: ElggEntity.php:690
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:748
prepareObject($object)
Prepare an object copy for toObject()
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:479
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
countAnnotations($name="")
Count annotations.
Definition: ElggEntity.php:883
$e
Definition: metadata.php:12
$CONFIG site_guid
The guid of the current site object.
Definition: config.php:65
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:704
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:656
saveIconFromUploadedFile($input_name, $type= 'icon', array $coords=array())
Saves icons using an uploaded file as the source.
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:89
canWriteToContainer($user_guid=0, $type= 'all', $subtype= 'all')
Can a user add an entity to this container.
$exportable_values
Definition: entity.php:23
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:672
$input_name
Definition: item.php:14
deleteOwnedMetadata($name=null)
Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
Definition: ElggEntity.php:504
$metadata
Definition: entity.php:19
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
Definition: ElggEntity.php:927
countComments()
Count the number of comments attached to this entity.
Definition: ElggEntity.php:937
get_subtype_from_id($subtype_id)
Gets the denormalized string for a given subtype ID.
Definition: entities.php:39
save()
Save an entity.
setMetadata($name, $value, $value_type= '', $multiple=false, $owner_guid=0, $access_id=null)
Set metadata on this entity.
Definition: ElggEntity.php:400
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:724
$data
Definition: opendd.php:13
$value
Definition: longtext.php:26
$subtype
Definition: delete.php:28
isFullyLoaded()
Tests to see whether the object has been persisted.
if(!$count) $offset
Definition: pagination.php:26
getGUID()
Returns the guid.
disableMetadata($name= '')
Disables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:528
$guid
Removes an admin notice.
getContainerGUID()
Gets the container GUID for this entity.
$collection
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=array())
Saves icons using a local file as the source.
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:769
canEdit($user_guid=0)
Can a user edit this entity?
export()
Export this class into an array of ODD Elements containing all necessary fields.
$url
Definition: exceptions.php:24
getIcon($size, $type= 'icon')
Returns entity icon as an ElggIcon object The icon file may or may not exist on filestore.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type= '')
Removes all relationships originating from a particular entity.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
Definition: ElggEntity.php:905
getSites($options=array())
Gets the sites this entity is a member of.
$options
Elgg admin footer.
Definition: footer.php:6
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:588
$params
Definition: login.php:72
setContainerGUID($container_guid)
Set the container for this object.
removeRelationship($guid_two, $relationship)
Remove a relationship.
Definition: ElggEntity.php:641
elgg_disable_annotations(array $options)
Disables annotations based on $options.
update_river_access_by_object($object_guid, $access_id)
Sets the access ID on river items for a particular object.
Definition: river.php:713
saveIconFromElggFile(\ElggFile $file, $type= 'icon', array $coords=array())
Saves icons using a file located in the data store as the source.
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
Definition: ElggEntity.php:991
getMetadata($name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:313
getEntitiesFromRelationship($options=array(), $inverse=false, $limit=50, $offset=0)
Gets an array of entities with a relationship to this entity.
Definition: ElggEntity.php:967
$owner_guid
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
Definition: ElggEntity.php:609
metadata_array_to_values($array)
Takes a metadata array (which has all kinds of properties) and turns it into a simple array of string...
Definition: metadata.php:311
getExportableValues()
Returns an array of fields which can be exported.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
Definition: entities.php:716
getTags($tag_names=null)
Returns tags for this entity.
$limit
Definition: userpicker.php:38
add_subtype($type, $subtype, $class="")
Register with a certain type and subtype to be loaded as a specific class.
Definition: entities.php:95
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $vartype="")
Adds an annotation to an entity.
Definition: ElggEntity.php:815
$temp_annotations
Holds annotations until entity is saved.
Definition: ElggEntity.php:63
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:568
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
elgg_enable_metadata(array $options)
Enables metadata based on $options.
Definition: metadata.php:187
$owner
Definition: crop.php:8
$key
Definition: summary.php:34
$container
Definition: delete.php:29
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
Definition: access.php:43
elgg_view_entity(\ElggEntity $entity, array $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:832
getAnnotationsAvg($name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:894
$comment owner_guid
Definition: save.php:58
global $CONFIG
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:65
setLocation($location)
Sets the 'location' metadata for the entity.
$time_created
Definition: online.php:16
const ACCESS_PRIVATE
Definition: elgglib.php:1988
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:166
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:73
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:2001
$temp_metadata
Holds metadata until entity is saved.
Definition: ElggEntity.php:57
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:316
canAnnotate($user_guid=0, $annotation_name= '')
Can a user annotate an entity?
elgg_enable_annotations(array $options)
Enables annotations based on $options.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1070
getIconURL($params=array())
Get the URL for this entity's icon.
$orig_attributes
Holds the original (persisted) attribute values that have been changed but not yet saved...
Definition: ElggEntity.php:80
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:170
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
get_entity_as_row($guid)
Returns a database row from the entities table.
Definition: entities.php:174
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1310
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:627
$comment container_guid
Definition: save.php:59
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
guid_to_uuid($guid)
Generate a UUID from a given GUID.
$comment access_id
Definition: save.php:60
$temp_private_settings
Holds private settings until entity is saved.
Definition: ElggEntity.php:69
$size
Definition: default.php:20
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:158
canDelete($user_guid=0)
Can a user delete this entity?
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:158
$hidden
Definition: save.php:13
hasIcon($size, $type= 'icon')
Returns if the entity has an icon of the passed type.
elgg_get_metadata(array $options=array())
Returns metadata.
Definition: metadata.php:143
getType()
Returns the entity type.
elgg_get_annotations(array $options=array())
Returns annotations.
Definition: ODD.php:9
setDisplayName($displayName)
Sets the title or name of this entity.
elgg_delete_river(array $options=array())
Delete river items.
Definition: river.php:162
set($name, $value)
Sets the value of an attribute or metadata.
Definition: ElggEntity.php:234
$filename
create()
Create a new entry in the entities table.
getIconLastChange($size, $type= 'icon')
Returns the timestamp of when the icon was changed.
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
Definition: elgglib.php:629
getOriginalAttributes()
Get the original values of attribute(s) that have been modified since the entity was persisted...
Definition: ElggEntity.php:246
setURL($url)
Overrides the URL returned by getURL()
$row
set_private_setting($entity_guid, $name, $value)
Sets a private setting for an entity.
getLocation()
Gets the 'location' metadata for the entity.
getLatitude()
Return the entity's latitude.
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
$container_guid
getContainerEntity()
Get the container entity for this object.
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
removeFromSite($site)
Remove this entity from a site.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $coords
Definition: crop.php:15
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggEntity.php:372
$user_guid
Avatar remove action.
Definition: remove.php:6
const ACCESS_DEFAULT
Definition: elgglib.php:1987
if(!$collection_name) $id
Definition: add.php:17
getSystemLogID()
Return an identification for the object for storage in the system log.
enableMetadata($name= '')
Enables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:549
disable($reason="", $recursive=true)
Disable this entity.
getURL()
Gets the URL for this entity.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42
load($guid)
Loads attributes from the entities table into the object.
_elgg_clear_entity_files($entity)
Removes all entity files.
Definition: filestore.php:415
getDisplayName()
Get the entity's display name.
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
Definition: ElggEntity.php:916
getLongitude()
Return the entity's longitude.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204
getObjectFromID($id)
For a given ID, return the object associated with it.
if(!$display_name) $type
Definition: delete.php:27
addToSite($site)
Add this entity to a site.
$url_override
If set, overrides the value of getURL()
Definition: ElggEntity.php:51
$volatile
Volatile data structure for this object, allows for storage of data in-memory that isn't sync'd back ...
Definition: ElggEntity.php:75