I am contemplating on using this module, but am at a loss as to how to search the data like a normal real estate search. I see the search API module works with this data, but are there any examples? Especially allowing the user to pull listings that meet their needs: price range, bedroom count, area, garage....

What about a search view that gives the user a set of custom controls for implementing a real estate search?

CommentFileSizeAuthor
#29 Bedroom select.png12.04 KBdroddis
#24 cville.png14.46 KBj9
#23 cville.png15.14 KBj9

Comments

twod’s picture

You could set up a View based on the Drealty Listings entity types you have, with some exposed filters to let users filter out listings based on those criteria.

kevinquillen’s picture

You can use Views out of the box. However, I have a feeling you are asking about how the View fields are presented to the user. You can do a simple price range by adding Price filter twice, one being greater than or equal to, and one being less than or equal to. But, its still text entry.

Here is some common code I use to 'pretty up' Views form filter interfaces for the end user. You may have to modify parts of it so it works for you, such as field names, form IDs, etc.

What I am doing below is making texts into selects, and populating the options with values from the database for city and property type. I am also creating price options as well.


if ($form['#id'] == 'views-exposed-form-YOURVIEWID-MACHINENAME') {
		$cities = db_query('SELECT DISTINCT(field_mls_address_locality) FROM {field_data_field_mls_address} ORDER BY field_mls_address_locality ASC', array(), array('fetch' => PDO::FETCH_OBJ));
		$property_types = db_query('SELECT DISTINCT(field_property_type_value) FROM {field_data_field_property_type} ORDER BY field_property_type_value ASC', array(), array('fetch' => PDO::FETCH_OBJ));

		/*
		$price = 0;
		
		while ($price <= 5000000) {
			$price_options[$price] = money_format('$%i', $price);
			if ($price < 1000000) {
				$price = $price + 50000;
			} else {
				$price = $price + 500000;
			}
		}
		
		unset($price_options[0]);
	*/	
		$city_options[''] = 'Choose a town';
		
		foreach ($cities as $record) {
			$city_options[$record->field_mls_address_locality] = $record->field_mls_address_locality;
		}
		
		$property_type_options[''] = 'Choose a property type';
		
		foreach ($property_types as $record) {
			$property_type_options[$record->field_property_type_value] = $record->field_property_type_value;
		}
		
		$form['rets_key']['#attributes'] = array('placeholder' => 'Enter an MLS Number');
		
		unset($form['field_mls_address_locality']['#size']);
		$form['field_mls_address_locality']['#default_value'] = '';
		$form['field_mls_address_locality']['#type'] = 'select';
		$form['field_mls_address_locality']['#options'] = $city_options;
		
		/*
		unset($form['field_price']['#size']);
		$form['field_price']['#type'] = 'select';
		$form['field_price']['#options'] = $price_options;
		$form['field_price']['#default_value'] = $price_options[1];
		
		unset($form['field_price_1']['#size']);
		$form['field_price_1']['#type'] = 'select';
		$form['field_price_1']['#options'] = $price_options;
		$form['field_price_1']['#default_value'] = $price_options[5];
		*/
		unset($form['field_property_type']['#size']);
		$form['field_property_type']['#default_value'] = '';
		$form['field_property_type']['#type'] = 'select';
		$form['field_property_type']['#options'] = $property_type_options;
		
	}
kevinquillen’s picture

The price fields are commented out, but they do work- I just did not need them on the project I am working on (yet).

kevinquillen’s picture

Status: Active » Postponed (maintainer needs more info)

Changing status. If this works for OP, I will open up a task for Views docs.

We can't provide a default search view out of the box, because of the entities being Fielded, and not supplying fields on install, because the user has to map them- so we do not know what the fields are. We should probably create some docs on how to setup a view, but, for now, this just needs clarification.

camidoo’s picture

Component: User interface » Documentation
Category: feature » support
Status: Postponed (maintainer needs more info) » Needs work

changing this to a support request / documentations & needs work. The OP has a valid point, however i honestly think that it is out of the scope of this particular module. However, i do agree that some documentation or a screen cast showing what is possible would go a long way in encouraging the use of this module if a potential user saw what was possible.

j9’s picture

Where does this code get inserted?
Excellent snippet and very useful! Thanks kevinquillen!

kevinquillen’s picture

It really depends on your view, field types (text, int, number, etc) and field names. Just your standard form alter code. Handbook pages forthcoming.

kevinquillen’s picture

Status: Needs work » Fixed

Documentation has started. It can be accessed from the main project page under 'Read Documentation'. We're actively building out a series of handbook pages.

j9’s picture

kevinquillen,

I am still wrapping my head around how to implement this.

I believe this is the code being used in the three showcase sites, yes?

This is exactly what I am looking to do to simplify the user selection of exposed view filters.

Do I put this code into a views textarea or somewhere in the Views admin ui?

I can adjust the form settings to match my filters, but do I put this code in a theme file or hack a views file?

