Elgg  Version 1.11
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->isLoaded($guid)) {
318  return $cache->getSingle($guid, $name);
319  } else {
320  $cache->populateFromEntities(array($guid));
321  // in case ignore_access was on, we have to check again...
322  if ($cache->isLoaded($guid)) {
323  return $cache->getSingle($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  return $value;
345  }
346 
357  public function __unset($name) {
358  if (array_key_exists($name, $this->attributes)) {
359  $this->attributes[$name] = "";
360  } else {
361  $this->deleteMetadata($name);
362  }
363  }
364 
385  public function setMetadata($name, $value, $value_type = '', $multiple = false, $owner_guid = 0, $access_id = null) {
386 
387  // normalize value to an array that we will loop over
388  // remove indexes if value already an array.
389  if (is_array($value)) {
390  $value = array_values($value);
391  } else {
392  $value = array($value);
393  }
394 
395  // saved entity. persist md to db.
396  if ($this->guid) {
397  // if overwriting, delete first.
398  if (!$multiple) {
399  $options = array(
400  'guid' => $this->getGUID(),
401  'metadata_name' => $name,
402  'limit' => 0
403  );
404  // @todo in 1.9 make this return false if can't add metadata
405  // https://github.com/elgg/elgg/issues/4520
406  //
407  // need to remove access restrictions right now to delete
408  // because this is the expected behavior
409  $ia = elgg_set_ignore_access(true);
410  if (false === elgg_delete_metadata($options)) {
411  return false;
412  }
414  }
415 
416  $owner_guid = (int)$owner_guid;
417  $access_id = ($access_id === null) ? $this->getAccessId() : (int)$access_id;
419 
420  // add new md
421  $result = true;
422  foreach ($value as $value_tmp) {
423  // at this point $value is appended because it was cleared above if needed.
424  $md_id = create_metadata($this->getGUID(), $name, $value_tmp, $value_type,
425  $owner_guid, $access_id, true);
426  if (!$md_id) {
427  return false;
428  }
429  }
430 
431  return $result;
432  } else {
433  // unsaved entity. store in temp array
434 
435  // returning single entries instead of an array of 1 element is decided in
436  // getMetaData(), just like pulling from the db.
437 
438  if ($owner_guid != 0 || $access_id !== null) {
439  $msg = "owner guid and access id cannot be used in \ElggEntity::setMetadata() until entity is saved.";
440  throw new \InvalidArgumentException($msg);
441  }
442 
443  // if overwrite, delete first
444  if (!$multiple || !isset($this->temp_metadata[$name])) {
445  $this->temp_metadata[$name] = array();
446  }
447 
448  // add new md
449  $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
450  return true;
451  }
452  }
453 
464  public function deleteMetadata($name = null) {
465 
466  if (!$this->guid) {
467  return false;
468  }
469 
470  $options = array(
471  'guid' => $this->guid,
472  'limit' => 0
473  );
474  if ($name) {
475  $options['metadata_name'] = $name;
476  }
477 
479  }
480 
489  public function deleteOwnedMetadata($name = null) {
490  // access is turned off for this because they might
491  // no longer have access to an entity they created metadata on.
492  $ia = elgg_set_ignore_access(true);
493  $options = array(
494  'metadata_owner_guid' => $this->guid,
495  'limit' => 0
496  );
497  if ($name) {
498  $options['metadata_name'] = $name;
499  }
500 
503  return $r;
504  }
505 
515  public function clearMetadata($name = '') {
516  elgg_deprecated_notice('\ElggEntity->clearMetadata() is deprecated by ->deleteMetadata()', 1.8);
517  return $this->deleteMetadata($name);
518  }
519 
527  public function disableMetadata($name = '') {
528  $options = array(
529  'guid' => $this->guid,
530  'limit' => 0
531  );
532  if ($name) {
533  $options['metadata_name'] = $name;
534  }
535 
537  }
538 
548  public function enableMetadata($name = '') {
549  $options = array(
550  'guid' => $this->guid,
551  'limit' => 0
552  );
553  if ($name) {
554  $options['metadata_name'] = $name;
555  }
556 
558  }
559 
567  public function getVolatileData($name) {
568  if (!is_array($this->volatile)) {
569  $this->volatile = array();
570  }
571 
572  if (array_key_exists($name, $this->volatile)) {
573  return $this->volatile[$name];
574  } else {
575  return null;
576  }
577  }
578 
587  public function setVolatileData($name, $value) {
588  if (!is_array($this->volatile)) {
589  $this->volatile = array();
590  }
591 
592  $this->volatile[$name] = $value;
593  }
594 
608  public function deleteRelationships($relationship = null) {
609  $relationship = (string)$relationship;
610  $result = remove_entity_relationships($this->getGUID(), $relationship);
611  return $result && remove_entity_relationships($this->getGUID(), $relationship, true);
612  }
613 
622  public function clearRelationships() {
623  elgg_deprecated_notice('\ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8);
624  return $this->deleteRelationships();
625  }
626 
639  public function addRelationship($guid_two, $relationship) {
640  return add_entity_relationship($this->getGUID(), $relationship, $guid_two);
641  }
642 
653  public function removeRelationship($guid_two, $relationship) {
654  return remove_entity_relationship($this->getGUID(), $relationship, $guid_two);
655  }
656 
668  public function setPrivateSetting($name, $value) {
669  if ((int) $this->guid > 0) {
670  return set_private_setting($this->getGUID(), $name, $value);
671  } else {
672  $this->temp_private_settings[$name] = $value;
673  return true;
674  }
675  }
676 
684  public function getPrivateSetting($name) {
685  if ((int) ($this->guid) > 0) {
686  return get_private_setting($this->getGUID(), $name);
687  } else {
688  if (isset($this->temp_private_settings[$name])) {
689  return $this->temp_private_settings[$name];
690  }
691  }
692  return null;
693  }
694 
702  public function removePrivateSetting($name) {
703  return remove_private_setting($this->getGUID(), $name);
704  }
705 
716  public function deleteAnnotations($name = null) {
717  $options = array(
718  'guid' => $this->guid,
719  'limit' => 0
720  );
721  if ($name) {
722  $options['annotation_name'] = $name;
723  }
724 
726  }
727 
736  public function deleteOwnedAnnotations($name = null) {
737  // access is turned off for this because they might
738  // no longer have access to an entity they created annotations on.
739  $ia = elgg_set_ignore_access(true);
740  $options = array(
741  'annotation_owner_guid' => $this->guid,
742  'limit' => 0
743  );
744  if ($name) {
745  $options['annotation_name'] = $name;
746  }
747 
750  return $r;
751  }
752 
760  public function disableAnnotations($name = '') {
761  $options = array(
762  'guid' => $this->guid,
763  'limit' => 0
764  );
765  if ($name) {
766  $options['annotation_name'] = $name;
767  }
768 
770  }
771 
781  public function enableAnnotations($name = '') {
782  $options = array(
783  'guid' => $this->guid,
784  'limit' => 0
785  );
786  if ($name) {
787  $options['annotation_name'] = $name;
788  }
789 
791  }
792 
800  private function getAnnotationCalculation($name, $calculation) {
801  $options = array(
802  'guid' => $this->getGUID(),
803  'distinct' => false,
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_services()->hooks->trigger('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  'distinct' => false,
977  ));
978  }
979  }
980 
994  public function getEntitiesFromRelationship($options = array(), $inverse = false, $limit = 50, $offset = 0) {
995  if (is_array($options)) {
996  $options['relationship_guid'] = $this->getGUID();
998  } else {
999  elgg_deprecated_notice("\ElggEntity::getEntitiesFromRelationship takes an options array", 1.9);
1001  'relationship' => $options,
1002  'relationship_guid' => $this->getGUID(),
1003  'inverse_relationship' => $inverse,
1004  'limit' => $limit,
1005  'offset' => $offset
1006  ));
1007  }
1008  }
1009 
1018  public function countEntitiesFromRelationship($relationship, $inverse_relationship = false) {
1020  'relationship' => $relationship,
1021  'relationship_guid' => $this->getGUID(),
1022  'inverse_relationship' => $inverse_relationship,
1023  'count' => true
1024  ));
1025  }
1026 
1037  public function canEdit($user_guid = 0) {
1038  $user_guid = (int)$user_guid;
1040  if (!$user) {
1041  $user = _elgg_services()->session->getLoggedInUser();
1042  }
1043 
1044  $return = false;
1045 
1046  // Test user if possible - should default to false unless a plugin hook says otherwise
1047  if ($user) {
1048  if ($this->getOwnerGUID() == $user->getGUID()) {
1049  $return = true;
1050  }
1051 
1052  if ($this->getContainerGUID() == $user->getGUID()) {
1053  $return = true;
1054  }
1055 
1056  if ($this->getGUID() == $user->getGUID()) {
1057  $return = true;
1058  }
1059 
1060  $container = $this->getContainerEntity();
1061  if ($container && $container->canEdit($user->getGUID())) {
1062  $return = true;
1063  }
1064  }
1065 
1066  $params = array('entity' => $this, 'user' => $user);
1067  return _elgg_services()->hooks->trigger('permissions_check', $this->type, $params, $return);
1068  }
1069 
1081  public function canDelete($user_guid = 0) {
1082  $user_guid = (int) $user_guid;
1083 
1084  if (!$user_guid) {
1085  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1086  }
1087 
1088  // need to ignore access and show hidden entities for potential hidden/disabled users
1089  $ia = elgg_set_ignore_access(true);
1090  $show_hidden = access_show_hidden_entities(true);
1091 
1092  $user = _elgg_services()->entityTable->get($user_guid, 'user');
1093 
1095  access_show_hidden_entities($show_hidden);
1096 
1097  if ($user_guid & !$user) {
1098  // requested to check access for a specific user_guid, but there is no user entity, so return false
1099  $message = _elgg_services()->translator->translate('entity:can_delete:invaliduser', array($user_guid));
1100  _elgg_services()->logger->warning($message);
1101 
1102  return false;
1103  }
1104 
1105  $return = $this->canEdit($user_guid);
1106 
1107  $params = array('entity' => $this, 'user' => $user);
1108  return _elgg_services()->hooks->trigger('permissions_check:delete', $this->type, $params, $return);
1109  }
1110 
1126  public function canEditMetadata($metadata = null, $user_guid = 0) {
1127  if (!$this->guid) {
1128  // @todo cannot edit metadata on unsaved entity?
1129  return false;
1130  }
1131 
1132  if ($user_guid) {
1134  if (!$user) {
1135  return false;
1136  }
1137  } else {
1138  $user = _elgg_services()->session->getLoggedInUser();
1139  $user_guid = $user->guid;
1140  }
1141 
1142  $return = null;
1143 
1144  // if metadata is not owned or owned by the user, then can edit
1145  if ($metadata && ($metadata->owner_guid == 0 || $metadata->owner_guid == $user_guid)) {
1146  $return = true;
1147  }
1148 
1149  if (is_null($return)) {
1150  $return = $this->canEdit($user_guid);
1151  }
1152 
1153  // metadata and user may be null
1154  $params = array('entity' => $this, 'user' => $user, 'metadata' => $metadata);
1155  return _elgg_services()->hooks->trigger('permissions_check:metadata', $this->type, $params, $return);
1156  }
1157 
1168  public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
1169  return can_write_to_container($user_guid, $this->guid, $type, $subtype);
1170  }
1171 
1182  public function canComment($user_guid = 0) {
1183  if ($user_guid == 0) {
1184  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1185  }
1187 
1188  // By default, we don't take a position of whether commenting is allowed
1189  // because it is handled by the subclasses of \ElggEntity
1190  $params = array('entity' => $this, 'user' => $user);
1191  return _elgg_services()->hooks->trigger('permissions_check:comment', $this->type, $params, null);
1192  }
1193 
1208  public function canAnnotate($user_guid = 0, $annotation_name = '') {
1209  if ($user_guid == 0) {
1210  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
1211  }
1213 
1214  $return = true;
1215  if (!$user) {
1216  $return = false;
1217  }
1218 
1219  $params = array(
1220  'entity' => $this,
1221  'user' => $user,
1222  'annotation_name' => $annotation_name,
1223  );
1224  return _elgg_services()->hooks->trigger('permissions_check:annotate', $this->type, $params, $return);
1225  }
1226 
1232  public function getAccessID() {
1233  return $this->access_id;
1234  }
1235 
1241  public function getGUID() {
1242  return $this->guid;
1243  }
1244 
1250  public function getType() {
1251  return $this->type;
1252  }
1253 
1259  public function getSubtype() {
1260  // If this object hasn't been saved, then return the subtype string.
1261  if ($this->attributes['guid']) {
1262  return get_subtype_from_id($this->attributes['subtype']);
1263  }
1264  return $this->attributes['subtype'];
1265  }
1266 
1272  public function getOwnerGUID() {
1273  return (int)$this->owner_guid;
1274  }
1275 
1282  public function getOwner() {
1283  elgg_deprecated_notice("\ElggEntity::getOwner deprecated for \ElggEntity::getOwnerGUID", 1.8);
1284  return $this->getOwnerGUID();
1285  }
1286 
1292  public function getOwnerEntity() {
1293  return get_entity($this->owner_guid);
1294  }
1295 
1304  return $this->container_guid = (int)$container_guid;
1305  }
1306 
1315  public function setContainer($container_guid) {
1316  elgg_deprecated_notice("\ElggObject::setContainer deprecated for \ElggEntity::setContainerGUID", 1.8);
1317  return $this->setContainerGUID('container_guid', $container_guid);
1318  }
1319 
1325  public function getContainerGUID() {
1326  return (int)$this->container_guid;
1327  }
1328 
1335  public function getContainer() {
1336  elgg_deprecated_notice("\ElggObject::getContainer deprecated for \ElggEntity::getContainerGUID", 1.8);
1337  return $this->getContainerGUID();
1338  }
1339 
1346  public function getContainerEntity() {
1347  return get_entity($this->getContainerGUID());
1348  }
1349 
1355  public function getTimeUpdated() {
1356  return $this->time_updated;
1357  }
1358 
1367  public function getURL() {
1368 
1369  $url = "";
1370 
1371  // @todo remove when elgg_register_entity_url_handler() has been removed
1372  if ($this->guid) {
1373  global $CONFIG;
1374  if (isset($CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()])) {
1375  $function = $CONFIG->entity_url_handler[$this->getType()][$this->getSubtype()];
1376  if (is_callable($function)) {
1377  $url = call_user_func($function, $this);
1378  }
1379  } elseif (isset($CONFIG->entity_url_handler[$this->getType()]['all'])) {
1380  $function = $CONFIG->entity_url_handler[$this->getType()]['all'];
1381  if (is_callable($function)) {
1382  $url = call_user_func($function, $this);
1383  }
1384  } elseif (isset($CONFIG->entity_url_handler['all']['all'])) {
1385  $function = $CONFIG->entity_url_handler['all']['all'];
1386  if (is_callable($function)) {
1387  $url = call_user_func($function, $this);
1388  }
1389  }
1390 
1391  if ($url) {
1393  }
1394  }
1395 
1396  $type = $this->getType();
1397  $params = array('entity' => $this);
1398  $url = _elgg_services()->hooks->trigger('entity:url', $type, $params, $url);
1399 
1400  // @todo remove when \ElggEntity::setURL() has been removed
1401  if (!empty($this->url_override)) {
1403  }
1404 
1405  return elgg_normalize_url($url);
1406  }
1407 
1418  public function setURL($url) {
1419  elgg_deprecated_notice('\ElggEntity::setURL() has been replaced by the "entity:url" plugin hook', 1.9);
1420  $this->url_override = $url;
1421  return $url;
1422  }
1423 
1435  public function getIconURL($params = array()) {
1436  if (is_array($params)) {
1437  $size = elgg_extract('size', $params, 'medium');
1438  } else {
1439  $size = is_string($params) ? $params : 'medium';
1440  $params = array();
1441  }
1443 
1444  if (isset($this->icon_override[$size])) {
1445  elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
1446  return $this->icon_override[$size];
1447  }
1448 
1449  $params['entity'] = $this;
1450  $params['size'] = $size;
1451 
1452  $type = $this->getType();
1453 
1454  $url = _elgg_services()->hooks->trigger('entity:icon:url', $type, $params, null);
1455  if ($url == null) {
1456  $url = "_graphics/icons/default/$size.png";
1457  }
1458 
1459  return elgg_normalize_url($url);
1460  }
1461 
1470  public function getIcon($size = 'medium') {
1471  elgg_deprecated_notice("getIcon() deprecated by getIconURL()", 1.8);
1472  return $this->getIconURL($size);
1473  }
1474 
1486  public function setIcon($url, $size = 'medium') {
1487  elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
1488 
1491 
1492  if (!$this->icon_override) {
1493  $this->icon_override = array();
1494  }
1495  $this->icon_override[$size] = $url;
1496 
1497  return true;
1498  }
1499 
1511  public function addToSite($site) {
1512  if (!elgg_instanceof($site, 'site')) {
1513  return false;
1514  }
1515 
1516  return $site->addEntity($this);
1517  }
1518 
1529  public function removeFromSite($site) {
1530  if (!elgg_instanceof($site, 'site')) {
1531  return false;
1532  }
1533 
1534  return $site->removeEntity($this);
1535  }
1536 
1549  public function getSites($options = array()) {
1550  $options['relationship'] = 'member_of_site';
1551  $options['relationship_guid'] = $this->guid;
1552  $options['inverse_relationship'] = false;
1553  if (!isset($options['site_guid']) || !isset($options['site_guids'])) {
1554  $options['site_guids'] = ELGG_ENTITIES_ANY_VALUE;
1555  }
1556 
1558  }
1559 
1565  public function isFullyLoaded() {
1566  return ! ($this->tables_loaded < $this->tables_split);
1567  }
1568 
1576  public function save() {
1577  $guid = $this->getGUID();
1578  if ($guid > 0) {
1579  return $this->update();
1580  } else {
1581  $guid = $this->create();
1582  if ($guid) {
1583  if (_elgg_services()->events->trigger('create', $this->type, $this)) {
1584  return $guid;
1585  } else {
1586  // plugins that return false to event don't need to override the access system
1587  $ia = elgg_set_ignore_access(true);
1588  $this->delete();
1590  }
1591  }
1592  }
1593 
1594  return false;
1595  }
1596 
1610  protected function create() {
1611  global $CONFIG;
1612 
1613  // Using attribute array directly; get function does something special!
1614  $type = $this->getDatabase()->sanitizeString($this->attributes['type']);
1615  if ($type == "") {
1616  throw new \InvalidParameterException("Entity type must be set.");
1617  }
1618 
1619  $subtype = $this->attributes['subtype'];
1620  $subtype_id = add_subtype($type, $subtype);
1621  $owner_guid = (int)$this->attributes['owner_guid'];
1622  $access_id = (int)$this->attributes['access_id'];
1623  $now = (string)time();
1624  $time_created = isset($this->attributes['time_created']) ? (int)$this->attributes['time_created'] : $now;
1625 
1626  $site_guid = $this->attributes['site_guid'];
1627  if ($site_guid == 0) {
1628  $site_guid = $CONFIG->site_guid;
1629  }
1630  $site_guid = (int)$site_guid;
1631 
1632  $container_guid = $this->attributes['container_guid'];
1633  if ($container_guid == 0) {
1635  }
1637 
1638  if ($access_id == ACCESS_DEFAULT) {
1639  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.h');
1640  }
1641 
1642  $owner = $this->getOwnerEntity();
1643  if ($owner && !$owner->canWriteToContainer(0, $type, $subtype)) {
1644  return false;
1645  }
1646 
1647  if ($owner_guid != $container_guid) {
1648  $container = $this->getContainerEntity();
1649  if ($container && !$container->canWriteToContainer(0, $type, $subtype)) {
1650  return false;
1651  }
1652  }
1653 
1654  $result = $this->getDatabase()->insertData("INSERT into {$CONFIG->dbprefix}entities
1655  (type, subtype, owner_guid, site_guid, container_guid,
1656  access_id, time_created, time_updated, last_action)
1657  values
1658  ('$type', $subtype_id, $owner_guid, $site_guid, $container_guid,
1659  $access_id, $time_created, $now, $now)");
1660 
1661  if (!$result) {
1662  throw new \IOException("Unable to save new object's base entity information!");
1663  }
1664 
1665  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1666  $this->attributes['subtype'] = (int)$subtype_id;
1667  $this->attributes['guid'] = (int)$result;
1668  $this->attributes['time_created'] = (int)$time_created;
1669  $this->attributes['time_updated'] = (int)$now;
1670  $this->attributes['last_action'] = (int)$now;
1671  $this->attributes['site_guid'] = (int)$site_guid;
1672  $this->attributes['container_guid'] = (int)$container_guid;
1673 
1674  // Save any unsaved metadata
1675  if (sizeof($this->temp_metadata) > 0) {
1676  foreach ($this->temp_metadata as $name => $value) {
1677  $this->$name = $value;
1678  }
1679 
1680  $this->temp_metadata = array();
1681  }
1682 
1683  // Save any unsaved annotations.
1684  if (sizeof($this->temp_annotations) > 0) {
1685  foreach ($this->temp_annotations as $name => $value) {
1686  $this->annotate($name, $value);
1687  }
1688 
1689  $this->temp_annotations = array();
1690  }
1691 
1692  // Save any unsaved private settings.
1693  if (sizeof($this->temp_private_settings) > 0) {
1694  foreach ($this->temp_private_settings as $name => $value) {
1695  $this->setPrivateSetting($name, $value);
1696  }
1697 
1698  $this->temp_private_settings = array();
1699  }
1700 
1701  _elgg_cache_entity($this);
1702 
1703  return $result;
1704  }
1705 
1713  protected function update() {
1714  global $CONFIG;
1715 
1716  // See #5600. This ensures canEdit() checks the BD persisted entity so it sees the
1717  // persisted owner_guid, container_guid, etc.
1718  _elgg_disable_caching_for_entity($this->guid);
1719  $persisted_entity = get_entity($this->guid);
1720  if (!$persisted_entity) {
1721  // Why worry about this case? If access control was off when the user fetched this object but
1722  // was turned back on again. Better to just bail than to turn access control off again.
1723  return false;
1724  }
1725 
1726  $allow_edit = $persisted_entity->canEdit();
1727  unset($persisted_entity);
1728 
1729  if ($allow_edit) {
1730  // give old update event a chance to stop the update
1731  $allow_edit = _elgg_services()->events->trigger('update', $this->type, $this);
1732  }
1733 
1734  _elgg_enable_caching_for_entity($this->guid);
1735 
1736  if (!$allow_edit) {
1737  return false;
1738  }
1739 
1740  // See #6225. We copy these after the update event in case a handler changed one of them.
1741  $guid = (int)$this->guid;
1742  $owner_guid = (int)$this->owner_guid;
1743  $access_id = (int)$this->access_id;
1744  $container_guid = (int)$this->container_guid;
1745  $time_created = (int)$this->time_created;
1746  $time = time();
1747 
1748  if ($access_id == ACCESS_DEFAULT) {
1749  throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
1750  }
1751 
1752  $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1753  set owner_guid='$owner_guid', access_id='$access_id',
1754  container_guid='$container_guid', time_created='$time_created',
1755  time_updated='$time' WHERE guid=$guid");
1756 
1757  elgg_trigger_after_event('update', $this->type, $this);
1758 
1759  // TODO(evan): Move this to \ElggObject?
1760  if ($this instanceof \ElggObject) {
1761  update_river_access_by_object($guid, $access_id);
1762  }
1763 
1764  // If memcache is available then delete this entry from the cache
1765  static $newentity_cache;
1766  if ((!$newentity_cache) && (is_memcache_available())) {
1767  $newentity_cache = new \ElggMemcache('new_entity_cache');
1768  }
1769  if ($newentity_cache) {
1770  $newentity_cache->delete($guid);
1771  }
1772 
1773  if ($ret !== false) {
1774  $this->attributes['time_updated'] = $time;
1775  }
1776 
1777  _elgg_cache_entity($this);
1778 
1779  // Handle cases where there was no error BUT no rows were updated!
1780  return $ret !== false;
1781  }
1782 
1790  protected function load($guid) {
1791  if ($guid instanceof \stdClass) {
1792  $row = $guid;
1793  } else {
1795  }
1796 
1797  if ($row) {
1798  // Create the array if necessary - all subclasses should test before creating
1799  if (!is_array($this->attributes)) {
1800  $this->attributes = array();
1801  }
1802 
1803  // Now put these into the attributes array as core values
1804  $objarray = (array) $row;
1805  foreach ($objarray as $key => $value) {
1806  $this->attributes[$key] = $value;
1807  }
1808 
1809  // Increment the portion counter
1810  if (!$this->isFullyLoaded()) {
1811  $this->tables_loaded++;
1812  }
1813 
1814  // guid needs to be an int https://github.com/elgg/elgg/issues/4111
1815  $this->attributes['guid'] = (int)$this->attributes['guid'];
1816 
1817  // for BC with 1.8, ->subtype always returns ID, ->getSubtype() the string
1818  $this->attributes['subtype'] = (int)$this->attributes['subtype'];
1819 
1820  // Cache object handle
1821  if ($this->attributes['guid']) {
1822  _elgg_cache_entity($this);
1823  }
1824 
1825  return true;
1826  }
1827 
1828  return false;
1829  }
1830 
1837  protected function loadAdditionalSelectValues(array $data) {
1838  foreach ($data as $name => $value) {
1839  $this->setVolatileData("select:$name", $value);
1840  }
1841  }
1842 
1855  public function refresh(\stdClass $row) {
1856  if ($row instanceof \stdClass) {
1857  return $this->load($row);
1858  }
1859  return false;
1860  }
1861 
1881  public function disable($reason = "", $recursive = true) {
1882  if (!$this->guid) {
1883  return false;
1884  }
1885 
1886  if (!_elgg_services()->events->trigger('disable', $this->type, $this)) {
1887  return false;
1888  }
1889 
1890  if (!$this->canEdit()) {
1891  return false;
1892  }
1893 
1894  _elgg_invalidate_cache_for_entity($this->guid);
1895 
1896  if ($reason) {
1897  $this->disable_reason = $reason;
1898  }
1899 
1900  global $CONFIG;
1901  $guid = (int)$this->guid;
1902 
1903  if ($recursive) {
1906  $ia = elgg_set_ignore_access(true);
1907 
1908  $sub_entities = $this->getDatabase()->getData("SELECT * FROM {$CONFIG->dbprefix}entities
1909  WHERE (
1910  container_guid = $guid
1911  OR owner_guid = $guid
1912  OR site_guid = $guid
1913  ) AND enabled='yes'", 'entity_row_to_elggstar');
1914 
1915  if ($sub_entities) {
1916  foreach ($sub_entities as $e) {
1917  add_entity_relationship($e->guid, 'disabled_with', $this->guid);
1918  $e->disable($reason);
1919  }
1920  }
1921 
1924  }
1925 
1926  $this->disableMetadata();
1927  $this->disableAnnotations();
1928 
1929  $res = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1930  SET enabled = 'no'
1931  WHERE guid = $guid");
1932 
1933  if ($res) {
1934  $this->attributes['enabled'] = 'no';
1935  _elgg_services()->events->trigger('disable:after', $this->type, $this);
1936  }
1937 
1938  return $res;
1939  }
1940 
1951  public function enable($recursive = true) {
1952  $guid = (int)$this->guid;
1953  if (!$guid) {
1954  return false;
1955  }
1956 
1957  if (!_elgg_services()->events->trigger('enable', $this->type, $this)) {
1958  return false;
1959  }
1960 
1961  if (!$this->canEdit()) {
1962  return false;
1963  }
1964 
1965  global $CONFIG;
1966 
1967  // Override access only visible entities
1968  $old_access_status = access_get_show_hidden_status();
1970 
1971  $result = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities
1972  SET enabled = 'yes'
1973  WHERE guid = $guid");
1974 
1975  $this->deleteMetadata('disable_reason');
1976  $this->enableMetadata();
1977  $this->enableAnnotations();
1978 
1979  if ($recursive) {
1980  $disabled_with_it = elgg_get_entities_from_relationship(array(
1981  'relationship' => 'disabled_with',
1982  'relationship_guid' => $guid,
1983  'inverse_relationship' => true,
1984  'limit' => 0,
1985  ));
1986 
1987  foreach ($disabled_with_it as $e) {
1988  $e->enable();
1989  remove_entity_relationship($e->guid, 'disabled_with', $guid);
1990  }
1991  }
1992 
1993  access_show_hidden_entities($old_access_status);
1994 
1995  if ($result) {
1996  $this->attributes['enabled'] = 'yes';
1997  _elgg_services()->events->trigger('enable:after', $this->type, $this);
1998  }
1999 
2000  return $result;
2001  }
2002 
2008  public function isEnabled() {
2009  return $this->enabled == 'yes';
2010  }
2011 
2029  public function delete($recursive = true) {
2030  global $CONFIG;
2031 
2032  $guid = $this->guid;
2033  if (!$guid) {
2034  return false;
2035  }
2036 
2037  // first check if we can delete this entity
2038  // NOTE: in Elgg <= 1.10.3 this was after the delete event,
2039  // which could potentially remove some content if the user didn't have access
2040  if (!$this->canDelete()) {
2041  return false;
2042  }
2043 
2044  // now trigger an event to let others know this entity is about to be deleted
2045  // so they can prevent it or take their own actions
2046  if (!_elgg_services()->events->trigger('delete', $this->type, $this)) {
2047  return false;
2048  }
2049 
2051 
2052  // If memcache is available then delete this entry from the cache
2053  static $newentity_cache;
2054  if ((!$newentity_cache) && (is_memcache_available())) {
2055  $newentity_cache = new \ElggMemcache('new_entity_cache');
2056  }
2057  if ($newentity_cache) {
2058  $newentity_cache->delete($guid);
2059  }
2060 
2061  // Delete contained owned and otherwise releated objects (depth first)
2062  if ($recursive) {
2063  // Temporarily overriding access controls
2064  $entity_disable_override = access_get_show_hidden_status();
2066  $ia = elgg_set_ignore_access(true);
2067 
2068  // @todo there was logic in the original code that ignored
2069  // entities with owner or container guids of themselves.
2070  // this should probably be prevented in \ElggEntity instead of checked for here
2071  $options = array(
2072  'wheres' => array(
2073  "((container_guid = $guid OR owner_guid = $guid OR site_guid = $guid)"
2074  . " AND guid != $guid)"
2075  ),
2076  'limit' => 0
2077  );
2078 
2079  $batch = new \ElggBatch('elgg_get_entities', $options);
2080  $batch->setIncrementOffset(false);
2081 
2082  foreach ($batch as $e) {
2083  $e->delete(true);
2084  }
2085 
2086  access_show_hidden_entities($entity_disable_override);
2088  }
2089 
2090  $entity_disable_override = access_get_show_hidden_status();
2092  $ia = elgg_set_ignore_access(true);
2093 
2094  // Now delete the entity itself
2095  $this->deleteMetadata();
2096  $this->deleteOwnedMetadata();
2097  $this->deleteAnnotations();
2098  $this->deleteOwnedAnnotations();
2099  $this->deleteRelationships();
2102 
2103  access_show_hidden_entities($entity_disable_override);
2105 
2106  elgg_delete_river(array('subject_guid' => $guid));
2107  elgg_delete_river(array('object_guid' => $guid));
2108  elgg_delete_river(array('target_guid' => $guid));
2110 
2111  $res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = $guid");
2112  if ($res) {
2113  $sub_table = "";
2114 
2115  // Where appropriate delete the sub table
2116  switch ($this->type) {
2117  case 'object' :
2118  $sub_table = $CONFIG->dbprefix . 'objects_entity';
2119  break;
2120  case 'user' :
2121  $sub_table = $CONFIG->dbprefix . 'users_entity';
2122  break;
2123  case 'group' :
2124  $sub_table = $CONFIG->dbprefix . 'groups_entity';
2125  break;
2126  case 'site' :
2127  $sub_table = $CONFIG->dbprefix . 'sites_entity';
2128  break;
2129  }
2130 
2131  if ($sub_table) {
2132  $this->getDatabase()->deleteData("DELETE FROM $sub_table WHERE guid = $guid");
2133  }
2134  }
2135 
2136  _elgg_clear_entity_files($this);
2137 
2138  return (bool)$res;
2139  }
2140 
2144  public function toObject() {
2145  $object = $this->prepareObject(new \stdClass());
2146  $params = array('entity' => $this);
2147  $object = _elgg_services()->hooks->trigger('to:object', 'entity', $params, $object);
2148  return $object;
2149  }
2150 
2157  protected function prepareObject($object) {
2158  $object->guid = $this->guid;
2159  $object->type = $this->getType();
2160  $object->subtype = $this->getSubtype();
2161  $object->owner_guid = $this->getOwnerGUID();
2162  $object->container_guid = $this->getContainerGUID();
2163  $object->site_guid = (int)$this->site_guid;
2164  $object->time_created = date('c', $this->getTimeCreated());
2165  $object->time_updated = date('c', $this->getTimeUpdated());
2166  $object->url = $this->getURL();
2167  $object->read_access = (int)$this->access_id;
2168  return $object;
2169  }
2170 
2171  /*
2172  * LOCATABLE INTERFACE
2173  */
2174 
2180  public function getLocation() {
2181  return $this->location;
2182  }
2183 
2191  public function setLocation($location) {
2192  $this->location = $location;
2193  }
2194 
2204  public function setLatLong($lat, $long) {
2205  $this->{"geo:lat"} = $lat;
2206  $this->{"geo:long"} = $long;
2207  }
2208 
2215  public function getLatitude() {
2216  return (float)$this->{"geo:lat"};
2217  }
2218 
2225  public function getLongitude() {
2226  return (float)$this->{"geo:long"};
2227  }
2228 
2229  /*
2230  * NOTABLE INTERFACE
2231  */
2232 
2247  public function setCalendarTimeAndDuration($hour = null, $minute = null, $second = null,
2248  $day = null, $month = null, $year = null, $duration = null) {
2249  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2250 
2251  $start = mktime($hour, $minute, $second, $month, $day, $year);
2252  $end = $start + abs($duration);
2253  if (!$duration) {
2254  $end = get_day_end($day, $month, $year);
2255  }
2256 
2257  $this->calendar_start = $start;
2258  $this->calendar_end = $end;
2259 
2260  return true;
2261  }
2262 
2269  public function getCalendarStartTime() {
2270  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2271  return (int)$this->calendar_start;
2272  }
2273 
2280  public function getCalendarEndTime() {
2281  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2282  return (int)$this->calendar_end;
2283  }
2284 
2285  /*
2286  * EXPORTABLE INTERFACE
2287  */
2288 
2295  public function getExportableValues() {
2296  elgg_deprecated_notice(__METHOD__ . ' has been deprecated by toObject()', 1.9);
2297  return array(
2298  'guid',
2299  'type',
2300  'subtype',
2301  'time_created',
2302  'time_updated',
2303  'container_guid',
2304  'owner_guid',
2305  'site_guid'
2306  );
2307  }
2308 
2317  public function export() {
2318  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2319  $tmp = array();
2320 
2321  // Generate uuid
2322  $uuid = guid_to_uuid($this->getGUID());
2323 
2324  // Create entity
2325  $odd = new ODDEntity(
2326  $uuid,
2327  $this->attributes['type'],
2328  get_subtype_from_id($this->attributes['subtype'])
2329  );
2330 
2331  $tmp[] = $odd;
2332 
2334 
2335  // Now add its attributes
2336  foreach ($this->attributes as $k => $v) {
2337  $meta = null;
2338 
2339  if (in_array($k, $exportable_values)) {
2340  switch ($k) {
2341  case 'guid': // Dont use guid in OpenDD
2342  case 'type': // Type and subtype already taken care of
2343  case 'subtype':
2344  break;
2345 
2346  case 'time_created': // Created = published
2347  $odd->setAttribute('published', date("r", $v));
2348  break;
2349 
2350  case 'site_guid': // Container
2351  $k = 'site_uuid';
2352  $v = guid_to_uuid($v);
2353  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2354  break;
2355 
2356  case 'container_guid': // Container
2357  $k = 'container_uuid';
2358  $v = guid_to_uuid($v);
2359  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2360  break;
2361 
2362  case 'owner_guid': // Convert owner guid to uuid, this will be stored in metadata
2363  $k = 'owner_uuid';
2364  $v = guid_to_uuid($v);
2365  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2366  break;
2367 
2368  default:
2369  $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
2370  }
2371 
2372  // set the time of any metadata created
2373  if ($meta) {
2374  $meta->setAttribute('published', date("r", $this->time_created));
2375  $tmp[] = $meta;
2376  }
2377  }
2378  }
2379 
2380  // Now we do something a bit special.
2381  /*
2382  * This provides a rendered view of the entity to foreign sites.
2383  */
2384 
2385  elgg_set_viewtype('default');
2386  $view = elgg_view_entity($this, array('full_view' => true));
2388 
2389  $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
2390  'renderedentity', $view, 'volatile');
2391 
2392  return $tmp;
2393  }
2394 
2395  /*
2396  * IMPORTABLE INTERFACE
2397  */
2398 
2409  public function import(ODD $data) {
2410  elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
2411  if (!($data instanceof ODDEntity)) {
2412  throw new \InvalidParameterException("import() passed an unexpected ODD class");
2413  }
2414 
2415  // Set type and subtype
2416  $this->attributes['type'] = $data->getAttribute('class');
2417  $this->attributes['subtype'] = $data->getAttribute('subclass');
2418 
2419  // Set owner
2420  $this->attributes['owner_guid'] = _elgg_services()->session->getLoggedInUserGuid(); // Import as belonging to importer.
2421 
2422  // Set time
2423  $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
2424  $this->attributes['time_updated'] = time();
2425 
2426  return true;
2427  }
2428 
2429  /*
2430  * SYSTEM LOG INTERFACE
2431  */
2432 
2439  public function getSystemLogID() {
2440  return $this->getGUID();
2441  }
2442 
2450  public function getObjectFromID($id) {
2451  return get_entity($id);
2452  }
2453 
2463  public function getTags($tag_names = null) {
2464  if ($tag_names && !is_array($tag_names)) {
2465  $tag_names = array($tag_names);
2466  }
2467 
2469  $entity_tags = array();
2470 
2471  foreach ($valid_tags as $tag_name) {
2472  if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
2473  continue;
2474  }
2475 
2476  if ($tags = $this->$tag_name) {
2477  // if a single tag, metadata returns a string.
2478  // if multiple tags, metadata returns an array.
2479  if (is_array($tags)) {
2480  $entity_tags = array_merge($entity_tags, $tags);
2481  } else {
2482  $entity_tags[] = $tags;
2483  }
2484  }
2485  }
2486 
2487  return $entity_tags;
2488  }
2489 
2497 
2498  if (!$this->guid) {
2499  return false;
2500  }
2501 
2502  if ($this->type !== 'user') {
2503  return true;
2504  }
2505 
2506  $ac = _elgg_services()->accessCollections;
2507 
2508  $collections = $ac->getCollectionsByMember($this->guid);
2509  if (empty($collections)) {
2510  return true;
2511  }
2512 
2513  $result = true;
2514  foreach ($collections as $collection) {
2515  $result = $result & $ac->removeUser($this->guid, $collection->id);
2516  }
2517 
2518  return $result;
2519  }
2520 
2527  public function deleteOwnedAccessCollections() {
2528 
2529  if (!$this->guid) {
2530  return false;
2531  }
2532 
2533  $ac = _elgg_services()->accessCollections;
2534 
2535  $collections = $ac->getEntityCollections($this->guid);
2536  if (empty($collections)) {
2537  return true;
2538  }
2539 
2540  $result = true;
2541  foreach ($collections as $collection) {
2542  $result = $result & $ac->delete($collection->id);
2543  }
2544 
2545  return $result;
2546  }
2547 }
_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
$tags
Definition: summary.php:41
deleteOwnedAccessCollections()
Remove all access collections owned by this entity.
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:230
refresh(\stdClass $row)
Load new data from database into existing entity.
elgg_disable_metadata(array $options)
Disables metadata based on $options.
Definition: metadata.php:171
getOwnerGUID()
Get the guid of the entity&#39;s owner.
getTimeCreated()
Returns the UNIX epoch time that this entity was created.
Definition: ElggData.php:131
__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:63
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:62
loadAdditionalSelectValues(array $data)
Stores non-attributes from the loading of the entity as volatile data.
getOwnerEntity()
Gets the that owns this entity.
remove_all_private_settings($entity_guid)
Deletes all private settings for an entity.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
elgg_normalize_url($url)
Definition: output.php:311
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:702
disableAnnotations($name= '')
Disables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:760
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:464
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:716
$object
Definition: upgrade.php:12
$CONFIG site_guid
The guid of the current site object.
Definition: config.php:122
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:668
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
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:684
deleteOwnedMetadata($name=null)
Deletes all metadata owned by this object (metadata.owner_guid = $this->guid).
Definition: ElggEntity.php:489
$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:169
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:385
deleteOwnedAnnotations($name=null)
Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
Definition: ElggEntity.php:736
$data
Definition: opendd.php:13
_elgg_cache_entity(\ElggEntity $entity)
Cache an entity.
Definition: entities.php:92
$value
Definition: longtext.php:26
$ia
Definition: upgrade.php:26
isFullyLoaded()
Tests to see whether the object has been fully loaded.
$return
Definition: opendd.php:15
if(!$count) $offset
Definition: pagination.php:25
getGUID()
Returns the guid.
disableMetadata($name= '')
Disables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:527
$guid
Removes an admin notice.
getContainerGUID()
Gets the container GUID for this entity.
getCalendarStartTime()
Returns the start timestamp.
$collection
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:49
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:1246
enableAnnotations($name= '')
Enables annotations for this entity, optionally based on name.
Definition: ElggEntity.php:781
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:174
canEdit($user_guid=0)
Can a user edit this entity?
export()
Export this class into an array of ODD Elements containing all necessary fields.
events($event="", $object_type="", $function="", $priority=500, $call=false, $object=null)
Deprecated events core function.
$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:622
setVolatileData($name, $value)
Set a piece of volatile (non-persisted) data on this entity.
Definition: ElggEntity.php:587
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:653
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:707
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:994
$owner_guid
deleteRelationships($relationship=null)
Remove all relationships to and from this entity.
Definition: ElggEntity.php:608
metadata_array_to_values($array)
Takes a metadata array (which has all kinds of properties) and turns it into a simple array of string...
Definition: metadata.php:311
getExportableValues()
Returns an array of fields which can be exported.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
Definition: entities.php:922
getTags($tag_names=null)
Returns tags for this entity.
if($entity) $container
Definition: access.php:62
$limit
Definition: userpicker.php:31
add_subtype($type, $subtype, $class="")
Register with a certain type and subtype to be loaded as a specific class.
Definition: entities.php:248
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:567
$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:187
$owner
Definition: crop.php:8
$key
Definition: summary.php:34
get_user($guid)
Get a user object from a GUID.
Definition: users.php:87
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
_elgg_services()
Definition: autoloader.php:14
global $CONFIG
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:65
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
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:1954
__set($name, $value)
Set an attribute or metadata value for this entity.
Definition: ElggEntity.php:197
const ELGG_ENTITIES_ANY_VALUE
Definition: elgglib.php:1967
$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:490
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:515
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
elgg global
Pointer to the global context.
Definition: elgglib.js:12
getCalendarEndTime()
Returns the end timestamp.
getIconURL($params=array())
Get the URL for this entity&#39;s icon.
$type
Definition: add.php:8
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:172
deleteAccessCollectionMemberships()
Remove the membership of all access collections for this entity (if the entity is a user) ...
isEnabled()
Is this entity enabled?
get_entity_as_row($guid)
Returns a database row from the entities table.
Definition: entities.php:352
addRelationship($guid_two, $relationship)
Add a relationship between this an another entity.
Definition: ElggEntity.php:639
update()
Update the entity in the database.
getAccessID()
Returns the access_id.
guid_to_uuid($guid)
Generate a UUID from a given GUID.
$comment access_id
Definition: save.php:61
$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:158
canDelete($user_guid=0)
Can a user delete this entity?
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:159
$hidden
Definition: save.php:13
elgg_get_metadata(array $options=array())
Returns metadata.
Definition: metadata.php:143
getType()
Returns the entity type.
elgg_get_annotations(array $options=array())
Returns annotations.
Definition: ODD.php:9
setDisplayName($displayName)
Sets the title or name of this entity.
elgg_delete_river(array $options=array())
Delete river items.
Definition: river.php:162
clearAnnotations($name="")
Remove an annotation or all annotations for this entity.
Definition: ElggEntity.php:898
elgg_view_entity(\ElggEntity $entity, $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:793
create()
Create a new entry in the entities table.
elgg_trigger_after_event($event, $object_type, $object=null)
Trigger an "After event" indicating a process has finished.
Definition: elgglib.php:610
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.
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
$container_guid
getContainerEntity()
Get the container entity for this object.
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
removeFromSite($site)
Remove this entity from a site.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
__unset($name)
Unset a property from metadata or attribute.
Definition: ElggEntity.php:357
$user_guid
Avatar remove action.
Definition: remove.php:6
const ACCESS_DEFAULT
Definition: elgglib.php:1953
$subtype
Definition: river.php:12
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:748
enableMetadata($name= '')
Enables metadata for this entity, optionally based on name.
Definition: ElggEntity.php:548
disable($reason="", $recursive=true)
Disable this entity.
getURL()
Gets the URL for this entity.
load($guid)
Loads attributes from the entities table into the object.
_elgg_clear_entity_files($entity)
Removes all entity files.
Definition: filestore.php:415
getDisplayName()
Get the entity&#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:382
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:60
$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