PHPackages                             tourze/user-ranking-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tourze/user-ranking-bundle

ActiveSymfony-bundle

tourze/user-ranking-bundle
==========================

UserRankingBundle模块

1.0.1(6mo ago)00MITPHPCI failing

Since Jun 3Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/user-ranking-bundle)[ Packagist](https://packagist.org/packages/tourze/user-ranking-bundle)[ RSS](/packages/tourze-user-ranking-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (47)Versions (4)Used By (0)

UserRankingBundle
=================

[](#userrankingbundle)

[![PHP Version](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](#)[![Code Coverage](https://camo.githubusercontent.com/d3e0920f68f9837d175e5629f6da1445f58f601015f35ac9ff746c8ac7485ab4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39322532352d627269676874677265656e2e737667)](#)

[English](README.md) | [中文](README.zh-CN.md)

User ranking functionality module that provides flexible user ranking management features.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Quick Start](#quick-start)
- [Installation](#installation)
- [Configuration](#configuration)
- [Directory Structure](#directory-structure)
- [Data Structure](#data-structure)
- [Basic Usage](#basic-usage)
- [Command Reference](#command-reference)
- [License](#license)

Quick Start
-----------

[](#quick-start)

### 1. Install the Bundle

[](#1-install-the-bundle)

```
composer require tourze/user-ranking-bundle
```

### 2. Configure the Bundle

[](#2-configure-the-bundle)

```
// config/bundles.php
return [
    // ...
    UserRankingBundle\UserRankingBundle::class => ['all' => true],
];
```

### 3. Update Database Schema

[](#3-update-database-schema)

```
php bin/console doctrine:migrations:migrate
```

### 4. Create Your First Ranking List

[](#4-create-your-first-ranking-list)

```
use UserRankingBundle\Entity\UserRankingList;
use UserRankingBundle\Enum\RefreshFrequency;

$rankingList = new UserRankingList();
$rankingList
    ->setTitle('Player Score Ranking')
    ->setScoreSql('SELECT user_id, score FROM user_scores ORDER BY score DESC')
    ->setRefreshFrequency(RefreshFrequency::DAILY)
    ->setValid(true);

$entityManager->persist($rankingList);
$entityManager->flush();
```

### 5. Calculate Rankings

[](#5-calculate-rankings)

```
php bin/console user-ranking:calculate
```

Features
--------

[](#features)

- Support for multiple ranking list management
- Flexible ranking calculation rules (configured via SQL)
- Support for fixed and dynamic rankings
- Ranking position management and recommendations
- Complete CRUD operation interface
- Command-line tools for batch ranking calculations
- Configurable update frequency (from per minute to daily)

Installation
------------

[](#installation)

Add the bundle to your `composer.json`:

```
composer require tourze/user-ranking-bundle
```

Configuration
-------------

[](#configuration)

Add the bundle to your Symfony configuration:

```
# config/bundles.php
return [
    // ...
    UserRankingBundle\UserRankingBundle::class => ['all' => true],
];
```

Directory Structure
-------------------

[](#directory-structure)

```
packages/user-ranking-bundle/
├── src/
│   ├── Command/                # Console commands
│   ├── Controller/             # HTTP controllers
│   ├── DependencyInjection/    # Service configuration
│   ├── Entity/                 # Doctrine entities
│   ├── Enum/                   # Enumeration types
│   ├── Event/                  # Event classes
│   ├── Repository/             # Entity repositories
│   ├── Resources/              # Configuration files
│   └── UserRankingBundle.php   # Bundle class
├── tests/                      # Unit and integration tests
├── composer.json               # Package dependencies
└── README.md                   # Documentation

```

Data Structure
--------------

[](#data-structure)

### UserRankingList (Ranking List)

[](#userrankinglist-ranking-list)

- Title (`title`)
- Subtitle (`subtitle`)
- Color identifier (`color`)
- Logo (`logoUrl`)
- Calculation rule SQL (`scoreSql`)
- Total number of rankings (`count`)
- Associated positions (`positions`)
- Update frequency (`updateFrequency`): supports per minute, 5 minutes, 15 minutes, 30 minutes, hourly, daily

### UserRankingItem (Ranking Item)

[](#userrankingitem-ranking-item)

- Rank (`number`)
- User ID (`userId`)
- Ranking reason (`textReason`)
- Score (`score`)
- Fixed ranking flag (`fixed`)
- Recommender avatar (`recommendThumb`)
- Recommendation reason (`recommendReason`)

### UserRankingPosition (Ranking Position)

[](#userrankingposition-ranking-position)

- Position name (`title`)
- Associated rankings (`lists`)

Basic Usage
-----------

[](#basic-usage)

### Creating a Ranking List

[](#creating-a-ranking-list)

```
use UserRankingBundle\Entity\UserRankingList;

$rankingList = new UserRankingList();
$rankingList->setTitle('Daily Sales Ranking')
    ->setColor('#FF6B6B')
    ->setScoreSql('SELECT user_id, SUM(amount) as score FROM orders WHERE DATE(created_at) = CURDATE() GROUP BY user_id ORDER BY score DESC')
    ->setCount(100);

$entityManager->persist($rankingList);
$entityManager->flush();
```

### Calculating Rankings

[](#calculating-rankings)

```
# Calculate all rankings
php bin/console user-ranking:calculate

# Calculate specific ranking
php bin/console user-ranking:calculate LIST_ID

# Dry run (preview without saving)
php bin/console user-ranking:calculate LIST_ID 1
```

Advanced Usage
--------------

[](#advanced-usage)

### Setting up Fixed Rankings

[](#setting-up-fixed-rankings)

```
use UserRankingBundle\Entity\UserRankingItem;

$fixedItem = new UserRankingItem();
$fixedItem->setList($rankingList)
    ->setUserId('123')
    ->setNumber(1)
    ->setFixed(true)
    ->setTextReason('CEO - Fixed Position');

$entityManager->persist($fixedItem);
$entityManager->flush();
```

### Managing Blacklists

[](#managing-blacklists)

```
use UserRankingBundle\Entity\UserRankingBlacklist;

$blacklist = new UserRankingBlacklist();
$blacklist->setList($rankingList)
    ->setUserId('456')
    ->setReason('Violated ranking rules')
    ->setUnblockTime(new \DateTimeImmutable('+7 days'));

$entityManager->persist($blacklist);
$entityManager->flush();
```

Command Reference
-----------------

[](#command-reference)

### Calculate Rankings

[](#calculate-rankings)

Use the following command to calculate rankings for one or all ranking lists:

```
# Calculate all rankings
php bin/console user-ranking:calculate

# Calculate specific ranking list
php bin/console user-ranking:calculate LIST_ID

# Dry run mode (preview changes without saving)
php bin/console user-ranking:calculate LIST_ID 1
```

The calculation process includes:

1. Execute the configured calculation SQL to get user scores
2. Filter out blacklisted users
3. Handle fixed rankings (preserve manually set positions)
4. Assign dynamic rankings based on scores
5. Respect total ranking count limits

Auto-refresh Rankings
---------------------

[](#auto-refresh-rankings)

Use the following command to automatically refresh eligible rankings:

```
# Check all rankings and trigger calculation for those needing updates
php bin/console user-ranking:refresh-list
```

This command will:

1. Check all valid ranking lists
2. Determine if updates are needed based on update frequency
3. Send asynchronous calculation tasks for rankings needing updates
4. Use message queues to avoid blocking execution

Archive Ranking Data
--------------------

[](#archive-ranking-data)

Use the following command to archive current data for a specified ranking:

```
# Archive current ranking data for specified list
php bin/console user-ranking:archive LIST_ID

# Archive with retention days
php bin/console user-ranking:archive LIST_ID --keep-days=60
```

The archiving process will:

1. Copy all current ranking data to the archive table
2. Clean up old archive data before specified days
3. Support data retention by days (default 30 days)

Clean Blacklist
---------------

[](#clean-blacklist)

Use the following command to clean expired blacklist records:

```
# Clean expired ranking blacklist records
php bin/console user-ranking:blacklist-cleanup
```

The cleanup process will:

1. Find all expired but still valid blacklist records
2. Mark expired records as invalid
3. Allow blacklisted users to participate in rankings again

Scheduled Tasks
---------------

[](#scheduled-tasks)

The following commands are configured for automatic execution:

- `user-ranking:refresh-list` - Runs every minute to auto-refresh rankings needing updates
- `user-ranking:blacklist-cleanup` - Runs every 5 minutes to clean expired blacklist records

Security
--------

[](#security)

This bundle includes several security features:

### Input Validation

[](#input-validation)

- All entity properties include Symfony Validator constraints
- SQL injection protection through parameterized queries
- User input sanitization and validation

### Access Control

[](#access-control)

- Admin interface integration with AntdCpBundle
- Role-based access control for ranking management
- Secure API endpoints with proper authentication

### Data Protection

[](#data-protection)

- Audit trails for all ranking changes
- User activity tracking and logging
- Secure handling of sensitive ranking data

Dependencies
------------

[](#dependencies)

- Depends on `AntdCpBundle` for admin interface
- Uses Doctrine ORM for data persistence
- Requires Symfony 6.4+ and PHP 8.1+

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance76

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~80 days

Total

3

Last Release

180d ago

Major Versions

0.0.1 → 1.0.02025-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-user-ranking-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-user-ranking-bundle/health.svg)](https://phpackages.com/packages/tourze-user-ranking-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