I am building www.charlottesvillerealestate.us and have the filters in place. I just dont know where to alter/insert your code so that my forms turn from text fields to dropdown menus.

Just not sure but it definitely is something that would help people use drealty!

Thanks very much for any further direction.

kevinquillen’s picture

j9, I started on the Views docs page:

http://drupal.org/node/1536884

j9’s picture

Awesome! Thanks for putting up the docs!

Am I correct that I have to write my own custom module to implement the drop down menus?

Any way this might work its way into the drealty release, to make it easy for people who dont know how to code?

Thanks again, kevinquillen! I'll keep a watch on the page and try and figure out what to do.

kevinquillen’s picture

Its tricky right now because we allow people to name fields whatever they want, because they also have to be mapped into their vendors RETS system.

j9’s picture

Okay, thanks kevinquillen,

I have moved my questions about implementing the dropdown menu search to the docs so we can focus on letting people (myself included :) get it implemented with ease. I still have not understood the process fully.

drealty Docs
Basic Searching with Views
http://drupal.org/node/1536884

Thanks always very much!

j9’s picture

Hi,

When it is said here: http://drupal.org/node/1536884

There is a way to make text fields become select drop downs with options, however. Lets start with City, since that is easy. In a custom module, write a form alter hook:

Does this mean we have to write our own custom drupal module? like one that goes in the sites/all/modules folder that works with drealty?

I am at a loss on how to implement the

Form Alter Your View Filter Form

<?php
function your_custom_module_form_alter(&$form, &$form_state, $form_id) {
   if ($form['#id'] == 'YOUR-CUSTOM-VIEW-ID') {

   }
}
?>

Can anyone share how to implement these dropdown menus to a non-coder?

Thanks! Searching drealty w/ dropdowns is essential! Much appreciate any guidance. :0)

kevinquillen’s picture

Yes, writing a form alter requires writing a custom module... its going to take code to adjust the output. Writing a module that does a form alter is possibly one of the easiest Drupal modules to cut your teeth on.

Start here:

http://drupal.org/node/1074362
http://drupal.org/node/1075072
http://drupal.org/node/1095546

You can run through those in about an hour or less.. then the search view tutorial might make more sense to you.

In the snippet above, once you have a hold on the 3 links above, replace 'your_custom_module' with the name of your module. You can then get the ID of the form on the view by typing:

var_dump($form['#id']);

Immediately after the first brace in the form alter.

j9’s picture

Thanks kevinquillen!

I will try to write a module following your instructions and the drupal doc links you posted above.

If I am successful, I will add the steps to the dRealty Docs. Thanks again! :0)

j9’s picture

Here is what I did and what happened:

I created folder drealty_dropdowns in sites/all/modules

I created file drealty_dropdowns.module inside the drealty_dropdowns folder.

drealty_dropdowns.module has this code (using my county field for a dropdown):

<?php
function drealty_dropdowns_form_alter(&$form, &$form_state, $form_id) {
   if ($form['#id'] == 'view-dom-id-80f9bed6e811ddc28f7d483fde83ff49') {

   }
}
?>

<?php
function drealty_dropdowns_form_alter(&$form, &$form_state, $form_id) {
   if ($form['#id'] == 'view-dom-id-80f9bed6e811ddc28f7d483fde83ff49') {
     $counties = db_query('SELECT DISTINCT(field_county_value) FROM {field_data_field_county} ORDER BY field_county_value ASC', array())->fetchAll();

     $county_options[''] = '- Select a county -';

     foreach ($counties as $record) {
       $county_options[$record->field_county_value] = $record->field_county_value;
     }

     unset($form['field_county']['#size']);
     $form['field_county']['#default_value'] = '';
     $form['field_county']['#type'] = 'select';
     $form['field_county']['#options'] = $county_options;
   }
}
?>

I created drealty_dropdowns.info in the drealty_dropdowns folder w/ this content:

name = dRealty Dropdowns
description = Alters Views exposed search boxes to dropdown menus.
core = 7.x

I went to the modules page in drupal, saw dRealty Dropdowns as an optional module, enabled it, saved, and it went to admin/modules/list/confirm and had a blank page.

I went back to my view and nothing has changed.

Also, I note that when I reload the modules page in drupal, I see that dRealty Dropdowns is *not* checked.

Am I anywhere close? Thanks very much!

j9’s picture

Okay, I turned on error reporting and see this on the white page when I try to enable the module:

Fatal error: Cannot redeclare drealty_dropdowns_form_alter() (previously declared in /var/www/vhosts/fly7/sites/all/modules/drealty_dropdowns/drealty_dropdowns.module:2) in /var/www/vhosts/fly7/sites/all/modules/drealty_dropdowns/drealty_dropdowns.module on line 25

Thanks for any pointer or bit of help.

j9’s picture

Okay, realized I had posted code twice in the same module.

Here is my module code now (successfully enabled, but not showing up in my view).

