Showing only properties with X parameter set to Y

From Jomres v4 manual

Jump to: navigation, search

Introduction

Jomres search functionality is pretty extensive, and will fit most scenarios, however it's possible that your client will ask something like "can we only list properties that have wiseprice enabled?" or some other property specific setting that it's impossible for me to anticipate and build into the system.

Strictly speaking, the answer is no, however I will show you how to use the existing Jomres framework to make some very simple changes to the filter script that will help us to do this.

Ok, to start off with we need to make a few assumptions.

First, we'll assume that you are reasonably familiar with simple sql statements like "SELECT * FROM jos_jomres_propertys" and hacking PHP scripts.

Next, We'll assume that you are going to try to access these search results via a url, something similar to "index.php?option=com_jomres". This is the default link to Jomres through Joomla. If no other parameters are specified then it will result in your guest being offered the default search, which is a random property list.

The random property list is a list of the first 100 published properties, randomly sorted, found in the database. Unless a specific search is triggered through a search module, this is what you'll see when a non-authorised user accesses Jomres.

How we'll do it

What we are going to do is modify the j01009filterproperties.class.php file, so the first thing to do is, if you don't already have the folder, is create a new folder in the /jomres/remote_plugins/ directory called "custom_code" and copy j01009filterproperties.class.php to that directory. Use the rebuild_registry feature in the administrator area of Jomres now, this will help Jomres to find your new version of this script. Until you do this, Jomres will not use your version of this file.

