From 8f0161a9d382b5610326576a6f572d0beb8c3e03 Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 10 Mar 2010 22:03:58 +0000 Subject: Added elgg_instanceof(). git-svn-id: http://code.elgg.org/elgg/trunk@5353 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 3 ++- engine/lib/entities.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 3c95ef2be..42d6ffc6f 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2757,6 +2757,7 @@ function elgg_boot() { function elgg_api_test($hook, $type, $value, $params) { global $CONFIG; $value[] = $CONFIG->path . 'engine/tests/api/entity_getter_functions.php'; + $value[] = $CONFIG->path . 'engine/tests/api/helpers.php'; $value[] = $CONFIG->path . 'engine/tests/regression/trac_bugs.php'; return $value; } @@ -2775,4 +2776,4 @@ define('ELGG_ENTITIES_NO_VALUE', 0); register_elgg_event_handler('init', 'system', 'elgg_init'); register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000); -register_plugin_hook('unit_test', 'system', 'elgg_api_test'); +register_plugin_hook('unit_test', 'system', 'elgg_api_test'); \ No newline at end of file diff --git a/engine/lib/entities.php b/engine/lib/entities.php index af5b140d9..17bc0aa1e 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -3630,6 +3630,28 @@ function recursive_delete_permissions_check($hook, $entity_type, $returnvalue, $ return NULL; } +/** + * Checks if $entity is an ElggEntity and optionally for type and subtype. + * + * @param $entity + * @param $type + * @param $subtype + * @return Bool + */ +function elgg_instanceof($entity, $type = NULL, $subtype = NULL) { + $return = ($entity instanceof ElggEntity); + + if ($type) { + $return = $return && ($entity->getType() == $type); + } + + if ($subtype) { + $return = $return && ($entity->getSubtype() == $subtype); + } + + return $return; +} + /** * Garbage collect stub and fragments from any broken delete/create calls * -- cgit v1.2.3