Index: openacs-4/contrib/packages/simulation/lib/yellow-pages.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/yellow-pages.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/packages/simulation/lib/yellow-pages.adp 12 Jan 2004 15:52:44 -0000 1.2
+++ openacs-4/contrib/packages/simulation/lib/yellow-pages.adp 9 Mar 2004 17:04:23 -0000 1.3
@@ -1,2 +1,3 @@
+
Index: openacs-4/contrib/packages/simulation/lib/yellow-pages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/yellow-pages.tcl,v
diff -u -r1.4 -r1.5
--- openacs-4/contrib/packages/simulation/lib/yellow-pages.tcl 11 Feb 2004 15:04:05 -0000 1.4
+++ openacs-4/contrib/packages/simulation/lib/yellow-pages.tcl 9 Mar 2004 17:04:23 -0000 1.5
@@ -17,6 +17,15 @@
set user_id [auth::get_user_id]
}
+ad_page_contract {
+} {
+ search_terms:optional
+}
+
+ad_form -name search -form {
+ {search_terms:text,optional {label "Restrict to items matching word or phrase"}}
+}
+
######################################################################
#
# objects list
@@ -52,6 +61,19 @@
#---------------------------------------------------------------------
# database query
+
+# Search support
+set where_clause(locations) ""
+set where_clause(characters) ""
+if { [exists_and_not_null search_terms] } {
+
+ set search_columns(locations) {sl.title sl.description cr.content sl.address sl.city sl.history}
+ set search_columns(characters) {sc.title sc.description cr.content}
+
+ set where_clause(locations) [simulation::object::search_clause $search_columns(locations) $search_terms]
+ set where_clause(characters) [simulation::object::search_clause $search_columns(characters) $search_terms]
+}
+
db_multirow -extend {view_url} objects select_objects "
select sl.object_id,
sl.object_type,
@@ -63,10 +85,13 @@
sl.description
from sim_locationsx sl,
cr_items ci,
- acs_object_types ot
+ acs_object_types ot,
+ cr_revisions cr
where sl.in_directory_p = 't'
and ci.live_revision = sl.revision_id
and ot.object_type = sl.object_type
+ and cr.revision_id = sl.revision_id
+ [ad_decode $where_clause(locations) "" "" "and $where_clause(locations)"]
UNION
select sc.object_id,
sc.object_type,
@@ -78,10 +103,13 @@
sc.description
from sim_charactersx sc,
cr_items ci,
- acs_object_types ot
+ acs_object_types ot,
+ cr_revisions cr
where sc.in_directory_p = 't'
and ci.live_revision = sc.revision_id
and ot.object_type = sc.object_type
+ and sc.revision_id = cr.revision_id
+ [ad_decode $where_clause(characters) "" "" "and $where_clause(characters)"]
[template::list::orderby_clause -orderby -name "objects"]
" {
Index: openacs-4/contrib/packages/simulation/tcl/object-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/object-procs.tcl,v
diff -u -r1.11 -r1.12
--- openacs-4/contrib/packages/simulation/tcl/object-procs.tcl 27 Feb 2004 20:12:13 -0000 1.11
+++ openacs-4/contrib/packages/simulation/tcl/object-procs.tcl 9 Mar 2004 17:04:24 -0000 1.12
@@ -352,3 +352,21 @@
return $xml_doc
}
+
+ad_proc -private simulation::object::search_clause {
+ search_columns
+ search_string
+} {
+ Return a SQL clause for searching the given search columns.
+
+ @author Peter Marklund
+} {
+ set trimmed_search_string [string trim [string tolower $search_string]]
+
+ set where_clauses [list]
+ foreach column $search_columns {
+ lappend where_clauses "lower($column) like '%$trimmed_search_string%'"
+ }
+
+ return "([join $where_clauses " or "])"
+}
Index: openacs-4/packages/simulation/lib/yellow-pages.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/yellow-pages.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/simulation/lib/yellow-pages.adp 12 Jan 2004 15:52:44 -0000 1.2
+++ openacs-4/packages/simulation/lib/yellow-pages.adp 9 Mar 2004 17:04:23 -0000 1.3
@@ -1,2 +1,3 @@
+
Index: openacs-4/packages/simulation/lib/yellow-pages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/yellow-pages.tcl,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/simulation/lib/yellow-pages.tcl 11 Feb 2004 15:04:05 -0000 1.4
+++ openacs-4/packages/simulation/lib/yellow-pages.tcl 9 Mar 2004 17:04:23 -0000 1.5
@@ -17,6 +17,15 @@
set user_id [auth::get_user_id]
}
+ad_page_contract {
+} {
+ search_terms:optional
+}
+
+ad_form -name search -form {
+ {search_terms:text,optional {label "Restrict to items matching word or phrase"}}
+}
+
######################################################################
#
# objects list
@@ -52,6 +61,19 @@
#---------------------------------------------------------------------
# database query
+
+# Search support
+set where_clause(locations) ""
+set where_clause(characters) ""
+if { [exists_and_not_null search_terms] } {
+
+ set search_columns(locations) {sl.title sl.description cr.content sl.address sl.city sl.history}
+ set search_columns(characters) {sc.title sc.description cr.content}
+
+ set where_clause(locations) [simulation::object::search_clause $search_columns(locations) $search_terms]
+ set where_clause(characters) [simulation::object::search_clause $search_columns(characters) $search_terms]
+}
+
db_multirow -extend {view_url} objects select_objects "
select sl.object_id,
sl.object_type,
@@ -63,10 +85,13 @@
sl.description
from sim_locationsx sl,
cr_items ci,
- acs_object_types ot
+ acs_object_types ot,
+ cr_revisions cr
where sl.in_directory_p = 't'
and ci.live_revision = sl.revision_id
and ot.object_type = sl.object_type
+ and cr.revision_id = sl.revision_id
+ [ad_decode $where_clause(locations) "" "" "and $where_clause(locations)"]
UNION
select sc.object_id,
sc.object_type,
@@ -78,10 +103,13 @@
sc.description
from sim_charactersx sc,
cr_items ci,
- acs_object_types ot
+ acs_object_types ot,
+ cr_revisions cr
where sc.in_directory_p = 't'
and ci.live_revision = sc.revision_id
and ot.object_type = sc.object_type
+ and sc.revision_id = cr.revision_id
+ [ad_decode $where_clause(characters) "" "" "and $where_clause(characters)"]
[template::list::orderby_clause -orderby -name "objects"]
" {
Index: openacs-4/packages/simulation/tcl/object-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/object-procs.tcl,v
diff -u -r1.11 -r1.12
--- openacs-4/packages/simulation/tcl/object-procs.tcl 27 Feb 2004 20:12:13 -0000 1.11
+++ openacs-4/packages/simulation/tcl/object-procs.tcl 9 Mar 2004 17:04:24 -0000 1.12
@@ -352,3 +352,21 @@
return $xml_doc
}
+
+ad_proc -private simulation::object::search_clause {
+ search_columns
+ search_string
+} {
+ Return a SQL clause for searching the given search columns.
+
+ @author Peter Marklund
+} {
+ set trimmed_search_string [string trim [string tolower $search_string]]
+
+ set where_clauses [list]
+ foreach column $search_columns {
+ lappend where_clauses "lower($column) like '%$trimmed_search_string%'"
+ }
+
+ return "([join $where_clauses " or "])"
+}