00001 <?php
00039 abstract class ElggEntity extends ElggData implements
00040 Notable,
00041 Locatable,
00042 Importable
00043 {
00044
00048 protected $url_override;
00049
00053 protected $icon_override;
00054
00059 protected $temp_metadata = array();
00060
00065 protected $temp_annotations = array();
00066
00071 protected $temp_private_settings = array();
00072
00077 protected $volatile = array();
00078
00086 protected function initializeAttributes() {
00087 parent::initializeAttributes();
00088
00089 $this->attributes['guid'] = NULL;
00090 $this->attributes['type'] = NULL;
00091 $this->attributes['subtype'] = NULL;
00092
00093 $this->attributes['owner_guid'] = elgg_get_logged_in_user_guid();
00094 $this->attributes['container_guid'] = elgg_get_logged_in_user_guid();
00095
00096 $this->attributes['site_guid'] = NULL;
00097 $this->attributes['access_id'] = ACCESS_PRIVATE;
00098 $this->attributes['time_created'] = NULL;
00099 $this->attributes['time_updated'] = NULL;
00100 $this->attributes['last_action'] = NULL;
00101 $this->attributes['enabled'] = "yes";
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 $this->attributes['tables_split'] = 1;
00119 $this->attributes['tables_loaded'] = 0;
00120 }
00121
00135 public function __clone() {
00136 $orig_entity = get_entity($this->guid);
00137 if (!$orig_entity) {
00138 elgg_log("Failed to clone entity with GUID $this->guid", "ERROR");
00139 return;
00140 }
00141
00142 $metadata_array = elgg_get_metadata(array(
00143 'guid' => $this->guid,
00144 'limit' => 0
00145 ));
00146
00147 $this->attributes['guid'] = "";
00148
00149 $this->attributes['subtype'] = $orig_entity->getSubtype();
00150
00151
00152
00153 if (is_array($metadata_array)) {
00154
00155 $metadata_names = array();
00156 foreach ($metadata_array as $metadata) {
00157 $metadata_names[] = $metadata['name'];
00158 }
00159
00160 $metadata_names = array_unique($metadata_names);
00161
00162
00163 foreach ($metadata_names as $name) {
00164 $this->set($name, $orig_entity->$name);
00165 }
00166 }
00167 }
00168
00188 public function get($name) {
00189
00190 if (array_key_exists($name, $this->attributes)) {
00191 return $this->attributes[$name];
00192 }
00193
00194
00195 $meta = $this->getMetaData($name);
00196
00197
00198 return $meta;
00199 }
00200
00224 public function set($name, $value) {
00225 if (array_key_exists($name, $this->attributes)) {
00226
00227 switch ($name) {
00228 case 'guid':
00229 case 'time_updated':
00230 case 'last_action':
00231 return FALSE;
00232 break;
00233 default:
00234 $this->attributes[$name] = $value;
00235 break;
00236 }
00237 } else {
00238 return $this->setMetaData($name, $value);
00239 }
00240
00241 return TRUE;
00242 }
00243
00251 public function getMetaData($name) {
00252 $guid = $this->getGUID();
00253
00254 if (! $guid) {
00255 if (isset($this->temp_metadata[$name])) {
00256
00257 if (count($this->temp_metadata[$name]) == 1) {
00258 return $this->temp_metadata[$name][0];
00259 } else {
00260 return $this->temp_metadata[$name];
00261 }
00262 } else {
00263 return null;
00264 }
00265 }
00266
00267
00268
00269 $cache = elgg_get_metadata_cache();
00270 if ($cache->isKnown($guid, $name)) {
00271 return $cache->load($guid, $name);
00272 } else {
00273 $cache->populateFromEntities(array($guid));
00274
00275 if ($cache->isKnown($guid, $name)) {
00276 return $cache->load($guid, $name);
00277 }
00278 }
00279
00280 $md = elgg_get_metadata(array(
00281 'guid' => $guid,
00282 'metadata_name' => $name,
00283 'limit' => 0,
00284 ));
00285
00286 $value = null;
00287
00288 if ($md && !is_array($md)) {
00289 $value = $md->value;
00290 } elseif (count($md) == 1) {
00291 $value = $md[0]->value;
00292 } else if ($md && is_array($md)) {
00293 $value = metadata_array_to_values($md);
00294 }
00295
00296 $cache->save($guid, $name, $value);
00297
00298 return $value;
00299 }
00300
00310 function __unset($name) {
00311 if (array_key_exists($name, $this->attributes)) {
00312 $this->attributes[$name] = "";
00313 } else {
00314 $this->deleteMetadata($name);
00315 }
00316 }
00317
00335 public function setMetaData($name, $value, $value_type = null, $multiple = false) {
00336
00337
00338
00339 if (is_array($value)) {
00340 $value = array_values($value);
00341 } else {
00342 $value = array($value);
00343 }
00344
00345
00346 if ($this->guid) {
00347
00348 if (!$multiple) {
00349 $options = array(
00350 'guid' => $this->getGUID(),
00351 'metadata_name' => $name,
00352 'limit' => 0
00353 );
00354
00355
00356
00357
00358
00359 $ia = elgg_set_ignore_access(true);
00360 if (false === elgg_delete_metadata($options)) {
00361 return false;
00362 }
00363 elgg_set_ignore_access($ia);
00364 }
00365
00366
00367 $result = true;
00368 foreach ($value as $value_tmp) {
00369
00370 $md_id = create_metadata($this->getGUID(), $name, $value_tmp, $value_type,
00371 $this->getOwnerGUID(), $this->getAccessId(), true);
00372 if (!$md_id) {
00373 return false;
00374 }
00375 }
00376
00377 return $result;
00378 } else {
00379
00380
00381
00382
00383
00384 if (!$multiple || !isset($this->temp_metadata[$name])) {
00385 $this->temp_metadata[$name] = array();
00386 }
00387
00388
00389 $this->temp_metadata[$name] = array_merge($this->temp_metadata[$name], $value);
00390 return true;
00391 }
00392 }
00393
00404 public function deleteMetadata($name = null) {
00405
00406 if (!$this->guid) {
00407 return false;
00408 }
00409
00410 $options = array(
00411 'guid' => $this->guid,
00412 'limit' => 0
00413 );
00414 if ($name) {
00415 $options['metadata_name'] = $name;
00416 }
00417
00418 return elgg_delete_metadata($options);
00419 }
00420
00429 public function deleteOwnedMetadata($name = null) {
00430
00431
00432 $ia = elgg_set_ignore_access(true);
00433 $options = array(
00434 'metadata_owner_guid' => $this->guid,
00435 'limit' => 0
00436 );
00437 if ($name) {
00438 $options['metadata_name'] = $name;
00439 }
00440
00441 $r = elgg_delete_metadata($options);
00442 elgg_set_ignore_access($ia);
00443 return $r;
00444 }
00445
00455 public function clearMetaData($name = '') {
00456 elgg_deprecated_notice('ElggEntity->clearMetadata() is deprecated by ->deleteMetadata()', 1.8);
00457 return $this->deleteMetadata($name);
00458 }
00459
00467 public function disableMetadata($name = '') {
00468 $options = array(
00469 'guid' => $this->guid,
00470 'limit' => 0
00471 );
00472 if ($name) {
00473 $options['metadata_name'] = $name;
00474 }
00475
00476 return elgg_disable_metadata($options);
00477 }
00478
00488 public function enableMetadata($name = '') {
00489 $options = array(
00490 'guid' => $this->guid,
00491 'limit' => 0
00492 );
00493 if ($name) {
00494 $options['metadata_name'] = $name;
00495 }
00496
00497 return elgg_enable_metadata($options);
00498 }
00499
00507 public function getVolatileData($name) {
00508 if (!is_array($this->volatile)) {
00509 $this->volatile = array();
00510 }
00511
00512 if (array_key_exists($name, $this->volatile)) {
00513 return $this->volatile[$name];
00514 } else {
00515 return NULL;
00516 }
00517 }
00518
00527 public function setVolatileData($name, $value) {
00528 if (!is_array($this->volatile)) {
00529 $this->volatile = array();
00530 }
00531
00532 $this->volatile[$name] = $value;
00533 }
00534
00543 public function deleteRelationships() {
00544 remove_entity_relationships($this->getGUID());
00545 remove_entity_relationships($this->getGUID(), "", true);
00546 return true;
00547 }
00548
00557 public function clearRelationships() {
00558 elgg_deprecated_notice('ElggEntity->clearRelationships() is deprecated by ->deleteRelationships()', 1.8);
00559 return $this->deleteRelationships();
00560 }
00561
00574 public function addRelationship($guid, $relationship) {
00575 return add_entity_relationship($this->getGUID(), $relationship, $guid);
00576 }
00577
00588 public function removeRelationship($guid, $relationship) {
00589 return remove_entity_relationship($this->getGUID(), $relationship, $guid);
00590 }
00591
00603 function setPrivateSetting($name, $value) {
00604 if ((int) $this->guid > 0) {
00605 return set_private_setting($this->getGUID(), $name, $value);
00606 } else {
00607 $this->temp_private_settings[$name] = $value;
00608 return true;
00609 }
00610 }
00611
00619 function getPrivateSetting($name) {
00620 if ((int) ($this->guid) > 0) {
00621 return get_private_setting($this->getGUID(), $name);
00622 } else {
00623 if (isset($this->temp_private_settings[$name])) {
00624 return $this->temp_private_settings[$name];
00625 }
00626 }
00627 return null;
00628 }
00629
00637 function removePrivateSetting($name) {
00638 return remove_private_setting($this->getGUID(), $name);
00639 }
00640
00651 public function deleteAnnotations($name = null) {
00652 $options = array(
00653 'guid' => $this->guid,
00654 'limit' => 0
00655 );
00656 if ($name) {
00657 $options['annotation_name'] = $name;
00658 }
00659
00660 return elgg_delete_annotations($options);
00661 }
00662
00671 public function deleteOwnedAnnotations($name = null) {
00672
00673
00674 $ia = elgg_set_ignore_access(true);
00675 $options = array(
00676 'annotation_owner_guid' => $this->guid,
00677 'limit' => 0
00678 );
00679 if ($name) {
00680 $options['annotation_name'] = $name;
00681 }
00682
00683 $r = elgg_delete_annotations($options);
00684 elgg_set_ignore_access($ia);
00685 return $r;
00686 }
00687
00695 public function disableAnnotations($name = '') {
00696 $options = array(
00697 'guid' => $this->guid,
00698 'limit' => 0
00699 );
00700 if ($name) {
00701 $options['annotation_name'] = $name;
00702 }
00703
00704 return elgg_disable_annotations($options);
00705 }
00706
00716 public function enableAnnotations($name = '') {
00717 $options = array(
00718 'guid' => $this->guid,
00719 'limit' => 0
00720 );
00721 if ($name) {
00722 $options['annotation_name'] = $name;
00723 }
00724
00725 return elgg_enable_annotations($options);
00726 }
00727
00735 private function getAnnotationCalculation($name, $calculation) {
00736 $options = array(
00737 'guid' => $this->getGUID(),
00738 'annotation_name' => $name,
00739 'annotation_calculation' => $calculation
00740 );
00741
00742 return elgg_get_annotations($options);
00743 }
00744
00761 function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_id = 0, $vartype = "") {
00762 if ((int) $this->guid > 0) {
00763 return create_annotation($this->getGUID(), $name, $value, $vartype, $owner_id, $access_id);
00764 } else {
00765 $this->temp_annotations[$name] = $value;
00766 }
00767 return true;
00768 }
00769
00780 function getAnnotations($name, $limit = 50, $offset = 0, $order = "asc") {
00781 if ((int) ($this->guid) > 0) {
00782
00783 $options = array(
00784 'guid' => $this->guid,
00785 'annotation_name' => $name,
00786 'limit' => $limit,
00787 'offset' => $offset,
00788 );
00789
00790 if ($order != 'asc') {
00791 $options['reverse_order_by'] = true;
00792 }
00793
00794 return elgg_get_annotations($options);
00795 } else if (isset($this->temp_annotations[$name])) {
00796 return array($this->temp_annotations[$name]);
00797 } else {
00798 return array();
00799 }
00800 }
00801
00812 function clearAnnotations($name = "") {
00813 elgg_deprecated_notice('ElggEntity->clearAnnotations() is deprecated by ->deleteAnnotations()', 1.8);
00814 return $this->deleteAnnotations($name);
00815 }
00816
00824 function countAnnotations($name = "") {
00825 return $this->getAnnotationCalculation($name, 'count');
00826 }
00827
00835 function getAnnotationsAvg($name) {
00836 return $this->getAnnotationCalculation($name, 'avg');
00837 }
00838
00846 function getAnnotationsSum($name) {
00847 return $this->getAnnotationCalculation($name, 'sum');
00848 }
00849
00857 function getAnnotationsMin($name) {
00858 return $this->getAnnotationCalculation($name, 'min');
00859 }
00860
00868 function getAnnotationsMax($name) {
00869 return $this->getAnnotationCalculation($name, 'max');
00870 }
00871
00878 function countComments() {
00879 $params = array('entity' => $this);
00880 $num = elgg_trigger_plugin_hook('comments:count', $this->getType(), $params);
00881
00882 if (is_int($num)) {
00883 return $num;
00884 } else {
00885 return $this->getAnnotationCalculation('generic_comment', 'count');
00886 }
00887 }
00888
00899 function getEntitiesFromRelationship($relationship, $inverse = false, $limit = 50, $offset = 0) {
00900 return elgg_get_entities_from_relationship(array(
00901 'relationship' => $relationship,
00902 'relationship_guid' => $this->getGUID(),
00903 'inverse_relationship' => $inverse,
00904 'limit' => $limit,
00905 'offset' => $offset
00906 ));
00907 }
00908
00917 function countEntitiesFromRelationship($relationship, $inverse_relationship = FALSE) {
00918 return elgg_get_entities_from_relationship(array(
00919 'relationship' => $relationship,
00920 'relationship_guid' => $this->getGUID(),
00921 'inverse_relationship' => $inverse_relationship,
00922 'count' => TRUE
00923 ));
00924 }
00925
00933 function canEdit($user_guid = 0) {
00934 return can_edit_entity($this->getGUID(), $user_guid);
00935 }
00936
00945 function canEditMetadata($metadata = null, $user_guid = 0) {
00946 return can_edit_entity_metadata($this->getGUID(), $user_guid, $metadata);
00947 }
00948
00958 public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
00959 return can_write_to_container($user_guid, $this->guid, $type, $subtype);
00960 }
00961
00972 public function canComment($user_guid = 0) {
00973 if ($user_guid == 0) {
00974 $user_guid = elgg_get_logged_in_user_guid();
00975 }
00976 $user = get_entity($user_guid);
00977
00978
00979
00980 $params = array('entity' => $this, 'user' => $user);
00981 return elgg_trigger_plugin_hook('permissions_check:comment', $this->type, $params, null);
00982 }
00983
00998 public function canAnnotate($user_guid = 0, $annotation_name = '') {
00999 if ($user_guid == 0) {
01000 $user_guid = elgg_get_logged_in_user_guid();
01001 }
01002 $user = get_entity($user_guid);
01003
01004 $return = true;
01005 if (!$user) {
01006 $return = false;
01007 }
01008
01009 $params = array(
01010 'entity' => $this,
01011 'user' => $user,
01012 'annotation_name' => $annotation_name,
01013 );
01014 return elgg_trigger_plugin_hook('permissions_check:annotate', $this->type, $params, $return);
01015 }
01016
01022 public function getAccessID() {
01023 return $this->get('access_id');
01024 }
01025
01031 public function getGUID() {
01032 return $this->get('guid');
01033 }
01034
01040 public function getType() {
01041 return $this->get('type');
01042 }
01043
01051 public function getSubtype() {
01052
01053 if (!((int) $this->guid > 0)) {
01054 return $this->get('subtype');
01055 }
01056
01057 return get_subtype_from_id($this->get('subtype'));
01058 }
01059
01065 public function getOwnerGUID() {
01066 return $this->owner_guid;
01067 }
01068
01075 public function getOwner() {
01076 elgg_deprecated_notice("ElggEntity::getOwner deprecated for ElggEntity::getOwnerGUID", 1.8);
01077 return $this->getOwnerGUID();
01078 }
01079
01085 public function getOwnerEntity() {
01086 return get_entity($this->owner_guid);
01087 }
01088
01096 public function setContainerGUID($container_guid) {
01097 $container_guid = (int)$container_guid;
01098
01099 return $this->set('container_guid', $container_guid);
01100 }
01101
01110 public function setContainer($container_guid) {
01111 elgg_deprecated_notice("ElggObject::setContainer deprecated for ElggEntity::setContainerGUID", 1.8);
01112 $container_guid = (int)$container_guid;
01113
01114 return $this->set('container_guid', $container_guid);
01115 }
01116
01122 public function getContainerGUID() {
01123 return $this->get('container_guid');
01124 }
01125
01132 public function getContainer() {
01133 elgg_deprecated_notice("ElggObject::getContainer deprecated for ElggEntity::getContainerGUID", 1.8);
01134 return $this->get('container_guid');
01135 }
01136
01143 public function getContainerEntity() {
01144 return get_entity($this->getContainerGUID());
01145 }
01146
01152 public function getTimeUpdated() {
01153 return $this->get('time_updated');
01154 }
01155
01163 public function getURL() {
01164 if (!empty($this->url_override)) {
01165 return $this->url_override;
01166 }
01167 return get_entity_url($this->getGUID());
01168 }
01169
01179 public function setURL($url) {
01180 $this->url_override = $url;
01181 return $url;
01182 }
01183
01195 public function getIconURL($size = 'medium') {
01196 $size = elgg_strtolower($size);
01197
01198 if (isset($this->icon_override[$size])) {
01199 elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
01200 return $this->icon_override[$size];
01201 }
01202
01203 $type = $this->getType();
01204 $params = array(
01205 'entity' => $this,
01206 'size' => $size,
01207 );
01208
01209 $url = elgg_trigger_plugin_hook('entity:icon:url', $type, $params, null);
01210 if ($url == null) {
01211 $url = "_graphics/icons/default/$size.png";
01212 }
01213
01214 return elgg_normalize_url($url);
01215 }
01216
01225 public function getIcon($size = 'medium') {
01226 elgg_deprecated_notice("getIcon() deprecated by getIconURL()", 1.8);
01227 return $this->getIconURL($size);
01228 }
01229
01241 public function setIcon($url, $size = 'medium') {
01242 elgg_deprecated_notice("icon_override on an individual entity is deprecated", 1.8);
01243
01244 $url = sanitise_string($url);
01245 $size = sanitise_string($size);
01246
01247 if (!$this->icon_override) {
01248 $this->icon_override = array();
01249 }
01250 $this->icon_override[$size] = $url;
01251
01252 return true;
01253 }
01254
01260 public function isFullyLoaded() {
01261 return ! ($this->attributes['tables_loaded'] < $this->attributes['tables_split']);
01262 }
01263
01270 public function save() {
01271 $guid = $this->getGUID();
01272 if ($guid > 0) {
01273 _elgg_cache_entity($this);
01274
01275 return update_entity(
01276 $guid,
01277 $this->get('owner_guid'),
01278 $this->get('access_id'),
01279 $this->get('container_guid'),
01280 $this->get('time_created')
01281 );
01282 } else {
01283
01284
01285 $this->attributes['guid'] = create_entity($this->attributes['type'],
01286 $this->attributes['subtype'], $this->attributes['owner_guid'],
01287 $this->attributes['access_id'], $this->attributes['site_guid'],
01288 $this->attributes['container_guid']);
01289
01290 if (!$this->attributes['guid']) {
01291 throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
01292 }
01293
01294
01295
01296 if (sizeof($this->temp_metadata) > 0) {
01297 foreach ($this->temp_metadata as $name => $value) {
01298 $this->$name = $value;
01299 unset($this->temp_metadata[$name]);
01300 }
01301 }
01302
01303
01304 if (sizeof($this->temp_annotations) > 0) {
01305 foreach ($this->temp_annotations as $name => $value) {
01306 $this->annotate($name, $value);
01307 unset($this->temp_annotations[$name]);
01308 }
01309 }
01310
01311
01312 if (sizeof($this->temp_private_settings) > 0) {
01313 foreach ($this->temp_private_settings as $name => $value) {
01314 $this->setPrivateSetting($name, $value);
01315 unset($this->temp_private_settings[$name]);
01316 }
01317 }
01318
01319
01320 $this->attributes['subtype'] = get_subtype_id($this->attributes['type'],
01321 $this->attributes['subtype']);
01322
01323 _elgg_cache_entity($this);
01324
01325 return $this->attributes['guid'];
01326 }
01327 }
01328
01336 protected function load($guid) {
01337 if ($guid instanceof stdClass) {
01338 $row = $guid;
01339 } else {
01340 $row = get_entity_as_row($guid);
01341 }
01342
01343 if ($row) {
01344
01345 if (!is_array($this->attributes)) {
01346 $this->attributes = array();
01347 }
01348
01349
01350 $objarray = (array) $row;
01351 foreach ($objarray as $key => $value) {
01352 $this->attributes[$key] = $value;
01353 }
01354
01355
01356 if (!$this->isFullyLoaded()) {
01357 $this->attributes['tables_loaded']++;
01358 }
01359
01360
01361 $this->attributes['guid'] = (int)$this->attributes['guid'];
01362
01363
01364 if ($this->attributes['guid']) {
01365 _elgg_cache_entity($this);
01366 }
01367
01368 return true;
01369 }
01370
01371 return false;
01372 }
01373
01392 public function disable($reason = "", $recursive = true) {
01393 if ($r = disable_entity($this->get('guid'), $reason, $recursive)) {
01394 $this->attributes['enabled'] = 'no';
01395 }
01396
01397 return $r;
01398 }
01399
01410 public function enable() {
01411 if ($r = enable_entity($this->get('guid'))) {
01412 $this->attributes['enabled'] = 'yes';
01413 }
01414
01415 return $r;
01416 }
01417
01423 public function isEnabled() {
01424 if ($this->enabled == 'yes') {
01425 return true;
01426 }
01427
01428 return false;
01429 }
01430
01438 public function delete($recursive = true) {
01439 return delete_entity($this->get('guid'), $recursive);
01440 }
01441
01442
01443
01444
01445
01451 public function getLocation() {
01452 return $this->location;
01453 }
01454
01464 public function setLocation($location) {
01465 $this->location = $location;
01466 return true;
01467 }
01468
01478 public function setLatLong($lat, $long) {
01479 $this->set('geo:lat', $lat);
01480 $this->set('geo:long', $long);
01481
01482 return true;
01483 }
01484
01491 public function getLatitude() {
01492 return (float)$this->get('geo:lat');
01493 }
01494
01500 public function getLongitude() {
01501 return (float)$this->get('geo:long');
01502 }
01503
01504
01505
01506
01507
01522 public function setCalendarTimeAndDuration($hour = NULL, $minute = NULL, $second = NULL,
01523 $day = NULL, $month = NULL, $year = NULL, $duration = NULL) {
01524
01525 $start = mktime($hour, $minute, $second, $month, $day, $year);
01526 $end = $start + abs($duration);
01527 if (!$duration) {
01528 $end = get_day_end($day, $month, $year);
01529 }
01530
01531 $this->calendar_start = $start;
01532 $this->calendar_end = $end;
01533
01534 return true;
01535 }
01536
01543 public function getCalendarStartTime() {
01544 return (int)$this->calendar_start;
01545 }
01546
01554 public function getCalendarEndTime() {
01555 return (int)$this->calendar_end;
01556 }
01557
01558
01559
01560
01561
01567 public function getExportableValues() {
01568 return array(
01569 'guid',
01570 'type',
01571 'subtype',
01572 'time_created',
01573 'time_updated',
01574 'container_guid',
01575 'owner_guid',
01576 'site_guid'
01577 );
01578 }
01579
01587 public function export() {
01588 $tmp = array();
01589
01590
01591 $uuid = guid_to_uuid($this->getGUID());
01592
01593
01594 $odd = new ODDEntity(
01595 $uuid,
01596 $this->attributes['type'],
01597 get_subtype_from_id($this->attributes['subtype'])
01598 );
01599
01600 $tmp[] = $odd;
01601
01602 $exportable_values = $this->getExportableValues();
01603
01604
01605 foreach ($this->attributes as $k => $v) {
01606 $meta = NULL;
01607
01608 if (in_array($k, $exportable_values)) {
01609 switch ($k) {
01610 case 'guid':
01611 case 'type':
01612 case 'subtype':
01613 break;
01614
01615 case 'time_created':
01616 $odd->setAttribute('published', date("r", $v));
01617 break;
01618
01619 case 'site_guid':
01620 $k = 'site_uuid';
01621 $v = guid_to_uuid($v);
01622 $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
01623 break;
01624
01625 case 'container_guid':
01626 $k = 'container_uuid';
01627 $v = guid_to_uuid($v);
01628 $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
01629 break;
01630
01631 case 'owner_guid':
01632 $k = 'owner_uuid';
01633 $v = guid_to_uuid($v);
01634 $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
01635 break;
01636
01637 default:
01638 $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
01639 }
01640
01641
01642 if ($meta) {
01643 $meta->setAttribute('published', date("r", $this->time_created));
01644 $tmp[] = $meta;
01645 }
01646 }
01647 }
01648
01649
01650
01651
01652
01653
01654 elgg_set_viewtype('default');
01655 $view = elgg_view_entity($this, array('full_view' => true));
01656 elgg_set_viewtype();
01657
01658 $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid,
01659 'renderedentity', $view, 'volatile');
01660
01661 return $tmp;
01662 }
01663
01664
01665
01666
01667
01677 public function import(ODD $data) {
01678 if (!($data instanceof ODDEntity)) {
01679 throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass'));
01680 }
01681
01682
01683 $this->attributes['type'] = $data->getAttribute('class');
01684 $this->attributes['subtype'] = $data->getAttribute('subclass');
01685
01686
01687 $this->attributes['owner_guid'] = elgg_get_logged_in_user_guid();
01688
01689
01690 $this->attributes['time_created'] = strtotime($data->getAttribute('published'));
01691 $this->attributes['time_updated'] = time();
01692
01693 return true;
01694 }
01695
01696
01697
01698
01699
01706 public function getSystemLogID() {
01707 return $this->getGUID();
01708 }
01709
01723 public function getObjectFromID($id) {
01724 return get_entity($id);
01725 }
01726
01736 public function getTags($tag_names = NULL) {
01737 if ($tag_names && !is_array($tag_names)) {
01738 $tag_names = array($tag_names);
01739 }
01740
01741 $valid_tags = elgg_get_registered_tag_metadata_names();
01742 $entity_tags = array();
01743
01744 foreach ($valid_tags as $tag_name) {
01745 if (is_array($tag_names) && !in_array($tag_name, $tag_names)) {
01746 continue;
01747 }
01748
01749 if ($tags = $this->$tag_name) {
01750
01751
01752 if (is_array($tags)) {
01753 $entity_tags = array_merge($entity_tags, $tags);
01754 } else {
01755 $entity_tags[] = $tags;
01756 }
01757 }
01758 }
01759
01760 return $entity_tags;
01761 }
01762 }