Elgg  Version 1.9
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_get_logged_in_user_guid();
110  $this->attributes['container_guid'] = elgg_get_logged_in_user_guid();
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_log("Failed to clone entity with GUID $this->guid", "ERROR");
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_get_metadata_cache();
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  ));
332 
333  $value = null;
334 
335  if ($md && !is_array($md)) {
336  $value = $md->value;
337  } elseif (count($md) == 1) {
338  $value = $md[0]->value;
339  } else if ($md && is_array($md)) {
341  }
342 
343  $cache->save($guid, $name, $value);
344 
345  return $value;
346  }
347 
358  public function __unset($name) {
359  if (array_key_exists($name, $this->attributes)) {
360  $this->attributes[$name] = "";
361  } else {
362  $this->deleteMetadata($name);
363  }
364  }
365 
386  public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) {
387 
388  // normalize value to an array that we will loop over
389  // remove indexes if value already an array.
390  if (is_array($value)) {
391  $value = array_values($value);
392  } else {
393  $value = array($value);
394  }
395 
396  // saved entity. persist md to db.
397  if ($this->guid) {
398  // if overwriting, delete first.
399  if (!$multiple) {
400  $options = array(
401  'guid' => $this->getGUID(),
402  'metadata_name' => $name,
403  'limit' => 0
404  );
405  // @todo in 1.9 make this return false if can't add metadata
406  // https://github.com/elgg/elgg/issues/4520
407  //
408  // need to remove access restrictions right now to delete
409  // because this is the expected behavior
410  $ia = elgg_set_ignore_access(true);
411  if (false === elgg_delete_metadata($options)) {
412  return false;
413  }
415  }
416 
417  $owner_guid = (int)$owner_guid;
418  $access_id = ($access_id === null) ? $this->getAccessId() : (int)$access_id;
420 
421  // add new md
422  $result = true;
423  foreach ($value as $value_tmp) {
424  // at this point $value is appended because it was cleared above if needed.
425  $md_id = create_metadata($this->getGUID(), $name, $value_tmp, $value_type,
426  $owner_guid, $access_id, true);
427  if (!$md_id) {
428  return false;
429  }
430  }
431 
432  return $result;
433  } else {
434  // unsaved entity. store in temp array
435 
436  // returning single entries instead of an array of 1 element is decided in
437  // getMetaData(), just like pulling from the db.
438 
439  if ($owner_guid != 0 || $access_id !== null) {
440  $msg = "owner guid and access id cannot be used in ElggEntity::setMetadata() until entity is saved.";
441  throw new InvalidArgumentException($msg);
442  }
443 
444  // if overwrite, delete first
445  if (!$multiple || !isset($this->temp_metadata[$name])) {
446  $this->temp_metadata[$name] = array();
447  }
448 
449  // add new md
450  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
451  return true;
452  }
453  }
454 
465  public function deleteMetadata($name = null) {
466 
467  if (!$this->guid) {
468  return false;
469  }
470 
471  $options = array(
472  'guid' => $this->guid,
473  'limit' => 0
474  );
475  if ($name) {
476  $options['metadata_name'] = $name;
477  }
478 
480  }
481 
490  public function deleteOwnedMetadata($name = null) {
491  // access is turned off for this because they might
492  // no longer have access to an entity they created metadata on.
493  $ia = elgg_set_ignore_access(true);
494  $options = array(
495  'metadata_owner_guid' => $this->guid,
496  'limit' => 0
497  );
498  if ($name) {
499  $options['metadata_name'] = $name;
500  }
501 
504  return $r;
505  }
506 
516  public function clearMetadata($name = '') {
517  elgg_deprecated_notice('ElggEntity->clearMetadata() is deprecated by ->deleteMetadata()', 1.8);
518  return $this->deleteMetadata($name);
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 
623  public function clearRelationships() {
624  elgg_deprecated_notice('ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8);
625  return $this->deleteRelationships();
626  }
627 
640  public function addRelationship($guid_two, $relationship) {
641  return add_entity_relationship($this->getGUID(), $relationship, $guid_two);
642  }
643 
654  public function removeRelationship($guid_two, $relationship) {
655  return remove_entity_relationship($this->getGUID(), $relationship, $guid_two);
656  }
657 
669  public function setPrivateSetting($name, $value) {
670  if ((int) $this->guid > 0) {
671  return set_private_setting($this->getGUID(), $name, $value);
672  } else {
673  $this->temp_private_settings[$name] = $value;
674  return true;
675  }
676  }
677 
685  public function getPrivateSetting($name) {
686  if ((int) ($this->guid) > 0) {
687  return get_private_setting($this->getGUID(), $name);
688  } else {
689  if (isset($this->temp_private_settings[$name])) {
690  return $this->temp_private_settings[$name];
691  }
692  }
693  return null;
694  }
695 
703  public function removePrivateSetting($name) {
704  return remove_private_setting($this->getGUID(), $name);
705  }
706 
717  public function deleteAnnotations($name = null) {
718  $options = array(
719  'guid' => $this->guid,
720  'limit' => 0
721  );
722  if ($name) {
723  $options['annotation_name'] = $name;
724  }
725 
727  }
728 
737  public function deleteOwnedAnnotations($name = null) {
738  // access is turned off for this because they might
739  // no longer have access to an entity they created annotations on.
740  $ia = elgg_set_ignore_access(true);
741  $options = array(
742  'annotation_owner_guid' => $this->guid,
743  'limit' => 0
744  );
745  if ($name) {
746  $options['annotation_name'] = $name;
747  }
748 
751  return $r;
752  }
753 
761  public function disableAnnotations($name = '') {
762  $options = array(
763  'guid' => $this->guid,
764  'limit' => 0
765  );
766  if ($name) {
767  $options['annotation_name'] = $name;
768  }
769 
771  }
772 
782  public function enableAnnotations($name = '') {
783  $options = array(
784  'guid' => $this->guid,
785  'limit' => 0
786  );
787  if ($name) {
788  $options['annotation_name'] = $name;
789  }
790 
792  }
793 
801  private function getAnnotationCalculation($name, $calculation) {
802  $options = array(
803  'guid' => $this->getGUID(),
804  'annotation_name' => $name,
805  'annotation_calculation' => $calculation
806  );
807 
809  }
810 
827  public function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_guid = 0, $vartype = "") {
828  if ((int) $this->guid > 0) {
829  return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_guid, $access_id);
830  } else {
831  $this->temp_annotations[$name] = $value;
832  }
833  return true;
834  }
835 
851  public function getAnnotations($options = array(), $limit = 50, $offset = 0, $order = "asc") {
852  if (!is_array($options)) {
853  elgg_deprecated_notice("ElggEntity::getAnnotations() takes an array of options.", 1.9);
854  }
855 
856  if ((int) ($this->guid) > 0) {
857  if (!is_array($options)) {
858  $options = array(
859  'guid' => $this->guid,
860  'annotation_name' => $options,
861  'limit' => $limit,
862  'offset' => $offset,
863  );
864 
865  if ($order != 'asc') {
866  $options['reverse_order_by'] = true;
867  }
868  } else {
869  $options['guid'] = $this->guid;
870  }
871 
873  } else {
874  if (!is_array($options)) {
875  $name = $options;
876  } else {
877  $name = elgg_extract('annotation_name', $options, '');
878  }
879 
880  if (isset($this->temp_annotations[$name])) {
881  return array($this->temp_annotations[$name]);
882  }
883  }
884 
885  return array();
886  }
887 
898  public function clearAnnotations($name = "") {
899  elgg_deprecated_notice('ElggEntity->clearAnnotations() is deprecated by ->deleteAnnotations()', 1.8);
900  return $this->deleteAnnotations($name);
901  }
902 
910  public function countAnnotations($name = "") {
911  return $this->getAnnotationCalculation($name, 'count');
912  }
913 
921  public function getAnnotationsAvg($name) {
922  return $this->getAnnotationCalculation($name, 'avg');
923  }
924 
932  public function getAnnotationsSum($name) {
933  return $this->getAnnotationCalculation($name, 'sum');
934  }
935 
943  public function getAnnotationsMin($name) {
944  return $this->getAnnotationCalculation($name, 'min');
945  }
946 
954  public function getAnnotationsMax($name) {
955  return $this->getAnnotationCalculation($name, 'max');
956  }
957 
964  public function countComments() {
965  $params = array('entity' => $this);
966  $num = elgg_trigger_plugin_hook('comments:count', $this->getType(), $params);
967 
968  if (is_int($num)) {
969  return $num;
970  } else {
971  return elgg_get_entities(array(
972  'type' => 'object',
973  'subtype' => 'comment',
974  'container_guid' => $this->getGUID(),
975  'count' => true,
976  ));
977  }
978  }
979 
993  public function getEntitiesFromRelationship($options = array(), $inverse = false, $limit = 50, $offset = 0) {
994  if (is_array($options)) {
995  $options['relationship_guid'] = $this->getGUID();
997  } else {
998  elgg_deprecated_notice("ElggEntity::getEntitiesFromRelationship takes an options array", 1.9);
1000  'relationship' => $options,
1001  'relationship_guid' => $this->getGUID(),
1002  'inverse_relationship' => $inverse,
1003  'limit' => $limit,
1004  'offset' => $offset
1005  ));
1006  }
1007  }
1008 
1017  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
1019  'relationship' => $relationship,
1020  'relationship_guid' => $this->getGUID(),
1021  'inverse_relationship' => $inverse_relationship,
1022  'count' => true
1023  ));
1024  }
1025 
1036  public function canEdit($user_guid = 0) {
1037  $user_guid = (int)$user_guid;
1039  if (!$user) {
1041  }
1042 
1043  $return = false;
1044 
1045  // Test user if possible - should default to false unless a plugin hook says otherwise
1046  if ($user) {
1047  if ($this->getOwnerGUID() == $user->getGUID()) {
1048  $return = true;
1049  }
1050 
1051  if ($this->getContainerGUID() == $user->getGUID()) {
1052  $return = true;
1053  }
1054 
1055  if ($this->getGUID() == $user->getGUID()) {
1056  $return = true;
1057  }
1058 
1059  $container = $this->getContainerEntity();
1060  if ($container && $container->canEdit($user->getGUID())) {
1061  $return = true;
1062  }
1063  }
1064 
1065  $params = array('entity' => $this, 'user' => $user);
1066  return elgg_trigger_plugin_hook('permissions_check', $this->type, $params, $return);
1067  }
1068 
1084  public function canEditMetadata($metadata = null, $user_guid = 0) {
1085  if (!$this->guid) {
1086  // @todo cannot edit metadata on unsaved entity?
1087  return false;
1088  }
1089 
1090  if ($user_guid) {
1092  if (!$user) {
1093  return false;
1094  }
1095  } else {
1097  $user_guid = $user->guid;
1098  }
1099 
1100  $return = null;
1101 
1102  // if metadata is not owned or owned by the user, then can edit
1103  if ($metadata && ($metadata->owner_guid == 0 || $metadata->owner_guid == $user_guid)) {
1104  $return = true;
1105  }
1106 
1107  if (is_null($return)) {
1108  $return = $this->canEdit($user_guid);
1109  }
1110 
1111  // metadata and user may be null
1112  $params = array('entity' => $this, 'user' => $user, 'metadata' => $metadata);
1113  return elgg_trigger_plugin_hook('permissions_check:metadata', $this->type, $params, $return);
1114  }
1115 
1126  public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
1127  return can_write_to_container($user_guid, $this->guid, $type, $subtype);
1128  }
1129 
1140  public function canComment($user_guid = 0) {
1141  if ($user_guid == 0) {
1143  }
1145 
1146  // By default, we don't take a position of whether commenting is allowed
1147  // because it is handled by the subclasses of ElggEntity
1148  $params = array('entity' => $this, 'user' => $user);
1149  return elgg_trigger_plugin_hook('permissions_check:comment', $this->type, $params, null);
1150  }
1151 
1166  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1167  if ($user_guid == 0) {
1169  }
1171 
1172  $return = true;
1173  if (!$user) {
1174  $return = false;
1175  }
1176 
1177  $params = array(
1178  'entity' => $this,
1179  'user' => $user,
1180  'annotation_name' => $annotation_name,
1181  );
1182  return elgg_trigger_plugin_hook('permissions_check:annotate', $this->type, $params, $return);
1183  }
1184 
1190  public function getAccessID() {
1191  return $this->access_id;
1192  }
1193 
1199  public function getGUID() {
1200  return $this->guid;
1201  }
1202 
1208  public function getType() {
1209  return $this->type;
1210  }
1211 
1217  public function getSubtype() {
1218  // If this object hasn't been saved, then return the subtype string.
1219  if ($this->attributes['guid']) {
1220  return get_subtype_from_id($this->attributes['subtype']);
1221  }
1222  return $this->attributes['subtype'];
1223  }
1224 
1230  public function getOwnerGUID() {
1231  return (int)$this->owner_guid;
1232  }
1233 
1240  public function getOwner() {
1241  elgg_deprecated_notice("ElggEntity::getOwner deprecated for ElggEntity::getOwnerGUID", 1.8);
1242  return $this->getOwnerGUID();
1243  }
1244 
1250  public function getOwnerEntity() {
1251  return get_entity($this->owner_guid);
1252  }
1253 
1261  public function setContainerGUID($container_guid) {
1262  return $this->container_guid = (int)$container_guid;
1263  }
1264 
1273  public function setContainer($container_guid) {
1274  elgg_deprecated_notice("ElggObject::setContainer deprecated for ElggEntity::setContainerGUID", 1.8);
1275  return $this->setContainerGUID('container_guid', $container_guid);
1276  }
1277 
1283  public function getContainerGUID() {
1284  return (int)$this->container_guid;
1285  }
1286 
1293  public function getContainer() {
1294  elgg_deprecated_notice("ElggObject::getContainer deprecated for ElggEntity::getContainerGUID", 1.8);
1295  return $this->getContainerGUID();
1296  }
1297 
1304  public function getContainerEntity() {
1305  return get_entity($this->getContainerGUID());
1306  }
1307 
1313  public function getTimeUpdated() {
1314  return $this->time_updated;
1315  }
1316 
1325  public function getURL() {
1326 
1327  $url = "";
1328 
1329  // @todo remove when elgg_register_entity_url_handler() has been removed
1330  if ($this->guid) {
1331  global $CONFIG;
1332  if (isset($CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1333  $function = $CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()];
1334  if (is_callable($function)) {
1335  $url = call_user_func($function, $this);
1336  }
1337  } elseif (isset($CONFIG->entity_url_handler[$this->getType()]['all'])) {
1338  $function = $CONFIG->entity_url_handler[$this->getType()]['all'];
1339  if (is_callable($function)) {
1340  $url = call_user_func($function, $this);
1341  }
1342  } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
1343  $function = $CONFIG->entity_url_handler['all']['all'];
1344  if (is_callable($function)) {
1345  $url = call_user_func($function, $this);
1346  }
1347  }
1348 
1349  if ($url) {
1351  }
1352  }
1353 
1354  $type = $this->getType();
1355  $params = array('entity' => $this);
1356  $url = elgg_trigger_plugin_hook('entity:url', $type, $params, $url);
1357 
1358  // @todo remove when ElggEntity::setURL() has been removed
1359  if (!empty($this->url_override)) {
1361  }
1362 
1363  return elgg_normalize_url($url);
1364  }
1365 
1376  public function setURL($url) {
1377  elgg_deprecated_notice('ElggEntity::setURL() has been replaced by the "entity:url" plugin hook', 1.9);
1378  $this->url_override = $url;
1379  return $url;
1380  }
1381 
1393  public function getIconURL($size = 'medium') {
1395 
1396  if (isset($this->icon_override[$size])) {
1397  elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
1398  return $this->icon_override[$size];
1399  }
1400 
1401  $type = $this->getType();
1402  $params = array(
1403  'entity' => $this,
1404  'size' => $size,
1405  );
1406 
1407  $url = elgg_trigger_plugin_hook('entity:icon:url', $type, $params, null);
1408  if ($url == null) {
1409  $url = "_graphics/icons/default/$size.png";
1410  }
1411 
1412  return elgg_normalize_url($url);
1413  }
1414 
1423  public function getIcon($size = 'medium') {
1424  elgg_deprecated_notice("getIcon() deprecated by getIconURL()", 1.8);
1425  return $this->getIconURL($size);
1426  }
1427 
1439  public function setIcon($url, $size = 'medium') {
1440  elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
1441 
1444 
1445  if (!$this->icon_override) {
1446  $this->icon_override = array();
1447  }
1448  $this->icon_override[$size] = $url;
1449 
1450  return true;
1451  }
1452 
1464  public function addToSite($site) {
1465  if (!elgg_instanceof($site, 'site')) {
1466  return false;
1467  }
1468 
1469  return $site->addEntity($this);
1470  }
1471 
1482  public function removeFromSite($site) {
1483  if (!elgg_instanceof($site, 'site')) {
1484  return false;
1485  }
1486 
1487  return $site->removeEntity($this);
1488  }
1489 
1502  public function getSites($options = array()) {
1503  $options['relationship'] = 'member_of_site';
1504  $options['relationship_guid'] = $this->guid;
1505  $options['inverse_relationship'] = false;
1506  if (!isset($options['site_guid']) || !isset($options['site_guids'])) {
1507  $options['site_guids'] = ELGG_ENTITIES_ANY_VALUE;
1508  }
1509 
1511  }
1512 
1518  public function isFullyLoaded() {
1519  return ! ($this->tables_loaded < $this->tables_split);
1520  }
1521 
1529  public function save() {
1530  $guid = $this->getGUID();
1531  if ($guid > 0) {
1532  return $this->update();
1533  } else {
1534  $guid = $this->create();
1535  if ($guid) {
1536  if (elgg_trigger_event('create', $this->type, $this)) {
1537  return $guid;
1538  } else {
1539  // plugins that return false to event don't need to override the access system
1540  $ia = elgg_set_ignore_access(true);
1541  $this->delete();
1543  }
1544  }
1545  }
1546 
1547  return false;
1548  }
1549 
1563  protected function create() {
1564  global $CONFIG;
1565 
1566  // Using attribute array directly; get function does something special!
1567  $type = $this->getDatabase()->sanitizeString($this->attributes['type']);
1568  if ($type == "") {
1569  throw new InvalidParameterException("Entity type must be set.");
1570  }
1571 
1572  $subtype = $this->attributes['subtype'];
1573  $subtype_id = add_subtype($type, $subtype);
1574  $owner_guid = (int)$this->attributes['owner_guid'];
1575  $access_id = (int)$this->attributes['access_id'];
1576  $now = (string)time();
1577  $time_created = isset($this->attributes['time_created']) ? (int)$this->attributes['time_created'] : $now;
1578 
1579  $site_guid = $this->attributes['site_guid'];
1580  if ($site_guid == 0) {
1581  $site_guid = $CONFIG->site_guid;
1582  }
1583  $site_guid = (int)$site_guid;
1584 
1585  $container_guid = $this->attributes['container_guid'];
1586  if ($container_guid == 0) {
1587  $container_guid = $owner_guid;
1588  }
1589  $container_guid = (int)$container_guid;
1590 
1591  if ($access_id == ACCESS_DEFAULT) {
1592  throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1593  }
1594 
1595  $owner = $this->getOwnerEntity();
1596  if ($owner && !$owner->canWriteToContainer(0, $type, $subtype)) {
1597  return false;
1598  }
1599 
1600  if ($owner_guid != $container_guid) {
1601  $container = $this->getContainerEntity();
1602  if ($container && !$container->canWriteToContainer(0, $type, $subtype)) {
1603  return false;
1604  }
1605  }
1606 
1607  $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities
1608  (type, subtype, owner_guid, site_guid, container_guid,
1609  access_id, time_created, time_updated, last_action)
1610  values
1611  ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1612  $access_id, $time_created, $now, $now)");
1613 
1614  if (!$result) {
1615  throw new IOException("Unable to save new object's base entity information!");
1616  }
1617 
1618  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1619  $this->attributes['subtype'] = (int)$subtype_id;
1620  $this->attributes['guid'] = (int)$result;
1621  $this->attributes['time_created'] = (int)$time_created;
1622  $this->attributes['time_updated'] = (int)$now;
1623  $this->attributes['last_action'] = (int)$now;
1624  $this->attributes['site_guid'] = (int)$site_guid;
1625  $this->attributes['container_guid'] = (int)$container_guid;
1626 
1627  // Save any unsaved metadata
1628  if (sizeof($this->temp_metadata) > 0) {
1629  foreach ($this->temp_metadata as $name => $value) {
1630  $this->$name = $value;
1631  }
1632 
1633  $this->temp_metadata = array();
1634  }
1635 
1636  // Save any unsaved annotations.
1637  if (sizeof($this->temp_annotations) > 0) {
1638  foreach ($this->temp_annotations as $name => $value) {
1639  $this->annotate($name, $value);
1640  }
1641 
1642  $this->temp_annotations = array();
1643  }
1644 
1645  // Save any unsaved private settings.
1646  if (sizeof($this->temp_private_settings) > 0) {
1647  foreach ($this->temp_private_settings as $name => $value) {
1648  $this->setPrivateSetting($name, $value);
1649  }
1650 
1651  $this->temp_private_settings = array();
1652  }
1653 
1654  _elgg_cache_entity($this);
1655 
1656  return $result;
1657  }
1658 
1666  protected function update() {
1667  global $CONFIG;
1668 
1669  // See #5600. This ensures canEdit() checks the BD persisted entity so it sees the
1670  // persisted owner_guid, container_guid, etc.
1671  _elgg_disable_caching_for_entity($this->guid);
1672  $persisted_entity = get_entity($this->guid);
1673  if (!$persisted_entity) {
1674  // Why worry about this case? If access control was off when the user fetched this object but
1675  // was turned back on again. Better to just bail than to turn access control off again.
1676  return false;
1677  }
1678 
1679  $allow_edit = $persisted_entity->canEdit();
1680  unset($persisted_entity);
1681 
1682  if ($allow_edit) {
1683  $allow_edit = elgg_trigger_event('update', $this->type, $this);
1684  }
1685 
1686  _elgg_enable_caching_for_entity($this->guid);
1687 
1688  if (!$allow_edit) {
1689  return false;
1690  }
1691 
1692  // See #6225. We copy these after the update event in case a handler changed one of them.
1693  $guid = (int)$this->guid;
1694  $owner_guid = (int)$this->owner_guid;
1695  $access_id = (int)$this->access_id;
1696  $container_guid = (int)$this->container_guid;
1697  $time_created = (int)$this->time_created;
1698  $time = time();
1699 
1700  if ($access_id == ACCESS_DEFAULT) {
1701  throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1702  }
1703 
1704  $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1705  set owner_guid='$owner_guid', access_id='$access_id',
1706  container_guid='$container_guid', time_created='$time_created',
1707  time_updated='$time' WHERE guid=$guid");
1708 
1709  // TODO(evan): Move this to ElggObject?
1710  if ($this instanceof ElggObject) {
1711  update_river_access_by_object($guid, $access_id);
1712  }
1713 
1714  // If memcache is available then delete this entry from the cache
1715  static $newentity_cache;
1716  if ((!$newentity_cache) && (is_memcache_available())) {
1717  $newentity_cache = new ElggMemcache('new_entity_cache');
1718  }
1719  if ($newentity_cache) {
1720  $newentity_cache->delete($guid);
1721  }
1722 
1723  if ($ret !== false) {
1724  $this->attributes['time_updated'] = $time;
1725  }
1726 
1727  _elgg_cache_entity($this);
1728 
1729  // Handle cases where there was no error BUT no rows were updated!
1730  return $ret !== false;
1731  }
1732 
1740  protected function load($guid) {
1741  if ($guid instanceof stdClass) {
1742  $row = $guid;
1743  } else {
1745  }
1746 
1747  if ($row) {
1748  // Create the array if necessary - all subclasses should test before creating
1749  if (!is_array($this->attributes)) {
1750  $this->attributes = array();
1751  }
1752 
1753  // Now put these into the attributes array as core values
1754  $objarray = (array) $row;
1755  foreach ($objarray as $key => $value) {
1756  $this->attributes[$key] = $value;
1757  }
1758 
1759  // Increment the portion counter
1760  if (!$this->isFullyLoaded()) {
1761  $this->tables_loaded++;
1762  }
1763 
1764  // guid needs to be an int https://github.com/elgg/elgg/issues/4111
1765  $this->attributes['guid'] = (int)$this->attributes['guid'];
1766 
1767  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1768  $this->attributes['subtype'] = (int)$this->attributes['subtype'];
1769 
1770  // Cache object handle
1771  if ($this->attributes['guid']) {
1772  _elgg_cache_entity($this);
1773  }
1774 
1775  return true;
1776  }
1777 
1778  return false;
1779  }
1780 
1787  protected function loadAdditionalSelectValues(array $data) {
1788  foreach ($data as $name => $value) {
1789  $this->setVolatileData("select:$name", $value);
1790  }
1791  }
1792 
1805  public function refresh(stdClass $row) {
1806  if ($row instanceof stdClass) {
1807  return $this->load($row);
1808  }
1809  return false;
1810  }
1811 
1831  public function disable($reason = "", $recursive = true) {
1832  if (!$this->guid) {
1833  return false;
1834  }
1835 
1836  if (!elgg_trigger_event('disable', $this->type, $this)) {
1837  return false;
1838  }
1839 
1840  if (!$this->canEdit()) {
1841  return false;
1842  }
1843 
1844  _elgg_invalidate_cache_for_entity($this->guid);
1845 
1846  if ($reason) {
1847  $this->disable_reason = $reason;
1848  }
1849 
1850  global $CONFIG;
1851  $guid = (int)$this->guid;
1852 
1853  if ($recursive) {
1856  $ia = elgg_set_ignore_access(true);
1857 
1858  $sub_entities = $this->getDatabase()->getData("SELECT * FROM {$CONFIG->dbprefix}entities
1859  WHERE (
1860  container_guid = $guid
1861  OR owner_guid = $guid
1862  OR site_guid = $guid
1863  ) AND enabled='yes'", 'entity_row_to_elggstar');
1864 
1865  if ($sub_entities) {
1866  foreach ($sub_entities as $e) {
1867  add_entity_relationship($e->guid, 'disabled_with', $this->guid);
1868  $e->disable($reason);
1869  }
1870  }
1871 
1874  }
1875 
1876  $this->disableMetadata();
1877  $this->disableAnnotations();
1878 
1879  $res = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1880  SET enabled = 'no'
1881  WHERE guid = $guid");
1882 
1883  if ($res) {
1884  $this->attributes['enabled'] = 'no';
1885  elgg_trigger_event('disable:after', $this->type, $this);
1886  }
1887 
1888  return $res;
1889  }
1890 
1901  public function enable($recursive = true) {
1902  $guid = (int)$this->guid;
1903  if (!$guid) {
1904  return false;
1905  }
1906 
1907  if (!elgg_trigger_event('enable', $this->type, $this)) {
1908  return false;
1909  }
1910 
1911  if (!$this->canEdit()) {
1912  return false;
1913  }
1914 
1915  global $CONFIG;
1916 
1917  // Override access only visible entities
1918  $old_access_status = access_get_show_hidden_status();
1920 
1921  $result = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1922  SET enabled = 'yes'
1923  WHERE guid = $guid");
1924 
1925  $this->deleteMetadata('disable_reason');
1926  $this->enableMetadata();
1927  $this->enableAnnotations();
1928 
1929  if ($recursive) {
1930  $disabled_with_it = elgg_get_entities_from_relationship(array(
1931  'relationship' => 'disabled_with',
1932  'relationship_guid' => $guid,
1933  'inverse_relationship' => true,
1934  'limit' => 0,
1935  ));
1936 
1937  foreach ($disabled_with_it as $e) {
1938  $e->enable();
1939  remove_entity_relationship($e->guid, 'disabled_with', $guid);
1940  }
1941  }
1942 
1943  access_show_hidden_entities($old_access_status);
1944 
1945  if ($result) {
1946  $this->attributes['enabled'] = 'yes';
1947  elgg_trigger_event('enable:after', $this->type, $this);
1948  }
1949 
1950  return $result;
1951  }
1952 
1958  public function isEnabled() {
1959  return $this->enabled == 'yes';
1960  }
1961 
1979  public function delete($recursive = true) {
1980  global $CONFIG;
1981 
1982  $guid = $this->guid;
1983  if (!$guid) {
1984  return false;
1985  }
1986 
1987  if (!elgg_trigger_event('delete', $this->type, $this)) {
1988  return false;
1989  }
1990 
1991  if (!$this->canEdit()) {
1992  return false;
1993  }
1994 
1996 
1997  // If memcache is available then delete this entry from the cache
1998  static $newentity_cache;
1999  if ((!$newentity_cache) && (is_memcache_available())) {
2000  $newentity_cache = new ElggMemcache('new_entity_cache');
2001  }
2002  if ($newentity_cache) {
2003  $newentity_cache->delete($guid);
2004  }
2005 
2006  // Delete contained owned and otherwise releated objects (depth first)
2007  if ($recursive) {
2008  // Temporary token overriding access controls
2009  // @todo Do this better.
2010  static $__RECURSIVE_DELETE_TOKEN;
2011  // Make it slightly harder to guess
2012  $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
2013 
2014  $entity_disable_override = access_get_show_hidden_status();
2016  $ia = elgg_set_ignore_access(true);
2017 
2018  // @todo there was logic in the original code that ignored
2019  // entities with owner or container guids of themselves.
2020  // this should probably be prevented in ElggEntity instead of checked for here
2021  $options = array(
2022  'wheres' => array(
2023  "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
2024  . " AND guid != $guid)"
2025  ),
2026  'limit' => 0
2027  );
2028 
2029  $batch = new ElggBatch('elgg_get_entities', $options);
2030  $batch->setIncrementOffset(false);
2031 
2032  foreach ($batch as $e) {
2033  $e->delete(true);
2034  }
2035 
2036  access_show_hidden_entities($entity_disable_override);
2037  $__RECURSIVE_DELETE_TOKEN = null;
2039  }
2040 
2041  $entity_disable_override = access_get_show_hidden_status();
2043  $ia = elgg_set_ignore_access(true);
2044 
2045  // Now delete the entity itself
2046  $this->deleteMetadata();
2047  $this->deleteOwnedMetadata();
2048  $this->deleteAnnotations();
2049  $this->deleteOwnedAnnotations();
2050  $this->deleteRelationships();
2051 
2052  access_show_hidden_entities($entity_disable_override);
2054 
2055  elgg_delete_river(array('subject_guid' => $guid));
2056  elgg_delete_river(array('object_guid' => $guid));
2057  elgg_delete_river(array('target_guid' => $guid));
2059 
2060  $res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = $guid");
2061  if ($res) {
2062  $sub_table = "";
2063 
2064  // Where appropriate delete the sub table
2065  switch ($this->type) {
2066  case 'object' :
2067  $sub_table = $CONFIG->dbprefix . 'objects_entity';
2068  break;
2069  case 'user' :
2070  $sub_table = $CONFIG->dbprefix . 'users_entity';
2071  break;
2072  case 'group' :
2073  $sub_table = $CONFIG->dbprefix . 'groups_entity';
2074  break;
2075  case 'site' :
2076  $sub_table = $CONFIG->dbprefix . 'sites_entity';
2077  break;
2078  }
2079 
2080  if ($sub_table) {
2081  $this->getDatabase()->deleteData("DELETE FROM $sub_table WHERE guid = $guid");
2082  }
2083  }
2084 
2085  return (bool)$res;
2086  }
2087 
2091  public function toObject() {
2092  $object = $this->prepareObject(new stdClass());
2093  $params = array('entity' => $this);
2094  $object = elgg_trigger_plugin_hook('to:object', 'entity', $params, $object);
2095  return $object;
2096  }
2097 
2104  protected function prepareObject($object) {
2105  $object->guid = $this->guid;
2106  $object->type = $this->getType();
2107  $object->subtype = $this->getSubtype();
2108  $object->owner_guid = $this->getOwnerGUID();
2109  $object->container_guid = $this->getContainerGUID();
2110  $object->site_guid = (int)$this->site_guid;
2111  $object->time_created = date('c', $this->getTimeCreated());
2112  $object->time_updated = date('c', $this->getTimeUpdated());
2113  $object->url = $this->getURL();
2114  $object->read_access = (int)$this->access_id;
2115  return $object;
2116  }
2117 
2118  /*
2119  * LOCATABLE INTERFACE
2120  */
2121 
2127  public function getLocation() {
2128  return $this->location;
2129  }
2130 
2138  public function setLocation($location) {
2139  $this->location = $location;
2140  }
2141 
2151  public function setLatLong($lat, $long) {
2152  $this->set('geo:lat', $lat);
2153  $this->set('geo:long', $long);
2154  }
2155 
2162  public function getLatitude() {
2163  return (float)$this->get('geo:lat');
2164  }
2165 
2172  public function getLongitude() {
2173  return (float)$this->get('geo:long');
2174  }
2175 
2176  /*
2177  * NOTABLE INTERFACE
2178  */
2179 
2194  public function setCalendarTimeAndDuration($hour = null, $minute = null, $second = null,
2195  $day = null, $month = null, $year = null, $duration = null) {
2196  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2197 
2198  $start = mktime($hour, $minute, $second, $month, $day, $year);
2199  $end = $start + abs($duration);
2200  if (!$duration) {
2201  $end = get_day_end($day, $month, $year);
2202  }
2203 
2204  $this->calendar_start = $start;
2205  $this->calendar_end = $end;
2206 
2207  return true;
2208  }
2209 
2216  public function getCalendarStartTime() {
2217  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2218  return (int)$this->calendar_start;
2219  }
2220 
2227  public function getCalendarEndTime() {
2228  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2229  return (int)$this->calendar_end;
2230  }
2231 
2232  /*
2233  * EXPORTABLE INTERFACE
2234  */
2235 
2242  public function getExportableValues() {
2243  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
2244  return array(
2245  'guid',
2246  'type',
2247  'subtype',
2248  'time_created',
2249  'time_updated',
2250  'container_guid',
2251  'owner_guid',
2252  'site_guid'
2253  );
2254  }
2255 
2264  public function export() {
2265  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2266  $tmp = array();
2267 
2268  // Generate uuid
2269  $uuid = guid_to_uuid($this->getGUID());
2270 
2271  // Create entity
2272  $odd = new ODDEntity(
2273  $uuid,
2274  $this->attributes['type'],
2275  get_subtype_from_id($this->attributes['subtype'])
2276  );
2277 
2278  $tmp[] = $odd;
2279 
2281 
2282  // Now add its attributes
2283  foreach ($this->attributes as $k => $v) {
2284  $meta = null;
2285 
2286  if (in_array($k, $exportable_values)) {
2287  switch ($k) {
2288  case 'guid': // Dont use guid in OpenDD
2289  case 'type': // Type and subtype already taken care of
2290  case 'subtype':
2291  break;
2292 
2293  case 'time_created': // Created = published
2294  $odd->setAttribute('published', date("r", $v));
2295  break;
2296 
2297  case 'site_guid': // Container
2298  $k = 'site_uuid';
2299  $v = guid_to_uuid($v);
2300  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2301  break;
2302 
2303  case 'container_guid': // Container
2304  $k = 'container_uuid';
2305  $v = guid_to_uuid($v);
2306  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2307  break;
2308 
2309  case 'owner_guid': // Convert owner guid to uuid, this will be stored in metadata
2310  $k = 'owner_uuid';
2311  $v = guid_to_uuid($v);
2312  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2313  break;
2314 
2315  default:
2316  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2317  }
2318 
2319  // set the time of any metadata created
2320  if ($meta) {
2321  $meta->setAttribute('published', date("r", $this->time_created));
2322  $tmp[] = $meta;
2323  }
2324  }
2325  }
2326 
2327  // Now we do something a bit special.
2328  /*
2329  * This provides a rendered view of the entity to foreign sites.
2330  */
2331 
2332  elgg_set_viewtype('default');
2333  $view = elgg_view_entity($this, array('full_view' => true));
2335 
2336  $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
2337  'renderedentity', $view, 'volatile');
2338 
2339  return $tmp;
2340  }
2341 
2342  /*
2343  * IMPORTABLE INTERFACE
2344  */
2345 
2356  public function import(ODD $data) {
2357  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2358  if (!($data instanceof ODDEntity)) {
2359  throw new InvalidParameterException("import() passed an unexpected ODD class");
2360  }
2361 
2362  // Set type and subtype
2363  $this->attributes['type'] = $data->getAttribute('class');
2364  $this->attributes['subtype'] = $data->getAttribute('subclass');
2365 
2366  // Set owner
2367  $this->attributes['owner_guid'] = elgg_get_logged_in_user_guid(); // Import as belonging to importer.
2368 
2369  // Set time
2370  $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
2371  $this->attributes['time_updated'] = time();
2372 
2373  return true;
2374  }
2375 
2376  /*
2377  * SYSTEM LOG INTERFACE
2378  */
2379 
2386  public function getSystemLogID() {
2387  return $this->getGUID();
2388  }
2389 
2397  public function getObjectFromID($id) {
2398  return get_entity($id);
2399  }
2400 
2410  public function getTags($tag_names = null) {
2411  if ($tag_names && !is_array($tag_names)) {
2412  $tag_names = array($tag_names);
2413  }
2414 
2416  $entity_tags = array();
2417 
2418  foreach ($valid_tags as $tag_name) {
2419  if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2420  continue;
2421  }
2422 
2423  if ($tags = $this->$tag_name) {
2424  // if a single tag, metadata returns a string.
2425  // if multiple tags, metadata returns an array.
2426  if (is_array($tags)) {
2427  $entity_tags = array_merge($entity_tags, $tags);
2428  } else {
2429  $entity_tags[] = $tags;
2430  }
2431  }
2432  }
2433 
2434  return $entity_tags;
2435  }
2436 }
_elgg_disable_caching_for_entity($guid)
Remove this entity from the entity cache and make sure it is not re-added.
Definition: entities.php:44
$tags
Definition: summary.php:41
enable($recursive=true)
Enable the entity.
$view
Definition: crop.php:68
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?
getIcon($size= 'medium')
Returns a URL for the entity&#39;s icon.
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:67
elgg_get_registered_tag_metadata_names()
Returns an array of valid metadata names for tags.
Definition: tags.php:229
elgg_disable_metadata(array $options)
Disables metadata based on $options.
Definition: metadata.php:329
getOwnerGUID()
Get the guid of the entity&#39;s owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:131
elgg_view_entity(ElggEntity $entity, $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:790
__clone()
Clone an entity.
Definition: ElggEntity.php:150
_elgg_invalidate_cache_for_entity($guid)
Invalidate this class&#39;s entry in the cache.
Definition: entities.php:72
getAnnotations($options=array(), $limit=50, $offset=0, $order="asc")
Gets an array of annotations.
Definition: ElggEntity.php:851
__get($name)
Get an attribute or metadata value.
Definition: ElggEntity.php:252
create_annotation($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE)
Create a new annotation.
Definition: annotations.php:66
loadAdditionalSelectValues(array $data)
Stores non-attributes from the loading of the entity as volatile data.
getOwnerEntity()
Gets the ElggEntity 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:703
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:761
prepareObject($object)
Prepare an object copy for toObject()
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
$size
Definition: view.php:10
deleteMetadata($name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: ElggEntity.php:465
if($show_access) if(!$custom_form_section &&!$access) $hidden
Definition: save.php:27
elgg_delete_annotations(array $options)
Deletes annotations based on $options.
countAnnotations($name="")
Count annotations.
Definition: ElggEntity.php:910
$e
Definition: metadata.php:12
setCalendarTimeAndDuration($hour=null, $minute=null, $second=null, $day=null, $month=null, $year=null, $duration=null)
Set the time and duration of an object.
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
Definition: ElggEntity.php:717
$object
Definition: upgrade.php:12
$CONFIG site_guid
The guid of the current site object.
Definition: config.php:129
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:669
initializeAttributes()
Initialize the attributes array.
Definition: ElggEntity.php:102
canWriteToContainer($user_guid=0, $type= 'all', $subtype= 'all')
Can a user add an entity to this container.
$exportable_values
Definition: entity.php:23
refresh(stdClass $row)
Load new data from database into existing entity.
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:685
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
deleteOwnedMetadata($name=null)
Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
Definition: ElggEntity.php:490
$metadata
Definition: entity.php:19
getAnnotationsMax($name)
Get the maximum of integer type annotations of a given name.
Definition: ElggEntity.php:954
countComments()
Count the number of comments attached to this entity.
Definition: ElggEntity.php:964
get_subtype_from_id($subtype_id)
Gets the denormalized string for a given subtype ID.
Definition: entities.php:194
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:386
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:737
_elgg_get_metadata_cache()
Get the global metadata cache instance.
Definition: metadata.php:849
$data
Definition: opendd.php:13
$value
Definition: longtext.php:29
$ia
Definition: upgrade.php:26
isFullyLoaded()
Tests to see whether the object has been fully loaded.
$return
Definition: opendd.php:15
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.
getCalendarStartTime()
Returns the start timestamp.
getTimeUpdated()
Returns the UNIX epoch time that this entity was last updated.
_elgg_enable_caching_for_entity($guid)
Allow this entity to be stored in the entity cache.
Definition: entities.php:58
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:1464
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:782
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:178
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
$icon_override
Icon override, overrides the value of getIcon().
Definition: ElggEntity.php:55
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:932
getSites($options=array())
Gets the sites this entity is a member of.
clearRelationships()
Remove all relationships to and from this entity.
Definition: ElggEntity.php:623
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:588
get_day_end($day=null, $month=null, $year=null)
Return a timestamp for the end of a given day (defaults today).
getContainer()
Gets the container GUID for this entity.
$params
Definition: login.php:72
$options
Definition: index.php:14
setContainerGUID($container_guid)
Set the container for this object.
removeRelationship($guid_two, $relationship)
Remove a relationship.
Definition: ElggEntity.php:654
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:692
countEntitiesFromRelationship($relationship, $inverse_relationship=false)
Gets the number of entities from a specific relationship type.
getMetadata($name)
Return the value of a piece of metadata.
Definition: ElggEntity.php:298
setContainer($container_guid)
Set the container for this object.
getEntitiesFromRelationship($options=array(), $inverse=false, $limit=50, $offset=0)
Gets an array of entities with a relationship to this entity.
Definition: ElggEntity.php:993
$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:751
getExportableValues()
Returns an array of fields which can be exported.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
Definition: entities.php:1886
getTags($tag_names=null)
Returns tags for this entity.
$limit
Definition: userpicker.php:33
add_subtype($type, $subtype, $class="")
Register ElggEntities with a certain type and subtype to be loaded as a specific class.
Definition: entities.php:331
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:70
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $vartype="")
Adds an annotation to an entity.
Definition: ElggEntity.php:827
$temp_annotations
Holds annotations until entity is saved.
Definition: ElggEntity.php:67
getVolatileData($name)
Get a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:568
$filehandler owner_guid
Definition: crop.php:21
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:356
$owner
Definition: crop.php:8
$key
Definition: summary.php:34
get_user($guid)
Get a user object from a GUID.
Definition: users.php:222
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
getAnnotationsAvg($name)
Get the average of an integer type annotation.
Definition: ElggEntity.php:921
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:69
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:449
setLocation($location)
Sets the &#39;location&#39; metadata for the entity.
setIcon($url, $size= 'medium')
Set an icon override for an icon and size.
sanitise_string($string)
Wrapper function for alternate English spelling (.
Definition: database.php:150
$user
Definition: ban.php:13
$time_created
Definition: online.php:16
const ACCESS_PRIVATE
Definition: elgglib.php:2121
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:197
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:2134
$temp_metadata
Holds metadata until entity is saved.
Definition: ElggEntity.php:61
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:777
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
canAnnotate($user_guid=0, $annotation_name= '')
Can a user annotate an entity?
elgg_enable_annotations(array $options)
Enables annotations based on $options.
clearMetadata($name= '')
Remove metadata.
Definition: ElggEntity.php:516
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
elgg global
Pointer to the global context.
Definition: elgglib.js:12
getCalendarEndTime()
Returns the end timestamp.
$type
Definition: add.php:8
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:299
isEnabled()
Is this entity enabled?
get_entity_as_row($guid)
Returns a database row from the entities table.
Definition: entities.php:502
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:640
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
guid_to_uuid($guid)
Generate a UUID from a given GUID.
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition: elgglib.php:1083
$comment access_id
Definition: save.php:52
$temp_private_settings
Holds private settings until entity is saved.
Definition: ElggEntity.php:73
getOwner()
Return the guid of the entity&#39;s owner.
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:306
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:286
elgg_get_metadata(array $options=array())
Returns metadata.
Definition: metadata.php:282
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:168
clearAnnotations($name="")
Remove an annotation or all annotations for this entity.
Definition: ElggEntity.php:898
getIconURL($size= 'medium')
Get the URL for this entity&#39;s icon.
create()
Create a new entry in the entities table.
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 &#39;location&#39; metadata for the entity.
getLatitude()
Return the entity&#39;s latitude.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
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.
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggEntity.php:358
$user_guid
Avatar remove action.
Definition: remove.php:6
const ACCESS_DEFAULT
Definition: elgglib.php:2120
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
Definition: elgglib.php:720
$subtype
Definition: river.php:10
if(!$collection_name) $id
Definition: add.php:17
getSystemLogID()
Return an identification for the object for storage in the system log.
list style type
Definition: admin.php:724
enableMetadata($name= '')
Enables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:549
disable($reason="", $recursive=true)
Disable this entity.
$container
Definition: access.php:30
_elgg_cache_entity(ElggEntity $entity)
Cache an entity.
Definition: entities.php:101
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 Object.
Definition: ElggObject.php:22
getDisplayName()
Get the entity&#39;s display name.
getAnnotationsMin($name)
Get the minimum of integer type annotations of given name.
Definition: ElggEntity.php:943
getLongitude()
Return the entity&#39;s longitude.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604
getObjectFromID($id)
For a given ID, return the object associated with it.
addToSite($site)
Add this entity to a site.
$url_override
If set, overrides the value of getURL()
Definition: ElggEntity.php:50
$comment container_guid
Definition: save.php:51
$volatile
Volatile data structure for this object, allows for storage of data in-memory that isn&#39;t sync&#39;d back ...
Definition: ElggEntity.php:79