Skip to content
Snippets Groups Projects
Commit 66e2083d authored by Preexo's avatar Preexo
Browse files
parent 30d5d09a
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,32 @@
* *********************************************************************************** */
class Google_Map_Helper {
public function __construct() {
self::initializeSchema();
}
/**
* Creates table if not exists
*/
private static function initializeSchema() {
if (!Vtiger_Utils::CheckTable('vtiger_google_map')) {
// create table
Vtiger_Utils::CreateTable('vtiger_google_map', '(module varchar(255), parameter_name varchar(255), parameter_field varchar(255))', true);
// fill with defaults
$db = PearDatabase::getInstance();
$db->pquery("INSERT INTO `vtiger_google_map` (`module`, `parameter_name`, `parameter_field`) VALUES
('Contacts', 'street', 'mailingstreet'),
('Contacts', 'city', 'mailingcity'),
('Contacts', 'country', 'mailingcountry'),
('Leads', 'street', 'lane'),
('Leads', 'city', 'city'),
('Leads', 'country', 'country'),
('Accounts', 'street', 'bill_street'),
('Accounts', 'city', 'bill_city'),
('Accounts', 'country', 'bill_country');");
}
}
/**
* get the location for the record based on the module type
......@@ -37,18 +63,30 @@ class Google_Map_Helper {
* @return type
*/
static function getLocationFields($module) {
switch ($module) {
case 'Contacts': return array('street' => 'mailingstreet', 'city' => 'mailingcity', 'country' => 'mailingcountry');
self::initializeSchema();
$db = PearDatabase::getInstance();
$result = $db->pquery("SELECT * FROM vtiger_google_map WHERE module='$module'");
$number = $db->num_rows($result);
$retArray = array();
if ($number >= 1){
// fill return array with db values
for($i=0;$i<$number;$i++) {
$row = $db->fetch_row($result);
$retArray[$row['parameter_name']] = $row['parameter_field'];
}
} else {
// in case nothing came from db
switch ($module) {
case 'Contacts': $retArray = array('street' => 'mailingstreet', 'city' => 'mailingcity', 'country' => 'mailingcountry');
break;
case 'Leads' : $retArray = array('street' => 'lane', 'city' => 'city', 'country' => 'country');
break;
case 'Leads' : return array('street' => 'lane', 'city' => 'city', 'country' => 'country');
case 'Accounts' : $retArray = array('street' => 'bill_street', 'city' => 'bill_city', 'country' => 'bill_country');
break;
case 'Accounts' : return array('street' => 'bill_street', 'city' => 'bill_city', 'country' => 'bill_country');
break;
default : return array();
default : $retArray = array();
break;
}
}
return $retArray;
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment