vectorxhd / trophy-bundle
为 Symfony 提供的简单奖杯包
V1.0.0
2018-07-17 22:59 UTC
Requires
- php: >=5.5.9
- doctrine/data-fixtures: ^1.3
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
- sensio/framework-extra-bundle: ^5.0.0
- twig/twig: ^1.0||^2.0
This package is auto-updated.
Last update: 2024-09-29 04:20:25 UTC
README
此包是对 grafikart 教程的“增强”
安装
$ composer require vectorxhd/trophy-bundle
配置
<?php // app/AppKernel.php public function registerBundles() { $bundles = [ // ... new VectorXHD\TrophyBundle\VectorXHDTrophyBundle(), ]; }
# app/config/config.yml vectorxhd_trophy: user_class: AppBundle\Entity\User
还需要在您的 user_class
实体上实现 UserTrophyInterface
更新数据库
$ php bin/console doctrine:schema:update --force
添加徽章
以下是一个用于评论的徽章示例
$badge = new Badge(); $badge->setName("Premier badge"); $badge->setActionName('comment'); $badge->setActionCount(1);
使用示例
// Recuperer le manager /** @var TrophyManager $trophyManager */ $trophyManager = $this->get('vectorxhd_trophy.manager.trophy'); // Debloquage d'un trophée $trophyManager->checkAndUnlock($user, 'comment', $commentsUserCount);
checkAndUnlock
方法需要以下内容
- 用户实例 (
$this->getUser();
) - 动作名称
- 动作发生的次数
在这个例子中,$commentsUserCount
对应于用户发表的评论数量。
事件
有两个事件分发
TrophyUnlockedEvent::PRE_CREATE
TrophyUnlockedEvent::POST_CREATE
此事件具有多个 getter 方法
getBadgeUnlock
getBadge
getUser
待办事项
- 添加测试
将包添加到 Packagist- 在多个版本的 Symfony 上进行测试