aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggObject.php
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2012-02-09 05:09:56 -0800
committerCash Costello <cash.costello@gmail.com>2012-02-09 05:09:56 -0800
commit1f4a462d84a2bda542580828d1c39bec0a5a6495 (patch)
tree28021e2dfbfe0e2309e4eee9ff07bbc8703423d0 /engine/classes/ElggObject.php
parentefb6ba4d0ab857703d721c5538150cf2a337347d (diff)
parent187fcf6c98ae723d4fb296801cc91ce7092e62c0 (diff)
downloadelgg-1f4a462d84a2bda542580828d1c39bec0a5a6495.tar.gz
elgg-1f4a462d84a2bda542580828d1c39bec0a5a6495.tar.bz2
Merge pull request #159 from cash/entity_load
More efficient entity loading
Diffstat (limited to 'engine/classes/ElggObject.php')
-rw-r--r--engine/classes/ElggObject.php27
1 files changed, 16 insertions, 11 deletions
diff --git a/engine/classes/ElggObject.php b/engine/classes/ElggObject.php
index 649e32490..b4bae6825 100644
--- a/engine/classes/ElggObject.php
+++ b/engine/classes/ElggObject.php
@@ -41,12 +41,12 @@ class ElggObject extends ElggEntity {
*
* If no arguments are passed, create a new entity.
*
- * If an argument is passed attempt to load a full Object entity. Arguments
- * can be:
+ * If an argument is passed, attempt to load a full ElggObject entity.
+ * Arguments can be:
* - The GUID of an object entity.
- * - A DB result object with a guid property
+ * - A DB result object from the entities table with a guid property
*
- * @param mixed $guid If an int, load that GUID. If a db row then will attempt to
+ * @param mixed $guid If an int, load that GUID. If a db row, then will attempt to
* load the rest of the data.
*
* @throws IOException If passed an incorrect guid
@@ -59,15 +59,15 @@ class ElggObject extends ElggEntity {
$this->initialise_attributes(false);
if (!empty($guid)) {
- // Is $guid is a DB row - either a entity row, or a object table row.
+ // Is $guid is a DB row from the entity table
if ($guid instanceof stdClass) {
// Load the rest
- if (!$this->load($guid->guid)) {
+ if (!$this->load($guid)) {
$msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid));
throw new IOException($msg);
}
- // Is $guid is an ElggObject? Use a copy constructor
+ // Is $guid is an ElggObject? Use a copy constructor
} else if ($guid instanceof ElggObject) {
elgg_deprecated_notice('This type of usage of the ElggObject constructor was deprecated. Please use the clone method.', 1.7);
@@ -75,11 +75,11 @@ class ElggObject extends ElggEntity {
$this->attributes[$key] = $value;
}
- // Is this is an ElggEntity but not an ElggObject = ERROR!
+ // Is this is an ElggEntity but not an ElggObject = ERROR!
} else if ($guid instanceof ElggEntity) {
throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggObject'));
- // We assume if we have got this far, $guid is an int
+ // Is it a GUID
} else if (is_numeric($guid)) {
if (!$this->load($guid)) {
throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid)));
@@ -93,17 +93,22 @@ class ElggObject extends ElggEntity {
/**
* Loads the full ElggObject when given a guid.
*
- * @param int $guid Guid of an ElggObject
+ * @param mixed $guid GUID of an ElggObject or the stdClass object from entities table
*
* @return bool
* @throws InvalidClassException
*/
protected function load($guid) {
- // Test to see if we have the generic stuff
+ // Load data from entity table if needed
if (!parent::load($guid)) {
return false;
}
+ // Only work with GUID from here
+ if ($guid instanceof stdClass) {
+ $guid = $guid->guid;
+ }
+
// Check the type
if ($this->attributes['type'] != 'object') {
$msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class()));