2012-11-08 19 views
0

我做了一個drupal 7網站。drupal測量作者的出版efficiensy drupal 7

我正在尋找測量作者(博客作者,文章作者)效率的解決方案。 我希望看到一些情況,每個月有多少個用戶(作者)創建節點,以及這些節點包含多少個字母。

你能給我一個模組或其他東西嗎?

感謝, 陶

回答

0

這裏是我的解決方案:

<?php 
/** 
* Implements hook_menu(). 
*/ 
function authors_efficiency_menu() { 
    $items = array(); 
    $items['admin/config/authors_efficiency'] = array(
    'title' => 'Own Settings', 
    'description' => 'Parent item', 
    'position' => 'left', 
    'weight' => -100, 
    'page callback' => 'system_admin_menu_block_page', 
    'page arguments' => array(), 
    'access arguments' => array('access administration pages'), 
    'file' => 'system.admin.inc', 
    'file path' => drupal_get_path('module', 'system'), 
); 
    // Need at least one child item before your section will appear. 
    $items['admin/config/authors_efficiency/efficiency'] = array(
    'title' => 'Authors efficiency', 
    'description' => 'Authors efficiency', 
    'page callback' => 'authors_efficiency_page_callback', 
    'page arguments' => array(), 
    'access arguments' => array('access administration pages'), 
    'type' => MENU_NORMAL_ITEM, 
); 

    return $items; 
} 

function authors_efficiency_page_callback($para=array()){ 
    $output= ''; 


    // define number of results per page 
    $num_per_page = 50; 

    $header = array('User','Month','Count','Length sum','Avarage length'); 

    // define sql to fetch results 
    $query= db_select('node','n'); 
    $query->condition('n.status', '1'); 
    $query->condition('n.created', (time()-(120*24*60*60)), '>'); 
    $query->join('field_data_body', 'b', 'n.nid = b.entity_id'); 
    $query->join('users', 'u', 'n.uid = u.uid'); 
    $query->condition('b.entity_type', 'node'); 
    $query->addExpression('CONCAT(YEAR(FROM_UNIXTIME(n.created)),\'-\',LPAD(MONTH(FROM_UNIXTIME(n.created)), 2, \'0\'))', 'node_month'); 
    $query->addExpression('SUM(CHAR_LENGTH(b.body_value))', 'node_char_length'); 
    $query->addExpression('COUNT(*)', 'node_count'); 
    $query->fields('n', array('uid')); 
    $query->fields('u', array('name')); 
    $query->groupBy('CONCAT(n.uid, \'@\', node_month)'); 
    $query->orderBy('node_month', 'DESC'); 
    $query->orderBy('u.name', 'ASC'); 


    $count_query= db_select('node','n'); 
    $count_query->condition('n.status', '1'); 
    $count_query->condition('n.created', (time()-(120*24*60*60)), '>'); 
    $count_query->addExpression('COUNT(*)', 'node_count'); 
    $count_query->fields('n', array('uid')); 
    $count_query->groupBy('CONCAT(n.uid, \'@\', CONCAT(YEAR(FROM_UNIXTIME(n.created)),\'-\',LPAD(MONTH(FROM_UNIXTIME(n.created)), 2, \'0\')))'); 


    $count_query = $count_query->countQuery(); 
    $maxCount = $count_query->execute()->fetchField();; 

    $page = pager_default_initialize($maxCount, $num_per_page); 
    $offset = $num_per_page * $page; 

    $query->range($offset, $num_per_page); 
    $result= $query->execute()->fetchAll(); 

    $rows = array(); 
    foreach($result as $record){ 
     $row = array(
        $record->name, 
        $record->node_month, 
        $record->node_count, 
        $record->node_char_length, 
        round($record->node_char_length/$record->node_count), 
       ); 
     $rows[] = $row; 
    } 

    // Depending on the context there may be a better choice than this 
    $output.= theme('table', array('header' => $header, 'rows' => $rows)); 
    $output.= theme('pager'); 


    return($output); 
} 
?>