<?php
function drealty_dropdowns_form_alter(&$form, &$form_state, $form_id) {
   if ($form['#id'] == 'view-dom-id-80f9bed6e811ddc28f7d483fde83ff49') {
     $counties = db_query('SELECT DISTINCT(field_county_value) FROM {field_data_field_county} ORDER BY field_county_value ASC', array())->fetchAll();

     $county_options[''] = '- Select a county -';

     foreach ($counties as $record) {
       $county_options[$record->field_county_value] = $record->field_county_value;
     }

     unset($form['field_county']['#size']);
     $form['field_county']['#default_value'] = '';
     $form['field_county']['#type'] = 'select';
     $form['field_county']['#options'] = $county_options;
   }
}
?>
jday’s picture

Try using 'views_exposed_form' for the form id, and the #id to target this specific exposed view like this (the name of my view is 'property-search' and I'm building a page view):

if ($form_id == 'views_exposed_form') {
    if ($form['#id'] == 'views-exposed-form-property-search-page') {
       //your select options here
    }
}
kevinquillen’s picture

Yes, your form id looks a bit off, but you should be close.

Welcome to the world of one of the most useful/powerful Drupal hooks, hook_form_alter.

If you want your $form['#id'] simply do var_dump($form['#id']); right after declaring the form alter. Then visit a page with the search form on it.

You can also influence the name of the view ID with the 'machine_name' property on the View configuration. You can find that in the bottom right area of the options (under 'Advanced').

You could also enable Devel module and use the function krumo() in place of var_dump. It will be a much nicer debug output.

Example: krumo($form);

This would show you whats inside the form array, so, for example, at the end of your form alter code, krumo($form). You could quickly see if any of your code affected the form array.

j9’s picture

StatusFileSize
new15.14 KB

I had the incorrect views form id.

With the following code, I was able to see a dropdown menu! :0)

See attached image for its display.

<?php
function drealty_dropdowns_form_alter(&$form, &$form_state, $form_id) {
   if ($form['#id'] == 'views-exposed-form-listings-page') {
     $counties = db_query('SELECT DISTINCT(field_county_value) FROM {field_data_field_county} ORDER BY field_county_value ASC', array())->fetchAll();

     $county_options[''] = '- Select a county -';

     foreach ($counties as $record) {
       $county_options[$record->field_county_value] = $record->field_county_value;
     }

     unset($form['field_county_value']['#size']);
     $form['field_county_value']['#default_value'] = '';
     $form['field_county_value']['#type'] = 'select';
     $form['field_county_value']['#options'] = $county_options;
   }
}
?>

Cool! Getting somewhere fast! :D

j9’s picture

StatusFileSize
new14.46 KB

Corrected screenshot -- see attached.

j9’s picture

Next logical question for dRealty views search form alterers would be, how do we make the form select dropdown menu display only the values we want to display?

Instead of all the counties provided by the rets server, we might just want 5 counties out of the lot.

Does anyone have a template for doing this?

Cool thanks! :0)

kevinquillen’s picture

Instead of querying for counties, just fill the array yourself:


$county_options['raw_database_value'] = 'County One';
$county_options['raw_database_value'] = 'County Two';
$county_options['raw_database_value'] = 'County Three';
$county_options['raw_database_value'] = 'County Four';
$county_options['raw_database_value'] = 'County Five';

j9’s picture

Super thanks kevinquillen!

I'll try that out. Big thanks! :D

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

droddis’s picture

StatusFileSize
new12.04 KB

I assume I can use this same format for the bedrooms search if I want to display 1+ bedrooms etc. Would I need to add anything in order to have it show all properties with more then 1 bedroom as opposed to only those with 1 bedroom?

As an example:

$bedrooms_options['1'] = '1+ Bedrooms';
$bedrooms_options['2'] = '2+ Bedrooms';
$bedrooms_options['3'] = '3+ Bedrooms';
$bedrooms_options['4'] = '4+ Bedrooms';
$bedrooms_options['5'] = '5+ Bedrooms';
$bedrooms_options['6'] = '6+ Bedrooms';

If I use these options then I get only those properties with the specified number of bedrooms as opposed to all those with the specified number and above.

Also using this code I notice that some values are overwritten by the raw database value. Any suggestions?

kevinquillen’s picture

To show greater than or equal to, change the filter to be that instead of equals.

droddis’s picture

facepalm...... thanks Kevin.

By the way the module is working out very well. Really appreciate all the help these forums have provided. I'm not sure I can help with any documentation but if I can I would be happy to help. Point me in the direction of something basic that needs done and I'll do my best!

droddis’s picture

Ok I may be due for another face/palm but I can't for the life of me figure out where I change the = sign to a greater than sign. I've tried all manner of combinations but I obviously don't understand the language well enough to get it to work.

Any further suggestions on where to look?

droddis’s picture

Ok the last comment on this I promise. I had the Bedrooms configured as a text field as opposed to an integer, meaning the Greater then option wasn't available.