2017 © Pedro Peláez
 

yii2-extension yii2-poll

A poll widget for yii2

image

lslsoft/yii2-poll

A poll widget for yii2

  • Wednesday, January 25, 2017
  • by Lsl-soft
  • Repository
  • 0 Watchers
  • 4 Stars
  • 94 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 19 % Grown

The README.md

Yii2-poll widget

This is simple poll widget for yii2 framework. You can use both single and multiple answer., (*1)

(More information: lslsoft.com), (*2)

Installing

Yii2-poll can be installed using composer. Run following command to download and install yii2-poll:, (*3)

composer require lslsoft/yii2-poll

or add this in require section of composer.json of your project, (*4)

"lslsoft/yii2-poll" : "dev-master"

Migrations

Migrations are in the folder, (*5)

lslsoft/yii2-poll/migrations/create

Files which are responsible for creating tables and relations needed, (*6)

lslsoft/yii2-poll/migrations/create

Files which are responsible for inserting some sample data, (*7)

to apply migrations add in your config file, (*8)

'migrate-lslsoft-create' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations/create',
            'migrationTable' => 'migration_lslsoft_create',
        ],

to run use the command, (*9)

php yii migrate-lslsoft-create

for creating tables and relations needed, (*10)

and for inserting some sample data:, (*11)

'migrate-lslsoft-insert' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => 'vendor/lslsoft/yii2-poll/migrations/insert',
            'migrationTable' => 'migration_lslsoft_insert',
        ],

to run use the command, (*12)

php yii migrate-lslsoft-insert

Internalization

You should add in your config file, (*13)

'i18n' => [ 'translations' => [ 'sourceLanguage' => 'en-En',, (*14)

            'polls*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@yii/vendor/lslsoft/poll/messages',
            ],

        ],
    ],

Basic language for extension - english In the folder lslsoft/yii2-poll/migrations/messages you will find folder for russian and chinese, (*15)

Usage

use lslsoft\poll\Poll;

 = Poll::widget(); ?>

Without any parameter will choose a first poll for which, (*16)

date_beg < today < date_end;
 <?= Poll::widget([
                    'idPoll' => 1,

                ]                     
                    ); ?>

will use poll from table polls with id=1;, (*17)

On default results will be shown as simple bar chart, (*18)

 <?= Poll::widget([
                    'idPoll' => 1,
                    'resultView'=>'table'

                ]                     
                    ); ?>

will display results as a GridView;, (*19)

Tables

TABLE `polls` (
  `id` int(11) NOT NULL COMMENT '№ poll',
  `question` text NOT NULL COMMENT 'Question', //text of the poll's question 
  `date_beg` date NOT NULL COMMENT 'Date begin',//Date when poll should start
  `date_end` date NOT NULL COMMENT 'Date end', //Date when poll should end
  `allow_multiple` tinyint(4) NOT NULL COMMENT 'Multiple answer', //Define type of poll - with only one possible answer or not
  `is_random` tinyint(4) NOT NULL COMMENT 'Random order', //if true - display answers in random order
  `anonymous` tinyint(4) NOT NULL COMMENT 'Anonymous answers',//if true - user can vote without sign up
  `show_vote` int(11) NOT NULL COMMENT 'Show number of votes' //if true - the results will be shown after sending vote
) ENGINE=InnoDB DEFAULT CHARSET=;
CREATE TABLE `polls_answers` (
  `id` int(11) NOT NULL COMMENT '№ answer',
  `id_poll` int(11) DEFAULT NULL COMMENT '№ poll',
  `answer` text NOT NULL COMMENT 'answer'
) ENGINE=InnoDB;

CREATE TABLE `polls_result` (
  `num` int(11) NOT NULL DEFAULT '0' COMMENT 'Number of the voting',
  `id_poll` int(11) NOT NULL COMMENT '№ of poll',
  `id_answer` int(11) NOT NULL COMMENT '№ of answer',
  `id_user` int(11) NOT NULL,
  `id` int(11) NOT NULL,
  `create_at` datetime NOT NULL,
  `update_at` datetime NOT NULL,
  `ip` varchar(20) NOT NULL,
  `host` varchar(20) DEFAULT NULL
) ENGINE=InnoDB;

Author

  • Leonid Lyalin

License

This project is licensed under the BSD-3-Clause, (*20)

Acknowledgments

  • Thanks to all Yii framework team for inspiration and special thanks to Alexander Makarov (@samdark)
  • Thanks to @Insolita for magic yii2-migrik

The Versions

25/01 2017

dev-master

9999999-dev http://lslsoft.com

A poll widget for yii2

  Sources   Download

BSD-3-Clause

extension yii2 poll