aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-05-22 14:07:05 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-05-22 14:07:05 +0000
commit6615b6f4d827811046564cd004bd167b4c3c38bf (patch)
treea8b13babab0bb2741e9612f46d0e6a113bd29026
parent18dd81e15a1159e73f0371e91b62640db3f5e9bf (diff)
downloadelgg-6615b6f4d827811046564cd004bd167b4c3c38bf.tar.gz
elgg-6615b6f4d827811046564cd004bd167b4c3c38bf.tar.bz2
Closes #1030: Group title and description search added, refs #965
git-svn-id: https://code.elgg.org/elgg/trunk@3300 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/group.php98
-rw-r--r--engine/lib/users.php12
-rw-r--r--engine/schema/mysql.sql4
-rw-r--r--engine/schema/upgrades/2009052201.sql5
-rw-r--r--languages/en.php3
-rw-r--r--search/groups.php40
-rw-r--r--version.php2
-rw-r--r--views/default/group/search/finishblurb.php15
-rw-r--r--views/default/group/search/startblurb.php8
9 files changed, 174 insertions, 13 deletions
diff --git a/engine/lib/group.php b/engine/lib/group.php
index bbd7fba57..f7face866 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -826,14 +826,108 @@
$group_tool_option->default_on = $default_on;
$CONFIG->group_tool_options[] = $group_tool_option;
+ }
+
+ /**
+ * Searches for a user based on a complete or partial name or username.
+ *
+ * @param string $criteria The partial or full name or username.
+ * @param int $limit Limit of the search.
+ * @param int $offset Offset.
+ * @param string $order_by The order.
+ * @param boolean $count Whether to return the count of results or just the results.
+ */
+ function search_for_group($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false)
+ {
+ global $CONFIG;
+
+ $criteria = sanitise_string($criteria);
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $order_by = sanitise_string($order_by);
+
+ $access = get_access_sql_suffix("e");
+
+ if ($order_by == "") $order_by = "e.time_created desc";
+
+ if ($count) {
+ $query = "SELECT count(e.guid) as total ";
+ } else {
+ $query = "SELECT e.* ";
+ }
+ $query .= "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}groups_entity g on e.guid=g.guid where ";
+ // $query .= " match(u.name,u.username) against ('$criteria') ";
+ $query .= "(g.name like \"%{$criteria}%\" or g.description like \"%{$criteria}%\")";
+ $query .= " and $access";
+
+ if (!$count) {
+ $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($count = get_data_row($query)) {
+ return $count->total;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns a formatted list of groups suitable for injecting into search.
+ *
+ */
+ function search_list_groups_by_name($hook, $user, $returnvalue, $tag) {
+
+ // Change this to set the number of groups that display on the search page
+ $threshold = 4;
+
+ $object = get_input('object');
+
+ if (!get_input('offset') && (empty($object) || $object == 'group'))
+ if ($groups = search_for_group($tag,$threshold)) {
+
+ $countgroups = search_for_group($tag,0,0,"",true);
+
+ $return = elgg_view('group/search/startblurb',array('count' => $countgroups, 'tag' => $tag));
+ foreach($groups as $group) {
+ $return .= elgg_view_entity($group);
+ }
+ $return .= elgg_view('group/search/finishblurb',array('count' => $countgroups, 'threshold' => $threshold, 'tag' => $tag));
+ return $return;
+
+ }
+
+ }
+
+ /**
+ * Displays a list of group objects that have been searched for.
+ *
+ * @see elgg_view_entity_list
+ *
+ * @param string $tag Search criteria
+ * @param int $limit The number of entities to display on a page
+ * @return string The list in a form suitable to display
+ */
+ function list_group_search($tag, $limit = 10) {
+
+ $offset = (int) get_input('offset');
+ $limit = (int) $limit;
+ $count = (int) search_for_user($tag, 10, 0, '', true);
+ $entities = search_for_group($tag, $limit, $offset);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, false);
+
}
/**
* Performs initialisation functions for groups
*
*/
- function group_init() {
- register_entity_type('group','');
+ function group_init() {
+ // Register an entity type
+ register_entity_type('group','');
+
+ // Register a search hook
+ register_plugin_hook('search','all','search_list_groups_by_name');
}
register_elgg_event_handler('init','system','group_init');
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 17ef2cd40..6b16e5e69 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -826,11 +826,7 @@
}
/**
- * Searches for a user based on a complete or partial name or username using full text searching.
- *
- * IMPORTANT NOTE: With MySQL's default setup:
- * 1) $criteria must be 4 or more characters long
- * 2) If $criteria matches greater than 50% of results NO RESULTS ARE RETURNED!
+ * Searches for a user based on a complete or partial name or username.
*
* @param string $criteria The partial or full name or username.
* @param int $limit Limit of the search.
@@ -877,10 +873,8 @@
*
* @see elgg_view_entity_list
*
- * @param int $user_guid The GUID of the user
- * @param string $subtype The object subtype
- * @param int $limit The number of entities to display on a page
- * @param true|false $fullview Whether or not to display the full view (default: true)
+ * @param string $tag Search criteria
+ * @param int $limit The number of entities to display on a page
* @return string The list in a form suitable to display
*/
function list_user_search($tag, $limit = 10) {
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql
index e8d823a3b..941f46c2a 100644
--- a/engine/schema/mysql.sql
+++ b/engine/schema/mysql.sql
@@ -165,7 +165,9 @@ CREATE TABLE `prefix_groups_entity` (
`name` text NOT NULL,
`description` text NOT NULL,
- PRIMARY KEY (`guid`),
+ PRIMARY KEY (`guid`),
+ KEY `name` (`name`(50)),
+ KEY `description` (`description`(50)),
FULLTEXT KEY (`name`,`description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
diff --git a/engine/schema/upgrades/2009052201.sql b/engine/schema/upgrades/2009052201.sql
new file mode 100644
index 000000000..b825f9936
--- /dev/null
+++ b/engine/schema/upgrades/2009052201.sql
@@ -0,0 +1,5 @@
+ALTER TABLE `prefix_groups_entity` DROP KEY `name`;
+ALTER TABLE `prefix_groups_entity` ADD KEY `name` (`name`(50));
+
+ALTER TABLE `prefix_groups_entity` DROP KEY `description`;
+ALTER TABLE `prefix_groups_entity` ADD KEY `description` (`description`(50));
diff --git a/languages/en.php b/languages/en.php
index f2525a74b..f36ac1cd4 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -428,6 +428,9 @@ To remove a widget drag it back to the <b>Widget gallery</b>.",
'user:search:startblurb' => "Users matching '%s':",
'user:search:finishblurb' => "To view more, click here.",
+
+ 'group:search:startblurb' => "Groups matching '%s':",
+ 'group:search:finishblurb' => "To view more, click here.",
/**
* Account
diff --git a/search/groups.php b/search/groups.php
new file mode 100644
index 000000000..e04a14606
--- /dev/null
+++ b/search/groups.php
@@ -0,0 +1,40 @@
+<?php
+
+ /**
+ * Generic search viewer
+ * Given a GUID, this page will try and display any entity
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.org/
+ */
+
+ // Load Elgg engine
+ require_once(dirname(dirname(__FILE__)) . "/engine/start.php");
+
+ // Set context
+ set_context('search');
+
+ // Get input
+ $tag = get_input('tag');
+
+ if (!empty($tag)) {
+ $title = sprintf(elgg_echo('users:searchtitle'),$tag);
+ $body = "";
+ $body .= elgg_view_title($title); // elgg_view_title(sprintf(elgg_echo('searchtitle'),$tag));
+ $body .= elgg_view('group/search/startblurb',array('tag' => $tag));
+ $body .= list_group_search($tag);
+ //$body = elgg_view_layout('two_column_left_sidebar','',$body);
+ } else {
+ $title = elgg_echo('item:group');
+ $body .= elgg_view_title($title);
+ $body .= list_entities('groups');
+ }
+
+ $body = elgg_view_layout('two_column_left_sidebar','',$body);
+ page_draw($title,$body);
+
+?> \ No newline at end of file
diff --git a/version.php b/version.php
index 461a07fa0..ef1c29149 100644
--- a/version.php
+++ b/version.php
@@ -13,7 +13,7 @@
* @link http://elgg.org/
*/
- $version = 2009051901; // YYYYMMDD = Elgg Date
+ $version = 2009052201; // YYYYMMDD = Elgg Date
// XX = Interim incrementer
$release = '1.5'; // Human-friendly version name
diff --git a/views/default/group/search/finishblurb.php b/views/default/group/search/finishblurb.php
new file mode 100644
index 000000000..af3ba3fd2
--- /dev/null
+++ b/views/default/group/search/finishblurb.php
@@ -0,0 +1,15 @@
+<?php
+
+ if ($vars['count'] > $vars['threshold']) {
+
+?>
+<div class="contentWrapper"><a href="<?php echo $vars['url']; ?>search/groups.php?tag=<?php echo urlencode($vars['tag']); ?>"><?php
+
+ echo elgg_echo("group:search:finishblurb");
+
+ ?></a></div>
+<?php
+
+ }
+
+?> \ No newline at end of file
diff --git a/views/default/group/search/startblurb.php b/views/default/group/search/startblurb.php
new file mode 100644
index 000000000..c7f3a4e55
--- /dev/null
+++ b/views/default/group/search/startblurb.php
@@ -0,0 +1,8 @@
+
+<div class="contentWrapper">
+ <?php
+
+ echo sprintf(elgg_echo("group:search:startblurb"),$vars['tag']);
+
+ ?>
+</div> \ No newline at end of file