Non dovrebbe essere difficile creare un modulo personalizzato per questo.
La query che il modulo statistiche corre è:
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1));
// If we affected 0 rows, this is the first time viewing the node.
if (!db_affected_rows()) {
// We must create a new row to store counters for the new node.
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time());
}
L'unica cosa che dobbiamo fare, è quello di sostituire arg(1)
con l'ID del nodo vogliamo aggiungere un conteggio per questo potrebbe essere fatto in un costume modulo qualcosa come questo.
function custom_module_menu() {
$items['custom/ajax/%node'] = array(
'title' => 'Update count',
'page callback' => 'custom_module_update_counter',
'page arguments' => array(2),
'access callback' => array('custom_module_access_control'),
);
function custom_module_update_counter($node) {
db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $node->nid);
// If we affected 0 rows, this is the first time viewing the node.
if (!db_affected_rows()) {
// We must create a new row to store counters for the new node.
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $node->nid, time());
}
}
Tutto ciò che rimane è quello di implementare una funzione di controllo di accesso personalizzato, è possibile verificare se la richiesta è Ajax o fare qualunque cosa che ti piace di controllo, la funzione deve semplicemente restituire true o false. Devi anche creare un evento Ajax con l'id del nodo nelle tue impostazioni, ma non dovrebbe essere troppo difficile.
è necessario colpire l'url custom/ajax/2
per aggiornare il nodo con id 2 ecc
Grazie molto per la risposta dettagliata. Otterrà cracking sul modulo personalizzato. – wiifm
Il mio modulo è ora disponibile per il download su d.o http://drupal.org/project/statistics_ajax - nel caso in cui qualcun altro abbia bisogno di funzionalità simili – wiifm