atm / competitionbundle
竞赛包
1.39
2021-05-10 14:11 UTC
Requires
- php: >=5.3.9
Requires (Dev)
- alcaeus/mongo-php-adapter: ^1.1
- doctrine/doctrine-bundle: ~1.4
- doctrine/mongodb-odm: ^1.3
- doctrine/mongodb-odm-bundle: ^3.6
- doctrine/orm: ^2.4.8
- friendsofsymfony/jsrouting-bundle: ^1.6
Suggests
- symfony/asset: For using the AssetExtension
- symfony/expression-language: For using the ExpressionExtension
- symfony/finder: For using the finder
- symfony/form: For using the FormExtension
- symfony/http-kernel: For using the HttpKernelExtension
- symfony/routing: For using the RoutingExtension
- symfony/security: For using the SecurityExtension
- symfony/stopwatch: For using the StopwatchExtension
- symfony/templating: For using the TwigEngine
- symfony/translation: For using the TranslationExtension
- symfony/var-dumper: For using the DumpExtension
- symfony/yaml: For using the YamlExtension
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_role: role for the contestants
froala_key: froala key
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: /
使用方法
创建一个新的竞赛后,您可以通过创建一个使用以下路径中的竞赛规范(twig文件)来自定义其着陆页。(假设竞赛名称为spring competition,其规范名称将为springcompetition):ATMCompetitionBundle\views\Frontend\competitioncanonical.html.twig
这些是在该视图中使用的变量
- competition: competition data as an array
- contestant_role: role 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的竞赛着陆页示例。