Elgg  Version 1.10
ElggEntity.php
Go to the documentation of this file.
1 <?php
41 abstract class ElggEntity extends \ElggData implements
42  Notable, // Calendar interface (deprecated 1.9)
43  Locatable, // Geocoding interface
44  Importable // Allow import of data (deprecated 1.9)
45 {
46 
50  protected $url_override;
51 
55  protected $icon_override;
56 
61  protected $temp_metadata = array();
62 
67  protected $temp_annotations = array();
68 
73  protected $temp_private_settings = array();
74 
79  protected $volatile = array();
80 
86  protected $tables_split;
87 
93  protected $tables_loaded;
94 
102  protected function initializeAttributes() {
103  parent::initializeAttributes();
104 
105  $this->attributes['guid'] = null;
106  $this->attributes['type'] = null;
107  $this->attributes['subtype'] = null;
108 
109  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid();
110  $this->attributes['container_guid'] = _elgg_services()->session->getLoggedInUserGuid();
111 
112  $this->attributes['site_guid'] = null;
113  $this->attributes['access_id'] = ACCESS_PRIVATE;
114  $this->attributes['time_updated'] = null;
115  $this->attributes['last_action'] = null;
116  $this->attributes['enabled'] = "yes";
117 
118  // There now follows a bit of a hack
119  /* Problem: To speed things up, some objects are split over several tables,
120  * this means that it requires n number of database reads to fully populate
121  * an entity. This causes problems for caching and create events
122  * since it is not possible to tell whether a subclassed entity is complete.
123  *
124  * Solution: We have two counters, one 'tables_split' which tells whatever is
125  * interested how many tables are going to need to be searched in order to fully
126  * populate this object, and 'tables_loaded' which is how many have been
127  * loaded thus far.
128  *
129  * If the two are the same then this object is complete.
130  *
131  * Use: isFullyLoaded() to check
132  */
133  $this->tables_split = 1;
134  $this->tables_loaded = 0;
135  }
136 
150  public function __clone() {
151  $orig_entity = get_entity($this->guid);
152  if (!$orig_entity) {
153  _elgg_services()->logger->error("Failed to clone entity with GUID $this->guid");
154  return;
155  }
156 
157  $metadata_array = elgg_get_metadata(array(
158  'guid' => $this->guid,
159  'limit' => 0
160  ));
161 
162  $this->attributes['guid'] = "";
163 
164  $this->attributes['subtype'] = $orig_entity->getSubtype();
165 
166  // copy metadata over to new entity - slightly convoluted due to
167  // handling of metadata arrays
168  if (is_array($metadata_array)) {
169  // create list of metadata names
170  $metadata_names = array();
171  foreach ($metadata_array as $metadata) {
172  $metadata_names[] = $metadata['name'];
173  }
174  // arrays are stored with multiple enties per name
175  $metadata_names = array_unique($metadata_names);
176 
177  // move the metadata over
178  foreach ($metadata_names as $name) {
179  $this->__set($name, $orig_entity->$name);
180  }
181  }
182  }
183 
197  public function __set($name, $value) {
198  if (array_key_exists($name, $this->attributes)) {
199  // Certain properties should not be manually changed!
200  switch ($name) {
201  case 'guid':
202  case 'time_updated':
203  case 'last_action':
204  return;
205  break;
206  case 'access_id':
207  case 'owner_guid':
208  case 'container_guid':
209  if ($value !== null) {
210  $this->attributes[$name] = (int)$value;
211  } else {
212  $this->attributes[$name] = null;
213  }
214  break;
215  default:
216  $this->attributes[$name] = $value;
217  break;
218  }
219  } else {
220  $this->setMetadata($name, $value);
221  }
222  }
223 
233  public function set($name, $value) {
234  elgg_deprecated_notice("Use -> instead of set()", 1.9);
235  $this->__set($name, $value);
236 
237  return true;
238  }
239 
252  public function __get($name) {
253  if (array_key_exists($name, $this->attributes)) {
254  if ($name === 'subtype' && $this->attributes['guid']) {
255  // note: only show deprecation notice if user reads ->subtype after save/load
256  elgg_deprecated_notice("Use getSubtype()", 1.9);
257  }
258  return $this->attributes[$name];
259  }
260 
261  return $this->getMetadata($name);
262  }
263 
271  public function get($name) {
272  elgg_deprecated_notice("Use -> instead of get()", 1.9);
273  return $this->__get($name);
274  }
275 
281  abstract public function getDisplayName();
282 
289  abstract public function setDisplayName($displayName);
290 
298  public function getMetadata($name) {
299  $guid = $this->getGUID();
300 
301  if (!$guid) {
302  if (isset($this->temp_metadata[$name])) {
303  // md is returned as an array only if more than 1 entry
304  if (count($this->temp_metadata[$name]) == 1) {
305  return $this->temp_metadata[$name][0];
306  } else {
307  return $this->temp_metadata[$name];
308  }
309  } else {
310  return null;
311  }
312  }
313 
314  // upon first cache miss, just load/cache all the metadata and retry.
315  // if this works, the rest of this function may not be needed!
316  $cache = _elgg_services()->metadataCache;
317  if ($cache->isKnown($guid, $name)) {
318  return $cache->load($guid, $name);
319  } else {
320  $cache->populateFromEntities(array($guid));
321  // in case ignore_access was on, we have to check again...
322  if ($cache->isKnown($guid, $name)) {
323  return $cache->load($guid, $name);
324  }
325  }
326 
327  $md = elgg_get_metadata(array(
328  'guid' => $guid,
329  'metadata_name' => $name,
330  'limit' => 0,
331  'distinct' => false,
332  ));
333 
334  $value = null;
335 
336  if ($md && !is_array($md)) {
337  $value = $md->value;
338  } elseif (count($md) == 1) {
339  $value = $md[0]->value;
340  } else if ($md && is_array($md)) {
342  }
343 
344  $cache->save($guid, $name, $value);
345 
346  return $value;
347  }
348 
359  public function __unset($name) {
360  if (array_key_exists($name, $this->attributes)) {
361  $this->attributes[$name] = "";
362  } else {
363  $this->deleteMetadata($name);
364  }
365  }
366 
387  public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) {
388 
389  // normalize value to an array that we will loop over
390  // remove indexes if value already an array.
391  if (is_array($value)) {
392  $value = array_values($value);
393  } else {
394  $value = array($value);
395  }
396 
397  // saved entity. persist md to db.
398  if ($this->guid) {
399  // if overwriting, delete first.
400  if (!$multiple) {
401  $options = array(
402  'guid' => $this->getGUID(),
403  'metadata_name' => $name,
404  'limit' => 0
405  );
406  // @todo in 1.9 make this return false if can't add metadata
407  // https://github.com/elgg/elgg/issues/4520
408  //
409  // need to remove access restrictions right now to delete
410  // because this is the expected behavior
411  $ia = elgg_set_ignore_access(true);
412  if (false === elgg_delete_metadata($options)) {
413  return false;
414  }
416  }
417 
418  $owner_guid = (int)$owner_guid;
419  $access_id = ($access_id === null) ? $this->getAccessId() : (int)$access_id;
421 
422  // add new md
423  $result = true;
424  foreach ($value as $value_tmp) {
425  // at this point $value is appended because it was cleared above if needed.
426  $md_id = create_metadata($this->getGUID(), $name, $value_tmp, $value_type,
427  $owner_guid, $access_id, true);
428  if (!$md_id) {
429  return false;
430  }
431  }
432 
433  return $result;
434  } else {
435  // unsaved entity. store in temp array
436 
437  // returning single entries instead of an array of 1 element is decided in
438  // getMetaData(), just like pulling from the db.
439 
440  if ($owner_guid != 0 || $access_id !== null) {
441  $msg = "owner guid and access id cannot be used in \ElggEntity::setMetadata() until entity is saved.";
442  throw new \InvalidArgumentException($msg);
443  }
444 
445  // if overwrite, delete first
446  if (!$multiple || !isset($this->temp_metadata[$name])) {
447  $this->temp_metadata[$name] = array();
448  }
449 
450  // add new md
451  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
452  return true;
453  }
454  }
455 
466  public function deleteMetadata($name = null) {
467 
468  if (!$this->guid) {
469  return false;
470  }
471 
472  $options = array(
473  'guid' => $this->guid,
474  'limit' => 0
475  );
476  if ($name) {
477  $options['metadata_name'] = $name;
478  }
479 
481  }
482 
491  public function deleteOwnedMetadata($name = null) {
492  // access is turned off for this because they might
493  // no longer have access to an entity they created metadata on.
494  $ia = elgg_set_ignore_access(true);
495  $options = array(
496  'metadata_owner_guid' => $this->guid,
497  'limit' => 0
498  );
499  if ($name) {
500  $options['metadata_name'] = $name;
501  }
502 
505  return $r;
506  }
507 
517  public function clearMetadata($name = '') {
518  elgg_deprecated_notice('\ElggEntity->clearMetadata() is deprecated by ->deleteMetadata()', 1.8);
519  return $this->deleteMetadata($name);
520  }
521 
529  public function disableMetadata($name = '') {
530  $options = array(
531  'guid' => $this->guid,
532  'limit' => 0
533  );
534  if ($name) {
535  $options['metadata_name'] = $name;
536  }
537 
539  }
540 
550  public function enableMetadata($name = '') {
551  $options = array(
552  'guid' => $this->guid,
553  'limit' => 0
554  );
555  if ($name) {
556  $options['metadata_name'] = $name;
557  }
558 
560  }
561 
569  public function getVolatileData($name) {
570  if (!is_array($this->volatile)) {
571  $this->volatile = array();
572  }
573 
574  if (array_key_exists($name, $this->volatile)) {
575  return $this->volatile[$name];
576  } else {
577  return null;
578  }
579  }
580 
589  public function setVolatileData($name, $value) {
590  if (!is_array($this->volatile)) {
591  $this->volatile = array();
592  }
593 
594  $this->volatile[$name] = $value;
595  }
596 
610  public function deleteRelationships($relationship = null) {
611  $relationship = (string)$relationship;
612  $result = remove_entity_relationships($this->getGUID(), $relationship);
613  return $result && remove_entity_relationships($this->getGUID(), $relationship, true);
614  }
615 
624  public function clearRelationships() {
625  elgg_deprecated_notice('\ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8);
626  return $this->deleteRelationships();
627  }
628 
641  public function addRelationship($guid_two, $relationship) {
642  return add_entity_relationship($this->getGUID(), $relationship, $guid_two);
643  }
644 
655  public function removeRelationship($guid_two, $relationship) {
656  return remove_entity_relationship($this->getGUID(), $relationship, $guid_two);
657  }
658 
670  public function setPrivateSetting($name, $value) {
671  if ((int) $this->guid > 0) {
672  return set_private_setting($this->getGUID(), $name, $value);
673  } else {
674  $this->temp_private_settings[$name] = $value;
675  return true;
676  }
677  }
678 
686  public function getPrivateSetting($name) {
687  if ((int) ($this->guid) > 0) {
688  return get_private_setting($this->getGUID(), $name);
689  } else {
690  if (isset($this->temp_private_settings[$name])) {
691  return $this->temp_private_settings[$name];
692  }
693  }
694  return null;
695  }
696 
704  public function removePrivateSetting($name) {
705  return remove_private_setting($this->getGUID(), $name);
706  }
707 
718  public function deleteAnnotations($name = null) {
719  $options = array(
720  'guid' => $this->guid,
721  'limit' => 0
722  );
723  if ($name) {
724  $options['annotation_name'] = $name;
725  }
726 
728  }
729 
738  public function deleteOwnedAnnotations($name = null) {
739  // access is turned off for this because they might
740  // no longer have access to an entity they created annotations on.
741  $ia = elgg_set_ignore_access(true);
742  $options = array(
743  'annotation_owner_guid' => $this->guid,
744  'limit' => 0
745  );
746  if ($name) {
747  $options['annotation_name'] = $name;
748  }
749 
752  return $r;
753  }
754 
762  public function disableAnnotations($name = '') {
763  $options = array(
764  'guid' => $this->guid,
765  'limit' => 0
766  );
767  if ($name) {
768  $options['annotation_name'] = $name;
769  }
770 
772  }
773 
783  public function enableAnnotations($name = '') {
784  $options = array(
785  'guid' => $this->guid,
786  'limit' => 0
787  );
788  if ($name) {
789  $options['annotation_name'] = $name;
790  }
791 
793  }
794 
802  private function getAnnotationCalculation($name, $calculation) {
803  $options = array(
804  'guid' => $this->getGUID(),
805  'distinct' => false,
806  'annotation_name' => $name,
807  'annotation_calculation' => $calculation
808  );
809 
811  }
812 
829  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $vartype = "") {
830  if ((int) $this->guid > 0) {
831  return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_guid, $access_id);
832  } else {
833  $this->temp_annotations[$name] = $value;
834  }
835  return true;
836  }
837 
853  public function getAnnotations($options = array(), $limit = 50, $offset = 0, $order = "asc") {
854  if (!is_array($options)) {
855  elgg_deprecated_notice("\ElggEntity::getAnnotations() takes an array of options.", 1.9);
856  }
857 
858  if ((int) ($this->guid) > 0) {
859  if (!is_array($options)) {
860  $options = array(
861  'guid' => $this->guid,
862  'annotation_name' => $options,
863  'limit' => $limit,
864  'offset' => $offset,
865  );
866 
867  if ($order != 'asc') {
868  $options['reverse_order_by'] = true;
869  }
870  } else {
871  $options['guid'] = $this->guid;
872  }
873 
875  } else {
876  if (!is_array($options)) {
877  $name = $options;
878  } else {
879  $name = elgg_extract('annotation_name', $options, '');
880  }
881 
882  if (isset($this->temp_annotations[$name])) {
883  return array($this->temp_annotations[$name]);
884  }
885  }
886 
887  return array();
888  }
889 
900  public function clearAnnotations($name = "") {
901  elgg_deprecated_notice('\ElggEntity->clearAnnotations() is deprecated by ->deleteAnnotations()', 1.8);
902  return $this->deleteAnnotations($name);
903  }
904 
912  public function countAnnotations($name = "") {
913  return $this->getAnnotationCalculation($name, 'count');
914  }
915 
923  public function getAnnotationsAvg($name) {
924  return $this->getAnnotationCalculation($name, 'avg');
925  }
926 
934  public function getAnnotationsSum($name) {
935  return $this->getAnnotationCalculation($name, 'sum');
936  }
937 
945  public function getAnnotationsMin($name) {
946  return $this->getAnnotationCalculation($name, 'min');
947  }
948 
956  public function getAnnotationsMax($name) {
957  return $this->getAnnotationCalculation($name, 'max');
958  }
959 
966  public function countComments() {
967  $params = array('entity' => $this);
968  $num = _elgg_services()->hooks->trigger('comments:count', $this->getType(), $params);
969 
970  if (is_int($num)) {
971  return $num;
972  } else {
973  return elgg_get_entities(array(
974  'type' => 'object',
975  'subtype' => 'comment',
976  'container_guid' => $this->getGUID(),
977  'count' => true,
978  'distinct' => false,
979  ));
980  }
981  }
982 
996  public function getEntitiesFromRelationship($options = array(), $inverse = false, $limit = 50, $offset = 0) {
997  if (is_array($options)) {
998  $options['relationship_guid'] = $this->getGUID();
1000  } else {
1001  elgg_deprecated_notice("\ElggEntity::getEntitiesFromRelationship takes an options array", 1.9);
1003  'relationship' => $options,
1004  'relationship_guid' => $this->getGUID(),
1005  'inverse_relationship' => $inverse,
1006  'limit' => $limit,
1007  'offset' => $offset
1008  ));
1009  }
1010  }
1011 
1020  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
1022  'relationship' => $relationship,
1023  'relationship_guid' => $this->getGUID(),
1024  'inverse_relationship' => $inverse_relationship,
1025  'count' => true
1026  ));
1027  }
1028 
1039  public function canEdit($user_guid = 0) {
1040  $user_guid = (int)$user_guid;
1042  if (!$user) {
1043  $user = _elgg_services()->session->getLoggedInUser();
1044  }
1045 
1046  $return = false;
1047 
1048  // Test user if possible - should default to false unless a plugin hook says otherwise
1049  if ($user) {
1050  if ($this->getOwnerGUID() == $user->getGUID()) {
1051  $return = true;
1052  }
1053 
1054  if ($this->getContainerGUID() == $user->getGUID()) {
1055  $return = true;
1056  }
1057 
1058  if ($this->getGUID() == $user->getGUID()) {
1059  $return = true;
1060  }
1061 
1062  $container = $this->getContainerEntity();
1063  if ($container && $container->canEdit($user->getGUID())) {
1064  $return = true;
1065  }
1066  }
1067 
1068  $params = array('entity' => $this, 'user' => $user);
1069  return _elgg_services()->hooks->trigger('permissions_check', $this->type, $params, $return);
1070  }
1071 
1087  public function canEditMetadata($metadata = null, $user_guid = 0) {
1088  if (!$this->guid) {
1089  // @todo cannot edit metadata on unsaved entity?
1090  return false;
1091  }
1092 
1093  if ($user_guid) {
1095  if (!$user) {
1096  return false;
1097  }
1098  } else {
1099  $user = _elgg_services()->session->getLoggedInUser();
1100  $user_guid = $user->guid;
1101  }
1102 
1103  $return = null;
1104 
1105  // if metadata is not owned or owned by the user, then can edit
1106  if ($metadata && ($metadata->owner_guid == 0 || $metadata->owner_guid == $user_guid)) {
1107  $return = true;
1108  }
1109 
1110  if (is_null($return)) {
1111  $return = $this->canEdit($user_guid);
1112  }
1113 
1114  // metadata and user may be null
1115  $params = array('entity' => $this, 'user' => $user, 'metadata' => $metadata);
1116  return _elgg_services()->hooks->trigger('permissions_check:metadata', $this->type, $params, $return);
1117  }
1118 
1129  public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
1130  return can_write_to_container($user_guid, $this->guid, $type, $subtype);
1131  }
1132 
1143  public function canComment($user_guid = 0) {
1144  if ($user_guid == 0) {
1145  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1146  }
1148 
1149  // By default, we don't take a position of whether commenting is allowed
1150  // because it is handled by the subclasses of \ElggEntity
1151  $params = array('entity' => $this, 'user' => $user);
1152  return _elgg_services()->hooks->trigger('permissions_check:comment', $this->type, $params, null);
1153  }
1154 
1169  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1170  if ($user_guid == 0) {
1171  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1172  }
1174 
1175  $return = true;
1176  if (!$user) {
1177  $return = false;
1178  }
1179 
1180  $params = array(
1181  'entity' => $this,
1182  'user' => $user,
1183  'annotation_name' => $annotation_name,
1184  );
1185  return _elgg_services()->hooks->trigger('permissions_check:annotate', $this->type, $params, $return);
1186  }
1187 
1193  public function getAccessID() {
1194  return $this->access_id;
1195  }
1196 
1202  public function getGUID() {
1203  return $this->guid;
1204  }
1205 
1211  public function getType() {
1212  return $this->type;
1213  }
1214 
1220  public function getSubtype() {
1221  // If this object hasn't been saved, then return the subtype string.
1222  if ($this->attributes['guid']) {
1223  return get_subtype_from_id($this->attributes['subtype']);
1224  }
1225  return $this->attributes['subtype'];
1226  }
1227 
1233  public function getOwnerGUID() {
1234  return (int)$this->owner_guid;
1235  }
1236 
1243  public function getOwner() {
1244  elgg_deprecated_notice("\ElggEntity::getOwner deprecated for \ElggEntity::getOwnerGUID", 1.8);
1245  return $this->getOwnerGUID();
1246  }
1247 
1253  public function getOwnerEntity() {
1254  return get_entity($this->owner_guid);
1255  }
1256 
1264  public function setContainerGUID($container_guid) {
1265  return $this->container_guid = (int)$container_guid;
1266  }
1267 
1276  public function setContainer($container_guid) {
1277  elgg_deprecated_notice("\ElggObject::setContainer deprecated for \ElggEntity::setContainerGUID", 1.8);
1278  return $this->setContainerGUID('container_guid', $container_guid);
1279  }
1280 
1286  public function getContainerGUID() {
1287  return (int)$this->container_guid;
1288  }
1289 
1296  public function getContainer() {
1297  elgg_deprecated_notice("\ElggObject::getContainer deprecated for \ElggEntity::getContainerGUID", 1.8);
1298  return $this->getContainerGUID();
1299  }
1300 
1307  public function getContainerEntity() {
1308  return get_entity($this->getContainerGUID());
1309  }
1310 
1316  public function getTimeUpdated() {
1317  return $this->time_updated;
1318  }
1319 
1328  public function getURL() {
1329 
1330  $url = "";
1331 
1332  // @todo remove when elgg_register_entity_url_handler() has been removed
1333  if ($this->guid) {
1334  global $CONFIG;
1335  if (isset($CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1336  $function = $CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()];
1337  if (is_callable($function)) {
1338  $url = call_user_func($function, $this);
1339  }
1340  } elseif (isset($CONFIG->entity_url_handler[$this->getType()]['all'])) {
1341  $function = $CONFIG->entity_url_handler[$this->getType()]['all'];
1342  if (is_callable($function)) {
1343  $url = call_user_func($function, $this);
1344  }
1345  } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
1346  $function = $CONFIG->entity_url_handler['all']['all'];
1347  if (is_callable($function)) {
1348  $url = call_user_func($function, $this);
1349  }
1350  }
1351 
1352  if ($url) {
1354  }
1355  }
1356 
1357  $type = $this->getType();
1358  $params = array('entity' => $this);
1359  $url = _elgg_services()->hooks->trigger('entity:url', $type, $params, $url);
1360 
1361  // @todo remove when \ElggEntity::setURL() has been removed
1362  if (!empty($this->url_override)) {
1364  }
1365 
1366  return elgg_normalize_url($url);
1367  }
1368 
1379  public function setURL($url) {
1380  elgg_deprecated_notice('\ElggEntity::setURL() has been replaced by the "entity:url" plugin hook', 1.9);
1381  $this->url_override = $url;
1382  return $url;
1383  }
1384 
1396  public function getIconURL($size = 'medium') {
1398 
1399  if (isset($this->icon_override[$size])) {
1400  elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
1401  return $this->icon_override[$size];
1402  }
1403 
1404  $type = $this->getType();
1405  $params = array(
1406  'entity' => $this,
1407  'size' => $size,
1408  );
1409 
1410  $url = _elgg_services()->hooks->trigger('entity:icon:url', $type, $params, null);
1411  if ($url == null) {
1412  $url = "_graphics/icons/default/$size.png";
1413  }
1414 
1415  return elgg_normalize_url($url);
1416  }
1417 
1426  public function getIcon($size = 'medium') {
1427  elgg_deprecated_notice("getIcon() deprecated by getIconURL()", 1.8);
1428  return $this->getIconURL($size);
1429  }
1430 
1442  public function setIcon($url, $size = 'medium') {
1443  elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
1444 
1447 
1448  if (!$this->icon_override) {
1449  $this->icon_override = array();
1450  }
1451  $this->icon_override[$size] = $url;
1452 
1453  return true;
1454  }
1455 
1467  public function addToSite($site) {
1468  if (!elgg_instanceof($site, 'site')) {
1469  return false;
1470  }
1471 
1472  return $site->addEntity($this);
1473  }
1474 
1485  public function removeFromSite($site) {
1486  if (!elgg_instanceof($site, 'site')) {
1487  return false;
1488  }
1489 
1490  return $site->removeEntity($this);
1491  }
1492 
1505  public function getSites($options = array()) {
1506  $options['relationship'] = 'member_of_site';
1507  $options['relationship_guid'] = $this->guid;
1508  $options['inverse_relationship'] = false;
1509  if (!isset($options['site_guid']) || !isset($options['site_guids'])) {
1510  $options['site_guids'] = ELGG_ENTITIES_ANY_VALUE;
1511  }
1512 
1514  }
1515 
1521  public function isFullyLoaded() {
1522  return ! ($this->tables_loaded < $this->tables_split);
1523  }
1524 
1532  public function save() {
1533  $guid = $this->getGUID();
1534  if ($guid > 0) {
1535  return $this->update();
1536  } else {
1537  $guid = $this->create();
1538  if ($guid) {
1539  if (_elgg_services()->events->trigger('create', $this->type, $this)) {
1540  return $guid;
1541  } else {
1542  // plugins that return false to event don't need to override the access system
1543  $ia = elgg_set_ignore_access(true);
1544  $this->delete();
1546  }
1547  }
1548  }
1549 
1550  return false;
1551  }
1552 
1566  protected function create() {
1567  global $CONFIG;
1568 
1569  // Using attribute array directly; get function does something special!
1570  $type = $this->getDatabase()->sanitizeString($this->attributes['type']);
1571  if ($type == "") {
1572  throw new \InvalidParameterException("Entity type must be set.");
1573  }
1574 
1575  $subtype = $this->attributes['subtype'];
1576  $subtype_id = add_subtype($type, $subtype);
1577  $owner_guid = (int)$this->attributes['owner_guid'];
1578  $access_id = (int)$this->attributes['access_id'];
1579  $now = (string)time();
1580  $time_created = isset($this->attributes['time_created']) ? (int)$this->attributes['time_created'] : $now;
1581 
1582  $site_guid = $this->attributes['site_guid'];
1583  if ($site_guid == 0) {
1584  $site_guid = $CONFIG->site_guid;
1585  }
1586  $site_guid = (int)$site_guid;
1587 
1588  $container_guid = $this->attributes['container_guid'];
1589  if ($container_guid == 0) {
1590  $container_guid = $owner_guid;
1591  }
1592  $container_guid = (int)$container_guid;
1593 
1594  if ($access_id == ACCESS_DEFAULT) {
1595  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1596  }
1597 
1598  $owner = $this->getOwnerEntity();
1599  if ($owner && !$owner->canWriteToContainer(0, $type, $subtype)) {
1600  return false;
1601  }
1602 
1603  if ($owner_guid != $container_guid) {
1604  $container = $this->getContainerEntity();
1605  if ($container && !$container->canWriteToContainer(0, $type, $subtype)) {
1606  return false;
1607  }
1608  }
1609 
1610  $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities
1611  (type, subtype, owner_guid, site_guid, container_guid,
1612  access_id, time_created, time_updated, last_action)
1613  values
1614  ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1615  $access_id, $time_created, $now, $now)");
1616 
1617  if (!$result) {
1618  throw new \IOException("Unable to save new object's base entity information!");
1619  }
1620 
1621  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1622  $this->attributes['subtype'] = (int)$subtype_id;
1623  $this->attributes['guid'] = (int)$result;
1624  $this->attributes['time_created'] = (int)$time_created;
1625  $this->attributes['time_updated'] = (int)$now;
1626  $this->attributes['last_action'] = (int)$now;
1627  $this->attributes['site_guid'] = (int)$site_guid;
1628  $this->attributes['container_guid'] = (int)$container_guid;
1629 
1630  // Save any unsaved metadata
1631  if (sizeof($this->temp_metadata) > 0) {
1632  foreach ($this->temp_metadata as $name => $value) {
1633  $this->$name = $value;
1634  }
1635 
1636  $this->temp_metadata = array();
1637  }
1638 
1639  // Save any unsaved annotations.
1640  if (sizeof($this->temp_annotations) > 0) {
1641  foreach ($this->temp_annotations as $name => $value) {
1642  $this->annotate($name, $value);
1643  }
1644 
1645  $this->temp_annotations = array();
1646  }
1647 
1648  // Save any unsaved private settings.
1649  if (sizeof($this->temp_private_settings) > 0) {
1650  foreach ($this->temp_private_settings as $name => $value) {
1651  $this->setPrivateSetting($name, $value);
1652  }
1653 
1654  $this->temp_private_settings = array();
1655  }
1656 
1657  _elgg_cache_entity($this);
1658 
1659  return $result;
1660  }
1661 
1669  protected function update() {
1670  global $CONFIG;
1671 
1672  // See #5600. This ensures canEdit() checks the BD persisted entity so it sees the
1673  // persisted owner_guid, container_guid, etc.
1674  _elgg_disable_caching_for_entity($this->guid);
1675  $persisted_entity = get_entity($this->guid);
1676  if (!$persisted_entity) {
1677  // Why worry about this case? If access control was off when the user fetched this object but
1678  // was turned back on again. Better to just bail than to turn access control off again.
1679  return false;
1680  }
1681 
1682  $allow_edit = $persisted_entity->canEdit();
1683  unset($persisted_entity);
1684 
1685  if ($allow_edit) {
1686  $allow_edit = _elgg_services()->events->trigger('update', $this->type, $this);
1687  }
1688 
1689  _elgg_enable_caching_for_entity($this->guid);
1690 
1691  if (!$allow_edit) {
1692  return false;
1693  }
1694 
1695  // See #6225. We copy these after the update event in case a handler changed one of them.
1696  $guid = (int)$this->guid;
1697  $owner_guid = (int)$this->owner_guid;
1698  $access_id = (int)$this->access_id;
1699  $container_guid = (int)$this->container_guid;
1700  $time_created = (int)$this->time_created;
1701  $time = time();
1702 
1703  if ($access_id == ACCESS_DEFAULT) {
1704  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1705  }
1706 
1707  $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1708  set owner_guid='$owner_guid', access_id='$access_id',
1709  container_guid='$container_guid', time_created='$time_created',
1710  time_updated='$time' WHERE guid=$guid");
1711 
1712  // TODO(evan): Move this to \ElggObject?
1713  if ($this instanceof \ElggObject) {
1714  update_river_access_by_object($guid, $access_id);
1715  }
1716 
1717  // If memcache is available then delete this entry from the cache
1718  static $newentity_cache;
1719  if ((!$newentity_cache) && (is_memcache_available())) {
1720  $newentity_cache = new \ElggMemcache('new_entity_cache');
1721  }
1722  if ($newentity_cache) {
1723  $newentity_cache->delete($guid);
1724  }
1725 
1726  if ($ret !== false) {
1727  $this->attributes['time_updated'] = $time;
1728  }
1729 
1730  _elgg_cache_entity($this);
1731 
1732  // Handle cases where there was no error BUT no rows were updated!
1733  return $ret !== false;
1734  }
1735 
1743  protected function load($guid) {
1744  if ($guid instanceof \stdClass) {
1745  $row = $guid;
1746  } else {
1748  }
1749 
1750  if ($row) {
1751  // Create the array if necessary - all subclasses should test before creating
1752  if (!is_array($this->attributes)) {
1753  $this->attributes = array();
1754  }
1755 
1756  // Now put these into the attributes array as core values
1757  $objarray = (array) $row;
1758  foreach ($objarray as $key => $value) {
1759  $this->attributes[$key] = $value;
1760  }
1761 
1762  // Increment the portion counter
1763  if (!$this->isFullyLoaded()) {
1764  $this->tables_loaded++;
1765  }
1766 
1767  // guid needs to be an int https://github.com/elgg/elgg/issues/4111
1768  $this->attributes['guid'] = (int)$this->attributes['guid'];
1769 
1770  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1771  $this->attributes['subtype'] = (int)$this->attributes['subtype'];
1772 
1773  // Cache object handle
1774  if ($this->attributes['guid']) {
1775  _elgg_cache_entity($this);
1776  }
1777 
1778  return true;
1779  }
1780 
1781  return false;
1782  }
1783 
1790  protected function loadAdditionalSelectValues(array $data) {
1791  foreach ($data as $name => $value) {
1792  $this->setVolatileData("select:$name", $value);
1793  }
1794  }
1795 
1808  public function refresh(\stdClass $row) {
1809  if ($row instanceof \stdClass) {
1810  return $this->load($row);
1811  }
1812  return false;
1813  }
1814 
1834  public function disable($reason = "", $recursive = true) {
1835  if (!$this->guid) {
1836  return false;
1837  }
1838 
1839  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1840  return false;
1841  }
1842 
1843  if (!$this->canEdit()) {
1844  return false;
1845  }
1846 
1847  _elgg_invalidate_cache_for_entity($this->guid);
1848 
1849  if ($reason) {
1850  $this->disable_reason = $reason;
1851  }
1852 
1853  global $CONFIG;
1854  $guid = (int)$this->guid;
1855 
1856  if ($recursive) {
1859  $ia = elgg_set_ignore_access(true);
1860 
1861  $sub_entities = $this->getDatabase()->getData("SELECT * FROM {$CONFIG->dbprefix}entities
1862  WHERE (
1863  container_guid = $guid
1864  OR owner_guid = $guid
1865  OR site_guid = $guid
1866  ) AND enabled='yes'", 'entity_row_to_elggstar');
1867 
1868  if ($sub_entities) {
1869  foreach ($sub_entities as $e) {
1870  add_entity_relationship($e->guid, 'disabled_with', $this->guid);
1871  $e->disable($reason);
1872  }
1873  }
1874 
1877  }
1878 
1879  $this->disableMetadata();
1880  $this->disableAnnotations();
1881 
1882  $res = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1883  SET enabled = 'no'
1884  WHERE guid = $guid");
1885 
1886  if ($res) {
1887  $this->attributes['enabled'] = 'no';
1888  _elgg_services()->events->trigger('disable:after', $this->type, $this);
1889  }
1890 
1891  return $res;
1892  }
1893 
1904  public function enable($recursive = true) {
1905  $guid = (int)$this->guid;
1906  if (!$guid) {
1907  return false;
1908  }
1909 
1910  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1911  return false;
1912  }
1913 
1914  if (!$this->canEdit()) {
1915  return false;
1916  }
1917 
1918  global $CONFIG;
1919 
1920  // Override access only visible entities
1921  $old_access_status = access_get_show_hidden_status();
1923 
1924  $result = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1925  SET enabled = 'yes'
1926  WHERE guid = $guid");
1927 
1928  $this->deleteMetadata('disable_reason');
1929  $this->enableMetadata();
1930  $this->enableAnnotations();
1931 
1932  if ($recursive) {
1933  $disabled_with_it = elgg_get_entities_from_relationship(array(
1934  'relationship' => 'disabled_with',
1935  'relationship_guid' => $guid,
1936  'inverse_relationship' => true,
1937  'limit' => 0,
1938  ));
1939 
1940  foreach ($disabled_with_it as $e) {
1941  $e->enable();
1942  remove_entity_relationship($e->guid, 'disabled_with', $guid);
1943  }
1944  }
1945 
1946  access_show_hidden_entities($old_access_status);
1947 
1948  if ($result) {
1949  $this->attributes['enabled'] = 'yes';
1950  _elgg_services()->events->trigger('enable:after', $this->type, $this);
1951  }
1952 
1953  return $result;
1954  }
1955 
1961  public function isEnabled() {
1962  return $this->enabled == 'yes';
1963  }
1964 
1982  public function delete($recursive = true) {
1983  global $CONFIG;
1984 
1985  $guid = $this->guid;
1986  if (!$guid) {
1987  return false;
1988  }
1989 
1990  // first check if we have edit access to this entity
1991  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
1992  // which could potentially remove some content if the user didn't have access
1993  if (!$this->canEdit()) {
1994  return false;
1995  }
1996 
1997  // now trigger an event to let others know this entity is about to be deleted
1998  // so they can prevent it or take their own actions
1999  if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
2000  return false;
2001  }
2002 
2004 
2005  // If memcache is available then delete this entry from the cache
2006  static $newentity_cache;
2007  if ((!$newentity_cache) && (is_memcache_available())) {
2008  $newentity_cache = new \ElggMemcache('new_entity_cache');
2009  }
2010  if ($newentity_cache) {
2011  $newentity_cache->delete($guid);
2012  }
2013 
2014  // Delete contained owned and otherwise releated objects (depth first)
2015  if ($recursive) {
2016  // Temporarily overriding access controls
2017  $entity_disable_override = access_get_show_hidden_status();
2019  $ia = elgg_set_ignore_access(true);
2020 
2021  // @todo there was logic in the original code that ignored
2022  // entities with owner or container guids of themselves.
2023  // this should probably be prevented in \ElggEntity instead of checked for here
2024  $options = array(
2025  'wheres' => array(
2026  "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
2027  . " AND guid != $guid)"
2028  ),
2029  'limit' => 0
2030  );
2031 
2032  $batch = new \ElggBatch('elgg_get_entities', $options);
2033  $batch->setIncrementOffset(false);
2034 
2035  foreach ($batch as $e) {
2036  $e->delete(true);
2037  }
2038 
2039  access_show_hidden_entities($entity_disable_override);
2041  }
2042 
2043  $entity_disable_override = access_get_show_hidden_status();
2045  $ia = elgg_set_ignore_access(true);
2046 
2047  // Now delete the entity itself
2048  $this->deleteMetadata();
2049  $this->deleteOwnedMetadata();
2050  $this->deleteAnnotations();
2051  $this->deleteOwnedAnnotations();
2052  $this->deleteRelationships();
2053 
2054  access_show_hidden_entities($entity_disable_override);
2056 
2057  elgg_delete_river(array('subject_guid' => $guid));
2058  elgg_delete_river(array('object_guid' => $guid));
2059  elgg_delete_river(array('target_guid' => $guid));
2061 
2062  $res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = $guid");
2063  if ($res) {
2064  $sub_table = "";
2065 
2066  // Where appropriate delete the sub table
2067  switch ($this->type) {
2068  case 'object' :
2069  $sub_table = $CONFIG->dbprefix . 'objects_entity';
2070  break;
2071  case 'user' :
2072  $sub_table = $CONFIG->dbprefix . 'users_entity';
2073  break;
2074  case 'group' :
2075  $sub_table = $CONFIG->dbprefix . 'groups_entity';
2076  break;
2077  case 'site' :
2078  $sub_table = $CONFIG->dbprefix . 'sites_entity';
2079  break;
2080  }
2081 
2082  if ($sub_table) {
2083  $this->getDatabase()->deleteData("DELETE FROM $sub_table WHERE guid = $guid");
2084  }
2085  }
2086 
2087  _elgg_clear_entity_files($this);
2088 
2089  return (bool)$res;
2090  }
2091 
2095  public function toObject() {
2096  $object = $this->prepareObject(new \stdClass());
2097  $params = array('entity' => $this);
2098  $object = _elgg_services()->hooks->trigger('to:object', 'entity', $params, $object);
2099  return $object;
2100  }
2101 
2108  protected function prepareObject($object) {
2109  $object->guid = $this->guid;
2110  $object->type = $this->getType();
2111  $object->subtype = $this->getSubtype();
2112  $object->owner_guid = $this->getOwnerGUID();
2113  $object->container_guid = $this->getContainerGUID();
2114  $object->site_guid = (int)$this->site_guid;
2115  $object->time_created = date('c', $this->getTimeCreated());
2116  $object->time_updated = date('c', $this->getTimeUpdated());
2117  $object->url = $this->getURL();
2118  $object->read_access = (int)$this->access_id;
2119  return $object;
2120  }
2121 
2122  /*
2123  * LOCATABLE INTERFACE
2124  */
2125 
2131  public function getLocation() {
2132  return $this->location;
2133  }
2134 
2142  public function setLocation($location) {
2143  $this->location = $location;
2144  }
2145 
2155  public function setLatLong($lat, $long) {
2156  $this->{"geo:lat"} = $lat;
2157  $this->{"geo:long"} = $long;
2158  }
2159 
2166  public function getLatitude() {
2167  return (float)$this->{"geo:lat"};
2168  }
2169 
2176  public function getLongitude() {
2177  return (float)$this->{"geo:long"};
2178  }
2179 
2180  /*
2181  * NOTABLE INTERFACE
2182  */
2183 
2198  public function setCalendarTimeAndDuration($hour = null, $minute = null, $second = null,
2199  $day = null, $month = null, $year = null, $duration = null) {
2200  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2201 
2202  $start = mktime($hour, $minute, $second, $month, $day, $year);
2203  $end = $start + abs($duration);
2204  if (!$duration) {
2205  $end = get_day_end($day, $month, $year);
2206  }
2207 
2208  $this->calendar_start = $start;
2209  $this->calendar_end = $end;
2210 
2211  return true;
2212  }
2213 
2220  public function getCalendarStartTime() {
2221  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2222  return (int)$this->calendar_start;
2223  }
2224 
2231  public function getCalendarEndTime() {
2232  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2233  return (int)$this->calendar_end;
2234  }
2235 
2236  /*
2237  * EXPORTABLE INTERFACE
2238  */
2239 
2246  public function getExportableValues() {
2247  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
2248  return array(
2249  'guid',
2250  'type',
2251  'subtype',
2252  'time_created',
2253  'time_updated',
2254  'container_guid',
2255  'owner_guid',
2256  'site_guid'
2257  );
2258  }
2259 
2268  public function export() {
2269  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2270  $tmp = array();
2271 
2272  // Generate uuid
2273  $uuid = guid_to_uuid($this->getGUID());
2274 
2275  // Create entity
2276  $odd = new ODDEntity(
2277  $uuid,
2278  $this->attributes['type'],
2279  get_subtype_from_id($this->attributes['subtype'])
2280  );
2281 
2282  $tmp[] = $odd;
2283 
2285 
2286  // Now add its attributes
2287  foreach ($this->attributes as $k => $v) {
2288  $meta = null;
2289 
2290  if (in_array($k, $exportable_values)) {
2291  switch ($k) {
2292  case 'guid': // Dont use guid in OpenDD
2293  case 'type': // Type and subtype already taken care of
2294  case 'subtype':
2295  break;
2296 
2297  case 'time_created': // Created = published
2298  $odd->setAttribute('published', date("r", $v));
2299  break;
2300 
2301  case 'site_guid': // Container
2302  $k = 'site_uuid';
2303  $v = guid_to_uuid($v);
2304  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2305  break;
2306 
2307  case 'container_guid': // Container
2308  $k = 'container_uuid';
2309  $v = guid_to_uuid($v);
2310  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2311  break;
2312 
2313  case 'owner_guid': // Convert owner guid to uuid, this will be stored in metadata
2314  $k = 'owner_uuid';
2315  $v = guid_to_uuid($v);
2316  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2317  break;
2318 
2319  default:
2320  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2321  }
2322 
2323  // set the time of any metadata created
2324  if ($meta) {
2325  $meta->setAttribute('published', date("r", $this->time_created));
2326  $tmp[] = $meta;
2327  }
2328  }
2329  }
2330 
2331  // Now we do something a bit special.
2332  /*
2333  * This provides a rendered view of the entity to foreign sites.
2334  */
2335 
2336  elgg_set_viewtype('default');
2337  $view = elgg_view_entity($this, array('full_view' => true));
2339 
2340  $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
2341  'renderedentity', $view, 'volatile');
2342 
2343  return $tmp;
2344  }
2345 
2346  /*
2347  * IMPORTABLE INTERFACE
2348  */
2349 
2360  public function import(ODD $data) {
2361  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2362  if (!($data instanceof ODDEntity)) {
2363  throw new \InvalidParameterException("import() passed an unexpected ODD class");
2364  }
2365 
2366  // Set type and subtype
2367  $this->attributes['type'] = $data->getAttribute('class');
2368  $this->attributes['subtype'] = $data->getAttribute('subclass');
2369 
2370  // Set owner
2371  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid(); // Import as belonging to importer.
2372 
2373  // Set time
2374  $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
2375  $this->attributes['time_updated'] = time();
2376 
2377  return true;
2378  }
2379 
2380  /*
2381  * SYSTEM LOG INTERFACE
2382  */
2383 
2390  public function getSystemLogID() {
2391  return $this->getGUID();
2392  }
2393 
2401  public function getObjectFromID($id) {
2402  return get_entity($id);
2403  }
2404 
2414  public function getTags($tag_names = null) {
2415  if ($tag_names && !is_array($tag_names)) {
2416  $tag_names = array($tag_names);
2417  }
2418 
2420  $entity_tags = array();
2421 
2422  foreach ($valid_tags as $tag_name) {
2423  if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2424  continue;
2425  }
2426 
2427  if ($tags = $this->$tag_name) {
2428  // if a single tag, metadata returns a string.
2429  // if multiple tags, metadata returns an array.
2430  if (is_array($tags)) {
2431  $entity_tags = array_merge($entity_tags, $tags);
2432  } else {
2433  $entity_tags[] = $tags;
2434  }
2435  }
2436  }
2437 
2438  return $entity_tags;
2439  }
2440 }
$owner
Definition: crop.php:8
$filehandler owner_guid
Definition: crop.php:21
$view
Definition: crop.php:68
$comment access_id
Definition: save.php:52
$comment container_guid
Definition: save.php:51
if(! $collection_name) $id
Definition: add.php:17
$params
Definition: login.php:72
$type
Definition: add.php:8
$ia
Definition: upgrade.php:26
$object
Definition: upgrade.php:12
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
elgg_enable_annotations(array $options)
Enables annotations based on $options.
elgg_disable_annotations(array $options)
Disables annotations based on $options.
create_annotation($entity_guid, $name, $value, $value_type='', $owner_guid=0, $access_id=ACCESS_PRIVATE)
Create a new annotation.
Definition: annotations.php:62
elgg_get_annotations(array $options=array())
Returns annotations.
if(! $autoload_available) _elgg_services()
Definition: autoloader.php:20
$user_guid
Avatar remove action.
Definition: remove.php:6
$size
Definition: view.php:10
$user
Definition: ban.php:13
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:67
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:131
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:102
setLocation($location)
Sets the 'location' metadata for the entity.
getSites($options=array())
Gets the sites this entity is a member of.
$url_override
If set, overrides the value of getURL()
Definition: ElggEntity.php:50
getType()
Returns the entity type.
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
Definition: ElggEntity.php:610
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:197
toObject()
{Get a plain old object copy for public consumption.\stdClass}
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
$volatile
Volatile data structure for this object, allows for storage of data in-memory that isn't sync'd back ...
Definition: ElggEntity.php:79
getSystemLogID()
Return an identification for the object for storage in the system log.
clearAnnotations($name="")
Remove an annotation or all annotations for this entity.
Definition: ElggEntity.php:900
refresh(\stdClass $row)
Load new data from database into existing entity.
getCalendarStartTime()
Returns the start timestamp.
$temp_private_settings
Holds private settings until entity is saved.
Definition: ElggEntity.php:73
$temp_annotations
Holds annotations until entity is saved.
Definition: ElggEntity.php:67
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $vartype="")
Adds an annotation to an entity.
Definition: ElggEntity.php:829
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:670
removePrivateSetting($name)
Removes private setting.
Definition: ElggEntity.php:704
getSubtype()
Get the entity subtype.
getIcon($size='medium')
Returns a URL for the entity's icon.
$icon_override
Icon override, overrides the value of getIcon().
Definition: ElggEntity.php:55
getTags($tag_names=null)
Returns tags for this entity.
canEditMetadata($metadata=null, $user_guid=0)
Can a user edit metadata on this entity?
getExportableValues()
Returns an array of fields which can be exported.
enableAnnotations($name='')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:783
getContainerGUID()
Gets the container GUID for this entity.
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:252
canAnnotate($user_guid=0, $annotation_name='')
Can a user annotate an entity?
$temp_metadata
Holds metadata until entity is saved.
Definition: ElggEntity.php:61
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:569
countAnnotations($name="")
Count annotations.
Definition: ElggEntity.php:912
enable($recursive=true)
Enable the entity.
prepareObject($object)
Prepare an object copy for toObject()
setDisplayName($displayName)
Sets the title or name of this entity.
load($guid)
Loads attributes from the entities table into the object.
export()
Export this class into an array of ODD Elements containing all necessary fields.
update()
Update the entity in the database.
getDisplayName()
Get the entity's display name.
getOwnerEntity()
Gets the \ElggEntity that owns this entity.
create()
Create a new entry in the entities table.
addToSite($site)
Add this entity to a site.
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:641
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:738
getContainerEntity()
Get the container entity for this object.
save()
Save an entity.
getURL()
Gets the URL for this entity.
disable($reason="", $recursive=true)
Disable this entity.
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggEntity.php:359
getLongitude()
Return the entity's longitude.
canEdit($user_guid=0)
Can a user edit this entity?
loadAdditionalSelectValues(array $data)
Stores non-attributes from the loading of the entity as volatile data.
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
Definition: ElggEntity.php:956
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:466
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
removeRelationship($guid_two, $relationship)
Remove a relationship.
Definition: ElggEntity.php:655
isEnabled()
Is this entity enabled?
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:686
getLocation()
Gets the 'location' metadata for the entity.
getIconURL($size='medium')
Get the URL for this entity's icon.
setCalendarTimeAndDuration($hour=null, $minute=null, $second=null, $day=null, $month=null, $year=null, $duration=null)
Set the time and duration of an object.
canWriteToContainer($user_guid=0, $type='all', $subtype='all')
Can a user add an entity to this container.
clearRelationships()
Remove all relationships to and from this entity.
Definition: ElggEntity.php:624
disableMetadata($name='')
Disables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:529
getAnnotations($options=array(), $limit=50, $offset=0, $order="asc")
Gets an array of annotations.
Definition: ElggEntity.php:853
setIcon($url, $size='medium')
Set an icon override for an icon and size.
getAnnotationsSum($name)
Get the sum of integer type annotations of a given name.
Definition: ElggEntity.php:934
getGUID()
Returns the guid.
setURL($url)
Overrides the URL returned by getURL()
getContainer()
Gets the container GUID for this entity.
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:718
getObjectFromID($id)
For a given ID, return the object associated with it.
isFullyLoaded()
Tests to see whether the object has been fully loaded.
disableAnnotations($name='')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:762
getCalendarEndTime()
Returns the end timestamp.
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
Definition: ElggEntity.php:945
setContainerGUID($container_guid)
Set the container for this object.
removeFromSite($site)
Remove this entity from a site.
getAnnotationsAvg($name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:923
enableMetadata($name='')
Enables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:550
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:589
__clone()
Clone an entity.
Definition: ElggEntity.php:150
setContainer($container_guid)
Set the container for this object.
getOwner()
Return the guid of the entity's owner.
getOwnerGUID()
Get the guid of the entity's owner.
setMetadata($name, $value, $value_type='', $multiple=false, $owner_guid=0, $access_id=null)
Set metadata on this entity.
Definition: ElggEntity.php:387
getLatitude()
Return the entity's latitude.
countComments()
Count the number of comments attached to this entity.
Definition: ElggEntity.php:966
clearMetadata($name='')
Remove metadata.
Definition: ElggEntity.php:517
getAccessID()
Returns the access_id.
getEntitiesFromRelationship($options=array(), $inverse=false, $limit=50, $offset=0)
Gets an array of entities with a relationship to this entity.
Definition: ElggEntity.php:996
getMetadata($name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:298
deleteOwnedMetadata($name=null)
Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
Definition: ElggEntity.php:491
setLatLong($lat, $long)
Set latitude and longitude metadata tags for a given entity.
canComment($user_guid=0)
Can a user comment on an entity?
Elgg Object.
Definition: ElggObject.php:22
Definition: ODD.php:9
$owner_guid
$CONFIG site_guid
The guid of the current site object.
Definition: config.php:122
$time_created
Definition: online.php:16
$exportable_values
Definition: entity.php:23
$metadata
Definition: entity.php:19
$r
$guid
Removes an admin notice.
$row
events($event="", $object_type="", $function="", $priority=500, $call=false, $object=null)
Deprecated events core function.
get_day_end($day=null, $month=null, $year=null)
Return a timestamp for the end of a given day (defaults today).
guid_to_uuid($guid)
Generate a UUID from a given GUID.
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:2059
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1349
const ACCESS_PRIVATE
Definition: elgglib.php:2046
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1055
const ACCESS_DEFAULT
Definition: elgglib.php:2045
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:170
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:157
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
Definition: access.php:43
sanitise_string($string)
Wrapper function for alternate English spelling (.
Definition: database.php:150
elgg_enable_metadata(array $options)
Enables metadata based on $options.
Definition: metadata.php:187
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
elgg_get_metadata(array $options=array())
Returns metadata.
Definition: metadata.php:143
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:158
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
elgg_disable_metadata(array $options)
Disables metadata based on $options.
Definition: metadata.php:171
update_river_access_by_object($object_guid, $access_id)
Sets the access ID on river items for a particular object.
Definition: river.php:700
elgg_delete_river(array $options=array())
Delete river items.
Definition: river.php:162
elgg_get_registered_tag_metadata_names()
Returns an array of valid metadata names for tags.
Definition: tags.php:229
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an \ElggEntity and optionally for type and subtype.
Definition: entities.php:921
_elgg_cache_entity(\ElggEntity $entity)
Cache an entity.
Definition: entities.php:92
_elgg_disable_caching_for_entity($guid)
Remove this entity from the entity cache and make sure it is not re-added.
Definition: entities.php:35
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382
_elgg_invalidate_cache_for_entity($guid)
Invalidate this class's entry in the cache.
Definition: entities.php:63
_elgg_enable_caching_for_entity($guid)
Allow this entity to be stored in the entity cache.
Definition: entities.php:49
get_subtype_from_id($subtype_id)
Gets the denormalized string for a given subtype ID.
Definition: entities.php:169
get_entity_as_row($guid)
Returns a database row from the entities table.
Definition: entities.php:352
can_write_to_container($user_guid=0, $container_guid=0, $type='all', $subtype='all')
Determine if a given user can write to an entity container.
Definition: entities.php:299
add_subtype($type, $subtype, $class="")
Register \ElggEntities with a certain type and subtype to be loaded as a specific class.
Definition: entities.php:248
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:490
$url
Definition: exceptions.php:24
_elgg_clear_entity_files($entity)
Removes all entity files.
Definition: filestore.php:407
$value
Definition: longtext.php:29
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:178
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
$tags
Definition: summary.php:41
$data
Definition: opendd.php:13
$return
Definition: opendd.php:15
elgg_normalize_url($url)
Definition: output.php:311
$options
Definition: index.php:14
$subtype
Definition: river.php:12
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
remove_all_private_settings($entity_guid)
Deletes all private settings for an entity.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
set_private_setting($entity_guid, $name, $value)
Sets a private setting for an entity.
remove_entity_relationships($guid, $relationship="", $inverse_relationship=false, $type='')
Removes all relationships originating from a particular entity.
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
$key
Definition: summary.php:34
global $CONFIG
$limit
Definition: userpicker.php:33
get_user($guid)
Get a user object from a GUID.
Definition: users.php:87
list style type
Definition: admin.php:747
$e
Definition: metadata.php:12
$hidden
Definition: save.php:13
$container
Definition: access.php:30
elgg_view_entity(\ElggEntity $entity, $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:788
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:70