diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index 430346f6..00cf227d 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -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 diff --git a/web/modules/custom/contrib_tracker/contrib_tracker.module b/web/modules/custom/contrib_tracker/contrib_tracker.module index 3f95b37d..c1babbe8 100644 --- a/web/modules/custom/contrib_tracker/contrib_tracker.module +++ b/web/modules/custom/contrib_tracker/contrib_tracker.module @@ -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, - ], - ], - ]; -} diff --git a/web/modules/custom/contrib_tracker/contrib_tracker.services.yml b/web/modules/custom/contrib_tracker/contrib_tracker.services.yml index 92229ea3..cfef9049 100644 --- a/web/modules/custom/contrib_tracker/contrib_tracker.services.yml +++ b/web/modules/custom/contrib_tracker/contrib_tracker.services.yml @@ -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'] diff --git a/web/modules/custom/contrib_tracker/css/ct-style.css b/web/modules/custom/ct_reports/css/ct-style.css similarity index 85% rename from web/modules/custom/contrib_tracker/css/ct-style.css rename to web/modules/custom/ct_reports/css/ct-style.css index 330b526c..513ea87f 100644 --- a/web/modules/custom/contrib_tracker/css/ct-style.css +++ b/web/modules/custom/ct_reports/css/ct-style.css @@ -1,6 +1,6 @@ /* -* Styles for the contrib-tracker module -*/ + * Styles for the ct_reports module. + */ .ct-height { height: 60vh; } diff --git a/web/modules/custom/ct_reports/ct_reports.info.yml b/web/modules/custom/ct_reports/ct_reports.info.yml new file mode 100644 index 00000000..17818f54 --- /dev/null +++ b/web/modules/custom/ct_reports/ct_reports.info.yml @@ -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 diff --git a/web/modules/custom/contrib_tracker/contrib_tracker.libraries.yml b/web/modules/custom/ct_reports/ct_reports.libraries.yml similarity index 100% rename from web/modules/custom/contrib_tracker/contrib_tracker.libraries.yml rename to web/modules/custom/ct_reports/ct_reports.libraries.yml diff --git a/web/modules/custom/ct_reports/ct_reports.module b/web/modules/custom/ct_reports/ct_reports.module new file mode 100644 index 00000000..6a31bdf1 --- /dev/null +++ b/web/modules/custom/ct_reports/ct_reports.module @@ -0,0 +1,21 @@ + [ + 'variables' => [ + 'totalContributions' => 0, + 'codeContributions' => 0, + 'totalContributors' => 0, + ], + ], + ]; +} diff --git a/web/modules/custom/contrib_tracker/contrib_tracker.routing.yml b/web/modules/custom/ct_reports/ct_reports.routing.yml similarity index 52% rename from web/modules/custom/contrib_tracker/contrib_tracker.routing.yml rename to web/modules/custom/ct_reports/ct_reports.routing.yml index a717f27f..84be60eb 100644 --- a/web/modules/custom/contrib_tracker/contrib_tracker.routing.yml +++ b/web/modules/custom/ct_reports/ct_reports.routing.yml @@ -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' diff --git a/web/modules/custom/ct_reports/ct_reports.services.yml b/web/modules/custom/ct_reports/ct_reports.services.yml new file mode 100644 index 00000000..1bcd0f48 --- /dev/null +++ b/web/modules/custom/ct_reports/ct_reports.services.yml @@ -0,0 +1,4 @@ +services: + ct_reports.statistics: + class: Drupal\ct_reports\ContributionStatistics + arguments: ['@entity_type.manager', '@database'] diff --git a/web/modules/custom/contrib_tracker/src/ContributionStatistics.php b/web/modules/custom/ct_reports/src/ContributionStatistics.php similarity index 62% rename from web/modules/custom/contrib_tracker/src/ContributionStatistics.php rename to web/modules/custom/ct_reports/src/ContributionStatistics.php index f1065952..04bd826f 100644 --- a/web/modules/custom/contrib_tracker/src/ContributionStatistics.php +++ b/web/modules/custom/ct_reports/src/ContributionStatistics.php @@ -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; /** @@ -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; } /** @@ -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, '!=') @@ -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); } } diff --git a/web/modules/custom/contrib_tracker/src/Controller/ContributionCountController.php b/web/modules/custom/ct_reports/src/Controller/ContributionCountController.php similarity index 68% rename from web/modules/custom/contrib_tracker/src/Controller/ContributionCountController.php rename to web/modules/custom/ct_reports/src/Controller/ContributionCountController.php index 8fd15dff..5eb862a3 100644 --- a/web/modules/custom/contrib_tracker/src/Controller/ContributionCountController.php +++ b/web/modules/custom/ct_reports/src/Controller/ContributionCountController.php @@ -1,8 +1,8 @@ get('contrib_tracker.statistics') + $container->get('ct_reports.statistics') ); } @@ -40,11 +40,12 @@ public static function create(ContainerInterface $container) { * 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; } diff --git a/web/modules/custom/contrib_tracker/templates/contrib-tracker-contribution-count.html.twig b/web/modules/custom/ct_reports/templates/ct-reports-contribution-count.html.twig similarity index 66% rename from web/modules/custom/contrib_tracker/templates/contrib-tracker-contribution-count.html.twig rename to web/modules/custom/ct_reports/templates/ct-reports-contribution-count.html.twig index 8ca873b7..21d27750 100644 --- a/web/modules/custom/contrib_tracker/templates/contrib-tracker-contribution-count.html.twig +++ b/web/modules/custom/ct_reports/templates/ct-reports-contribution-count.html.twig @@ -7,7 +7,7 @@ */ #} -{{ attach_library('contrib_tracker/ct-style') }} +{{ attach_library('ct_reports/ct-style') }} {{ title_prefix }} @@ -26,16 +26,16 @@
-

Total contribution

-

{{ totalContribution }}

+

Total Contributions

+

{{ totalContributions }}

-

Contribution with patches

-

{{ contributionWithPatches }}

+

Code Contributions

+

{{ codeContributions }}

-

Total Patches

-

{{ totalPatches }}

+

Total Contributors

+

{{ totalContributors }}