Tuesday 14 February 2012

Making some changes on a Joomla MVC Component.

I thought I'd write a blog about some changes paid to get made to the Rentalotplus component last week. To be honest my requirements must have been lost in translation as the results weren't a working example of what I needed. However I do feel the code is of note.

The result of the changes do this . * make a row check of bookings in the database

* if there has been too many bookings then the 'Book Now' button will not show.


Here's the code changes.

OPEN models/classic.php

in the function &getData

ADD

$result = $this->totalBooking($unit_id);


UNDERNEATH


$this->stats_hit($unit_id);


AFTER THE CLOSING BRACKET OF THAT FUNCTION ADD

function totalBooking($unit_id)
{

$sql="SELECT COUNT(unit_id) AS totalRecord FROM m37hf_rentalot_plus_bookings WHERE unit_id='".$unit_id."'";
$this->_db->setQuery($sql);

$Result = $this->_db->loadObjectList();
//print_r($Result);
return $Result;


}
// --



the OPEN views/daily/view.html.php


FIND the line

$classic_model = $this->getModel('classic');


AFTER ADD


$itemstext = $classic_model->totalBooking($unit_id); //GHRIX


$totalBooking=$itemstext[0]->totalRecord;

$unit_model = $this->getModel('unit');

$unit_data = $unit_model->getOne($unit_id);

$max_people = $unit_data->max_people - 1;


if($totalBooking<$max_people) { $book_button = $menu_params->get('book_button', 'yes');

}
else
{
$
book_button = '';
}



#####


Basically in the Model view we load the data with the information about how many reservations have been made for this unit.

Then in the view we retrieve that information .

$classic_model has already been used to load the data from the model

* so we then use $itemstext to get the 'totalBooking' infromation from that data.

* its an array though so using $itemstext[0] gets the number we're after

* using the getModel('unit') we can access the unit information that we need for comparison.

* the comparrison is done and button displayed if we need it to be.


the only thing is that it doesn't really do anything as for it to be in anyway of use I'll need to put a date check on the mysql call and we'll need to change the check on the availability check on the following page.


No comments: