PHPackages                             tourze/diy-page-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. [Admin Panels](/categories/admin)
4. /
5. tourze/diy-page-bundle

ActiveSymfony-bundle[Admin Panels](/categories/admin)

tourze/diy-page-bundle
======================

DIY页面管理系统，提供广告位和页面装修功能

0.0.1(11mo ago)00MITPHPPHP ^8.1CI passing

Since Jun 3Pushed 4mo ago1 watchersCompare

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

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

DIY Page Bundle - Dynamic Page &amp; Advertisement Management
=============================================================

[](#diy-page-bundle---dynamic-page--advertisement-management)

[![PHP Version](https://camo.githubusercontent.com/f870cee2a2e2a442c6b62c8bf79f45ec0ce794dc5af13834902518c9107230f9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312532422d626c75652e737667)](https://www.php.net/)[![Symfony Version](https://camo.githubusercontent.com/2c82d2634c15cafc7bd4e441e2bbaf41b25037d65b0cb06b401ad5d5b1359193/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d362e342532422d677265656e2e737667)](https://symfony.com/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](#)[![Code Coverage](https://camo.githubusercontent.com/06e33fb4024f7f9c576cc80d22e78dbb33bd31fd8dbf978c6effb2adbf0f5087/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39352532352d627269676874677265656e2e737667)](#)

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

A comprehensive Symfony bundle for managing dynamic page content, advertisement blocks, and page decoration systems. Built on a Block-Element architecture with support for expression rule engine, time-based control, and visitor tracking.

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

[](#table-of-contents)

- [Quick Start](#quick-start)
- [Installation](#installation)
- [Core Concepts](#core-concepts)
- [Basic Usage](#basic-usage)
- [Configuration](#configuration)
- [Advanced Usage](#advanced-usage)
- [API Endpoints](#api-endpoints)
- [Admin Interface](#admin-interface)
- [Testing](#testing)
- [Architecture Overview](#architecture-overview)
- [Dependencies](#dependencies)
- [Contributing](#contributing)
- [License](#license)

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

[](#quick-start)

Get started with DIY Page Bundle in 3 minutes:

```
# 1. Install the bundle
composer require tourze/diy-page-bundle

# 2. Create database tables
php bin/console doctrine:migrations:migrate

# 3. Load sample data (optional)
php bin/console doctrine:fixtures:load
```

```
// 4. Create your first block in controller or command
use DiyPageBundle\Entity\Block;
use DiyPageBundle\Entity\Element;

$block = new Block();
$block->setCode('welcome_banner')
      ->setTitle('Welcome Banner')
      ->setValid(true);

$element = new Element();
$element->setTitle('Welcome to Our Site!')
        ->setThumb1('/images/welcome.jpg')
        ->setPath('/welcome')
        ->setValid(true)
        ->setBlock($block);

$entityManager->persist($block);
$entityManager->persist($element);
$entityManager->flush();
```

```
// 5. Display in your template
$blocks = $rpcClient->call('GetDiyPageElementByCode', ['codes' => ['welcome_banner']]);
```

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

[](#installation)

```
composer require tourze/diy-page-bundle
```

Core Concepts
-------------

[](#core-concepts)

### Block (Advertisement Position)

[](#block-advertisement-position)

Content containers within pages supporting:

- Unique identifier (code)
- Display rule expressions
- Time control (start/end time)
- Sorting and priority

### Element (Content Item)

[](#element-content-item)

Specific content items within blocks supporting:

- Images and titles
- Jump paths/URLs
- Custom attributes
- Display control
- Subtitle and description

### BlockAttribute (Block Attributes)

[](#blockattribute-block-attributes)

Key-value pairs for block configuration:

- Custom block properties
- Configuration parameters
- Display settings
- Extensible metadata

### VisitLog (Access Tracking)

[](#visitlog-access-tracking)

User behavior tracking for:

- Statistical analysis
- User behavior insights
- Data-driven decisions

Features
--------

[](#features)

- 🎨 **Dynamic Page Decoration**: Visual page decoration system based on Block-Element architecture
- 📱 **Advertisement Management**: Create and manage various types of advertisement blocks
- 🔧 **Rule Engine**: Expression-based rules to control content display logic
- ⏰ **Time Control**: Schedule content display with start and end time support
- 📊 **Visitor Analytics**: Automatic visitor behavior tracking with analytics support
- 🔄 **Event System**: Extension points for custom data formatting
- 💾 **Cache Support**: Built-in caching mechanism for performance optimization
- 🗑️ **Auto Cleanup**: Automatic cleanup of visit logs with configurable retention period

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

[](#basic-usage)

### Creating Advertisement Blocks

[](#creating-advertisement-blocks)

```
use DiyPageBundle\Entity\Block;
use DiyPageBundle\Entity\Element;

// Create a block
$block = new Block();
$block->setCode('homepage_banner')
      ->setTitle('Homepage Banner')
      ->setShowExpression('user.isVip or env.DEBUG')
      ->setStartTime(new \DateTime('2024-01-01'))
      ->setEndTime(new \DateTime('2024-12-31'));

// Add elements
$element = new Element();
$element->setTitle('New Year Sale')
        ->setImageUrl('/images/banner.jpg')
        ->setJumpPath('/promotion/newyear')
        ->setBlock($block);

$entityManager->persist($block);
$entityManager->persist($element);
$entityManager->flush();
```

### Retrieving Block Data

[](#retrieving-block-data)

```
// Using JSON-RPC interface
$response = $this->rpcClient->call('GetDiyPageElementByCode', [
    'codes' => ['homepage_banner', 'sidebar_ad']
]);

// Process returned data
foreach ($response as $code => $elements) {
    foreach ($elements as $element) {
        echo $element['title'];    // Element title
        echo $element['imageUrl']; // Image URL
        echo $element['jumpPath']; // Jump path
    }
}
```

### Expression Rule Examples

[](#expression-rule-examples)

```
// Based on user attributes
$block->setShowExpression('user.level >= 3');

// Based on environment variables
$block->setShowExpression('env.FEATURE_FLAG_ENABLED');

// Composite conditions
$block->setShowExpression('user.isVip and datetime.now >= "2024-01-01"');
```

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

[](#configuration)

### Visit Log Retention

[](#visit-log-retention)

```
# config/packages/diy_page.yaml
parameters:
    env(DIY_PAGE_VISIT_LOG_PERSIST_DAY_NUM): 7  # Default: 7 days
```

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

[](#advanced-usage)

### Event Listeners

[](#event-listeners)

```
use DiyPageBundle\Event\BlockDataFormatEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class BlockDataFormatSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            BlockDataFormatEvent::class => 'onBlockDataFormat',
        ];
    }

    public function onBlockDataFormat(BlockDataFormatEvent $event)
    {
        $data = $event->getData();
        $data['customField'] = 'customValue';
        $event->setData($data);
    }
}
```

### Expression Language Functions

[](#expression-language-functions)

The bundle provides custom expression functions:

- `visitLog(userId, blockCode)`: Get visit log for specific user and block
- Custom functions can be added via `VisitLogFunctionProvider`

API Endpoints
-------------

[](#api-endpoints)

### GetDiyPageElementByCode

[](#getdiypageelementbycode)

Batch retrieve element data by block codes:

```
$response = $rpcClient->call('GetDiyPageElementByCode', [
    'codes' => ['banner', 'sidebar'],
    'limit' => 10
]);
```

### GetOneDiyPageElement

[](#getonediypageelement)

Retrieve single element details:

```
$response = $rpcClient->call('GetOneDiyPageElement', [
    'id' => 123
]);
```

Admin Interface
---------------

[](#admin-interface)

The bundle integrates with EasyAdmin providing a complete administrative interface:

1. **Block Management**: Create, edit, and delete advertisement blocks
2. **Element Management**: Manage specific content within blocks
3. **Visit Analytics**: View access logs and statistical data

Access the admin interface at `/admin`.

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit packages/diy-page-bundle/tests
```

Architecture Overview
---------------------

[](#architecture-overview)

```
DiyPageBundle/
├── Entity/              # Domain models
│   ├── Block.php       # Advertisement block entity
│   ├── BlockAttribute.php # Block attribute entity
│   ├── Element.php     # Content element entity
│   └── VisitLog.php    # Visitor tracking entity
├── Repository/          # Data access layer
│   ├── BlockRepository.php
│   ├── ElementRepository.php
│   └── VisitLogRepository.php
├── Service/            # Business logic
│   └── AdminMenu.php   # Admin menu service
├── Event/              # Event classes
│   ├── BlockDataFormatEvent.php
│   └── ElementDataFormatEvent.php
├── Procedure/          # JSON-RPC procedures
│   ├── GetDiyPageElementByCode.php
│   └── GetOneDiyPageElement.php
├── ExpressionLanguage/ # Custom expression functions
│   └── Function/
│       └── VisitLogFunctionProvider.php
├── Controller/         # Web controllers
└── DataFixtures/       # Test data fixtures

```

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

[](#dependencies)

- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- Expression Language component
- JSON-RPC Core bundle
- Various Tourze bundles for enhanced functionality

Design References
-----------------

[](#design-references)

- [App Advertisement Design for Product Managers](http://www.woshipm.com/pd/2028587.html)
- [Business Cloud - Advertisement Management Solution](https://www.shangtaoyun.net/mnewsdetail-1006.html)

Roadmap
-------

[](#roadmap)

1. Location-based advertisement targeting
2. User level-based content differentiation
3. Time-based advertisement rotation
4. A/B testing support
5. Enhanced analytics features

Contributing
------------

[](#contributing)

Issues and Pull Requests are welcome.

License
-------

[](#license)

MIT License

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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

341d 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 (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-diy-page-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M650](/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.3k](/packages/contao-core-bundle)[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)

PHPackages © 2026

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