PHPackages                             tourze/user-tag-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/user-tag-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/user-tag-bundle
======================

用户标签系统，支持智能规则和SQL规则的标签分配与管理

0.0.1(6mo ago)012MITPHPCI passing

Since Nov 13Pushed 4mo ago1 watchersCompare

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

READMEChangelog (1)Dependencies (59)Versions (2)Used By (0)

User Tag Bundle
===============

[](#user-tag-bundle)

[![PHP Version](https://camo.githubusercontent.com/acffb6ae1962992d26e4466782832787e79504a6250f80d732c4283458b9f497/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c75652e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](https://github.com/tourze/tourze)[![Code Coverage](https://camo.githubusercontent.com/06e33fb4024f7f9c576cc80d22e78dbb33bd31fd8dbf978c6effb2adbf0f5087/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39352532352d627269676874677265656e2e737667)](https://github.com/tourze/tourze)

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

A comprehensive user tagging system for Symfony applications, supporting static tags, smart tags, and SQL-based tags with category management.

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

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Advanced Usage](#advanced-usage)
- [API Reference](#api-reference)
- [Requirements](#requirements)
- [License](#license)

Features
--------

[](#features)

- **Static Tags**: Manual assignment of tags to users
- **Smart Tags**: Automatic tag assignment based on JSON rules and cron expressions
- **SQL Tags**: Dynamic tag assignment using custom SQL queries
- **Category Management**: Hierarchical organization of tags
- **Assignment Tracking**: Complete audit trail of tag assignments
- **EasyAdmin Integration**: Ready-to-use admin interface
- **JSON-RPC API**: RESTful API for tag management

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

[](#installation)

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

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

[](#configuration)

The bundle works out of the box with minimal configuration. Services are auto-configured through `services.yaml`.

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

[](#quick-start)

### 1. Register the Bundle

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

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

### 2. Configure Database

[](#2-configure-database)

Run migrations to create the required tables:

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

### 3. Basic Usage

[](#3-basic-usage)

```
use UserTagBundle\Entity\Tag;
use UserTagBundle\Entity\Category;
use UserTagBundle\Enum\TagType;

// Create a category
$category = new Category();
$category->setName('Customer Status');
$entityManager->persist($category);

// Create a static tag
$tag = new Tag();
$tag->setName('VIP Customer')
    ->setType(TagType::StaticTag)
    ->setCategory($category)
    ->setDescription('High-value customers');
$entityManager->persist($tag);

// Create a smart tag with JSON rules
$smartTag = new Tag();
$smartTag->setName('Active User')
         ->setType(TagType::SmartTag)
         ->setCategory($category);

$smartRule = new SmartRule();
$smartRule->setTag($smartTag)
          ->setCronStatement('0 0 * * *') // Daily at midnight
          ->setJsonStatement([
              'conditions' => [
                  ['field' => 'last_login', 'operator' => '>=', 'value' => '7 days ago']
              ]
          ]);

$entityManager->persist($smartTag);
$entityManager->persist($smartRule);
$entityManager->flush();

// Create a SQL-based tag
$sqlTag = new Tag();
$sqlTag->setName('Recent Buyers')
       ->setType(TagType::SqlTag)
       ->setCategory($category);

$sqlRule = new SqlRule();
$sqlRule->setTag($sqlTag)
        ->setSqlStatement("
            SELECT user_id
            FROM orders
            WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
            GROUP BY user_id
            HAVING COUNT(*) >= 3
        ");

$entityManager->persist($sqlTag);
$entityManager->persist($sqlRule);
$entityManager->flush();
```

### 4. Using JSON-RPC API

[](#4-using-json-rpc-api)

```
// Get user tags
$procedure = new GetUserTagList();
$result = $procedure->execute();

// Assign tag to user
$assignProcedure = new AssignTagToBizUser();
$assignProcedure->setParameters([
    'tagId' => $tag->getId(),
    'bizUserId' => $userId
]);
$assignProcedure->execute();
```

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

[](#advanced-usage)

### Custom Tag Types

[](#custom-tag-types)

You can extend the system with custom tag types by implementing the `TagInterface`:

```
use UserTagBundle\Enum\TagType;

// Create a custom tag type
class CustomTagType extends TagType
{
    public const CustomType = 'custom';
}
```

### Event Listeners

[](#event-listeners)

The bundle dispatches events that you can listen to:

```
use UserTagBundle\Event\BeforeAddTagEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class TagEventSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            BeforeAddTagEvent::class => 'onBeforeAddTag',
        ];
    }

    public function onBeforeAddTag(BeforeAddTagEvent $event): void
    {
        // Custom logic before tag assignment
        $user = $event->getUser();
        $tag = $event->getTag();

        // Example: Validate business rules
        if (!$this->validateTagAssignment($user, $tag)) {
            throw new \InvalidArgumentException('Tag assignment not allowed');
        }
    }
}
```

### Smart Tag Rules

[](#smart-tag-rules)

Configure complex JSON rules for smart tags:

```
$smartRule->setJsonStatement([
    'conditions' => [
        [
            'field' => 'user.orders.count',
            'operator' => '>=',
            'value' => 10
        ],
        [
            'field' => 'user.totalSpent',
            'operator' => '>',
            'value' => 1000
        ]
    ],
    'logic' => 'AND' // or 'OR'
]);
```

### SQL Tag Examples

[](#sql-tag-examples)

Dynamic tags using SQL queries:

```
$sqlRule->setSqlStatement("
    SELECT user_id
    FROM orders
    WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
    GROUP BY user_id
    HAVING COUNT(*) >= 3
");
```

API Reference
-------------

[](#api-reference)

### JSON-RPC Procedures

[](#json-rpc-procedures)

#### Tag Management

[](#tag-management)

- `CreateSingleUserTag` - Create a new tag
- `UpdateSingleUserTag` - Update existing tag
- `DeleteSingleUserTag` - Delete a tag
- `GetUserTagList` - List all tags

#### Category Management

[](#category-management)

- `CreateSingleUserTagCategory` - Create a new category
- `UpdateSingleUserTagCategory` - Update existing category
- `DeleteSingleUserTagCategory` - Delete a category
- `GetUserTagCategories` - List all categories

#### Tag Assignment

[](#tag-assignment)

- `AssignTagToBizUser` - Assign tag to user
- `UnassignTagToBizUser` - Remove tag from user
- `GetAssignTagsByBizUserId` - Get user's assigned tags
- `AdminGetAssignLogsByTag` - Get assignment history

### Entities

[](#entities)

- `Tag` - Main tag entity with support for different types
- `Category` - Hierarchical category system
- `SmartRule` - JSON-based rules for smart tags
- `SqlRule` - SQL-based rules for dynamic tags
- `AssignLog` - Assignment tracking and audit trail

Requirements
------------

[](#requirements)

- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- Doctrine DBAL 3.0+

### Required Packages

[](#required-packages)

- `symfony/framework-bundle`
- `doctrine/orm`
- `doctrine/doctrine-bundle`
- `tourze/doctrine-timestamp-bundle`
- `tourze/doctrine-snowflake-bundle`
- `tourze/arrayable`

License
-------

[](#license)

This bundle is released under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance72

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

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

Unknown

Total

1

Last Release

180d ago

### 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-tag-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[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)[open-dxp/opendxp

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

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

PHPackages © 2026

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