Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
51b2408a
Commit
51b2408a
authored
Dec 22, 2006
by
Nigel McNie
Committed by
Nigel McNie
Dec 22, 2006
Browse files
Implemented community searching.
parent
5c0cdaa4
Changes
3
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/searchlib.php
View file @
51b2408a
...
...
@@ -108,4 +108,43 @@ function search_group($query_string, $limit, $offset = 0) {
return
call_static_method
(
generate_class_name
(
'search'
,
$plugin
),
'search_group'
,
$query_string
,
$limit
,
$offset
);
}
/**
* Given a query string and limits, return an array of matching communities using the
* search plugin defined in config.php
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* name => string,
* owner => integer,
* description => string,
* ctime => string,
* mtime => string,
* ),
* array(
* id => integer,
* name => string,
* owner => integer,
* description => string,
* ctime => string,
* mtime => string,
* ),
* array(...),
* ),
* );
*/
function
search_community
(
$query_string
,
$limit
,
$offset
=
0
)
{
$plugin
=
get_config
(
'searchplugin'
);
safe_require
(
'search'
,
$plugin
);
return
call_static_method
(
generate_class_name
(
'search'
,
$plugin
),
'search_community'
,
$query_string
,
$limit
,
$offset
);
}
?>
htdocs/search/internal/lib.php
View file @
51b2408a
...
...
@@ -103,9 +103,7 @@ class PluginSearchInternal extends PluginSearch {
OR email ILIKE '%' || ? || '%'
)
"
,
array
(
$query_string
,
$query_string
,
$query_string
,
$query_string
),
$offset
,
$limit
array
(
$query_string
,
$query_string
,
$query_string
,
$query_string
)
);
}
// TODO
...
...
@@ -189,16 +187,95 @@ class PluginSearchInternal extends PluginSearch {
OR description ILIKE '%' || ? || '%'
)
"
,
array
(
$USER
->
get
(
'id'
),
$query_string
,
$query_string
),
array
(
$USER
->
get
(
'id'
),
$query_string
,
$query_string
)
);
}
// TODO
// else if ( is_mysql() ) {
// }
else
{
throw
new
SQLException
(
'search_group() is not implemented for your database engine ('
.
get_config
(
'dbtype'
)
.
')'
);
}
return
array
(
'count'
=>
$count
,
'limit'
=>
$limit
,
'offset'
=>
$offset
,
'data'
=>
$data
,
);
}
/**
* Implement community searching with SQL
*
* @param string The query string
* @param integer How many results to return
* @param integer What result to start at (0 == first result)
* @return array A data structure containing results looking like ...
* $results = array(
* count => integer, // total number of results
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* data => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
* );
*/
public
static
function
search_community
(
$query_string
,
$limit
,
$offset
=
0
)
{
global
$USER
;
if
(
is_postgres
()
)
{
$data
=
get_records_sql_array
(
"
SELECT
id, name, description, jointype, owner, ctime, mtime
FROM
"
.
get_config
(
'dbprefix'
)
.
"community
WHERE
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
"
,
array
(
$query_string
,
$query_string
),
$offset
,
$limit
);
$count
=
get_field_sql
(
"
SELECT
COUNT(*)
FROM
"
.
get_config
(
'dbprefix'
)
.
"usr_group u
WHERE
owner = ?
AND (
name ILIKE '%' || ? || '%'
OR description ILIKE '%' || ? || '%'
)
"
,
array
(
$query_string
,
$query_string
)
);
}
// TODO
// else if ( is_mysql() ) {
// }
else
{
throw
new
SQLException
(
'search_
group
() is not implemented for your database engine ('
.
get_config
(
'dbtype'
)
.
')'
);
throw
new
SQLException
(
'search_
community
() is not implemented for your database engine ('
.
get_config
(
'dbtype'
)
.
')'
);
}
return
array
(
...
...
htdocs/view/create4.json.php
View file @
51b2408a
...
...
@@ -44,6 +44,9 @@ switch ($type) {
case
'group'
:
$data
=
get_group_results
(
$query
,
$limit
,
$offset
);
break
;
case
'community'
:
$data
=
get_community_results
(
$query
,
$limit
,
$offset
);
break
;
}
json_headers
();
...
...
@@ -82,4 +85,15 @@ function get_group_results($query, $limit, $offset) {
return
$data
;
}
function
get_community_results
(
$query
,
$limit
,
$offset
)
{
$data
=
search_community
(
$query
,
$limit
,
$offset
);
if
(
$data
[
'data'
])
{
foreach
(
$data
[
'data'
]
as
&
$result
)
{
}
}
return
$data
;
}
?>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment