Git Product home page Git Product logo

yupe-vote's Introduction

yupe-vote

This module allows you to attach vote widgets, like/favorite buttons to your models (ported from hauntd/yii2-vote).

Demo

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

Dependency

  1. Yupe - CMS on Yii Framework 1.x (tested on yupe v1.1)

Installation

Step 1: Download and copy the vote folder to protected/modules/

Step 2: Configuring your application

  1. configure your module

1.1 Edit your module settings (template file: vote/install/vote.php), then copy it to protected/config/modules/

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

return [
  'modules' => [
    'vote' => [
      'class' => 'application.modules.vote.VoteModule',
        'guestTimeLimit' => 3600,
        'entities' => [
          // First Entity -> Settings
		  // Blog post Entity -> Settings
		  'postVote' => 'post', // your model
		  'postVoteGuests' => [
			  'modelName' => 'post', // your model
			  'allowGuests' => true,
		  ],
		  'postLike' => [
			  'modelName' => 'post', // your model
			  'type' => 'toggle', // TYPE_TOGGLE like/favorite button
		  ],
		  'postFavorite' => [
			  'modelName' => 'post', // your model
			  'type' => 'toggle', // like/favorite button
		  ],
		  // You can add other model Entity just like below
		  /*
          'itemVote' => 'product', // your model, such as 'product', 'post'
          'itemVoteGuests' => [
              'modelName' => 'product', // your model
              'allowGuests' => true,
          ],
          'itemLike' => [
              'modelName' => 'product', // your model
              'type' => 'toggle', // like/favorite button
          ],
          'itemFavorite' => [
              'modelName' => 'product', // your model
              'type' => 'toggle', // like/favorite button
          ], */
      ],
    ],
  ],
  'components' => [
    ...
  ]
];

1.2 Setup redis cache component for voteAttribute. If you already have redis cache component available, skip this step.

'components' => [
	//...
	'cache' => [
		'class'=>'CRedisCache',
		'hostname'=>'127.0.0.1',
		'port'=>6379,
		'password'=> 'foobared',	//changed to your password
		'database'=>6,	//changed to your db
		'options'=>STREAM_CLIENT_CONNECT,
	],
	//...
  1. Add behavior to you model

e.g. protected/modules/blog/models/Post.php

public function behaviors()
{
	$module = Yii::app()->getModule('blog');

	return [
		//...			
		'vote' => [
			'class' => 'application.modules.vote.components.behaviors.VoteBehavior',
			'entity' => 'postVote',	// must be the same as you set in the previous step 1
			'cacheID' => 'cache'	// redis cache component ID you setup in "/protected/config/main.php"
		],
	];
}
  1. Add vote widget to your views

e.g. Add all three widgets to view of blog/post/view (themes/default/views/blog/post/view.php)

<div class="row like_box">
	<div class="col-sm-12">
		<div class="pull-left">
			<?php $this->widget('application.modules.vote.widgets.LikeWidget', [
				'entity' => 'postLike',
				'model' => $post,
			]); ?>
		</div>
		<div class="col-sm-4 hidden-xs">
			<?php $this->widget('application.modules.vote.widgets.FavoriteWidget', [
				'entity' => 'postFavorite',
				'model' => $post,
			]); ?>
		</div>
		<div class="pull-right">					
			<?php $this->widget('application.modules.vote.widgets.VoteWidget', [
				'entity' => 'postVote',
				'model' => $post,
				'options' => ['class' => 'vote vote-visible-buttons'],
			]); ?>
		</div>
	</div>
</div>

Step 3: Updating database schema

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

  1. Method 1: through Control panel of "Yupe!"

After login into yupe backend, on index page - "Fast access to modules", click on the icon of Vote to "Apply new migrations".

or direct visit http://YourWebsiteUrl/backend/modupdate?name=vote

  1. method 2: through Command line:

yiic yupe updateMigrations --modules=vote

If prompted "There is no modules to update migrations."

yiic yupe flushCache

Usage

Vote widget:

<?php $this->widget('application.modules.vote.widgets.VoteWidget', [
	'entity' => 'itemVote',
	'model' => $model,
	'options' => ['class' => 'vote vote-visible-buttons'],
]); ?>

Like/Favorite widgets:

<?php $this->widget('application.modules.vote.widgets.FavoriteWidget', [
	'entity' => 'itemFavorite',
	'model' => $model,
]); ?>

<?php $this->widget('application.modules.vote.widgets.LikeWidget', [
	'entity' => 'itemLike',
	'model' => $model,
]); ?>

Change log

Please see CHANGELOG for more information what has changed recently.

Known issues

1. Click "no response" under the default browser of Android 4.1.2. Probably because it is not compatible with HTML5 Custom Data Attributes (data-*). After adjusting the code call order of the js code, the problem is solved.

License

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

yupe-vote's People

Contributors

vulcangz avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.