/[drupal]/contributions/modules/semantic_search/includes/semantic_search.searches.inc
ViewVC logotype

Contents of /contributions/modules/semantic_search/includes/semantic_search.searches.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jun 5 06:37:07 2007 UTC (2 years, 5 months ago) by hendler
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
adding files from our SVN
1 <?php
2
3
4 /*
5 * Copyright (C) 2007 Jonathan Hendler
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * The author can be contacted at:
22 * - jonathan [at] civicactions (dot) com
23 *
24 * @license http://www.affero.org/oagpl.html
25 * @link http://drupal.org/project/semantic_search
26 */
27
28 /**
29 * generate forms for adding an removing search fields
30 * */
31 function _semantic_search_admin_form_search_fields($search_type_select, $search_id) {
32 //fields
33 //dbg($search_type_select, $search_id);
34 }
35
36 /**
37 * places in semantic_search_menu to
38 *
39 * @return array search_paths
40 * */
41 function _semantic_search_get_menus(& $items, &$searches, $may_cache) {
42
43 if (!$may_cache) {
44 //get all searches
45
46 foreach ($searches as $key => $search) {
47 $search_name = $search['name'];
48 $search_path = $search['path'];
49 $search_id = $search['id'];
50 $search_type = $search['id'];
51
52 $items[] = array (
53 'path' => $search_path,
54 'title' => t($search['title']),
55 'description' => t($search['description']),
56 'callback' => '_semantic_search_load_search',
57 'callback arguments' => array (
58 $search_name,
59 $search_id,
60 $search_type,
61 ),
62 'access' => user_access($search_name . ': access search'),
63 'weight' => $key +1,
64 'type' => MENU_LOCAL_TASK);
65 }// end foreach
66 } // end may_cache
67 }
68
69 /**
70 * special themeing function for the search form
71 * */
72 function theme_semantic_search_search(&$_semantic_search_search,$form,$cache_stats_only = false){
73 if ($cache_stats_only){
74 return _semantic_search_cacheStatsFromForm($form);
75 } else {
76 return _semantic_search_form_render($form);
77 }
78 }
79
80 /**
81 * generate a search form
82 * */
83 function _semantic_search_load_search($search_name, $search_id= null,$search_type = null, $cache_stats_only = false,$rpc = false) {
84
85 $data = _semantic_search_get_search_form_vars($search_name);
86
87
88 /**
89 * base URL for semantic_search in drupal.
90 * */
91 define('SEMANTIC_SEARCH_BASE_URL', $data['path']);
92
93 _semantic_search_set_constants();
94
95 $cache_stats_only = ($cache_stats_only) ? 1 : 0;
96 $fields = _semantic_search_get_form_search_fields($data['id']);
97 global $_semantic_search_search;
98 if (empty ($_semantic_search_search))
99 _SEMANTIC_SEARCH_INIT();
100 //dbg($fields);
101
102 $count = 0;
103
104 // [sid] => 1
105 // [id] => 2
106 //TODO add $search_name hidden
107
108
109 foreach($fields as $field){
110 $form_element = array();
111 $form_element['#type'] = $field['form_type'];
112 $form_element['#query_type'] = $field['search_field_type'];
113 $form_element['#multiple_facet'] = $field['multiple'];
114 //$form_element['#show_in_search_count'] = $field['search_field_type'];
115 $form_element['uris'] = SONIA_H :: decodeURI($field['uris']);
116 $form_element['#title'] = $field['title'];
117 $form_element['#title_as_option'] = $field['title_as_option'];
118 $form_element['#grand_total'] = $field['grand_total'];
119 $form_element['#search_name'] = $search_name;
120 //$form_element['#top_option'] = 'national';
121
122
123 $form['search_criteria']['a'.$count]['#value'] = '<div class="semantic-search-form-element-wrapper">';
124 $form['search_criteria']['b'.$count] = $_semantic_search_search->getSearchFormElement($form_element);
125 $form['search_criteria']['c'.$count]['#value'] ='</div>';
126
127 $count++;
128 }
129
130
131
132 //check to see if search is rpc or custom API
133 if (!$rpc){
134 return _semantic_search_search($form);
135 }
136 else { //use rpc and return just the form
137 return $form;
138 }
139
140 }
141
142
143 /**
144 * retrieve the search form fields from the db for a search
145 *
146 * */
147 function _semantic_search_get_form_search_fields($search_id) {
148 $return_array = array();
149 $results = db_query("SELECT * FROM {semantic_search_searches_fields} WHERE sid=%d",$search_id);
150 while( $result = db_fetch_array($results)){
151 $return_array[] = $result;
152 }
153 return $return_array;
154 }
155
156 /**
157 * retrieve the search form info for a field from the db
158 *
159 * */
160 function _semantic_search_get_form_search_field($field_id) {
161 return db_fetch_array( db_query("SELECT * FROM {semantic_search_searches_fields} WHERE id=%d LIMIT 1",$field_id));
162
163 }
164
165
166 /**
167 * retrieve the search form fields from the db for a search
168 * can be used for insert or update
169 * */
170 function _semantic_search_set_form_search_fields($params) {
171 $params['uris'] = base64_encode(serialize($params['uris']));
172 $return_array = array();
173 if (!isset($params['id'])){
174 $results = db_query("INSERT INTO {semantic_search_searches_fields} ( sid , uris , form_type , search_field_type , title , description , grand_total , top_option , title_as_option )
175 VALUES (
176 %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d); ",
177 $params['sid'],$params['uris'],$params['form_type'],$params['search_field_type'],$params['title'],$params['description'],$params['grand_total'],$params['top_option'],$params['title_as_option']);
178 drupal_set_message('Facet '.$params['title'].' added to search.');
179
180 } else {
181 $results = db_query("UPDATE {semantic_search_searches_fields} SET sid = %d, , uris ='%s', form_type= '%s', search_field_type='%s', title= '%s', description= '%s', grand_total= %d, top_option =%d, title_as_option=%d WHERE id = %d; ",
182 $params['sid'],$params['uris'],$params['form_type'],$params['search_field_type'],$params['title'],$params['description'],$params['grand_total'],$params['top_option'],$params['title_as_option'],$params['id']);
183 drupal_set_message('Facet '.$params['title'].' updated.');
184 }
185 }
186
187
188 /**
189 *
190 * */
191 function _semantic_search_get_all_search_form_vars(){
192 global $semantic_search_searches; //limit db calls
193
194 $return_array = array();
195 $results = db_query("SELECT * FROM {semantic_search_searches}");
196 while( $result = db_fetch_array($results)){
197 $return_array[] = $result;
198 }
199 return $return_array;
200 }

  ViewVC Help
Powered by ViewVC 1.1.2