aboutsummaryrefslogtreecommitdiff
path: root/mod/search/views
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-11 22:58:55 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-11 22:58:55 +0000
commit23594f5a78f4557b183d5cc2a045b684cf32cc74 (patch)
treed354462c702524775a48439dc66c7036e9ec2d7d /mod/search/views
parenta69015e09a9627c63be577d10c99143190648b7b (diff)
downloadelgg-23594f5a78f4557b183d5cc2a045b684cf32cc74.tar.gz
elgg-23594f5a78f4557b183d5cc2a045b684cf32cc74.tar.bz2
Pulling out entity views in search.
Adding dev documentation. git-svn-id: http://code.elgg.org/elgg/trunk@3795 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/search/views')
-rw-r--r--mod/search/views/default/search/comments/entity.php59
-rw-r--r--mod/search/views/default/search/comments/listing.php107
-rw-r--r--mod/search/views/default/search/entity.php41
-rw-r--r--mod/search/views/default/search/listing.php43
4 files changed, 112 insertions, 138 deletions
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 @@
+<?php
+/**
+ * Elgg search entity
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+$entity = $vars['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 = "<a>$title</a>";
+} 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 = "<a href=\"$url\">$title</a>";
+}
+
+$description = $entity->getVolatileData('search_matched_comment');
+$tc = $entity->getVolatileData('search_matched_comment_time_created');;
+$time = friendly_time($tc);
+
+echo <<<___END
+ <div class="search_listing">
+ <div class="search_listing_icon">$icon</div>
+ <div class="search_listing_info">
+ <p class="ItemTitle">$title</p>$description
+ <p class="ItemTimestamp">$time</p>
+ </div>
+ </div>
+___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 @@
-<?php
-/**
- * Elgg comments search listing
- *
- * @package Elgg
- * @subpackage Core
- * @author Curverider Ltd
- * @link http://elgg.org/
- */
-
-if (!is_array($vars['entities']) || !count($vars['entities'])) {
- return FALSE;
-}
-
-$title_str = elgg_echo('comments');
-
-$query = htmlspecialchars(http_build_query(
- array(
- 'q' => $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 = "<div class='search_listing'><a href=\"$url\">$more_str</a></div>";
-} 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 = "<a>$title</a>";
- } 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 = "<a href=\"$url\">$title</a>";
- }
-
- $description = $entity->getVolatileData('search_matched_comment');
- $tc = $entity->getVolatileData('search_matched_comment_time_created');;
- $time = friendly_time($tc);
-
- $body .= <<<___END
- <div class="search_listing">
- <div class="search_listing_icon">$icon</div>
- <div class="search_listing_info">
- <p class="ItemTitle">$title</p>$description
- <p class="ItemTimestamp">$time</p>
- </div>
- </div>
-___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 @@
+<?php
+/**
+ * Elgg search entity
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
+
+$entity = $vars['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 = '';
+}
+
+$title = $entity->getVolatileData('search_matched_title');
+$description = $entity->getVolatileData('search_matched_description');
+$extra_info = $entity->getVolatileData('search_matched_extra');
+$url = $entity->getURL();
+$title = "<a href=\"$url\">$title</a>";
+$tc = $entity->time_created;
+$tu = $entity->time_updated;
+$time = friendly_time(($tu > $tc) ? $tu : $tc);
+
+echo <<<___END
+ <div class="search_listing">
+ <div class="search_listing_icon">$icon</div>
+ <div class="search_listing_info">
+ <p class="ItemTitle">$title</p>$description
+ <p class="ItemTimestamp">$time $extra_info</p>
+ </div>
+ </div>
+___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 = "<a href=\"$url\">$title</a>";
- $tc = $entity->time_created;
- $tu = $entity->time_updated;
- $time = friendly_time(($tu > $tc) ? $tu : $tc);
-
- $body .= <<<___END
- <div class="search_listing">
- <div class="search_listing_icon">$icon</div>
- <div class="search_listing_info">
- <p class="ItemTitle">$title</p>$description
- <p class="ItemTimestamp">$time $extra_info</p>
- </div>
- </div>
-___END;
}
echo $body;
echo $more_link;