diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-28 15:35:11 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-28 15:35:11 +0000 |
commit | 1705abb86f976f3e0e0bd979e03d6f7048cb70c3 (patch) | |
tree | 49940a21f44dcc0e0a3e56a056190dfed433322e /engine | |
parent | 9fe114978201e2f306a524f4d7382f951f088a2b (diff) | |
download | elgg-1705abb86f976f3e0e0bd979e03d6f7048cb70c3.tar.gz elgg-1705abb86f976f3e0e0bd979e03d6f7048cb70c3.tar.bz2 |
Added elgg_view_entity(ElggEntity $entity) to intelligently display entities
git-svn-id: https://code.elgg.org/elgg/trunk@280 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index f421673e6..74585a6d9 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -153,6 +153,50 @@ }
/**
+ * When given an entity, views it intelligently.
+ *
+ * Expects a view to exist called entity-type/subtype, or for the entity to have a parameter
+ * 'view' which lists a different view to display. In both cases, elgg_view will be called with
+ * array('entity' => $entity) as its parameters, and therefore this is what the view should expect
+ * to receive.
+ *
+ * @param ElggEntity $entity The entity to display
+ * @return string HTML (etc) to display
+ */
+ function elgg_view_entity(ElggEntity $entity) {
+
+ $view = $entity->view;
+ if (is_string($view)) {
+ return elgg_view($view,array('entity' => $entity));
+ }
+
+ $classes = array(
+ 'ElggUser' => 'user',
+ 'ElggObject' => 'object',
+ 'ElggSite' => 'site',
+ 'ElggCollection' => 'collection'
+ );
+
+ $entity_class = get_class($entity);
+ if (isset($classes[$entity_class])) {
+ $entity_type = $classes[$entity_class];
+ } else {
+ foreach($classes as $class => $type) {
+ if (is_subclass_of($entity,$class)) {
+ $entity_type = $class;
+ break;
+ }
+ }
+ }
+ if (!isset($entity_class)) return false;
+
+ $subtype = $entity->getSubtype();
+
+ return elgg_view("{$entity_type}/{$subtype}",array('entity' => $entity));
+
+ }
+
+ /**
* Sets an alternative function to handle templates, which will be passed to by elgg_view.
* This function must take the $view and $vars parameters from elgg_view:
*
|