├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── CHANGE.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── StarRating.php ├── StarRatingAsset.php └── StarRatingThemeAsset.php /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to yii2-widget-rating 2 | ================================== 3 | Looking to contribute something to yii2-widget-rating? **Here's how you can help.** 4 | 5 | Please take a moment to review this document in order to make the contribution 6 | process easy and effective for everyone involved. 7 | 8 | Following these guidelines helps to communicate that you respect the time of 9 | the developers managing and developing this open source project. In return, 10 | they should reciprocate that respect in addressing your issue or assessing 11 | patches and features. 12 | 13 | Using the issue tracker 14 | ----------------------- 15 | When [reporting bugs][reporting-bugs] or 16 | [requesting features][requesting-features], the 17 | [issue tracker on GitHub][issue-tracker] is the recommended channel to use. 18 | 19 | The issue tracker **is not** a place for support requests. Refer the 20 | [widget documentation and demos](http://demos.krajee.com/widget-details/rating) and/or refer to the 21 | [webtips Q & A forum](http://webtips.krajee.com/questions) which are the better places to get help. 22 | 23 | Reporting bugs with yii2-widget-rating 24 | -------------------------------------- 25 | We really appreciate clear bug reports that _consistently_ show an issue 26 | _within yii2-widget-rating_. 27 | 28 | The ideal bug report follows these guidelines: 29 | 30 | 1. **Use the [GitHub issue search][issue-search]** — Check if the issue 31 | has already been reported. 32 | 2. **Check if the issue has been fixed** — Try to reproduce the problem 33 | using the code in the `master` branch. 34 | 3. **Isolate the problem** — Try to create an 35 | [isolated js fiddle][isolated-case] that consistently reproduces the problem 36 | in case of javascript/client level code issues. 37 | 38 | Please try to be as detailed as possible in your bug report, especially if an 39 | isolated test case cannot be made. Some useful questions to include the answer 40 | to are: 41 | 42 | - What steps can be used to reproduce the issue? 43 | - What is the bug and what is the expected outcome? 44 | - What browser(s) and Operating System have you tested with? 45 | - Does the bug happen consistently across all tested browsers? 46 | - What version of jQuery are you using? And what version of yii2-widget-rating? 47 | - Are you using yii2-widget-rating with other plugins? 48 | 49 | All of these questions will help others fix and identify any potential bugs. 50 | 51 | Requesting features in yii2-widget-rating 52 | ----------------------------------------- 53 | Before starting work on a major feature for yii2-widget-rating, **read the 54 | [documentation](http://demos.krajee.com/widget-details/rating) first** or you may risk spending a considerable amount of 55 | time on something which the project developers are not interested in bringing into the project. 56 | 57 | ### Submitting a pull request 58 | 59 | We use GitHub's pull request system for submitting patches. Here are some 60 | guidelines to follow when creating the pull request for your fix. 61 | 62 | 1. Make sure to create a ticket for your pull request. This will serve as the 63 | bug ticket, and any discussion about the bug will take place there. Your pull 64 | request will be focused on the specific changes that fix the bug. 65 | 2. Make sure to reference the ticket you are fixing within your pull request. 66 | This will allow us to close off the ticket once we merge the pull request, or 67 | follow up on the ticket if there are any related blocking issues. 68 | 3. Explain why the specific change was made. Not everyone who is reviewing your 69 | pull request will be familiar with the problem it is fixing. 70 | 4. Run your tests first. If your tests aren't passing, the pull request won't 71 | be able to be merged. If you're breaking existing tests, make sure that you 72 | aren't causing any breaking changes. 73 | 5. Only include source changes. While it's not required, only including changes 74 | from the `src` directory will prevent merge conflicts from occuring. Making 75 | this happen can be as a simple as not committing changes from the `dist` 76 | directory. 77 | 78 | By following these steps, you will make it easier for your pull request to be 79 | reviewed and eventually merged. 80 | 81 | Triaging issues and pull requests 82 | --------------------------------- 83 | Anyone can help the project maintainers triage issues and review pull requests. 84 | 85 | ### Handling new issues 86 | 87 | yii2-widget-rating regularly receives new issues which need to be tested and organized. 88 | 89 | When a new issue that comes in that is similar to another existing issue, it 90 | should be checked to make sure it is not a duplicate. Duplicates issues should 91 | be marked by replying to the issue with "Duplicate of #[issue number]" where 92 | `[issue number]` is the url or issue number for the existing issue. This will 93 | allow the project maintainers to quickly close off additional issues and keep 94 | the discussion focused within a single issue. 95 | 96 | If you can test issues that are reported to yii2-widget-rating that contain test cases and 97 | confirm under what conditions bugs happen, that will allow others to identify 98 | what causes a bug quicker. 99 | 100 | ### Reviewing pull requests 101 | 102 | It is very common for pull requests to be opened for issues that contain a clear 103 | solution to the problem. These pull requests should be rigorously reviewed by 104 | the community before being accepted. If you are not sure about a piece of 105 | submitted code, or know of a better way to do something, do not hesitate to make 106 | a comment on the pull request. 107 | 108 | ### Reviving old tickets 109 | 110 | If you come across tickets which have not been updated for a while, you are 111 | encouraged to revive them. While this can be as simple as saying `:+1:`, it is 112 | best if you can include more information on the issue. Common bugs and feature 113 | requests are more likely to be fixed, whether it is by the community or the 114 | developers, so keeping tickets up to date is encouraged. 115 | 116 | Licensing 117 | --------- 118 | 119 | It should also be made clear that **all code contributed to yii2-widget-rating** must be 120 | licensable under the [BSD-3 license][licensing]. Code that cannot be released 121 | under this license **cannot be accepted** into the project. 122 | 123 | [isolated-case]: https://jsfiddle.net/ 124 | [issue-search]: https://github.com/kartik-v/yii2-widget-rating/search?q=&type=Issues 125 | [issue-tracker]: https://github.com/kartik-v/yii2-widget-rating/issues 126 | [licensing]: https://github.com/kartik-v/yii2-widget-rating/blob/master/LICENSE.md 127 | [reporting-bugs]: #reporting-bugs-with-yii2-widget-rating 128 | [requesting-features]: #requesting-features-in-yii2-widget-rating -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | 3 | - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate. 4 | - [ ] The issue still exists against the latest `master` branch of yii2-widget-rating. 5 | - [ ] This is not an usage question. I confirm having read the [widget documentation and demos](http://demos.krajee.com/widget-details/rating). 6 | - [ ] This is not a general programming / coding question. (Those should be directed to the [webtips Q & A forum](http://webtips.krajee.com/questions)). 7 | - [ ] This is not a source plugin (rating) issue. (Those should be directed to the [plugin issues repo](https://github.com/rating/rating/search?q=&type=Issues)). 8 | - [ ] I have attempted to find the simplest possible steps to reproduce the issue. 9 | - [ ] I have included a failing test as a pull request (Optional). 10 | 11 | ## Steps to reproduce the issue 12 | 13 | 1. 14 | 2. 15 | 3. 16 | 17 | ## Expected behavior and actual behavior 18 | 19 | When I follow those steps, I see... 20 | 21 | I was expecting... 22 | 23 | ## Environment 24 | 25 | Browsers 26 | 27 | - [ ] Google Chrome 28 | - [ ] Mozilla Firefox 29 | - [ ] Internet Explorer 30 | - [ ] Safari 31 | 32 | Operating System 33 | 34 | - [ ] Windows 35 | - [ ] Mac OS X 36 | - [ ] Linux 37 | - [ ] Mobile 38 | 39 | Libraries 40 | 41 | - jQuery version: 42 | - yii2-widget-rating version: 43 | 44 | ## Isolating the problem 45 | 46 | - [ ] This bug happens [on the widget demos page](http://demos.krajee.com/widget-details/rating) 47 | - [ ] The bug happens consistently across all tested browsers 48 | - [ ] This bug happens when using yii2-widget-rating without other plugins 49 | - [ ] I can reproduce this bug in [a jsbin](https://jsbin.com/) -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Scope 2 | This pull request includes a 3 | 4 | - [ ] Bug fix 5 | - [ ] New feature 6 | - [ ] Translation 7 | 8 | ## Changes 9 | The following changes were made 10 | 11 | - 12 | - 13 | - 14 | 15 | ## Related Issues 16 | If this is related to an existing ticket, include a link to it as well. -------------------------------------------------------------------------------- /CHANGE.md: -------------------------------------------------------------------------------- 1 | Change Log: `yii2-widget-rating` 2 | ================================ 3 | 4 | ## Version 1.0.5 5 | 6 | **Date:** 20-Nov-2021 7 | 8 | - (enh #16): Enhancements to support Bootstrap v5.x 9 | 10 | ## Version 1.0.4 11 | 12 | **Date:** 16-Sep-2018 13 | 14 | - Updates to support Bootstrap 4.x. 15 | - Reorganize relevant code in "src" directory. 16 | 17 | ## Version 1.0.3 18 | 19 | **Date:** 18-Nov-2017 20 | 21 | - Add github contribution and issue/PR log templates. 22 | - (enh #10): Correct language initialization. 23 | 24 | ## Version 1.0.2 25 | 26 | **Date:** 18-Feb-2016 27 | 28 | - Add branch alias for dev-master latest release. 29 | - Updates and enhancements for release v4.0.0 of the bootstrap-star-rating plugin 30 | - Added locale/language validation 31 | - Added asset validation for theme 32 | 33 | ## Version 1.0.1 34 | 35 | **Date:** 12-Jan-2016 36 | 37 | - enh #5: Enhancements for PJAX based reinitialization. Complements enhancements in kartik-v/yii2-krajee-base#52 and kartik-v/yii2-krajee-base#53. 38 | 39 | ## Version 1.0.0 40 | 41 | **Date:** 08-Nov-2014 42 | 43 | - Initial release 44 | - Sub repo split from [yii2-widgets](https://github.com/kartik-v/yii2-widgets) -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 - 2021, Kartik Visweswaran 2 | Krajee.com 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | * Neither the names of Kartik Visweswaran or Krajee nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Krajee Logo 4 | 5 |
6 | yii2-widget-rating 7 |
8 | Donate 10 |       11 | kartikv 12 |

13 | 14 |
15 | 16 | [![Stable Version](https://poser.pugx.org/kartik-v/yii2-widget-rating/v/stable)](https://packagist.org/packages/kartik-v/yii2-widget-rating) 17 | [![Unstable Version](https://poser.pugx.org/kartik-v/yii2-widget-rating/v/unstable)](https://packagist.org/packages/kartik-v/yii2-widget-rating) 18 | [![License](https://poser.pugx.org/kartik-v/yii2-widget-rating/license)](https://packagist.org/packages/kartik-v/yii2-widget-rating) 19 | [![Total Downloads](https://poser.pugx.org/kartik-v/yii2-widget-rating/downloads)](https://packagist.org/packages/kartik-v/yii2-widget-rating) 20 | [![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-widget-rating/d/monthly)](https://packagist.org/packages/kartik-v/yii2-widget-rating) 21 | [![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-widget-rating/d/daily)](https://packagist.org/packages/kartik-v/yii2-widget-rating) 22 | 23 |
24 | 25 | The StarRating widget is a wrapper for the [Bootstrap Star Rating Plugin](http://plugins.krajee.com/star-rating) JQuery Plugin designed by Krajee. This plugin is a simple yet powerful JQuery star rating plugin for Bootstrap. Developed with a focus on utlizing pure CSS-3 styling to render the control. 26 | 27 | > NOTE: This extension is a sub repo split of [yii2-widgets](https://github.com/kartik-v/yii2-widgets). The split has been done since 08-Nov-2014 to allow developers to install this specific widget in isolation if needed. One can also use the extension the previous way with the whole suite of [yii2-widgets](http://demos.krajee.com/widgets). 28 | 29 | ## Installation 30 | 31 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). Check the [composer.json](https://github.com/kartik-v/yii2-widget-rating/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json. 32 | 33 | To install, either run 34 | 35 | ``` 36 | $ php composer.phar require kartik-v/yii2-widget-rating "*" 37 | ``` 38 | 39 | or add 40 | 41 | ``` 42 | "kartik-v/yii2-widget-rating": "*" 43 | ``` 44 | 45 | to the ```require``` section of your `composer.json` file. 46 | 47 | ## Latest Release 48 | 49 | > NOTE: Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-widget-rating/blob/master/CHANGE.md) for details on changes to various releases. 50 | 51 | ## Demo 52 | 53 | You can refer detailed [documentation and demos](http://demos.krajee.com/widget-details/star-rating) on usage of the extension. 54 | 55 | ## Usage 56 | 57 | ```php 58 | use kartik\rating\StarRating; 59 | 60 | // Usage with ActiveForm and model 61 | echo $form->field($model, 'rating')->widget(StarRating::classname(), [ 62 | 'pluginOptions' => ['size'=>'lg'] 63 | ]); 64 | 65 | 66 | // With model & without ActiveForm 67 | echo StarRating::widget([ 68 | 'name' => 'rating_1', 69 | 'pluginOptions' => ['disabled'=>true, 'showClear'=>false] 70 | ]); 71 | ``` 72 | 73 | ## License 74 | 75 | **yii2-widget-rating** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kartik-v/yii2-widget-rating", 3 | "description": "A Yii2 widget for the simple yet powerful bootstrap-star-rating plugin with fractional rating support (sub repo split from yii2-widgets)", 4 | "keywords": ["yii2", "extension", "widget", "input", "form", "rating", "star", "bootstrap", "jquery", "plugin"], 5 | "homepage": "https://github.com/kartik-v/yii2-widget-rating", 6 | "type": "yii2-extension", 7 | "license": "BSD-3-Clause", 8 | "authors": [ 9 | { 10 | "name": "Kartik Visweswaran", 11 | "email": "kartikv2@gmail.com", 12 | "homepage": "http://www.krajee.com/" 13 | } 14 | ], 15 | "require": { 16 | "kartik-v/yii2-krajee-base": ">=1.9", 17 | "kartik-v/bootstrap-star-rating": "~4.0" 18 | }, 19 | "autoload": { 20 | "psr-4": { 21 | "kartik\\rating\\": "src" 22 | } 23 | }, 24 | "extra": { 25 | "branch-alias": { 26 | "dev-master": "1.0.x-dev" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/StarRating.php: -------------------------------------------------------------------------------- 1 | 25 | * @since 1.0 26 | */ 27 | class StarRating extends InputWidget 28 | { 29 | /** 30 | * @inheritdoc 31 | */ 32 | public $pluginName = 'rating'; 33 | 34 | /** 35 | * @var array the list of inbuilt themes 36 | */ 37 | private static $_themes = ['krajee-fa', 'krajee-fas', 'krajee-uni', 'krajee-svg']; 38 | 39 | /** 40 | * @inheritdoc 41 | */ 42 | public function run() 43 | { 44 | $this->initLanguage(); 45 | if (!isset($this->pluginOptions['theme'])) { 46 | $this->pluginOptions['theme'] = 'krajee-svg'; 47 | } 48 | $this->registerAssets(); 49 | if ($this->pluginLoading) { 50 | Html::addCssClass($this->options, 'rating-loading'); 51 | } 52 | echo $this->getInput('textInput'); 53 | } 54 | 55 | /** 56 | * Registers the needed assets 57 | */ 58 | public function registerAssets() 59 | { 60 | $view = $this->getView(); 61 | $theme = ArrayHelper::getValue($this->pluginOptions, 'theme'); 62 | if (!empty($theme) && in_array($theme, self::$_themes)) { 63 | StarRatingThemeAsset::register($view)->addTheme($theme); 64 | } 65 | StarRatingAsset::register($view)->addLanguage($this->language, '', 'js/locales'); 66 | $this->registerPlugin($this->pluginName); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/StarRatingAsset.php: -------------------------------------------------------------------------------- 1 | 18 | * @since 1.0 19 | */ 20 | class StarRatingAsset extends AssetBundle 21 | { 22 | /** 23 | * @inheritdoc 24 | */ 25 | public function init() 26 | { 27 | $this->setSourcePath('@vendor/kartik-v/bootstrap-star-rating'); 28 | $this->setupAssets('css', ['css/star-rating']); 29 | $this->setupAssets('js', ['js/star-rating']); 30 | parent::init(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/StarRatingThemeAsset.php: -------------------------------------------------------------------------------- 1 | 18 | * @since 1.0 19 | */ 20 | class StarRatingThemeAsset extends AssetBundle 21 | { 22 | /** 23 | * @inheritdoc 24 | */ 25 | public $sourcePath = '@vendor/kartik-v/bootstrap-star-rating'; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function init() 31 | { 32 | $this->depends = array_merge($this->depends, ['kartik\rating\StarRatingAsset']); 33 | parent::init(); 34 | } 35 | 36 | /** 37 | * Add star rating theme file 38 | * 39 | * @param string $theme the theme file name 40 | */ 41 | public function addTheme($theme) 42 | { 43 | $this->js[] = "themes/{$theme}/theme." . (YII_DEBUG ? "js" : "min.js"); 44 | $this->css[] = "themes/{$theme}/theme." . (YII_DEBUG ? "css" : "min.css"); 45 | } 46 | } --------------------------------------------------------------------------------