From 23594f5a78f4557b183d5cc2a045b684cf32cc74 Mon Sep 17 00:00:00 2001 From: brettp Date: Mon, 11 Jan 2010 22:58:55 +0000 Subject: Pulling out entity views in search. Adding dev documentation. git-svn-id: http://code.elgg.org/elgg/trunk@3795 36083f99-b078-4883-b0ff-0f9b5a30f544 --- .../views/default/search/comments/entity.php | 59 ++++++++++++ .../views/default/search/comments/listing.php | 107 --------------------- mod/search/views/default/search/entity.php | 41 ++++++++ mod/search/views/default/search/listing.php | 43 +++------ 4 files changed, 112 insertions(+), 138 deletions(-) create mode 100644 mod/search/views/default/search/comments/entity.php delete mode 100644 mod/search/views/default/search/comments/listing.php create mode 100644 mod/search/views/default/search/entity.php (limited to 'mod/search/views/default') diff --git a/mod/search/views/default/search/comments/entity.php b/mod/search/views/default/search/comments/entity.php new file mode 100644 index 000000000..8b4d286c9 --- /dev/null +++ b/mod/search/views/default/search/comments/entity.php @@ -0,0 +1,59 @@ +getVolatileData('search_matched_comment_owner_guid')); + +if ($owner instanceof ElggUser) { + $icon = elgg_view('profile/icon', array('entity' => $owner, 'size' => 'small')); +} else { + $icon = ''; +} + +// @todo Sometimes we find comments on entities we can't display... +if ($entity->getVolatileData('search_unavailable_entity')) { + $title = sprintf(elgg_echo('search:comment_on'), elgg_echo('search:unavailable_entity')); + // keep anchor for formatting. + $title = "$title"; +} else { + if ($entity->getType() == 'object') { + $title = $entity->title; + } else { + $title = $entity->name; + } + + if (!$title) { + $title = elgg_echo('item:' . $entity->getType() . ':' . $entity->getSubtype()); + } + + if (!$title) { + $title = elgg_echo('item:' . $entity->getType()); + } + + $title = sprintf(elgg_echo('search:comment_on'), $title); + $url = $entity->getURL() . '#annotation-' . $entity->getVolatileData('search_match_annotation_id'); + $title = "$title"; +} + +$description = $entity->getVolatileData('search_matched_comment'); +$tc = $entity->getVolatileData('search_matched_comment_time_created');; +$time = friendly_time($tc); + +echo <<<___END +
+
$icon
+
+

$title

$description +

$time

+
+
+___END; + +?> \ No newline at end of file diff --git a/mod/search/views/default/search/comments/listing.php b/mod/search/views/default/search/comments/listing.php deleted file mode 100644 index 34456bde8..000000000 --- a/mod/search/views/default/search/comments/listing.php +++ /dev/null @@ -1,107 +0,0 @@ - $vars['params']['query'], - 'entity_type' => $vars['params']['type'], - 'entity_subtype' => $vars['params']['subtype'], - 'limit' => get_input('limit', 10), - 'offset' => get_input('offset', 0), - 'search_type' => 'comments', - ) -)); - -$url = "{$vars['url']}pg/search?$query"; - -// get pagination -if (array_key_exists('pagination', $vars) && $vars['pagination']) { - $nav .= elgg_view('navigation/pagination',array( - 'baseurl' => $url, - 'offset' => $vars['params']['offset'], - 'count' => $vars['count'], - 'limit' => $vars['params']['limit'], - )); -} else { - $nav = ''; -} - -// get more links -$more_check = $vars['count'] - ($vars['params']['offset'] + $vars['params']['limit']); -$more = ($more_check > 0) ? $more_check : 0; - -if ($more) { - $title_key = ($more == 1) ? 'comment' : 'comments'; - $more_str = sprintf(elgg_echo('search:more'), $vars['count'], elgg_echo($title_key)); - $more_link = "
$more_str
"; -} else { - $more_link = ''; -} - -$body = elgg_view_title($title_str); - -foreach ($vars['entities'] as $entity) { - $owner = get_entity($entity->getVolatileData('search_matched_comment_owner_guid')); - - if ($owner instanceof ElggUser) { - $icon = elgg_view('profile/icon', array('entity' => $owner, 'size' => 'small')); - } else { - $icon = ''; - } - - // @todo Sometimes we find comments on entities we can't display... - if ($entity->getVolatileData('search_unavailable_entity')) { - $title = sprintf(elgg_echo('search:comment_on'), elgg_echo('search:unavailable_entity')); - // keep anchor for formatting. - $title = "$title"; - } else { - if ($entity->getType() == 'object') { - $title = $entity->title; - } else { - $title = $entity->name; - } - - if (!$title) { - $title = elgg_echo('item:' . $entity->getType() . ':' . $entity->getSubtype()); - } - - if (!$title) { - $title = elgg_echo('item:' . $entity->getType()); - } - - $title = sprintf(elgg_echo('search:comment_on'), $title); - $url = $entity->getURL() . '#annotation-' . $entity->getVolatileData('search_match_annotation_id'); - $title = "$title"; - } - - $description = $entity->getVolatileData('search_matched_comment'); - $tc = $entity->getVolatileData('search_matched_comment_time_created');; - $time = friendly_time($tc); - - $body .= <<<___END -
-
$icon
-
-

