| |
273 |
273 |
# on the cr_items table. This should speed things up. This assumes |
| |
274 |
274 |
# that packages other than contacts that add search condition |
| |
275 |
275 |
# types do not need the revision_id column, and only needs the |
| |
276 |
276 |
# party_id column. If this is not the case we may want to add a |
| |
277 |
277 |
# callback here to check if another package needs the revisions |
| |
278 |
278 |
# table. |
| |
279 |
279 |
# |
| |
280 |
280 |
# If this needs to change you should also update the |
| |
281 |
281 |
# contacts/lib/contacts.tcl file which behave the same way. |
| |
282 |
282 |
set cr_where "" |
| |
283 |
283 |
set cr_from "" |
| |
284 |
284 |
} |
| |
285 |
285 |
} else { |
| |
286 |
286 |
set object_type "party" |
| |
287 |
287 |
set page_query_name "contacts_pagination" |
| |
288 |
288 |
set search_clause [contact::search_clause -and -query $query -search_id "" -party_id "parties.party_id" -limit_type_p "0"] |
| |
289 |
289 |
set cr_from "" |
| |
290 |
290 |
set cr_where "" |
| |
291 |
291 |
} |
| |
292 |
292 |
|
| |
293 |
|
return [db_string select_${object_type}_results_count {}] |
| |
|
293 |
set results "" |
| |
|
294 |
db_transaction { |
| |
|
295 |
# we don't want to break the contact searches page if there is an error. |
| |
|
296 |
set results [db_string select_${object_type}_results_count {}] |
| |
|
297 |
} on_error {} |
| |
|
298 |
return $results |
| |
294 |
299 |
|
| |
295 |
300 |
} |
| |
296 |
301 |
|
| |
297 |
302 |
ad_proc -private contact::party_id_in_sub_search_clause { |
| |
298 |
303 |
{-search_id} |
| |
299 |
304 |
{-party_id "party_id"} |
| |
300 |
305 |
{-not:boolean} |
| |
301 |
306 |
} { |
| |
302 |
307 |
} { |
| |
303 |
308 |
# If we do not have a search_id, limit the list to only users in the default group. |
| |
304 |
309 |
|
| |
305 |
310 |
if {[exists_and_not_null search_id]} { |
| |
306 |
311 |
set group_where_clause "" |
| |
307 |
312 |
} else { |
| |
308 |
313 |
set group_where_clause "and group_distinct_member_map.group_id in ([template::util::tcl_to_sql_list [contacts::default_groups]])" |
| |
309 |
314 |
# set group_where_clause "and group_distinct_member_map.group_id = [contacts::default_group]" |
| |
310 |
315 |
} |
| |
|
316 |
|
| |
311 |
317 |
set query " |
| |
312 |
318 |
select parties.party_id |
| |
313 |
319 |
from parties left join cr_items on (parties.party_id = cr_items.item_id) left join cr_revisions on (cr_items.latest_revision = cr_revisions.revision_id ), |
| |
314 |
320 |
group_distinct_member_map |
| |
315 |
321 |
where parties.party_id = group_distinct_member_map.member_id |
| |
316 |
322 |
$group_where_clause |
| |
317 |
323 |
[contact::search_clause -and -search_id $search_id -query "" -party_id "parties.party_id" -revision_id "revision_id"] |
| |
318 |
324 |
" |
| |
|
325 |
|
| |
|
326 |
|
| |
|
327 |
|
| |
|
328 |
|
| |
319 |
329 |
if { [exists_and_not_null query] } { |
| |
320 |
330 |
set result ${party_id} |
| |
321 |
331 |
if { $not_p } { |
| |
322 |
332 |
append result " not" |
| |
323 |
333 |
} |
| |
324 |
334 |
append result " in ( $query )" |
| |
325 |
335 |
} else { |
| |
326 |
336 |
set result "" |
| |
327 |
337 |
} |
| |
328 |
338 |
return $result |
| |
329 |
339 |
} |
| |
330 |
340 |
|
| |
331 |
341 |
|
| |
332 |
342 |
ad_proc -public contact::search_clause { |
| |
333 |
343 |
{-and:boolean} |
| |
334 |
344 |
{-search_id} |
| |
335 |
345 |
{-query ""} |
| |
336 |
346 |
{-party_id "party_id"} |
| |
337 |
347 |
{-revision_id "revision_id"} |
| |
338 |
348 |
{-limit_type_p "1"} |