This repository has been archived by the owner on Jun 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews_saved_searches.views.inc
373 lines (198 loc) · 6.75 KB
/
views_saved_searches.views.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
//$Id
/**
* Implementation of hook_views_data
* Expose this module's data to views
*/
function views_saved_searches_views_data() {
$data = array(
//Saved searches table
'views_saved_searches' => array(
//explain the table overall to views
'table' => array(
'group' => 'Views Saved Searches',
'base' => array(
'field' => 'sid',
'title' => t('Saved Search'),
'help' => t('Saved searches'),
'weight' => -10,
),
),
//sid field
'sid' => array(
'title' => 'Search ID',
'help' => 'The search id of the saved search.',
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
//uid field
'uid' => array(
'title' => 'User ID',
'help' => 'The user id of the user who saved the search.',
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_user_uid',
'numeric' => TRUE,
'validate type' => 'uid',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'users',
'base_field' => 'uid',
),
),
//view_name field
'view_name' => array(
'title' => 'View Name',
'help' => 'The name of the view that returns the search results.',
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'filter' => array(
'handler' => 'views_saved_searches_handler_filter_view_name',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
//search_name field
'search_name' => array(
'title' => 'Search Name',
'help' => 'The name the user gave the search.',
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
//search_query field
'search_query' => array(
'title' => 'Search Query',
'help' => 'The query for the search.',
'field' => array(
'handler' => 'views_handler_field',
),
),
//timestamp field
'timestamp' => array(
'title' => 'Search Timestamp',
'help' => 'The created timestamp for the search.',
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
),
//link to run search
'view_search' => array(
'field' => array(
'title' => 'Search Link',
'help' => 'Provide a url to run the search.',
'handler' => 'views_saved_searches_handler_field_view_saved_search_link',
),
),
//link to edit saved searche
'edit_search' => array(
'field' => array(
'title' => 'Edit Search Link',
'help' => 'Provide a url to edit the saved search.',
'handler' => 'views_saved_searches_handler_field_edit_saved_search_link',
),
),
//link to delete search from saved searches
'delete_search' => array(
'field' => array(
'title' => 'Delete Search Link',
'help' => 'Provide a url to delete the saved search.',
'handler' => 'views_saved_searches_handler_field_delete_saved_search_link',
),
),
),
);
return $data;
}
/**
* Implementation of hook_views_handlers()
*/
function views_saved_searches_views_handlers() {
return array(
'handlers' => array(
'views_saved_searches_handler_field_view_saved_search_link' => array(
'parent' => 'views_handler_field_url',
),
'views_saved_searches_handler_field_edit_saved_search_link' => array(
'parent' => 'views_handler_field_url',
),
'views_saved_searches_handler_field_delete_saved_search_link' => array(
'parent' => 'views_handler_field_url',
),
'views_saved_searches_handler_filter_view_name' => array(
'parent' => 'views_handler_filter_in_operator',
),
),
);
}
/**
* Implementation of hook_views_pre_render()
*/
function views_saved_searches_views_pre_render(&$view) {
// only show an 'save this search' links on search views
// if there are user supplied arguments and if there are no errors
global $user;
if(in_array($view->name . "_" . $view->current_display, variable_get("views_saved_searches_view_names", array()))) {
// They can save a search, can they save this search?
// form_get_errors() returns null if there are no errors
$errors = form_get_errors();
if(count($view->exposed_input) > 0 && !isset($errors))
{ //either put a save this search link, or put an 'update this search link'
if(isset($_GET['update_saved_search'])){
drupal_set_message(t("To edit your saved search, change the parameters as you wish, then submit the search to check you're happy with the results. Then you can click the 'Update saved search' link at the bottom of the form to save your changes."));
}
elseif(isset($_GET['new_search_submitted'])){
$view->attachment_before .= theme("update_this_search_link", $view, $_GET['new_search_submitted']);
}
else {
//not from an existing saved search
$view->attachment_before .= theme("save_this_search_link", $view);
}
}
}
}