Hi
I'm trying to build a custom toolbar button that will get all selected items, build a link to open into google map (route planning).
In my view.html.php I have added:
// Map
JToolBarHelper::customX('orders.getMap', 'map', 'map', "Google Map");
So I have my button on the view.
In my orders controller.php file I have added:
public function getMap(){
// Get the input
$input = JFactory::getApplication()->input;
$pks = $input->post->get('cid', array(), 'array');
// Sanitize the input
JArrayHelper::toInteger($pks);
// Get the model
$model = $this->getModel();
$return = $model->getMap($pks);
}
Then in my order model I've added this:
public function getMap($pks)
{
// perform whatever you want on each item checked in the list
$idList = implode($pks,',');
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select(array('address', 'zip_code', 'city'));
$query->from('#__orders');
$query->where('id IN ('.$idList.')');
$query->order('zip_code ASC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects.
$results = $db->loadObjectList();
// create the addresslist
foreach ($results as $item) {
if ($item === end($results)) {
$to = "";
} else {
$to = "+to:";
}
$adrList .= $item->address . "," . $item->zip_code . "," . $item->city . $to;
}
$startAdr = "Denmark"; // replace with real start address
// some work needs to be done here, to send this link to a new window, and return to view
echo '<div style="text-align:center;"><a target="_blank" href="https://maps.google.com/maps?saddr='.$startAdr.'&daddr='.$adrList.'">Google Map Route</a></div>';
return true;
}
This returns the data of my selected items.
The link is created but not opened in a new window automatically.
I'm stuck on how to do this. Any help is appreciated.