Property Types with Subtypes, "We also have ..."

16 posts by 3 authors in: Forums > CMS Builder
Last Post: April 9, 2010   (RSS)

Re: [AlanMacDonald] Property Types with Subtypes, "We also have ..."

By Chris - March 2, 2010

Hi Alan,

That is a little complicated for a first CMSB project, yikes!

A Category Menu will solve your first requirement. When you create a section, you'll find Category Menu under <Advanced Menus>. Create one called "Property Types" and fill it with your types and subtypes.

You'll also want two Multi Record sections: "Locations" and "Listings".

Your Listing records will need to point to both a Location and a Property Type. Add two "list" fields to the Listings section:

Field Label: Location
Field Name: location
Field Type: list
Display As: pulldown
List Options: Get options from database (advanced)
Section Tablename: "locations"
Use this field for option values: "num"
Use this field for option labels: "title"


Field Label: Property Type
Field Name: property_type
Field Type: list
Display As: pulldown
List Options: Get options from database (advanced)
Section Tablename: "property_types"
Use this field for option values: "num"
Use this field for option labels: "breadcrumb"


Try creating some locations and listings and make sure everything works properly.

Let me know when you've gotten this far, then we'll tackle your search page with counts for "similar" searches.
All the best,
Chris

Re: [chris] Property Types with Subtypes, "We also have ..."

By (Deleted User) - March 8, 2010

Hi,

Thanks for the info - I will look at this again when I get back to the site - been pulled away for a couple of days.

Alan

Re: [AlanMacDonald] Property Types with Subtypes, "We also have ..."

By (Deleted User) - March 29, 2010

Hi,

I'm back :)

Okay, got this working, and I can see how it works, which is a bonus :)

Only thing is, the output on the list page viewer and detail page viewer is coming out as

---------8<-------------snip
Title: First Property
Property Type: 12
Location: 2
---------8<-------------snip

Any way to replace the numbers there with the actual items from the list, in this case

---------8<-------------snip
Title: First Property
Property Type: INDUSTRIAL : Office & Storage
Location: City Suburbs / Business Parks
---------8<-------------snip

I had a look at the CMSB cookbook and Multi Level Category Functions post (http://www.interactivetools.com/forum/gforum.cgi?post=64259) but could not see it.

Alan

Re: [AlanMacDonald] Property Types with Subtypes, "We also have ..."

By (Deleted User) - March 30, 2010

OK, I've got the first one myself, managed to get the property type.

// locate in the property_types category, the property type of the
// current record.
list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'property_types',
'selectedCategoryNum' => $propertiesRecord['property_type'],
'categoryFormat' => 'showall', // showall, onelevel, twolevel
));

...

Property Type: <?php echo $selectedCategory['name'] ?>


but when I try similar code for the location, it does not work


list($locationsRecords, $locationsMetaData) = getRecords(array(
'tableName' => 'locations',
'where' => $propertiesRecord['location'],
'limit' => '1',
));
$locationsRecord = @$locationsRecords[0];

...

Location: <?php echo $locationsRecord['title'] ?>


Basically, each property has a location, the locations are set up as a multi-record. I know the number of the location for the current property, n, so how do I get the n'th record on the locations multi-record?

I'm sure it's simple, I just can't get my head around it.

Re: [AlanMacDonald] Property Types with Subtypes, "We also have ..."

By (Deleted User) - March 30, 2010

and I got the second one too.

I dunno, posting here really crystallises the thinking!

list($locationsRecords, $locationsMetaData) = getRecords(array(
'tableName' => 'locations',
'where' => 'num = "'.$propertiesRecord['location'].'"',
'limit' => '1',
));
$locationsRecord = @$locationsRecords[0];

...

Location: <?php echo $locationsRecord['title'] ?>


I'm just wondering - is all this stuff dealt with in some documentation I am not aware of? Can anyone point me to a good place to start?

I've looked at the online help, and the CMSB cookbook.

Re: [AlanMacDonald] Property Types with Subtypes, "We also have ..."

By Chris - March 30, 2010

Hi Alan,

Glad you got everything figured out! :D

We're currently trying to come up with simpler ways to "join" data from related records, so no, this isn't documented yet. Once we figure something out that we like (and that everyone will like too) I'll probably post a tutorial here in the forums.

Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Property Types with Subtypes, "We also have ..."

By (Deleted User) - April 6, 2010

Hi,

OK, how do we perform searches on these criteria as set up above? Going slightly nutty here.

We have property types, and locations.

We want to be able to search for a set of property types, and list those properties in a single location.

How do you set up OR and and AND searching?

User would choose

Types

INDUSTRIAL : Retail Warehousing
INDUSTRIAL : Office & Storage

Location

Town 2

The search needs to be (INDUSTRIAL : Retail Warehousing OR INDUSTRIAL : Office & Storage) AND Town 2

i.e., they need to be able to check a set of boxes for what type of property they are looking for, and then a location.

I just can't see it myself. :(

Re: [AlanMacDonald] Property Types with Subtypes, "We also have ..."

By Chris - April 6, 2010

Hi Alan,

CMS Builder does simple searching automatically (unless you ask it not to,) but you'll need a little extra code to get the OR part working.

Let's start with the simple search:

Create a form which will submit to your listing page. Add a dropdown for your locations and checkboxes for property_types:

<form action="listings.php" method="POST">

Location: <select name="location">
<option value="1">Uptown</option>
<option value="2">Downtown</option>
</select>

Property Type: <br/>
<input type="checkbox" name="property_type[]" value="1" id="pt1"> <label for="pt1">Residential</label><br/>
<input type="checkbox" name="property_type[]" value="2" id="pt2"> <label for="pt2">Commercial</label><br/>

</form>


The value="123" numbers will need to be the correct nums of the corresponding records. You could generate that form using PHP, but let's keep this explanation simple. :)

The location search will actually work right now, but you'll need to make a small change to your listing page to get the checkboxes to turn into an OR (which we'll accomplish by using MySQL's IN operator.) On your listings page, add this 'where' clause to your getRecords(), and the code above it:

$property_typeCSV = '';
if (@$_REQUEST['property_type']) {
$property_typeCSV = join(',', $_REQUEST['property_type']);
}

// load records
list($listingsRecords, $listingsMetaData) = getRecords(array(
'tableName' => 'listings',
'where' => $property_typeCSV ? ("property_type IN (" . mysql_escape($property_typeCSV) . ")") : '1'
));


I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Property Types with Subtypes, "We also have ..."

By (Deleted User) - April 7, 2010

Hi,

Thank you for that code - it worked perfectly. I had to temporarily make a lister for my property types, as the values were not what I expected, but once I had the correct values entered, off she flew.

I can now search

(type of property OR type of property OR ...) AND (Location)

This behaves correctly in all the tests I have tried.

Now, I am thinking out loud here, as it seems to help me work these things out.

Thanks to the wonder of Shifting Requirements (tm) I have to do:

Step 1 - Are you looking for a property to
[] Let [] Buy [] Either

Step 2 - What type of property?
Property types as checkboxes

Step 3 - Where do you want to search?
Property locations as a dropdown.

I am trying to think what is the best way to record the

To Let (AND/OR) To Buy

status of a property, and then allow searching on that status.

I could use a checkbox record, To-Let-chk and To-Buy-chk, and then use a simple javascript on the Either checkbox that simply sets both To Let and To Buy to selected. It could get horribly complicated if I decided to look at what happens if someone subsequently clicks again on a To Let or To Buy checkbox, but I am going to wilfully ignore that scenario.

That seems the simplest way to me. Does that solution make sense, or is there a better way?

By the way, I am completely ignoring the fact that I have the following fields in my database:

Sale Price
P.O.A. -- These two cover properties with a sale price, either explicit, or Price on Application which overrides any sale price
Rental Price -- the rental price, if any.

I am pretty sure that some very clever coding could be done to figure out the status of a property as to whether it is for sale, for rental, or both, based on the contents or empty state of these fields, but that is at a php/mysql guru level which I have nowhere near the experience points to approach!