Skip to content

Commit

Permalink
CONT-00: Issue contrib-tracker#12 by gkapoor121212: Added controller …
Browse files Browse the repository at this point in the history
…for displaying statistics.
  • Loading branch information
gkapoor121212 committed Dec 29, 2021
1 parent 70d870f commit e2cb41f
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 47 deletions.
1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module:
ct_drupal: 0
ct_github: 0
ct_manager: 0
ct_reports: 0
ct_user: 0
datetime: 0
datetime_range: 0
Expand Down
15 changes: 0 additions & 15 deletions web/modules/custom/contrib_tracker/contrib_tracker.module
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,3 @@ function contrib_tracker_mail_alter(&$message) {
$message['send'] = FALSE;
}
}

/**
* Implements hook_theme().
*/
function contrib_tracker_theme($existing) {
return [
'contrib_tracker_contribution_count' => [
'variables' => [
'totalContribution' => 0,
'contributionWithPatches' => 0,
'totalPatches' => 0,
],
],
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ services:
logger.channel.contrib_tracker:
parent: logger.channel_base
arguments: ['contrib_tracker']
contrib_tracker.statistics:
class: Drupal\contrib_tracker\ContributionStatistics
arguments: ['@entity_type.manager']
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Styles for the contrib-tracker module
*/
* Styles for the ct_reports module.
*/
.ct-height {
height: 60vh;
}
Expand Down
4 changes: 4 additions & 0 deletions web/modules/custom/ct_reports/ct_reports.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: Contribution Tracker Reports
type: module
description: Provides functionality to generate reports based on contribution data.
core_version_requirement: ^8.9 || ^9
21 changes: 21 additions & 0 deletions web/modules/custom/ct_reports/ct_reports.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @file
* Module for contribution tracker reports module.
*/

/**
* Implements hook_theme().
*/
function ct_reports_theme($existing) {
return [
'ct_reports_contribution_count' => [
'variables' => [
'totalContributions' => 0,
'codeContributions' => 0,
'totalContributors' => 0,
],
],
];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contrib_tracker.count:
ct_reports.count:
path: '/contribution-count'
defaults:
_controller: '\Drupal\contrib_tracker\Controller\ContributionCountController::content'
_controller: '\Drupal\ct_reports\Controller\ContributionCountController::content'
_title: 'Contribution Count'
requirements:
_permission: 'access content'
4 changes: 4 additions & 0 deletions web/modules/custom/ct_reports/ct_reports.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
ct_reports.statistics:
class: Drupal\ct_reports\ContributionStatistics
arguments: ['@entity_type.manager', '@database']
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

declare(strict_types=1);

namespace Drupal\contrib_tracker;
namespace Drupal\ct_reports;

use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;

/**
Expand All @@ -18,11 +19,19 @@ class ContributionStatistics {
*/
protected $nodeStorage;

/**
* Drupal\Core\Database\Driver\mysql\Connection definition.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;

/**
* Contribution storage constructor.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database) {
$this->nodeStorage = $entityTypeManager->getStorage('node');
$this->database = $database;
}

/**
Expand All @@ -39,7 +48,7 @@ public function totalContributions(): int {
/**
* Calcuate total contributions with patches.
*/
public function contributionWithPatches(): int {
public function codeContributions(): int {
$query = $this->nodeStorage->getQuery();
$nids = $query->condition('type', 'code_contribution')
->condition('field_code_contrib_patches_count', 0, '!=')
Expand All @@ -49,15 +58,14 @@ public function contributionWithPatches(): int {
}

/**
* Calcuate total number of patches.
* Calcuate total number of contributors.
*/
public function totalPatches(): int {
$query = $this->nodeStorage->getQuery();
$nids = $query->condition('type', 'code_contribution')
->condition('field_code_contrib_patches_count', 0, '!=')
->condition('status', '1')
->execute();
return count($nids);
public function totalContributors(): int {
$query = $this->database->select('node__field_contribution_author', 'ca');
$query->fields('ca', ['field_contribution_author_target_id']);
$result = $query->distinct()->execute()->fetchAll();

return count($result);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Drupal\contrib_tracker\Controller;
namespace Drupal\ct_reports\Controller;

use Drupal\contrib_tracker\ContributionStatistics;
use Drupal\ct_reports\ContributionStatistics;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -32,19 +32,20 @@ public function __construct(ContributionStatistics $contrib_stats) {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('contrib_tracker.statistics')
$container->get('ct_reports.statistics')
);
}

/**
* Returns a render-able array with contribution statistics.
*/
public function content() {

$build = [
'#theme' => 'contrib_tracker_contribution_count',
'#totalContribution' => $this->contribStats->totalContributions(),
'#contributionWithPatches' => $this->contribStats->contributionWithPatches(),
'#totalPatches' => $this->contribStats->totalPatches(),
'#theme' => 'ct_reports_contribution_count',
'#totalContributions' => $this->contribStats->totalContributions(),
'#codeContributions' => $this->contribStats->codeContributions(),
'#totalContributors' => $this->contribStats->totalContributors(),
];
return $build;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#}

{{ attach_library('contrib_tracker/ct-style') }}
{{ attach_library('ct_reports/ct-style') }}

<div{{ attributes.addClass(classes) }}>
{{ title_prefix }}
Expand All @@ -26,16 +26,16 @@
<div class="row ct-height">
<div class="col-md-12 ct-margin">
<div class="col-md-3 ct-results">
<p class="ct-label">Total contribution</p>
<p class="ct-count">{{ totalContribution }}</p>
<p class="ct-label">Total Contributions</p>
<p class="ct-count">{{ totalContributions }}</p>
</div>
<div class="col-md-3 ct-results">
<p class="ct-label">Contribution with patches</p>
<p class="ct-count">{{ contributionWithPatches }}</p>
<p class="ct-label">Code Contributions</p>
<p class="ct-count">{{ codeContributions }}</p>
</div>
<div class="col-md-3 ct-results">
<p class="ct-label">Total Patches</p>
<p class="ct-count">{{ totalPatches }}</p>
<p class="ct-label">Total Contributors</p>
<p class="ct-count">{{ totalContributors }}</p>
</div>
</div>
</div>
Expand Down

0 comments on commit e2cb41f

Please sign in to comment.