如何计算drupal中特定用户的当前周发布节点

时间:2015-09-19 08:17:41

标签: drupal count nodes content-type

如何计算drupal中特定用户对特定内容类型的当前周发布节点?

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

// select the number of nodes that is of a specific content type and
// were created this week by the named user
function <theme>_post_count($user_name, $content_type) {
   $query = "SELECT COUNT(*) node_count FROM {node} n
             INNER JOIN {users} u ON u.name = :user_name && u.uid = n.uid
             WHERE n.type = :content_type && 
             WEEK(FROM_UNIXTIME(n.created)) = WEEK(CURRENT_TIMESTAMP())";

   $result = db_query($query, 
                      array(
                        ':user_name' => $user_name,
                        ':content_type' => $content_type
                      ))->fetch();

   return $result->node_count; 
}

您可以轻松修改上述查询,以取代uid而不是用户名等。

然后你会这样调用这个函数:

print 'Articles added by admin during this week: '.<theme>_post_count('admin', 'article');