Ok, now you have a custom version of that file which will not be modified when Jomres is upgraded, so let's go in there and take a look at it. I'll remove some of it for clarity.


  1. class j01009filterproperties
  2. {
  3. function j01009filterproperties($componentArgs)
  4. {
  5. // Must be in all minicomponents. Minicomponents with templates that can contain editable text should run $this->template_touch() else just return
  6. $MiniComponents =jomres_getSingleton('mcHandler');
  7. if ($MiniComponents->template_touch)
  8. {
  9. $this->template_touchable=true; return;
  10. }
  11. $data_only=false;
  12. if (isset($_REQUEST['dataonly']))
  13. $data_only=true;
  14. $propertys_uids=$componentArgs['propertys_uids'];
  15. $sortid = intval(jomresGetParam( $_COOKIE, 'jomsearch_sortby', 1));
  16. switch ($sortid)
  17. {
  18. #########################################################################################
  19. case '1':
  20. $this->propertys_uids = $propertys_uids;
  21. break;
  22. #########################################################################################
  23. case '2':
  24. $gor=genericOr($propertys_uids,'propertys_uid');
  25. $query = "SELECT propertys_uid, property_name FROM #__jomres_propertys WHERE $gor ORDER BY property_name";
  26. $uids = doSelectSql($query);
  27. foreach ($uids as $u)
  28. $this->propertys_uids[] = $u->propertys_uid;
  29. break;
  30. / * edited for brevity */
  31. default:
  32. $this->propertys_uids = $propertys_uids;
  33. break;
  34. }
  35. $sortArray=array();
  36.  
  37. $sortArray[]=jomresHTML::makeOption("1", jr_gettext('_JOMRES_SORTORDER_DEFAULT',_JOMRES_SORTORDER_DEFAULT,false,false));
  38. $sortArray[]=jomresHTML::makeOption("2", jr_gettext('_JOMRES_SORTORDER_PROPERTYNAME',_JOMRES_SORTORDER_PROPERTYNAME,false,false));
  39. $sortArray[]=jomresHTML::makeOption("3", jr_gettext('_JOMRES_SORTORDER_PROPERTYREGION',_JOMRES_SORTORDER_PROPERTYREGION,false,false));
  40. $sortArray[]=jomresHTML::makeOption("4", jr_gettext('_JOMRES_SORTORDER_PROPERTYTOWN',_JOMRES_SORTORDER_PROPERTYTOWN,false,false));
  41. $sortArray[]=jomresHTML::makeOption("5", jr_gettext('_JOMRES_SORTORDER_STARS',_JOMRES_SORTORDER_STARS,false,false));
  42.  
  43. $order['HORDER']=jr_gettext('_JOMRES_ORDER',_JOMRES_ORDER);
  44.  
  45. $order['ORDER']=jomresHTML::selectList( $sortArray, 'sortby', 'onchange="gosearch();" id="sortby" size="1"', 'value', 'text', $sortid );
  46. $sortorder=array();
  47. $sortorder[]=$order;
  48.  
  49. if (!$data_only)
  50. {
  51. $tmpl = new patTemplate();
  52. $tmpl->setRoot( JOMRES_TEMPLATEPATH_FRONTEND );
  53. $tmpl->readTemplatesFromInput( 'order.html' );
  54. $tmpl->addRows( 'sort_order', $sortorder);
  55. $tmpl->displayParsedTemplate();
  56. }
  57. }

What happens is this script is passed a selection of property uids via the $componentArgs['propertys_uids'] variable. These are all of the property uids that were returned by a search (be it specifically via a search module, or the random list found by default) so what we're going to do is invent a new parameter to pass via the url, and if that parameter is found in the url we'll filter the search results based on that parameter.

How is this done?

It's simple enough. Let's assume that we have a url like "index.php?option=com_jomres&filt=wp". In this example I've added "filt" to the url, and we'll tell this script to use that parameter to make some decisions if that's set.

After the line that says

  1. $propertys_uids=$componentArgs['propertys_uids'];

We'll add

  1. if (isset($_GET['filt']))
  2. {
  3. // Do stuff
  4. }

What this does is tell the script that if the "filt" option has been passed to the script, then depending on the value of $_GET['filt'], we can make some decisions on what to filter out. Let's do that here

  1. if ($_GET['filt']=="wp")
  2. {
  3. // Do some filtering
  4. }

So, we now have a bit of code that looks like

  1. if (isset($_GET['filt']))
  2. {
  3. if ($_GET['filt']=="wp")
  4. {
  5. // Do some filtering
  6. }
  7. }

Clear enough? Good, let's continue.

Next, we need to do the actual filtering. This is easy enough. First we'll search the jos_jomres_settings table to find propertys who use the wiseprice feature and put those property uids into an array. The entire lines would look like :

  1. $temp_array = array();
  2. $query = "SELECT property_uid FROM `#__jomres_settings` WHERE `akey` = 'wisepriceactive' AND `value`= 1";
  3. $uids = doSelectSql($query);
  4. foreach ($uids as $u)
  5. {
  6. $temp_array[] = $u->property_uid;
  7. }

Now we need to compare the results with what's in the original $propertys_uids variable. We'll loop through the temp array, and if the uid is in the $propertys_uids variable then we'll add that uid to a new variable $filtered.

  1. $filtered = array();
  2. foreach ($temp_array as $temp_uid)
  3. {
  4. if ( in_array($temp_uid,$propertys_uids) )
  5. $filtered[] = $temp_uid;
  6. }

Finally, we need to replace the contents of $propertys_uids with our filtered property uids, like so :

  1. $propertys_uids = $filtered;


So, what does this look like in it's entirety? Note that I've left a line above and below from the original section of script to show where it fits into the section of code.

  1. $propertys_uids=$componentArgs['propertys_uids'];
  2. if (isset($_GET['filt']))
  3. {
  4. if ($_GET['filt']=="wp")
  5. {
  6. // Do some filtering
  7. $temp_array = array();
  8. $query = "SELECT property_uid FROM `#__jomres_settings` WHERE `akey` = 'wisepriceactive' AND `value`= 1";
  9. $uids = doSelectSql($query);
  10. foreach ($uids as $u)
  11. {
  12. $temp_array[] = $u->property_uid;
  13. }
  14. $filtered = array();
  15. foreach ($temp_array as $temp_uid)
  16. {
  17. if ( in_array($temp_uid,$propertys_uids) )
  18. $filtered[] = $temp_uid;
  19. }
  20. $propertys_uids = $filtered;
  21. }
  22. }
  23. $sortid = intval(jomresGetParam( $_COOKIE, 'jomsearch_sortby', 1));
  24. switch ($sortid)

Now, in theory, we should be able to put http://www.domain.com/index.php?option=com_jomres&fil=wp into the address bar of the browser and see that only properties with the wiseprice option set to Yes are returned in the list.


Now, this might seem like a slightly complicated way of doing things, we could have put the filtering code elsewhere, however it allows us to use the original search functionality and this new code together. Let's say that we've got a search module that searches on property type, like so:

index.php?option=com_jomres&ptype=1&send=Search&calledByModule=mod_jomsearch_m1

ptype=1 is where it searches on a property type. On my system ptype 1 = "Hotel/Villa/Apartment"

Now, we can add the filt=wp option to that url to show only property Hotels, Villas or Apartments that use wiseprice :

index.php?option=com_jomres&ptype=1&filt=wp&send=Search&calledByModule=mod_jomsearch_m1

Personal tools