Javascript files can get pretty messy pretty quick if you prefer to keep everything contained in one javascript file.  Together with jQuery, I find that creating objects using the literal notation form works best.

Just like any language, it’s ideal to create objects that represent something or else you’re back to square one.  An example below will show several functions which will be broken down into page specific objects.

$(function(){

	homepageFunction();
	anotherFunction();
	setSomething();
	validateForm();
	makeSaveSubmit();

});

function homepageFunction(){
	// method code
}

function anotherFunction(){
	// method code
}

function setSomething(){
	// method code
}

function validateForm(){
	// method code
}

function makeSaveSubmit(){
	// method code
}

Now, assuming the first three functions are used on the homepage and the last two on a contact page, using literal notation to create the two objects, it would look something like..

$(function(){

	Homepage.homepageFunction();
	Homepage.anotherFunction();
	Homepage.setSomething();

	Contact.validateForm();
	Contact.makeSaveSubmit();

});

var Homepage = {

	homepageFunction: function(){
		//method code
	}, 

	anotherFunction: function(){
		//method code
	}, 

	setSomething: function(){
		//method code
	}
};

var Contact = {

	validateForm: function(){
		//method code
	}, 

	makeSaveSubmit: function(){
		//method code
	}

};

This can be further improved by moving each object specific initialize code into the object itself.

$(function(){

	Homepage.init();
	Contact.init();

});

var Homepage = {

	init: function(){
		this.homepageFunction();
		this.anotherFunction();
		this.setSomething();
	},

	homepageFunction: function(){
		//method code
	}, 

	anotherFunction: function(){
		//method code
	}, 

	setSomething: function(){
		//method code
	}
};

var Contact = {

	init: function(){
		this.validateForm();
		this.makeSaveSubmit();
	},

	validateForm: function(){
		//method code
	}, 

	makeSaveSubmit: function(){
		//method code
	}

};

If you need to pass parameters to a function when using literal notation objects, an object would look like..

var Telephone = {

	ringNumber: function(number){
		// do something with the number.
	}

};

And passing parameters into the object method would look like…

Telephone.ringNumber("077123222");

If you use an IDE such as Aptana, PDT or Zend, then there is a good chance the IDE will recognize these objects.

Tip: When creating the objects, be careful with your placing of commas after a function.  If you put a comma after a function and a function does not follow, in IE you will get errors.  Firefox and Chrome are forgiving.

This is wrong.

var Telephone = {

	ringNumber: function(number){

	},  // Notice this incorrectly placed comma.

};

A not so new feature of PHP which dates back to version 5.0 is PDO (PHP Data Objects).  PDO is a data-access abstraction layer that can access several database engines whilst maintaining the same set of functions.  I’m surprised I hadn’t discovered PDO earlier considering its been around way before I knew PHP.

As part of my project, my sponsor has asked me to look into the differences between mysql, mysqli (which will replace mysql at some point in the future) and PDO methods of interacting with a MySQL database.  The following table which I stumbled upon whilst researching explains it pretty well.

Source: http://www.php.net/manual/en/mysqli.overview.php

The original mysql extension listed in the third column has a development status of maintenance only.  My interpretation of this is that at some point, in a future release this extension will be dropped, meaning it’s time to move on and use something more up to date.

The mysqli (with the i meaning improved) extension looks to be the replacement for the original extension and the preferred for new projects.

The major difference between PDO and Mysqli is (of course) mysqli is limited to a MySQL databases.  PDO is an abstraction layer which can interact with a number of databases – the complete list of drivers are here.

Reading further into the two, another key difference between the two is that PDO allows prepared statements with named parameters.

So where the following would work with both PDO and mysqli

SELECT * FROM table WHERE id = ? AND display = ?

Only the following would work with PDO

SELECT * FROM table WHERE id = :id AND display = :display

Not a great difference, however the second option would in my eyes, be the preferred method of doing a prepared statement for the sake of readability.

Therefore, for my project, I will dump the old mysql extension and handle all database actions through the PDO layer.

It’s time to get back on the bandwagon.  My final year project is to create a website that combines property sales with social actions, something like a social website for property sales.  The idea is to remove the need for an estate agent.

Whats required?

Apart from a lot of programming time, some research, a few reports, the most important feature is a webservice that provides data for properties already on the market.

Initially the idea was to use Google Base as I’ve used this in the past, however Google sank that ship shortly after I drew up the project proposal.  I’m now left with providers which include Zoopla and Nestoria which could allow the ability to import from a third party website, a major feature of the system.

The Retired Google Base

I know, I need to let it go! From memory working with Google Base – the data provided was perfect.  You would have access to the same amount of data provided by the two above, however you have access to several images and more of a summary that could be useful. But by the time this project is finished, Google Base won’t be around.

Nestoria

I’ve looked into this service in the past, back then it the data was limited and outdated.  Looking at it today, it seems to be pulling a lot of data from Zoopla and Findaproperty.

The output of a property listing would look like the following:

{
            "auction_date" : null,
            "bathroom_number" : "3",
            "bedroom_number" : "4",
            "car_spaces" : null,
            "commission" : null,
            "construction_year" : null,
            "datasource_name" : "Zoopla!",
            "guid" : "g1-TNtcDN5QDO1MwN==",
            "img_height" : "120",
            "img_url" : "http://1.l.uk.nestoria.nestimg.com/1v9/f/1/1v9f1bc60ddaf7e6b9789f319305725226e77cc7d2.2.jpg",
            "img_width" : "160",
            "keywords" : "Leasehold, Mews, Porter",
            "latitude" : "51.51310",
            "lister_name" : "Winkworth",
            "lister_url" : "http://rd.nestoria.co.uk/rd?l=....",
            "listing_type" : "buy",
            "location_accuracy" : "9",
            "longitude" : "-0.13372",
            "price" : 2000000,
            "price_coldrent" : 0,
            "price_currency" : "GBP",
            "price_formatted" : "2,000,000 GBP",
            "price_high" : 2000000,
            "price_low" : 2000000,
            "price_type" : "fixed",
            "property_type" : "",
            "summary" : "Third floor flat in this very central Manhattan Lofts development in Dean...",
            "thumb_height" : "60",
            "thumb_url" : "http://3.l.uk.nestoria.nestimg.com/1v9/f/1/1v9f1bc60ddaf7e6b9789f319305725226e77cc7d2.1.jpg",
            "thumb_width" : "60",
            "title" : "Soho Lofts, Richmond Mews, Soho, W1",
            "updated_in_days" : 308.5,
            "updated_in_days_formatted" : "over a month ago"
         }

Looks perfect, has everything I could possibly need such as the latitude and longitude, price and a nice thumbnail/image.  But it’s not enough, there isn’t enough description/summary text and one image?

The purpose is to drag in the data set by estate agents as a base for the user to simply fine tune.  There needs to be more description/summary text. Sorry Nestoria, It’s not you.

Enter Zoopla

Reading the API documentation it seems the data provided by Nestoria is a mirror of that provided by Zoopla but with possibly more data fields provided by Nestoria for which I assume would be provided by other data set providers.

After obtaining an API key and looking at a few examples, there is sufficient data provided in terms of the description, bedrooms, bathrooms etc.  The only limit Zoopla has in place is the limit of images that are available.  However Zoopla seems to fit perfectly for what is required.