]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added search for group, tags, and users.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 6 Nov 2009 01:49:35 +0000 (01:49 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 6 Nov 2009 01:49:35 +0000 (01:49 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@3624 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/group.php
engine/lib/tags.php
engine/lib/users.php

index 9fc937ff3dace4e3405637d82b5172ff32f2a5bd..289e1fc0c07e587fbe01ba307ee71726e6089506 100644 (file)
@@ -950,4 +950,54 @@ function group_init() {
        register_plugin_hook('search','all','search_list_groups_by_name');
 }
 
+
+/**
+ * Return default results for searches on groups.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ * @return unknown_type
+ */
+function groups_search_hook($hook, $type, $value, $params) {
+       global $CONFIG;
+
+       $query = $params['query'];
+
+       $join = "JOIN {$CONFIG->dbprefix}groups_entity ge ON e.guid = ge.guid";
+       $params['joins'] = array($join);
+
+       $where = "(ge.guid = e.guid
+               AND (ge.name LIKE '%$query%'
+                       OR ge.description LIKE '%$query%'
+                       )
+               )";
+       $params['wheres'] = array($where);
+
+       $entities = elgg_get_entities($params);
+       $params['count'] = TRUE;
+       $count = elgg_get_entities($params);
+
+       // no need to continue if nothing here.
+       if (!$count) {
+               return array('entities' => array(), 'count' => $count);
+       }
+
+       // add the volatile data for why these entities have been returned.
+       foreach ($entities as $entity) {
+               $description = search_get_relevant_substring($entity->description, $query, '<strong class="searchMatch">', '</strong>');
+               $entity->setVolatileData('search_matched_title', $description);
+
+               $name = search_get_relevant_substring($entity->name, $query, '<strong class="searchMatch">', '</strong>');
+               $entity->setVolatileData('search_matched_description', $name);
+       }
+
+       return array(
+               'entities' => $entities,
+               'count' => $count,
+       );
+}
+
 register_elgg_event_handler('init','system','group_init');
+register_plugin_hook('search', 'group', 'groups_search_hook');
index 3c65c2a7aac75534a1b84dfe430a8662a3396778..cdcf213c01a012cca651454b43df6c8d9eca29e6 100644 (file)
@@ -174,4 +174,62 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type
 
 function display_tagcloud($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1) {
        return elgg_view("output/tagcloud",array('value' => get_tags($threshold, $limit, $metadata_name, $entity_type, $entity_subtype, $owner_guid, $site_guid),'object' => $entity_type, 'subtype' => $entity_subtype));
-}
\ No newline at end of file
+}
+
+
+
+/**
+ * Return default results for searches on groups.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ * @return unknown_type
+ */
+function tags_search_hook($hook, $type, $value, $params) {
+       global $CONFIG;
+
+       $query = $params['query'];
+
+       $params['metadata_name_value_pair'] = array ('name' => 'tags', 'value' => $query, 'case_sensitive' => FALSE);
+
+       $entities = elgg_get_entities_from_metadata($params);
+       $params['count'] = TRUE;
+       $count = elgg_get_entities_from_metadata($params);
+
+       // no need to continue if nothing here.
+       if (!$count) {
+               return array('entities' => array(), 'count' => $count);
+       }
+
+       // add the volatile data for why these entities have been returned.
+       foreach ($entities as $entity) {
+               $tags = implode(',', $entity->tags);
+               $tags_str = search_get_relevant_substring($tags, $query, '<strong class="searchMatch">', '</strong>');
+               $entity->setVolatileData('search_matched_tags', $tags_str);
+       }
+
+       return array(
+               'entities' => $entities,
+               'count' => $count,
+       );
+}
+
+/**
+ * Register tags as a custom search type.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ * @return unknown_type
+ */
+function tags_search_custom_types_hook($hook, $type, $value, $params) {
+       $value[] = 'tags';
+       return $value;
+}
+
+
+register_plugin_hook('search', 'tags', 'tags_search_hook');
+register_plugin_hook('search_types', 'get_types', 'tags_search_custom_types_hook');
\ No newline at end of file
index a15330501e544bb5e7ccfee494cb124bb237a7ec..0d2a75dbb91f92afd207423a55edbbbbc5ab0f67 100644 (file)
@@ -1532,16 +1532,66 @@ function users_settings_save() {
        include($CONFIG->path . "actions/user/default_access.php");
 }
 
-//register actions *************************************************************
-register_elgg_event_handler('init','system','users_init',0);
-register_elgg_event_handler('pagesetup','system','users_pagesetup',0);
-
 /**
  * Runs unit tests for ElggObject
  */
-register_plugin_hook('unit_test', 'system', 'users_test');
 function users_test($hook, $type, $value, $params) {
        global $CONFIG;
        $value[] = "{$CONFIG->path}engine/tests/objects/users.php";
        return $value;
-}
\ No newline at end of file
+}
+
+/**
+ * Return default results for searches on users.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ * @return unknown_type
+ */
+function users_search_hook($hook, $type, $value, $params) {
+       global $CONFIG;
+
+       $query = $params['query'];
+
+       $join = "JOIN {$CONFIG->dbprefix}users_entity ue ON e.guid = ue.guid";
+       $params['joins'] = array($join);
+
+       $where = "(ue.guid = e.guid
+               AND (ue.username LIKE '%$query%'
+                       OR ue.name LIKE '%$query%'
+                       )
+               )";
+       $params['wheres'] = array($where);
+
+       $entities = elgg_get_entities($params);
+       $params['count'] = TRUE;
+       $count = elgg_get_entities($params);
+
+       // no need to continue if nothing here.
+       if (!$count) {
+               return array('entities' => array(), 'count' => $count);
+       }
+
+       // add the volatile data for why these entities have been returned.
+       foreach ($entities as $entity) {
+               $username = search_get_relevant_substring($entity->username, $query, '<strong class="searchMatch">', '</strong>');
+               $entity->setVolatileData('search_matched_title', $username);
+
+               $name = search_get_relevant_substring($entity->name, $query, '<strong class="searchMatch">', '</strong>');
+               $entity->setVolatileData('search_matched_description', $name);
+       }
+
+       return array(
+               'entities' => $entities,
+               'count' => $count,
+       );
+}
+
+
+//register actions *************************************************************
+register_elgg_event_handler('init','system','users_init',0);
+register_elgg_event_handler('pagesetup','system','users_pagesetup',0);
+register_plugin_hook('unit_test', 'system', 'users_test');
+register_plugin_hook('search', 'user', 'users_search_hook');