Commit 1362d1fe authored by Marco Villegas's avatar Marco Villegas
Browse files

Issue #1998000: Ported tablesort_sql use to D7.

parent d5a99a78
Loading
Loading
Loading
Loading
+39 −10
Changes for versioncontrol_project.module: 39 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -321,9 +321,9 @@ function versioncontrol_project_views_api() {
 *
 * @param $nid
 *   Project node ID to get committers for.
 * @param $sort
 *   Optional ORDER BY clause to use for the list of committers. Defaults to
 *   sorting by the most recent commit.
 * @param $header_with_order
 *   The value used by TableSort::orderByHeader() in the query or NULL to use
 *   the default.
 * @param $only_maintainers
 *   Optional boolean to indicate if the list should only include users that
 *   currently have VCS write access to the project. Defaults to TRUE.
@@ -331,14 +331,43 @@ function versioncontrol_project_views_api() {
 * @return
 *   Array containing objects of committer information, keyed by uid.
 */
function versioncontrol_project_get_project_committers($nid, $order = '', $only_maintainers = TRUE) {
  if (empty($order)) {
    $order = ' ORDER BY last_commit DESC';
function versioncontrol_project_get_project_committers($nid, $header_with_order = NULL, $only_maintainers = TRUE) {
  if (is_null($header_with_order)) {
    $header_with_order = array(
      array(
        'data' => t('User'),
        'field' => 'u.name',
      ),
      array(
        'data' => t('Last commit'),
        'field' => 'last_commit',
        'sort' => 'desc',
      ),
      array(
        'data' => t('First commit'),
        'field' => 'first_commit',
      ),
      array(
        'data' => t('Commits'),
        'field' => 'commits',
      ),
    );
  }
  $repo = versioncontrol_project_repository_load($nid);
  $query = "SELECT o.author_uid as uid, MIN(o.author_date) AS first_commit, MAX(o.author_date) AS last_commit, COUNT(o.vc_op_id) AS commits, u.name FROM {versioncontrol_operations} o INNER JOIN {users} u ON o.author_uid = u.uid WHERE o.repo_id = :repo_id AND o.author_uid != 0 GROUP BY o.repo_id, o.author_uid $order";
  // TODO Please convert this statement to the D7 database API syntax.
  $result = db_query($query, array(':repo_id' => $repo->repo_id));
  $query = db_select('versioncontrol_operations', 'o')->extend('TableSort');
  $query->join('users', 'u', 'o.author_uid = u.uid');
  $query->addExpression('MIN(o.author_date)', 'first_commit');
  $query->addExpression('MAX(o.author_date)', 'last_commit');
  $query->addExpression('COUNT(o.vc_op_id)', 'commits');
  $query->addField('o', 'author_uid', 'uid');
  $result = $query
    ->fields('u', array('name'))
    ->condition('o.repo_id', $repo->repo_id)
    ->condition('o.author_uid', 0, '!=')
    ->groupBy('repo_id')
    ->groupBy('uid')
    ->orderByHeader($header_with_order)
    ->execute();
  $committers = array();
  foreach ($result as $committer) {
    $committers[$committer->uid] = $committer;
@@ -377,7 +406,7 @@ function versioncontrol_project_committers_page($project) {
  );
  // Use FALSE for the 3rd argument to get all committers, not just the users
  // that currently have commit access.
  $committers = versioncontrol_project_get_project_committers($project->nid, tablesort_sql($header), FALSE);
  $committers = versioncontrol_project_get_project_committers($project->nid, $header, FALSE);
  $rows = array();
  foreach ($committers as $committer) {
    $rows[] = array(