hauntd/yii2-vote Votes, likes, favorites.

modulevotesfavoriteslikes

Yii2-Vote Latest Version License Scrutinizer Code Quality Code Climate

This module allows you to attach vote widgets, like/favorite buttons to your models.

Demo

  • Attach as many widgets to model as you need
  • Customization (action, events, views)
  • Useful widgets included (Favorite button, Like button, Rating "up/down")

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist hauntd/yii2-vote "0.3.*"

or add

"hauntd/yii2-vote": "*"

to the require section of your composer.json file.

Configuration

Add module settings to your application config (config/main.php).

Entity names should be in camelCase like itemVote, itemVoteGuests, itemLike and itemFavorite.

return [
  'modules' => [
    'vote' => [
      'class' => hauntd\vote\Module::class,
        'guestTimeLimit' => 3600,
        'entities' => [
          // Entity -> Settings
          'itemVote' => app\models\Item::class, // your model
          'itemVoteGuests' => [
              'modelName' => app\models\Item::class, // your model
              'allowGuests' => true,
              'allowSelfVote' => false,
              'entityAuthorAttribute' => 'user_id',
          ],
          'itemLike' => [
              'modelName' => app\models\Item::class, // your model
              'type' => hauntd\vote\Module::TYPE_TOGGLE, // like/favorite button
          ],
          'itemFavorite' => [
              'modelName' => app\models\Item::class, // your model
              'type' => hauntd\vote\Module::TYPE_TOGGLE, // like/favorite button
          ],
      ],
    ],
  ],
  'components' => [
    ...
  ]
];

After you downloaded and configured hauntd/yii2-vote, the last thing you need to do is updating your database schema by applying the migrations:

php yii migrate/up --migrationPath=@vendor/hauntd/yii2-vote/migrations/

Usage

Vote widget:

<?= \hauntd\vote\widgets\Vote::widget([
  'entity' => 'itemVote',
  'model' => $model,
  'options' => ['class' => 'vote vote-visible-buttons']
]); ?>

Like/Favorite widgets:

<?= \hauntd\vote\widgets\Favorite::widget([
    'entity' => 'itemFavorite',
    'model' => $model,
]); ?>

<?= \hauntd\vote\widgets\Like::widget([
    'entity' => 'itemLike',
    'model' => $model,
]); ?>

Change log

Please see CHANGELOG for more information what has changed recently.

Documentation

License

BSD 3-Clause License. Please see License File for more information.

Changelog

Changelog

[0.3.3] - 2018-10-08

  • fix Exception thrown when primary key attribute is not 'id' (dronz)

[0.3.2] - 2018-06-29

  • enh JS Events on/off optimization (loveorigami)

[0.3.1] - 2018-06-23

  • new Scope for select only favorite items (loveorigami)
  • fix Fixes (loveorigami)

[0.3] - 2017-11-01

  • enh Self-vote option (sokoji)
  • fix Migration fix (sokoji)

[0.2.5] - 2016-08-16

  • enh PHP 5.4 Support

[0.2.4] - 2016-08-09

  • enh Refactoring

[0.2.3] - 2016-07-11

  • enh Auto-detect vote behavior

[0.2.2] - 2016-07-10

  • enh Visual improvements, loading state
  • new Added view params to widgets
  • new Added vote action events (beforeAction, afterAction)
  • new Ability to exclude default styles (VoteAsset)

[0.2.1] - 2016-07-08

  • enh Visual improvements
  • enh Performance improvements

[0.2] - 2016-07-07

  • new Model and Query behaviors
  • new Favorite widget

[0.1.0] - 2016-07-02

  • new Initial release

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



0.3.3 is the latest of 13 releases



BSD-3-Clause license
Stats
39 github stars & 11 github forks
8 downloads in the last day
44 downloads in the last 30 days
2816 total downloads