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

How to count current week publish node by specific user in drupal

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

像这样的东西应该可以工作:

// 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');