Free Android CakePHP GMaps Articles by Bali Web Design

August 31, 2009

How to print javascript object properties

Filed under: html,javascript — Tags: — admin @ 2:32 am

Sometime we need to print the structure data that return by a function. I was work on a task for google map and need to print object properties of Placemarks object on javascript. I need to analyze what kind of structure data return by geocoding function. The code below is a short function to print object properties in javascript

function isObject(obj) {
return obj.constructor == Object;
}

function print_object(object, level){
var tab = “”;
if(level > 0){
for(i = 0; i < level; i++) tab += “\t”;
}
var str = “”;
for(prop in object) {
if(!isObject(object[prop])) str += tab + prop + ” value :” + object[prop] + “\n”;
else str += tab + prop + “\n” + print_object(object[prop], level + 1);
}
return str;
}

and how to use this function is really simple approach

address = addresses.Placemark[0];
alert(print_object(address, 0));

in this scenario, i would like to print first placemark object return by geocoding function. Parameter level is use to make nice print view using tab character.

August 19, 2009

How to do GROUP BY HAVING in CakePHP

Filed under: cakephp,php — admin @ 11:23 pm

Before June 2008, there is no clean implementation for GROUP BY. commonly people code with CakePHP will put GROUP BY sintak on conditions, something like this

$this->Product->find(‘all’, array(‘conditions’ => ‘1=1 GROUP BY Product.category_id’));

Now CakePhp have a clean sintak for GROUP BY by new additional paramater on find function. We can use ‘group’ to define GROUP BY on cakephp. For example

$this->Product->find(‘all’, array(‘fields’ => array(‘Product.category_id’, ‘COUNT(Product.hotel_id) as total’), ‘group‘ => array(‘Product.category_id’)));

How if we want to have HAVING sintak on query? i ussually use this solution for new cakephp

$this->Product->find(‘all’, array(‘fields’ => array(‘Product.category_id’, ‘COUNT(Product.hotel_id) as total’), ‘group’ => array(‘Product.category_id HAVING COUNT(Product.hotel_id) > 1′)));

August 2, 2009

Passing data or parameter to another Activity Android

Filed under: android,java — admin @ 11:34 pm

Sometime we need to pass data or parameter to another Activity on Android. Only one activity is active at once. An activity open new activity for result and opened activity need parameter to set their interface or another option based on request. So it is important a system can handle sending and retrieve parameter between two Activity.

To open an activity and wait for a result, we can use this sintax

Intent newIntent = new Intent(this.getApplicationContext(), ActivityClass2.class);
startActivityForResult(newIntent, 0);

ActivityClass2 is the class name of activity that we need to create and then open it from current activity. startActivityForResult is a method to run newActivity. Later we can have the result by add this function on current Activity (more…)