I have to develop a drupal site that allows authenticated users to create personal profiles with data such as interests, personal details, educations, etc.
I created a profile2 type with all needed fields and organize the view of the data with views3. I want to create a filter (search form) that allows other users and visitors to search the name (first- and last name in one "name" single textfield, an OR'ed query), the city, a proximity field as an addt. option if the zip code is entered (by probably using the location module) and also an additional field that searches thru various other profile fields in one single textfield (all fields OR'ed).
For that reason I thought it might be a good idea to create a views custom filter to build such search form and sql queries. I can not find any way using the regular filter criteria such the way I want it described above. For example, I do not get a single textfield for the OR'ed name query, etc.
The code skeleton I have up to now does not generate any filter entry in the criteria dialog at all. The filter modue is enabled in the modules section. I have the strong feeling that the "hook_views_data()" is not defined the right way for "profile2 fields". I been looking at various filter examples, but found nothing profile2 data related.
Here is what I have up to now .. like said, just a skeleton I try to work out step by step.
xconsultantview.info
; $Id$
name = XConsultantView
description = Custom consultant filter
version = 7.x-1.x-dev
core = 7.x
dependencies[] = views
files[] = xconsultantview_handler_filter_profile.inc
xconsultantview.module
<?php
/**
*
*/
function xconsultantview_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'xconsultantview')
);
}
?>
xconsultantview.views.inc
<?php
function xconsultantview_views_data() {
$data = array();
// consultant filter
$data['node']['consultant_search_filter'] = array(
'group' => t('Custom'),
'title' => t('Eliteberater specific consultant filter'),
'help' => t('Filter consultants on specific fields'),
'filter' => array(
'handler' => 'xconsultantview_handler_filter_view'
),
);
?>
xconsultantview_handler_filter_view.inc
<?php
class xconsultantview_handler_filter_view extends views_handler_filter {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// ...
}
function value_form(&$form, &$form_state) {
// not quiet sure if this is needed here
$form['xconsultantview'] = array(
'#type' => 'textfield',
'#title' => t('Term Name'),
'#default_value' => NULL
);
return $form;
}
function expose_form(&$form, &$form_state) {
// seems like here I should define my complete form
// ...
}
function query() {
$this->ensure_my_table();
// ... sql query ...
}
};
?>
As I already found out the hook_views_handlers() is no more needed in D7, because the include files are defined via the files[] in the module info file.
Can anybody shed some light on my question, if such custom filter in general is possible at all or if there are other more simpler solutions. My main problem of understanding lies in the hook_views_data() fct and the profile2 fields or if I have to define a subset of the profile2 fields, at least the ones that I need to filter.
Is there any example with an custom filter filtering profile2 fields in a view?
It is my first drupal project, so my in-depth knowledge at this time is quiet limited...
Thanks so much in advance for your help!