xlabs/competitionbundle

竞赛包

安装: 23

依赖: 0

建议者: 0

安全: 0

类型:laravel-library

1.0.3 2023-11-06 14:50 UTC

This package is auto-updated.

Last update: 2024-09-06 16:57:59 UTC


README

通过composer安装

php -d memory_limit=-1 composer.phar require atm/competitionbundle

在你的AppKernel中

public function registerbundles()
{
    return [
    	...
    	...
    	new ATM\CompetitionBundle\ATMCompetitionBundle(),
    ];
}

配置示例

# app/config/config.yml
  
atm_competition:
    user: User namespace
    media_folder: path to media folder
    contestant_roles: array of roles for the contestants
    main_picture_width: width for images
    main_picture_height: height for images
    watermark_image_small: 'watermark_small.png'
    watermark_image_medium: 'watermark_medium.png'
    watermark_image_big: 'watermark_big.png'
    email_from_name: Name for the from email address
    email_from_address: from email address
    email_subject: Subject for the email when a anonymous user vote
    site_domain: site domain
    messages:
        not_allowed: message when a contestant is not allowed to join a competition 
        vote_link_sent: message when a link sent to an anonymous user for voting
        already_voted: message shown when a user already voted
        email_not_validated: message when the email of an anonymous user is not validated
        voted_successfully: message shown when a user votes
    media_entity:
        namespace: media entity namespace
        order_by_field: field for sorting results
        order_by_direction: sorting direction

路由

追加到主路由文件

# app/config/routing.yml

atm_competition:
    resource: "@ATMCompetitionBundle/Controller/CompetitionController.php"
    type:     annotation
    prefix:   /

# The frontend routing should be not protected by the firewall
atm_competition_frontend:
    resource: "@ATMCompetitionBundle/Controller/FrontendController.php"
    type:     annotation
    prefix:   /

使用方法

创建一个新的竞赛后,你可以通过在该路径下创建一个使用竞赛规范(canonical)的twig文件来自定义其着陆页。(假设竞赛名称为spring competition,其规范为springcompetition):ATMCompetitionBundle\views\Frontend\competitioncanonical.html.twig

该视图使用以下变量

- competition: competition data as an array
- contestant_roles: roles from the configuration that the contestant have to had in order to join the competition
- page: needed in case to show a list of contestants.

要显示竞赛的参赛者,你可以使用以下函数

    {{ render(controller('ATMCompetitionBundle:Frontend:searchContestants',{
        'params' : {
            'page': page,
            'competition_id': competition.id,
            'order_by_field': 'name',
            'order_by_direction': 'DESC',
            'max_results' : 10
        }
    })) }} 

服务

有3个用于搜索的服务。

SearchCompetition

此服务接受以下参数以搜索竞赛

$defaultOptions = array(
    'name' => null,
    'date' => null,
    'ids' => null,
    'pagination' => null,
    'page' => 1,
    'order_by_field' => 'name',
    'order_by_direction' => 'DESC',
    'max_results' => null
);

它将返回一个包含2个键的数组

- results: results from the query
- pagination: pagination object in case that pagination is true

SearchContestants

此服务接受以下参数以搜索参赛者

$defaultOptions = array(
    'name' => null,
    'date' => null,
    'ids' => null,
    'competition' => null,
    'pagination' => null,
    'page' => 1,
    'order_by_field' => 'name',
    'order_by_direction' => 'DESC',
    'max_results' => null
);

它将返回一个包含2个键的数组

- results: results from the query
- pagination: pagination object in case that pagination is true

_如果你设置order_byfield = 'votes',你将按总票数排序的参赛者。

SearchVotes

此服务接受以下参数以搜索投票

$defaultOptions = array(
    'email' => null,
    'competition_id' => null,
    'contestant_id' => null,
    'creation_date' => null,
    'ids' => null,
    'sorting' => 'DESC',
    'sorting_field' => null,
    'date_limit' => array(
        'min' => null,
        'max' => null
    ),
    'limit' => null,
    'hydrate' => true,
    'page' => 1,
    'max_results' => null,
    'pagination' => null,
    'count' => null
);

它将返回一个包含2个键的数组

- results: results from the query
- pagination: pagination object in case that pagination is true

如果count为true,它将返回一个只包含1个键的数组

- count: total amount of votes of a contestant

Twig 扩展

以下是你可以在twig中使用的函数

    - ATMCompIsContestant($competitionId,$userId): checks if a user is a contestant of a competition.
    - ATMCompGetLastUserMedia($maxResults,$userId): gets the media based on the media namespace in the configuration.
    - ATMCompIsRegisterPeriod($competitionId): checks if it's the register period of a competition.
    - ATMCompIsCompetitionActive($competitionId): checks if a competition is active.
    - ATMCompContestantTotalVotes($contestantId): get contestant total votes.

匿名用户收到的邮件

如果投票的用户未登录系统,系统将发送一封带有投票链接的邮件。你可以通过在views/Mail中创建一个twig文件来自定义邮件模板,文件名为competitioncanonical_vote_link.html.twig。系统传递一个名为{{ vote_link }}的变量。

在views/Mail文件夹中有一个名为thegoodone_vote_link.html.twig的示例模板。

示例

在views/Frontend中,你可以看到一个名为thegoodone.html.twig的竞赛着陆页示例。