how to have Count below google map visualisation

lballard

New Member
Hello I have made a google map visualization and put on a article the below code :
{fabrik view=visualization id=1}
Il y a <?php
$db =JFactory::getDBO();
$query1='SELECT count(id) FROM `fd_annonces` WHERE `date_dep_jusquau`>=date(now()) AND `visibilite` = 1';
$db->setQuery($query1);
$count = $db->loadResult();
echo $count;
?> annonces disponibles sur

You can see the result on the joined image.

The googlemap visualization have the ajax refresh activated. I want to know how i can have the count refresh when the visualization is refresh.

I think I must use ajax but how ?

Thank you for your help

lballard
 

Attachments

  • count.png
    count.png
    240.6 KB · Views: 170
Yes, it is relativel difficult, as there are no accessible event fired off when we do the AJAX update of the map.

Do you know how to do an AJAX call in JS, and modify the DOM when you get the result back from the server?

If so, I can add an event to ur main viz code which will fire when the map has been updated through AJAX, and you can then fire off yur own AJAX call to get the new count to insert in to the DOM.

If not, we'll ned to add that event to our code, and write a Javascrito AJAX call and the PHP server side handler for you.

-- hugh
 
OK, as of this comit:

https://github.com/Fabrik/fabrik/commit/8fd7eb818c043907158e90c6a9ed4b67160254ee

... I've added firing the Fabrik event 'fabrik.viz.googlemap.ajax.refresh' when we have completed a succesful AJAX refresh of the map.

This means you can add a viz_X.js to ./components/com_fabrik/js (where X is the numeric ID of your viz), in which you do:

Code:
Fabrik.addEvent('fabrik.viz.googlemap.ajax.refresh', function(viz) {
// your code for AJAX call to the server and update DOM goes here
});

... which will then get fired off whenever the map updates.


Do you need help writing the user_ajax.php and the response handler? See the ./compoents/com_fabrik/user_ajax_example.php file for a fairly comprehensive example of how to write an AJAX handler in JS, and and the PHP method to hand back the response your need.

-- hugh
 
Hugh,

I need more help :

I've replaced googlemap.js and googlemap-min.js with the code of the link in the github.

I've created user_ajax.php with this code :

class UserAjax
{

public function countannonces()
{
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$retStr = '';
$query='SELECT count(id) FROM `ft_annonces` WHERE `date_dep_jusquau`>=date(now()) AND

`visibilite` = 1';
$db->setQuery($query);
$resultann = $db->loadResult();
$retStr="il y a $resultann disponibles sur Fd";

echo $retStr;


}


}

I've created viz_1.js in /components/com_fabrik/js that contains :

Fabrik.addEvent('fabrik.viz.googlemap.ajax.refresh', function(viz) {
var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=countannonces";
new Request({url:url,
method: 'get',
update: document.id('Annonces')
}).send()

}
);

The map is shown and there is no error in firebug but the text "il y a..." not.

Where is the error ?

Thank in advance.

Lballard
 
Hello I've modified viz_1.js in /components/com_fabrik/js like this with no more success :
Fabrik.addEvent('fabrik.viz.googlemap.ajax.refresh', function(viz) {
var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax;
new Ajax(url,{data{method:'countannonces'} }, onComplete:function(r){}
);} );
 
I'll need access to your site to help any further. Can you fill in your My Sites (link to the list of any of your posts).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top