$title

$description -

$time

-
-
-___END; -} - -echo $body; -echo $more_link; -echo $nav; diff --git a/mod/search/views/default/search/entity.php b/mod/search/views/default/search/entity.php new file mode 100644 index 000000000..06dd54f39 --- /dev/null +++ b/mod/search/views/default/search/entity.php @@ -0,0 +1,41 @@ +getOwnerEntity()) { + $icon = elgg_view('profile/icon', array('entity' => $owner, 'size' => 'small')); +} elseif ($entity instanceof ElggUser) { + $icon = elgg_view('profile/icon', array('entity' => $entity, 'size' => 'small')); +} else { + $icon = ''; +} + +$title = $entity->getVolatileData('search_matched_title'); +$description = $entity->getVolatileData('search_matched_description'); +$extra_info = $entity->getVolatileData('search_matched_extra'); +$url = $entity->getURL(); +$title = "$title"; +$tc = $entity->time_created; +$tu = $entity->time_updated; +$time = friendly_time(($tu > $tc) ? $tu : $tc); + +echo <<<___END +
+
$icon
+
+

$title

$description +

$time $extra_info

+
+
+___END; + +// php bug. must have close tag after heredocs +?> \ No newline at end of file diff --git a/mod/search/views/default/search/listing.php b/mod/search/views/default/search/listing.php index 867523d65..36032940d 100644 --- a/mod/search/views/default/search/listing.php +++ b/mod/search/views/default/search/listing.php @@ -8,11 +8,10 @@ * @link http://elgg.org/ */ +$entities = $vars['results']['entities']; +$count = $vars['results']['count'] - count($entities); -$entities = $vars['entities']; -$count = $vars['count'] - count($vars['entities']); - -if (!is_array($vars['entities']) || !count($vars['entities'])) { +if (!is_array($entities) || !count($entities)) { return FALSE; } @@ -34,7 +33,7 @@ if (array_key_exists('pagination', $vars) && $vars['pagination']) { $nav .= elgg_view('navigation/pagination',array( 'baseurl' => $url, 'offset' => $vars['params']['offset'], - 'count' => $vars['count'], + 'count' => $vars['results']['count'], 'limit' => $vars['params']['limit'], )); } else { @@ -84,7 +83,7 @@ if (array_key_exists('pagination', $vars['params']) && $vars['params']['paginati $nav .= elgg_view('navigation/pagination',array( 'baseurl' => $url, 'offset' => $vars['params']['offset'], - 'count' => $vars['count'], + 'count' => $vars['results']['count'], 'limit' => $vars['params']['limit'], )); } else { @@ -92,7 +91,7 @@ if (array_key_exists('pagination', $vars['params']) && $vars['params']['paginati } // get any more links. -$more_check = $vars['count'] - ($vars['params']['offset'] + $vars['params']['limit']); +$more_check = $vars['results']['count'] - ($vars['params']['offset'] + $vars['params']['limit']); $more = ($more_check > 0) ? $more_check : 0; if ($more) { @@ -106,31 +105,13 @@ if ($more) { $body = elgg_view_title($type_str); foreach ($entities as $entity) { - if ($owner = $entity->getOwnerEntity()) { - $icon = elgg_view('profile/icon', array('entity' => $owner, 'size' => 'small')); - } elseif ($entity instanceof ElggUser) { - $icon = elgg_view('profile/icon', array('entity' => $entity, 'size' => 'small')); - } else { - $icon = ''; + if ($view = search_get_search_view($vars['params'], 'entity')) { + $body .= elgg_view($view, array( + 'entity' => $entity, + 'params' => $vars['params'], + 'results' => $vars['results'] + )); } - $title = $entity->getVolatileData('search_matched_title'); - $description = $entity->getVolatileData('search_matched_description'); - $extra_info = $entity->getVolatileData('search_matched_extra'); - $url = $entity->getURL(); - $title = "$title"; - $tc = $entity->time_created; - $tu = $entity->time_updated; - $time = friendly_time(($tu > $tc) ? $tu : $tc); - - $body .= <<<___END -
-
$icon
-
-

$title

$description -

$time $extra_info

-
-
-___END; } echo $body; echo $more_link; -- cgit v1.2.3