爲此製作定製模塊不應該很難。
的統計模塊運行的查詢是:
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());
}
我們需要做的唯一的事情,是我們要添加一個計數,這可能在定製完成節點ID替換arg(1)
模塊是這樣的。
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());
}
}
所有剩下的就是實現一個自定義訪問控制功能,您可以檢查是否請求是AJAX,或讓你喜歡的任何控制,該函數必須只返回TRUE或FALSE。您還需要在設置中使用節點標識創建一個ajax事件,但這也不應該太難。
您需要點擊的URL custom/ajax/2
更新ID爲2等
三江源很爲你詳細解答節點。將開始在自定義模塊。 – wiifm 2010-03-20 22:20:05
我的模塊現在可以在http://drupal.org/project/statistics_ajax的d.o上下載 - 以防其他人需要類似的功能 – wiifm 2010-06-12 04:35:09