atm/pollbundle

投票包

安装: 138

依赖项: 0

建议者: 0

安全: 0

类型:symfony-bundle

1.23 2020-09-07 09:29 UTC

This package is auto-updated.

Last update: 2024-09-07 19:11:49 UTC


README

通过composer安装

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

在您的AppKernel中

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

配置示例

# app/config/config.yml
  
atm_poll:
    media_folder: path to media folder

路由

追加到主路由文件

# app/config/routing.yml

atm_poll:
    resource: "@ATMPollBundle/Controller/PollController.php"
    type:     annotation
    prefix:   /members

服务

只有一个服务可以搜索投票并按投票排序检索投票中的项目。这些是函数

    public function search($options){
            $defaultOptions = array(
                'poll_id' => null,
                'user_id' => null,
                'item_id' => null,
                'creation_date' => null,
                'ids' => null,
                'sorting_field' => null,
                'date_limit' => array(
                    'min' => null,
                    'max' => null
                ),
                'limit' => null,
                'hydrate' => true,
                'page' => 1,
                'max_results' => null,
                'pagination' => null,
                'count' => null
            );
    }

如果count为true,则返回以下结构的数组

    array(
        'count' => $totalVotes
    );
     public function getItemsByVotes($pollId){}

显示投票

您可以通过在您的twig模板中使用以下调用在您的网站上显示投票

    {{ render(controller('ATMPollBundle:Poll:showPoll',{
        'pollId' :  pollId
    })) }}

您还可以使用以下路由在单独的页面上显示投票

    {{ path('atm_poll_show',{ 'pollId':pollId }) }}

返回视图的路径是

ATMPollBundle:Poll:show_poll.html.twig

传递给该视图的变量如下

- poll -> poll object
- items -> items in that poll sorted by number of votes
- totalPollVotes -> total amount of votes of this poll

还有一个额外功能,每次用户成功投票时都会显示纸屑,以下是使用它的步骤

- Include this script in your page:
    <script src="{{ asset('bundles/atmpoll/plugins/confetti/confetti.js') }}"></script>
- Create a <canvas id="canvas"></canvas> somewhere in you page with these styles:
    canvas {display: block;position: fixed;z-index: 1;pointer-events: none;top:0;left:0}
- Create these 2 buttons:
    <button id="confetti_start" style="display: none"></button>
    <button id="confetti_stop" style="display: none"></button>
- Show and hide the confetti with this code:
    $('#confetti_start').click();
    setTimeout(function(){
        $('#confetti_stop').click();
    }, 2000);